aboutsummaryrefslogtreecommitdiffstats
path: root/database
diff options
context:
space:
mode:
authorLibravatar MCMXC <16797721+mcmxcdev@users.noreply.github.com>2024-02-10 18:37:40 -0700
committerLibravatar Vijay A <vraravam@users.noreply.github.com>2024-02-13 06:59:44 +0530
commite1c47572a6235fd8fd20af888ac3a11c7ae1369d (patch)
tree2dccff36a441916d7014037cef3f7ce84a790cad /database
parentrefactor: project maintenance (diff)
downloadferdium-server-e1c47572a6235fd8fd20af888ac3a11c7ae1369d.tar.gz
ferdium-server-e1c47572a6235fd8fd20af888ac3a11c7ae1369d.tar.zst
ferdium-server-e1c47572a6235fd8fd20af888ac3a11c7ae1369d.zip
updates
Diffstat (limited to 'database')
-rw-r--r--database/factories/ServiceFactory.ts6
-rw-r--r--database/factories/TokenFactory.ts15
-rw-r--r--database/factories/UserFactory.ts17
-rw-r--r--database/factories/WorkspaceFactory.ts6
-rw-r--r--database/migrations/1503250034279_user.ts22
-rw-r--r--database/migrations/1503250034280_token.ts22
-rw-r--r--database/migrations/1566385379883_service_schema.ts24
-rw-r--r--database/migrations/1566554231482_recipe_schema.ts20
-rw-r--r--database/migrations/1566554359294_workspace_schema.ts26
-rw-r--r--database/migrations/1612629845398_users_update_schema.ts14
-rw-r--r--database/migrations/1658076326250_correct_token_relations.ts16
-rw-r--r--database/migrations/1696110557648_jwt_tokens.ts34
12 files changed, 118 insertions, 104 deletions
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 @@
1import Service from '#app/Models/Service' 1import Service from '#app/Models/Service';
2import Factory from '@adonisjs/lucid/factories' 2import Factory from '@adonisjs/lucid/factories';
3 3
4export default Factory.define(Service, ({ faker }) => ({ 4export default Factory.define(Service, ({ faker }) => ({
5 name: faker.company.name(), 5 name: faker.company.name(),
6 recipeId: faker.string.alphanumeric(9), 6 recipeId: faker.string.alphanumeric(9),
7 serviceId: faker.string.alphanumeric(10), 7 serviceId: faker.string.alphanumeric(10),
8})).build() 8})).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 @@
1import Token from '#app/Models/Token' 1import Token from '#app/Models/Token';
2import Factory from '@adonisjs/lucid/factories' 2import Factory from '@adonisjs/lucid/factories';
3import { DateTime } from 'luxon' 3import { DateTime } from 'luxon';
4 4
5export default Factory.define(Token, async ({ faker }) => ({ 5export default Factory.define(Token, async ({ faker }) => ({
6 token: faker.string.alphanumeric(32), 6 token: faker.string.alphanumeric(32),
@@ -9,6 +9,9 @@ export default Factory.define(Token, async ({ faker }) => ({
9 created_at: DateTime.now(), 9 created_at: DateTime.now(),
10 updated_at: DateTime.now(), 10 updated_at: DateTime.now(),
11})) 11}))
12 .state('old_token', (token) => (token.updated_at = DateTime.now().minus({ hours: 25 }))) 12 .state(
13 .state('revoked', (token) => (token.is_revoked = true)) 13 'old_token',
14 .build() 14 token => (token.updated_at = DateTime.now().minus({ hours: 25 })),
15 )
16 .state('revoked', token => (token.is_revoked = true))
17 .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 @@
1import User from '#app/Models/User' 1import User from '#app/Models/User';
2import Factory from '@adonisjs/lucid/factories' 2import Factory from '@adonisjs/lucid/factories';
3import WorkspaceFactory from './WorkspaceFactory.js' 3import WorkspaceFactory from './WorkspaceFactory.js';
4import ServiceFactory from './ServiceFactory.js' 4import ServiceFactory from './ServiceFactory.js';
5import crypto from 'node:crypto' 5import crypto from 'node:crypto';
6 6
7const hashedPassword = crypto.createHash('sha256').update('password').digest('base64') 7const hashedPassword = crypto
8 .createHash('sha256')
9 .update('password')
10 .digest('base64');
8 11
9export default Factory.define(User, async ({ faker }) => ({ 12export default Factory.define(User, async ({ faker }) => ({
10 email: faker.internet.email(), 13 email: faker.internet.email(),
@@ -15,4 +18,4 @@ export default Factory.define(User, async ({ faker }) => ({
15})) 18}))
16 .relation('workspaces', () => WorkspaceFactory) 19 .relation('workspaces', () => WorkspaceFactory)
17 .relation('services', () => ServiceFactory) 20 .relation('services', () => ServiceFactory)
18 .build() 21 .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 @@
1import Workspace from '#app/Models/Workspace' 1import Workspace from '#app/Models/Workspace';
2import Factory from '@adonisjs/lucid/factories' 2import Factory from '@adonisjs/lucid/factories';
3 3
4export default Factory.define(Workspace, ({ faker }) => ({ 4export default Factory.define(Workspace, ({ faker }) => ({
5 name: faker.internet.userName(), 5 name: faker.internet.userName(),
6 workspaceId: faker.string.alphanumeric(10), 6 workspaceId: faker.string.alphanumeric(10),
7})).build() 7})).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 @@
1import { BaseSchema } from '@adonisjs/lucid/schema' 1import { BaseSchema } from '@adonisjs/lucid/schema';
2 2
3export default class extends BaseSchema { 3export default class extends BaseSchema {
4 protected tableName = 'users' 4 protected tableName = 'users';
5 5
6 public async up(): Promise<void> { 6 public async up(): Promise<void> {
7 this.schema.createTable(this.tableName, (table) => { 7 this.schema.createTable(this.tableName, table => {
8 table.increments() 8 table.increments();
9 table.string('username', 80).notNullable() 9 table.string('username', 80).notNullable();
10 table.string('email', 254).notNullable().unique() 10 table.string('email', 254).notNullable().unique();
11 table.string('password', 60).notNullable() 11 table.string('password', 60).notNullable();
12 table.json('settings') 12 table.json('settings');
13 table.timestamps() 13 table.timestamps();
14 }) 14 });
15 } 15 }
16 16
17 public async down(): Promise<void> { 17 public async down(): Promise<void> {
18 this.schema.dropTable(this.tableName) 18 this.schema.dropTable(this.tableName);
19 } 19 }
20} 20}
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 @@
1import { BaseSchema } from '@adonisjs/lucid/schema' 1import { BaseSchema } from '@adonisjs/lucid/schema';
2 2
3export default class extends BaseSchema { 3export default class extends BaseSchema {
4 protected tableName = 'tokens' 4 protected tableName = 'tokens';
5 5
6 public async up(): Promise<void> { 6 public async up(): Promise<void> {
7 this.schema.createTable(this.tableName, (table) => { 7 this.schema.createTable(this.tableName, table => {
8 table.increments() 8 table.increments();
9 table.integer('user_id').unsigned().references('users.id') 9 table.integer('user_id').unsigned().references('users.id');
10 table.string('token', 255).notNullable().unique().index() 10 table.string('token', 255).notNullable().unique().index();
11 table.string('type', 80).notNullable() 11 table.string('type', 80).notNullable();
12 table.boolean('is_revoked').defaultTo(false) 12 table.boolean('is_revoked').defaultTo(false);
13 table.timestamps() 13 table.timestamps();
14 }) 14 });
15 } 15 }
16 16
17 public async down(): Promise<void> { 17 public async down(): Promise<void> {
18 this.schema.dropTable(this.tableName) 18 this.schema.dropTable(this.tableName);
19 } 19 }
20} 20}
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 @@
1import { BaseSchema } from '@adonisjs/lucid/schema' 1import { BaseSchema } from '@adonisjs/lucid/schema';
2 2
3export default class extends BaseSchema { 3export default class extends BaseSchema {
4 protected tableName = 'services' 4 protected tableName = 'services';
5 5
6 public async up(): Promise<void> { 6 public async up(): Promise<void> {
7 this.schema.createTable(this.tableName, (table) => { 7 this.schema.createTable(this.tableName, table => {
8 table.increments() 8 table.increments();
9 table.string('userId', 80).notNullable() 9 table.string('userId', 80).notNullable();
10 table.string('serviceId', 80).notNullable() 10 table.string('serviceId', 80).notNullable();
11 table.string('name', 80).notNullable() 11 table.string('name', 80).notNullable();
12 table.string('recipeId', 254).notNullable() 12 table.string('recipeId', 254).notNullable();
13 table.json('settings') 13 table.json('settings');
14 table.timestamps() 14 table.timestamps();
15 }) 15 });
16 } 16 }
17 17
18 public async down(): Promise<void> { 18 public async down(): Promise<void> {
19 this.schema.dropTable(this.tableName) 19 this.schema.dropTable(this.tableName);
20 } 20 }
21} 21}
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 @@
1import { BaseSchema } from '@adonisjs/lucid/schema' 1import { BaseSchema } from '@adonisjs/lucid/schema';
2 2
3export default class extends BaseSchema { 3export default class extends BaseSchema {
4 protected tableName = 'recipes' 4 protected tableName = 'recipes';
5 5
6 public async up(): Promise<void> { 6 public async up(): Promise<void> {
7 this.schema.createTable(this.tableName, (table) => { 7 this.schema.createTable(this.tableName, table => {
8 table.increments() 8 table.increments();
9 table.string('name', 80).notNullable() 9 table.string('name', 80).notNullable();
10 table.string('recipeId', 254).notNullable().unique() 10 table.string('recipeId', 254).notNullable().unique();
11 table.json('data') 11 table.json('data');
12 table.timestamps() 12 table.timestamps();
13 }) 13 });
14 } 14 }
15 15
16 public async down(): Promise<void> { 16 public async down(): Promise<void> {
17 this.schema.dropTable(this.tableName) 17 this.schema.dropTable(this.tableName);
18 } 18 }
19} 19}
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 @@
1import { BaseSchema } from '@adonisjs/lucid/schema' 1import { BaseSchema } from '@adonisjs/lucid/schema';
2 2
3export default class extends BaseSchema { 3export default class extends BaseSchema {
4 protected tableName = 'workspaces' 4 protected tableName = 'workspaces';
5 5
6 public async up(): Promise<void> { 6 public async up(): Promise<void> {
7 this.schema.createTable(this.tableName, (table) => { 7 this.schema.createTable(this.tableName, table => {
8 table.increments() 8 table.increments();
9 table.string('workspaceId', 80).notNullable().unique() 9 table.string('workspaceId', 80).notNullable().unique();
10 table.string('userId', 80).notNullable() 10 table.string('userId', 80).notNullable();
11 table.string('name', 80).notNullable() 11 table.string('name', 80).notNullable();
12 table.integer('order') 12 table.integer('order');
13 table.json('services') 13 table.json('services');
14 table.json('data') 14 table.json('data');
15 table.timestamps() 15 table.timestamps();
16 }) 16 });
17 } 17 }
18 18
19 public async down(): Promise<void> { 19 public async down(): Promise<void> {
20 this.schema.dropTable(this.tableName) 20 this.schema.dropTable(this.tableName);
21 } 21 }
22} 22}
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 @@
1import { BaseSchema } from '@adonisjs/lucid/schema' 1import { BaseSchema } from '@adonisjs/lucid/schema';
2 2
3export default class extends BaseSchema { 3export default class extends BaseSchema {
4 public async up(): Promise<void> { 4 public async up(): Promise<void> {
5 this.schema.alterTable('users', (table) => { 5 this.schema.alterTable('users', table => {
6 table.string('lastname', 80).notNullable().defaultTo('') 6 table.string('lastname', 80).notNullable().defaultTo('');
7 }) 7 });
8 } 8 }
9 9
10 public async down(): Promise<void> { 10 public async down(): Promise<void> {
11 this.schema.alterTable('users', (table) => { 11 this.schema.alterTable('users', table => {
12 table.dropColumn('lastname') 12 table.dropColumn('lastname');
13 }) 13 });
14 } 14 }
15} 15}
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 @@
1import { BaseSchema } from '@adonisjs/lucid/schema' 1import { BaseSchema } from '@adonisjs/lucid/schema';
2 2
3export default class extends BaseSchema { 3export default class extends BaseSchema {
4 protected tableName = 'tokens' 4 protected tableName = 'tokens';
5 5
6 public async up(): Promise<void> { 6 public async up(): Promise<void> {
7 await this.db.rawQuery('DELETE FROM tokens WHERE user_id NOT IN (SELECT id FROM users)') 7 await this.db.rawQuery(
8 'DELETE FROM tokens WHERE user_id NOT IN (SELECT id FROM users)',
9 );
8 10
9 this.schema.alterTable(this.tableName, (table) => { 11 this.schema.alterTable(this.tableName, table => {
10 table.dropForeign('user_id') 12 table.dropForeign('user_id');
11 13
12 table.foreign('user_id').references('users.id').onDelete('cascade') 14 table.foreign('user_id').references('users.id').onDelete('cascade');
13 }) 15 });
14 } 16 }
15 17
16 public async down(): Promise<void> { 18 public async down(): Promise<void> {
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 @@
1import { BaseSchema } from '@adonisjs/lucid/schema' 1import { BaseSchema } from '@adonisjs/lucid/schema';
2 2
3export default class JwtTokens extends BaseSchema { 3export default class JwtTokens extends BaseSchema {
4 protected tableName = 'jwt_tokens' 4 protected tableName = 'jwt_tokens';
5 5
6 public async up() { 6 public async up() {
7 this.schema.createTable(this.tableName, (table) => { 7 this.schema.createTable(this.tableName, table => {
8 table.increments('id').primary() 8 table.increments('id').primary();
9 table.integer('user_id').unsigned().references('users.id').onDelete('CASCADE') 9 table
10 table.string('name').notNullable() 10 .integer('user_id')
11 table.string('type').notNullable() 11 .unsigned()
12 table.string('token', 64).notNullable().unique() 12 .references('users.id')
13 table.timestamp('expires_at', { useTz: true }).nullable() 13 .onDelete('CASCADE');
14 table.string('refresh_token').notNullable().unique().index() 14 table.string('name').notNullable();
15 table.timestamp('refresh_token_expires_at', { useTz: true }).notNullable() 15 table.string('type').notNullable();
16 table.timestamp('created_at', { useTz: true }).notNullable() 16 table.string('token', 64).notNullable().unique();
17 }) 17 table.timestamp('expires_at', { useTz: true }).nullable();
18 table.string('refresh_token').notNullable().unique().index();
19 table
20 .timestamp('refresh_token_expires_at', { useTz: true })
21 .notNullable();
22 table.timestamp('created_at', { useTz: true }).notNullable();
23 });
18 } 24 }
19 25
20 public async down() { 26 public async down() {
21 this.schema.dropTable(this.tableName) 27 this.schema.dropTable(this.tableName);
22 } 28 }
23} 29}