mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-08 22:53:25 +00:00
refactor: controllers and models to adapt them to the previous version of my-links
This commit is contained in:
@@ -1,27 +1,26 @@
|
||||
import { defaultTableFields } from '#database/default_table_fields';
|
||||
import { BaseSchema } from '@adonisjs/lucid/schema';
|
||||
|
||||
export default class extends BaseSchema {
|
||||
protected tableName = 'users';
|
||||
export default class CreateUsersTable extends BaseSchema {
|
||||
static tableName = 'users';
|
||||
|
||||
async up() {
|
||||
this.schema.createTable(this.tableName, (table) => {
|
||||
table.uuid('id').primary().unique().notNullable();
|
||||
|
||||
this.schema.createTableIfNotExists(CreateUsersTable.tableName, (table) => {
|
||||
table.string('email', 254).notNullable().unique();
|
||||
table.string('name', 254).notNullable();
|
||||
table.string('nick_name', 254).notNullable();
|
||||
table.string('nick_name', 254).nullable();
|
||||
table.text('avatar_url').notNullable();
|
||||
table.boolean('is_admin').defaultTo(0).notNullable();
|
||||
|
||||
table.json('token').notNullable();
|
||||
table.json('token').nullable();
|
||||
table.string('provider_id').notNullable();
|
||||
table.enum('provider_type', ['google']).notNullable().defaultTo('google');
|
||||
|
||||
table.timestamp('created_at').notNullable();
|
||||
table.timestamp('updated_at').nullable();
|
||||
defaultTableFields(table);
|
||||
});
|
||||
}
|
||||
|
||||
async down() {
|
||||
this.schema.dropTable(this.tableName);
|
||||
this.schema.dropTable(CreateUsersTable.tableName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +1,44 @@
|
||||
import { defaultTableFields } from '#database/default_table_fields';
|
||||
import { BaseSchema } from '@adonisjs/lucid/schema';
|
||||
import { Visibility } from '../../app/enums/visibility.js';
|
||||
|
||||
export default class extends BaseSchema {
|
||||
protected tableName = 'collections';
|
||||
export default class CreateCollectionTable extends BaseSchema {
|
||||
static tableName = 'collections';
|
||||
private visibilityEnumName = 'collection_visibility';
|
||||
|
||||
async up() {
|
||||
this.schema.raw(`DROP TYPE IF EXISTS ${this.visibilityEnumName}`);
|
||||
this.schema.createTable(this.tableName, (table) => {
|
||||
table.uuid('id').primary().unique().notNullable();
|
||||
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');
|
||||
|
||||
table.string('name', 254).notNullable();
|
||||
table.string('description', 254);
|
||||
table
|
||||
.uuid('next_id')
|
||||
.references('id')
|
||||
.inTable('collections')
|
||||
.defaultTo(null);
|
||||
table
|
||||
.uuid('author_id')
|
||||
.references('id')
|
||||
.inTable('users')
|
||||
.onDelete('CASCADE');
|
||||
table.enum('visibility', Object.values(Visibility), {
|
||||
useNative: true,
|
||||
enumName: this.visibilityEnumName,
|
||||
existingType: false,
|
||||
});
|
||||
|
||||
table.timestamp('created_at');
|
||||
table.timestamp('updated_at');
|
||||
});
|
||||
defaultTableFields(table);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async down() {
|
||||
this.schema.raw(`DROP TYPE IF EXISTS ${this.visibilityEnumName}`);
|
||||
this.schema.dropTable(this.tableName);
|
||||
this.schema.dropTable(CreateCollectionTable.tableName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,31 @@
|
||||
import { defaultTableFields } from '#database/default_table_fields';
|
||||
import { BaseSchema } from '@adonisjs/lucid/schema';
|
||||
|
||||
export default class extends BaseSchema {
|
||||
protected tableName = 'links';
|
||||
export default class CreateLinksTable extends BaseSchema {
|
||||
static tableName = 'links';
|
||||
|
||||
async up() {
|
||||
this.schema.createTable(this.tableName, (table) => {
|
||||
table.uuid('id').primary().unique().notNullable();
|
||||
|
||||
this.schema.createTableIfNotExists(CreateLinksTable.tableName, (table) => {
|
||||
table.string('name', 254).notNullable();
|
||||
table.string('description', 254);
|
||||
table.string('description', 254).nullable();
|
||||
table.text('url').notNullable();
|
||||
table.boolean('favorite').notNullable().defaultTo(0);
|
||||
table
|
||||
.uuid('collection_id')
|
||||
.integer('collection_id')
|
||||
.references('id')
|
||||
.inTable('collections')
|
||||
.onDelete('CASCADE');
|
||||
table
|
||||
.uuid('author_id')
|
||||
.integer('author_id')
|
||||
.references('id')
|
||||
.inTable('users')
|
||||
.onDelete('CASCADE');
|
||||
|
||||
table.timestamp('created_at');
|
||||
table.timestamp('updated_at');
|
||||
defaultTableFields(table);
|
||||
});
|
||||
}
|
||||
|
||||
async down() {
|
||||
this.schema.dropTable(this.tableName);
|
||||
this.schema.dropTable(CreateLinksTable.tableName);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user