mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-08 14:43:24 +00:00
38 lines
989 B
TypeScript
38 lines
989 B
TypeScript
import { defaultTableFields } from '#database/default_table_fields';
|
|
import { BaseSchema } from '@adonisjs/lucid/schema';
|
|
|
|
export default class CreateLinksTable extends BaseSchema {
|
|
static tableName = 'links';
|
|
|
|
async up() {
|
|
const exists = await this.schema.hasTable(CreateLinksTable.tableName);
|
|
if (exists) {
|
|
return console.warn(`Table ${CreateLinksTable.tableName} already
|
|
exists.`);
|
|
}
|
|
|
|
this.schema.createTable(CreateLinksTable.tableName, (table) => {
|
|
table.string('name', 254).notNullable();
|
|
table.string('description', 254).nullable();
|
|
table.text('url').notNullable();
|
|
table.boolean('favorite').notNullable().defaultTo(0);
|
|
table
|
|
.integer('collection_id')
|
|
.references('id')
|
|
.inTable('collections')
|
|
.onDelete('CASCADE');
|
|
table
|
|
.integer('author_id')
|
|
.references('id')
|
|
.inTable('users')
|
|
.onDelete('CASCADE');
|
|
|
|
defaultTableFields(table);
|
|
});
|
|
}
|
|
|
|
async down() {
|
|
this.schema.dropTable(CreateLinksTable.tableName);
|
|
}
|
|
}
|