refactor: fix lucid warning

This commit is contained in:
Sonny
2024-10-07 02:24:27 +02:00
parent c8fb5af44d
commit 8b4e5740d7
3 changed files with 45 additions and 28 deletions

View File

@@ -5,7 +5,14 @@ export default class CreateUsersTable extends BaseSchema {
static tableName = 'users';
async up() {
this.schema.createTableIfNotExists(CreateUsersTable.tableName, (table) => {
const exists = await this.schema.hasTable(CreateUsersTable.tableName);
if (exists) {
return console.warn(
`Table ${CreateUsersTable.tableName} already exists.`
);
}
this.schema.createTable(CreateUsersTable.tableName, (table) => {
table.string('email', 254).notNullable().unique();
table.string('name', 254).notNullable();
table.string('nick_name', 254).nullable();

View File

@@ -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() {

View File

@@ -5,7 +5,13 @@ export default class CreateLinksTable extends BaseSchema {
static tableName = 'links';
async up() {
this.schema.createTableIfNotExists(CreateLinksTable.tableName, (table) => {
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();