From 0300c85c15088e3ff2756b344a0adbd3ca235fd3 Mon Sep 17 00:00:00 2001 From: MCMXC <16797721+mcmxcdev@users.noreply.github.com> Date: Sat, 10 Feb 2024 18:19:14 -0700 Subject: refactor: project maintenance - work in progress --- database/factories/ServiceFactory.ts | 6 ++-- database/factories/TokenFactory.ts | 15 ++++------ database/factories/UserFactory.ts | 17 +++++------ database/factories/WorkspaceFactory.ts | 6 ++-- database/migrations/1503250034279_user.ts | 22 +++++++------- database/migrations/1503250034280_token.ts | 22 +++++++------- .../migrations/1566385379883_service_schema.ts | 24 +++++++-------- database/migrations/1566554231482_recipe_schema.ts | 20 ++++++------- .../migrations/1566554359294_workspace_schema.ts | 26 ++++++++--------- .../1612629845398_users_update_schema.ts | 14 ++++----- .../1658076326250_correct_token_relations.ts | 16 +++++----- database/migrations/1696110557648_jwt_tokens.ts | 34 +++++++++------------- 12 files changed, 104 insertions(+), 118 deletions(-) (limited to 'database') diff --git a/database/factories/ServiceFactory.ts b/database/factories/ServiceFactory.ts index f675063..696a049 100644 --- a/database/factories/ServiceFactory.ts +++ b/database/factories/ServiceFactory.ts @@ -1,8 +1,8 @@ -import Service from 'App/Models/Service'; -import Factory from '@ioc:Adonis/Lucid/Factory'; +import Service from '#app/Models/Service' +import Factory from '@adonisjs/lucid/factories' export default Factory.define(Service, ({ faker }) => ({ name: faker.company.name(), recipeId: faker.string.alphanumeric(9), serviceId: faker.string.alphanumeric(10), -})).build(); +})).build() diff --git a/database/factories/TokenFactory.ts b/database/factories/TokenFactory.ts index 5afc679..0774dcd 100644 --- a/database/factories/TokenFactory.ts +++ b/database/factories/TokenFactory.ts @@ -1,6 +1,6 @@ -import Token from 'App/Models/Token'; -import Factory from '@ioc:Adonis/Lucid/Factory'; -import { DateTime } from 'luxon'; +import Token from '#app/Models/Token' +import Factory from '@adonisjs/lucid/factories' +import { DateTime } from 'luxon' export default Factory.define(Token, async ({ faker }) => ({ token: faker.string.alphanumeric(32), @@ -9,9 +9,6 @@ export default Factory.define(Token, async ({ faker }) => ({ created_at: DateTime.now(), updated_at: DateTime.now(), })) - .state( - 'old_token', - token => (token.updated_at = DateTime.now().minus({ hours: 25 })), - ) - .state('revoked', token => (token.is_revoked = true)) - .build(); + .state('old_token', (token) => (token.updated_at = DateTime.now().minus({ hours: 25 }))) + .state('revoked', (token) => (token.is_revoked = true)) + .build() diff --git a/database/factories/UserFactory.ts b/database/factories/UserFactory.ts index ee6553e..caa2ea9 100644 --- a/database/factories/UserFactory.ts +++ b/database/factories/UserFactory.ts @@ -1,13 +1,10 @@ -import User from 'App/Models/User'; -import Factory from '@ioc:Adonis/Lucid/Factory'; -import WorkspaceFactory from './WorkspaceFactory'; -import ServiceFactory from './ServiceFactory'; -import crypto from 'node:crypto'; +import User from '#app/Models/User' +import Factory from '@adonisjs/lucid/factories' +import WorkspaceFactory from './WorkspaceFactory.js' +import ServiceFactory from './ServiceFactory.js' +import crypto from 'node:crypto' -const hashedPassword = crypto - .createHash('sha256') - .update('password') - .digest('base64'); +const hashedPassword = crypto.createHash('sha256').update('password').digest('base64') export default Factory.define(User, async ({ faker }) => ({ email: faker.internet.email(), @@ -18,4 +15,4 @@ export default Factory.define(User, async ({ faker }) => ({ })) .relation('workspaces', () => WorkspaceFactory) .relation('services', () => ServiceFactory) - .build(); + .build() diff --git a/database/factories/WorkspaceFactory.ts b/database/factories/WorkspaceFactory.ts index 40cda6b..7d29829 100644 --- a/database/factories/WorkspaceFactory.ts +++ b/database/factories/WorkspaceFactory.ts @@ -1,7 +1,7 @@ -import Workspace from 'App/Models/Workspace'; -import Factory from '@ioc:Adonis/Lucid/Factory'; +import Workspace from '#app/Models/Workspace' +import Factory from '@adonisjs/lucid/factories' export default Factory.define(Workspace, ({ faker }) => ({ name: faker.internet.userName(), workspaceId: faker.string.alphanumeric(10), -})).build(); +})).build() diff --git a/database/migrations/1503250034279_user.ts b/database/migrations/1503250034279_user.ts index 262a472..4a58213 100644 --- a/database/migrations/1503250034279_user.ts +++ b/database/migrations/1503250034279_user.ts @@ -1,20 +1,20 @@ -import BaseSchema from '@ioc:Adonis/Lucid/Schema'; +import { BaseSchema } from '@adonisjs/lucid/schema' export default class extends BaseSchema { - protected tableName = 'users'; + protected tableName = 'users' public async up(): Promise { - this.schema.createTable(this.tableName, table => { - table.increments(); - table.string('username', 80).notNullable(); - table.string('email', 254).notNullable().unique(); - table.string('password', 60).notNullable(); - table.json('settings'); - table.timestamps(); - }); + this.schema.createTable(this.tableName, (table) => { + table.increments() + table.string('username', 80).notNullable() + table.string('email', 254).notNullable().unique() + table.string('password', 60).notNullable() + table.json('settings') + table.timestamps() + }) } public async down(): Promise { - this.schema.dropTable(this.tableName); + this.schema.dropTable(this.tableName) } } diff --git a/database/migrations/1503250034280_token.ts b/database/migrations/1503250034280_token.ts index 5a030d0..3830c98 100644 --- a/database/migrations/1503250034280_token.ts +++ b/database/migrations/1503250034280_token.ts @@ -1,20 +1,20 @@ -import BaseSchema from '@ioc:Adonis/Lucid/Schema'; +import { BaseSchema } from '@adonisjs/lucid/schema' export default class extends BaseSchema { - protected tableName = 'tokens'; + protected tableName = 'tokens' public async up(): Promise { - this.schema.createTable(this.tableName, table => { - table.increments(); - table.integer('user_id').unsigned().references('users.id'); - table.string('token', 255).notNullable().unique().index(); - table.string('type', 80).notNullable(); - table.boolean('is_revoked').defaultTo(false); - table.timestamps(); - }); + this.schema.createTable(this.tableName, (table) => { + table.increments() + table.integer('user_id').unsigned().references('users.id') + table.string('token', 255).notNullable().unique().index() + table.string('type', 80).notNullable() + table.boolean('is_revoked').defaultTo(false) + table.timestamps() + }) } public async down(): Promise { - this.schema.dropTable(this.tableName); + this.schema.dropTable(this.tableName) } } diff --git a/database/migrations/1566385379883_service_schema.ts b/database/migrations/1566385379883_service_schema.ts index 9c3e23d..3c46cab 100644 --- a/database/migrations/1566385379883_service_schema.ts +++ b/database/migrations/1566385379883_service_schema.ts @@ -1,21 +1,21 @@ -import BaseSchema from '@ioc:Adonis/Lucid/Schema'; +import { BaseSchema } from '@adonisjs/lucid/schema' export default class extends BaseSchema { - protected tableName = 'services'; + protected tableName = 'services' public async up(): Promise { - this.schema.createTable(this.tableName, table => { - table.increments(); - table.string('userId', 80).notNullable(); - table.string('serviceId', 80).notNullable(); - table.string('name', 80).notNullable(); - table.string('recipeId', 254).notNullable(); - table.json('settings'); - table.timestamps(); - }); + this.schema.createTable(this.tableName, (table) => { + table.increments() + table.string('userId', 80).notNullable() + table.string('serviceId', 80).notNullable() + table.string('name', 80).notNullable() + table.string('recipeId', 254).notNullable() + table.json('settings') + table.timestamps() + }) } public async down(): Promise { - this.schema.dropTable(this.tableName); + this.schema.dropTable(this.tableName) } } diff --git a/database/migrations/1566554231482_recipe_schema.ts b/database/migrations/1566554231482_recipe_schema.ts index 3a9784d..567c89f 100644 --- a/database/migrations/1566554231482_recipe_schema.ts +++ b/database/migrations/1566554231482_recipe_schema.ts @@ -1,19 +1,19 @@ -import BaseSchema from '@ioc:Adonis/Lucid/Schema'; +import { BaseSchema } from '@adonisjs/lucid/schema' export default class extends BaseSchema { - protected tableName = 'recipes'; + protected tableName = 'recipes' public async up(): Promise { - this.schema.createTable(this.tableName, table => { - table.increments(); - table.string('name', 80).notNullable(); - table.string('recipeId', 254).notNullable().unique(); - table.json('data'); - table.timestamps(); - }); + this.schema.createTable(this.tableName, (table) => { + table.increments() + table.string('name', 80).notNullable() + table.string('recipeId', 254).notNullable().unique() + table.json('data') + table.timestamps() + }) } public async down(): Promise { - this.schema.dropTable(this.tableName); + this.schema.dropTable(this.tableName) } } diff --git a/database/migrations/1566554359294_workspace_schema.ts b/database/migrations/1566554359294_workspace_schema.ts index 77e1189..b863200 100644 --- a/database/migrations/1566554359294_workspace_schema.ts +++ b/database/migrations/1566554359294_workspace_schema.ts @@ -1,22 +1,22 @@ -import BaseSchema from '@ioc:Adonis/Lucid/Schema'; +import { BaseSchema } from '@adonisjs/lucid/schema' export default class extends BaseSchema { - protected tableName = 'workspaces'; + protected tableName = 'workspaces' public async up(): Promise { - this.schema.createTable(this.tableName, table => { - table.increments(); - table.string('workspaceId', 80).notNullable().unique(); - table.string('userId', 80).notNullable(); - table.string('name', 80).notNullable(); - table.integer('order'); - table.json('services'); - table.json('data'); - table.timestamps(); - }); + this.schema.createTable(this.tableName, (table) => { + table.increments() + table.string('workspaceId', 80).notNullable().unique() + table.string('userId', 80).notNullable() + table.string('name', 80).notNullable() + table.integer('order') + table.json('services') + table.json('data') + table.timestamps() + }) } public async down(): Promise { - this.schema.dropTable(this.tableName); + this.schema.dropTable(this.tableName) } } diff --git a/database/migrations/1612629845398_users_update_schema.ts b/database/migrations/1612629845398_users_update_schema.ts index 8831ea4..76dc816 100644 --- a/database/migrations/1612629845398_users_update_schema.ts +++ b/database/migrations/1612629845398_users_update_schema.ts @@ -1,15 +1,15 @@ -import BaseSchema from '@ioc:Adonis/Lucid/Schema'; +import { BaseSchema } from '@adonisjs/lucid/schema' export default class extends BaseSchema { public async up(): Promise { - this.schema.alterTable('users', table => { - table.string('lastname', 80).notNullable().defaultTo(''); - }); + this.schema.alterTable('users', (table) => { + table.string('lastname', 80).notNullable().defaultTo('') + }) } public async down(): Promise { - this.schema.alterTable('users', table => { - table.dropColumn('lastname'); - }); + this.schema.alterTable('users', (table) => { + table.dropColumn('lastname') + }) } } diff --git a/database/migrations/1658076326250_correct_token_relations.ts b/database/migrations/1658076326250_correct_token_relations.ts index 5486657..1013861 100644 --- a/database/migrations/1658076326250_correct_token_relations.ts +++ b/database/migrations/1658076326250_correct_token_relations.ts @@ -1,18 +1,16 @@ -import BaseSchema from '@ioc:Adonis/Lucid/Schema'; +import { BaseSchema } from '@adonisjs/lucid/schema' export default class extends BaseSchema { - protected tableName = 'tokens'; + protected tableName = 'tokens' public async up(): Promise { - await this.db.rawQuery( - 'DELETE FROM tokens WHERE user_id NOT IN (SELECT id FROM users)', - ); + await this.db.rawQuery('DELETE FROM tokens WHERE user_id NOT IN (SELECT id FROM users)') - this.schema.alterTable(this.tableName, table => { - table.dropForeign('user_id'); + this.schema.alterTable(this.tableName, (table) => { + table.dropForeign('user_id') - table.foreign('user_id').references('users.id').onDelete('cascade'); - }); + table.foreign('user_id').references('users.id').onDelete('cascade') + }) } public async down(): Promise { diff --git a/database/migrations/1696110557648_jwt_tokens.ts b/database/migrations/1696110557648_jwt_tokens.ts index 9400de7..7823283 100644 --- a/database/migrations/1696110557648_jwt_tokens.ts +++ b/database/migrations/1696110557648_jwt_tokens.ts @@ -1,29 +1,23 @@ -import BaseSchema from '@ioc:Adonis/Lucid/Schema'; +import { BaseSchema } from '@adonisjs/lucid/schema' export default class JwtTokens extends BaseSchema { - protected tableName = 'jwt_tokens'; + protected tableName = 'jwt_tokens' public async up() { - this.schema.createTable(this.tableName, table => { - table.increments('id').primary(); - table - .integer('user_id') - .unsigned() - .references('users.id') - .onDelete('CASCADE'); - table.string('name').notNullable(); - table.string('type').notNullable(); - table.string('token', 64).notNullable().unique(); - table.timestamp('expires_at', { useTz: true }).nullable(); - table.string('refresh_token').notNullable().unique().index(); - table - .timestamp('refresh_token_expires_at', { useTz: true }) - .notNullable(); - table.timestamp('created_at', { useTz: true }).notNullable(); - }); + this.schema.createTable(this.tableName, (table) => { + table.increments('id').primary() + table.integer('user_id').unsigned().references('users.id').onDelete('CASCADE') + table.string('name').notNullable() + table.string('type').notNullable() + table.string('token', 64).notNullable().unique() + table.timestamp('expires_at', { useTz: true }).nullable() + table.string('refresh_token').notNullable().unique().index() + table.timestamp('refresh_token_expires_at', { useTz: true }).notNullable() + table.timestamp('created_at', { useTz: true }).notNullable() + }) } public async down() { - this.schema.dropTable(this.tableName); + this.schema.dropTable(this.tableName) } } -- cgit v1.2.3-70-g09d2