aboutsummaryrefslogtreecommitdiffstats
path: root/database
diff options
context:
space:
mode:
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, 104 insertions, 118 deletions
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 @@
1import Service from 'App/Models/Service'; 1import Service from '#app/Models/Service'
2import Factory from '@ioc:Adonis/Lucid/Factory'; 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 5afc679..0774dcd 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 '@ioc:Adonis/Lucid/Factory'; 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,9 +9,6 @@ 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( 12 .state('old_token', (token) => (token.updated_at = DateTime.now().minus({ hours: 25 })))
13 'old_token', 13 .state('revoked', (token) => (token.is_revoked = true))
14 token => (token.updated_at = DateTime.now().minus({ hours: 25 })), 14 .build()
15 )
16 .state('revoked', token => (token.is_revoked = true))
17 .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 @@
1import User from 'App/Models/User'; 1import User from '#app/Models/User'
2import Factory from '@ioc:Adonis/Lucid/Factory'; 2import Factory from '@adonisjs/lucid/factories'
3import WorkspaceFactory from './WorkspaceFactory'; 3import WorkspaceFactory from './WorkspaceFactory.js'
4import ServiceFactory from './ServiceFactory'; 4import ServiceFactory from './ServiceFactory.js'
5import crypto from 'node:crypto'; 5import crypto from 'node:crypto'
6 6
7const hashedPassword = crypto 7const hashedPassword = crypto.createHash('sha256').update('password').digest('base64')
8 .createHash('sha256')
9 .update('password')
10 .digest('base64');
11 8
12export default Factory.define(User, async ({ faker }) => ({ 9export default Factory.define(User, async ({ faker }) => ({
13 email: faker.internet.email(), 10 email: faker.internet.email(),
@@ -18,4 +15,4 @@ export default Factory.define(User, async ({ faker }) => ({
18})) 15}))
19 .relation('workspaces', () => WorkspaceFactory) 16 .relation('workspaces', () => WorkspaceFactory)
20 .relation('services', () => ServiceFactory) 17 .relation('services', () => ServiceFactory)
21 .build(); 18 .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 @@
1import Workspace from 'App/Models/Workspace'; 1import Workspace from '#app/Models/Workspace'
2import Factory from '@ioc:Adonis/Lucid/Factory'; 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 262a472..4a58213 100644
--- a/database/migrations/1503250034279_user.ts
+++ b/database/migrations/1503250034279_user.ts
@@ -1,20 +1,20 @@
1import BaseSchema from '@ioc:Adonis/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 5a030d0..3830c98 100644
--- a/database/migrations/1503250034280_token.ts
+++ b/database/migrations/1503250034280_token.ts
@@ -1,20 +1,20 @@
1import BaseSchema from '@ioc:Adonis/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 9c3e23d..3c46cab 100644
--- a/database/migrations/1566385379883_service_schema.ts
+++ b/database/migrations/1566385379883_service_schema.ts
@@ -1,21 +1,21 @@
1import BaseSchema from '@ioc:Adonis/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 3a9784d..567c89f 100644
--- a/database/migrations/1566554231482_recipe_schema.ts
+++ b/database/migrations/1566554231482_recipe_schema.ts
@@ -1,19 +1,19 @@
1import BaseSchema from '@ioc:Adonis/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 77e1189..b863200 100644
--- a/database/migrations/1566554359294_workspace_schema.ts
+++ b/database/migrations/1566554359294_workspace_schema.ts
@@ -1,22 +1,22 @@
1import BaseSchema from '@ioc:Adonis/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 8831ea4..76dc816 100644
--- a/database/migrations/1612629845398_users_update_schema.ts
+++ b/database/migrations/1612629845398_users_update_schema.ts
@@ -1,15 +1,15 @@
1import BaseSchema from '@ioc:Adonis/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 5486657..1013861 100644
--- a/database/migrations/1658076326250_correct_token_relations.ts
+++ b/database/migrations/1658076326250_correct_token_relations.ts
@@ -1,18 +1,16 @@
1import BaseSchema from '@ioc:Adonis/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( 7 await this.db.rawQuery('DELETE FROM tokens WHERE user_id NOT IN (SELECT id FROM users)')
8 'DELETE FROM tokens WHERE user_id NOT IN (SELECT id FROM users)',
9 );
10 8
11 this.schema.alterTable(this.tableName, table => { 9 this.schema.alterTable(this.tableName, (table) => {
12 table.dropForeign('user_id'); 10 table.dropForeign('user_id')
13 11
14 table.foreign('user_id').references('users.id').onDelete('cascade'); 12 table.foreign('user_id').references('users.id').onDelete('cascade')
15 }); 13 })
16 } 14 }
17 15
18 public async down(): Promise<void> { 16 public async down(): Promise<void> {
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 @@
1import BaseSchema from '@ioc:Adonis/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 9 table.integer('user_id').unsigned().references('users.id').onDelete('CASCADE')
10 .integer('user_id') 10 table.string('name').notNullable()
11 .unsigned() 11 table.string('type').notNullable()
12 .references('users.id') 12 table.string('token', 64).notNullable().unique()
13 .onDelete('CASCADE'); 13 table.timestamp('expires_at', { useTz: true }).nullable()
14 table.string('name').notNullable(); 14 table.string('refresh_token').notNullable().unique().index()
15 table.string('type').notNullable(); 15 table.timestamp('refresh_token_expires_at', { useTz: true }).notNullable()
16 table.string('token', 64).notNullable().unique(); 16 table.timestamp('created_at', { useTz: true }).notNullable()
17 table.timestamp('expires_at', { useTz: true }).nullable(); 17 })
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 });
24 } 18 }
25 19
26 public async down() { 20 public async down() {
27 this.schema.dropTable(this.tableName); 21 this.schema.dropTable(this.tableName)
28 } 22 }
29} 23}