mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-08 14:43:24 +00:00
fix: relations between tables
This commit is contained in:
@@ -5,7 +5,7 @@ export default class extends BaseSchema {
|
||||
|
||||
async up() {
|
||||
this.schema.createTable(this.tableName, (table) => {
|
||||
table.uuid('id').notNullable();
|
||||
table.uuid('id').unique().notNullable();
|
||||
|
||||
table.string('email', 254).notNullable().unique();
|
||||
table.string('name', 254).notNullable();
|
||||
|
||||
@@ -8,12 +8,20 @@ export default class extends BaseSchema {
|
||||
async up() {
|
||||
this.schema.raw(`DROP TYPE IF EXISTS ${this.visibilityEnumName}`);
|
||||
this.schema.createTable(this.tableName, (table) => {
|
||||
table.uuid('id').notNullable();
|
||||
table.uuid('id').unique().notNullable();
|
||||
|
||||
table.string('name', 254).notNullable();
|
||||
table.string('description', 254);
|
||||
table.uuid('next_id').defaultTo(null);
|
||||
table.uuid('author_id').notNullable();
|
||||
table
|
||||
.uuid('next_id')
|
||||
.references('id')
|
||||
.inTable('collections')
|
||||
.defaultTo(null);
|
||||
table
|
||||
.uuid('author_id')
|
||||
.references('id')
|
||||
.inTable('users')
|
||||
.onDelete('CASCADE');
|
||||
table.enum('visibility', Object.values(Visibility), {
|
||||
useNative: true,
|
||||
enumName: this.visibilityEnumName,
|
||||
|
||||
@@ -5,14 +5,22 @@ export default class extends BaseSchema {
|
||||
|
||||
async up() {
|
||||
this.schema.createTable(this.tableName, (table) => {
|
||||
table.uuid('id').notNullable();
|
||||
table.uuid('id').unique().notNullable();
|
||||
|
||||
table.string('name', 254).notNullable();
|
||||
table.string('description', 254);
|
||||
table.text('url').notNullable();
|
||||
table.boolean('favorite').notNullable().defaultTo(0);
|
||||
table.uuid('collection_id').notNullable();
|
||||
table.uuid('author_id').notNullable();
|
||||
table
|
||||
.uuid('collection_id')
|
||||
.references('id')
|
||||
.inTable('collections')
|
||||
.onDelete('CASCADE');
|
||||
table
|
||||
.uuid('author_id')
|
||||
.references('id')
|
||||
.inTable('users')
|
||||
.onDelete('CASCADE');
|
||||
|
||||
table.timestamp('created_at');
|
||||
table.timestamp('updated_at');
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { BaseSchema } from '@adonisjs/lucid/schema';
|
||||
|
||||
export default class extends BaseSchema {
|
||||
protected tableName = 'collection_link';
|
||||
|
||||
async up() {
|
||||
this.schema.createTable(this.tableName, (table) => {
|
||||
table
|
||||
.uuid('collection_id')
|
||||
.references('id')
|
||||
.inTable('collections')
|
||||
.onDelete('CASCADE');
|
||||
table
|
||||
.uuid('link_id')
|
||||
.references('id')
|
||||
.inTable('links')
|
||||
.onDelete('CASCADE');
|
||||
});
|
||||
}
|
||||
|
||||
async down() {
|
||||
this.schema.dropTable(this.tableName);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user