mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-09 23:15:36 +00:00
refactor: fix lucid warning
This commit is contained in:
@@ -8,33 +8,37 @@ export default class CreateCollectionTable extends BaseSchema {
|
||||
|
||||
async up() {
|
||||
this.schema.raw(`DROP TYPE IF EXISTS ${this.visibilityEnumName}`);
|
||||
this.schema.createTableIfNotExists(
|
||||
CreateCollectionTable.tableName,
|
||||
(table) => {
|
||||
table.string('name', 254).notNullable();
|
||||
table.string('description', 254).nullable();
|
||||
table
|
||||
.enum('visibility', Object.values(Visibility), {
|
||||
useNative: true,
|
||||
enumName: this.visibilityEnumName,
|
||||
existingType: false,
|
||||
})
|
||||
.nullable()
|
||||
.defaultTo(Visibility.PRIVATE);
|
||||
table
|
||||
.integer('next_id')
|
||||
.references('id')
|
||||
.inTable('collections')
|
||||
.defaultTo(null);
|
||||
table
|
||||
.integer('author_id')
|
||||
.references('id')
|
||||
.inTable('users')
|
||||
.onDelete('CASCADE');
|
||||
const exists = await this.schema.hasTable(CreateCollectionTable.tableName);
|
||||
if (exists) {
|
||||
return console.warn(
|
||||
`Table ${CreateCollectionTable.tableName} already exists.`
|
||||
);
|
||||
}
|
||||
|
||||
defaultTableFields(table);
|
||||
}
|
||||
);
|
||||
this.schema.createTable(CreateCollectionTable.tableName, (table) => {
|
||||
table.string('name', 254).notNullable();
|
||||
table.string('description', 254).nullable();
|
||||
table
|
||||
.enum('visibility', Object.values(Visibility), {
|
||||
useNative: true,
|
||||
enumName: this.visibilityEnumName,
|
||||
existingType: false,
|
||||
})
|
||||
.nullable()
|
||||
.defaultTo(Visibility.PRIVATE);
|
||||
table
|
||||
.integer('next_id')
|
||||
.references('id')
|
||||
.inTable('collections')
|
||||
.defaultTo(null);
|
||||
table
|
||||
.integer('author_id')
|
||||
.references('id')
|
||||
.inTable('users')
|
||||
.onDelete('CASCADE');
|
||||
|
||||
defaultTableFields(table);
|
||||
});
|
||||
}
|
||||
|
||||
async down() {
|
||||
|
||||
Reference in New Issue
Block a user