mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-08 22:53:25 +00:00
refactor: fix lucid warning
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user