From e1c47572a6235fd8fd20af888ac3a11c7ae1369d Mon Sep 17 00:00:00 2001 From: MCMXC <16797721+mcmxcdev@users.noreply.github.com> Date: Sat, 10 Feb 2024 18:37:40 -0700 Subject: updates --- 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, 118 insertions(+), 104 deletions(-) (limited to 'database') diff --git a/database/factories/ServiceFactory.ts b/database/factories/ServiceFactory.ts index 696a049..6e91c75 100644 --- a/database/factories/ServiceFactory.ts +++ b/database/factories/ServiceFactory.ts @@ -1,8 +1,8 @@ -import Service from '#app/Models/Service' -import Factory from '@adonisjs/lucid/factories' +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 0774dcd..9ca03f6 100644 --- a/database/factories/TokenFactory.ts +++ b/database/factories/TokenFactory.ts @@ -1,6 +1,6 @@ -import Token from '#app/Models/Token' -import Factory from '@adonisjs/lucid/factories' -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,6 +9,9 @@ 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 caa2ea9..2e60052 100644 --- a/database/factories/UserFactory.ts +++ b/database/factories/UserFactory.ts @@ -1,10 +1,13 @@ -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' +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(), @@ -15,4 +18,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 7d29829..dcaade8 100644 --- a/database/factories/WorkspaceFactory.ts +++ b/database/factories/WorkspaceFactory.ts @@ -1,7 +1,7 @@ -import Workspace from '#app/Models/Workspace' -import Factory from '@adonisjs/lucid/factories' +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 4a58213..190d47d 100644 --- a/database/migrations/1503250034279_user.ts +++ b/database/migrations/1503250034279_user.ts @@ -1,20 +1,20 @@ -import { BaseSchema } from '@adonisjs/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 3830c98..f7b572b 100644 --- a/database/migrations/1503250034280_token.ts +++ b/database/migrations/1503250034280_token.ts @@ -1,20 +1,20 @@ -import { BaseSchema } from '@adonisjs/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 3c46cab..cdaff73 100644 --- a/database/migrations/1566385379883_service_schema.ts +++ b/database/migrations/1566385379883_service_schema.ts @@ -1,21 +1,21 @@ -import { BaseSchema } from '@adonisjs/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 567c89f..4620be3 100644 --- a/database/migrations/1566554231482_recipe_schema.ts +++ b/database/migrations/1566554231482_recipe_schema.ts @@ -1,19 +1,19 @@ -import { BaseSchema } from '@adonisjs/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 b863200..32821b3 100644 --- a/database/migrations/1566554359294_workspace_schema.ts +++ b/database/migrations/1566554359294_workspace_schema.ts @@ -1,22 +1,22 @@ -import { BaseSchema } from '@adonisjs/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 76dc816..2ee4ee4 100644 --- a/database/migrations/1612629845398_users_update_schema.ts +++ b/database/migrations/1612629845398_users_update_schema.ts @@ -1,15 +1,15 @@ -import { BaseSchema } from '@adonisjs/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 1013861..a083c88 100644 --- a/database/migrations/1658076326250_correct_token_relations.ts +++ b/database/migrations/1658076326250_correct_token_relations.ts @@ -1,16 +1,18 @@ -import { BaseSchema } from '@adonisjs/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 7823283..23040e1 100644 --- a/database/migrations/1696110557648_jwt_tokens.ts +++ b/database/migrations/1696110557648_jwt_tokens.ts @@ -1,23 +1,29 @@ -import { BaseSchema } from '@adonisjs/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