mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-08 14:43:24 +00:00
refactor: fix lucid warning
This commit is contained in:
@@ -5,7 +5,14 @@ export default class CreateUsersTable extends BaseSchema {
|
|||||||
static tableName = 'users';
|
static tableName = 'users';
|
||||||
|
|
||||||
async up() {
|
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('email', 254).notNullable().unique();
|
||||||
table.string('name', 254).notNullable();
|
table.string('name', 254).notNullable();
|
||||||
table.string('nick_name', 254).nullable();
|
table.string('nick_name', 254).nullable();
|
||||||
|
|||||||
@@ -8,33 +8,37 @@ export default class CreateCollectionTable extends BaseSchema {
|
|||||||
|
|
||||||
async up() {
|
async up() {
|
||||||
this.schema.raw(`DROP TYPE IF EXISTS ${this.visibilityEnumName}`);
|
this.schema.raw(`DROP TYPE IF EXISTS ${this.visibilityEnumName}`);
|
||||||
this.schema.createTableIfNotExists(
|
const exists = await this.schema.hasTable(CreateCollectionTable.tableName);
|
||||||
CreateCollectionTable.tableName,
|
if (exists) {
|
||||||
(table) => {
|
return console.warn(
|
||||||
table.string('name', 254).notNullable();
|
`Table ${CreateCollectionTable.tableName} already exists.`
|
||||||
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);
|
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() {
|
async down() {
|
||||||
|
|||||||
@@ -5,7 +5,13 @@ export default class CreateLinksTable extends BaseSchema {
|
|||||||
static tableName = 'links';
|
static tableName = 'links';
|
||||||
|
|
||||||
async up() {
|
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('name', 254).notNullable();
|
||||||
table.string('description', 254).nullable();
|
table.string('description', 254).nullable();
|
||||||
table.text('url').notNullable();
|
table.text('url').notNullable();
|
||||||
|
|||||||
Reference in New Issue
Block a user