diff options
Diffstat (limited to 'database')
-rw-r--r-- | database/factories/ServiceFactory.ts | 6 | ||||
-rw-r--r-- | database/factories/TokenFactory.ts | 15 | ||||
-rw-r--r-- | database/factories/UserFactory.ts | 17 | ||||
-rw-r--r-- | database/factories/WorkspaceFactory.ts | 6 | ||||
-rw-r--r-- | database/migrations/1503250034279_user.ts | 22 | ||||
-rw-r--r-- | database/migrations/1503250034280_token.ts | 22 | ||||
-rw-r--r-- | database/migrations/1566385379883_service_schema.ts | 24 | ||||
-rw-r--r-- | database/migrations/1566554231482_recipe_schema.ts | 20 | ||||
-rw-r--r-- | database/migrations/1566554359294_workspace_schema.ts | 26 | ||||
-rw-r--r-- | database/migrations/1612629845398_users_update_schema.ts | 14 | ||||
-rw-r--r-- | database/migrations/1658076326250_correct_token_relations.ts | 16 | ||||
-rw-r--r-- | database/migrations/1696110557648_jwt_tokens.ts | 34 |
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 @@ | |||
1 | import Service from '#app/Models/Service' | 1 | import Service from '#app/Models/Service'; |
2 | import Factory from '@adonisjs/lucid/factories' | 2 | import Factory from '@adonisjs/lucid/factories'; |
3 | 3 | ||
4 | export default Factory.define(Service, ({ faker }) => ({ | 4 | export 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 @@ | |||
1 | import Token from '#app/Models/Token' | 1 | import Token from '#app/Models/Token'; |
2 | import Factory from '@adonisjs/lucid/factories' | 2 | import Factory from '@adonisjs/lucid/factories'; |
3 | import { DateTime } from 'luxon' | 3 | import { DateTime } from 'luxon'; |
4 | 4 | ||
5 | export default Factory.define(Token, async ({ faker }) => ({ | 5 | export 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 @@ | |||
1 | import User from '#app/Models/User' | 1 | import User from '#app/Models/User'; |
2 | import Factory from '@adonisjs/lucid/factories' | 2 | import Factory from '@adonisjs/lucid/factories'; |
3 | import WorkspaceFactory from './WorkspaceFactory.js' | 3 | import WorkspaceFactory from './WorkspaceFactory.js'; |
4 | import ServiceFactory from './ServiceFactory.js' | 4 | import ServiceFactory from './ServiceFactory.js'; |
5 | import crypto from 'node:crypto' | 5 | import crypto from 'node:crypto'; |
6 | 6 | ||
7 | const hashedPassword = crypto.createHash('sha256').update('password').digest('base64') | 7 | const hashedPassword = crypto |
8 | .createHash('sha256') | ||
9 | .update('password') | ||
10 | .digest('base64'); | ||
8 | 11 | ||
9 | export default Factory.define(User, async ({ faker }) => ({ | 12 | export 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 @@ | |||
1 | import Workspace from '#app/Models/Workspace' | 1 | import Workspace from '#app/Models/Workspace'; |
2 | import Factory from '@adonisjs/lucid/factories' | 2 | import Factory from '@adonisjs/lucid/factories'; |
3 | 3 | ||
4 | export default Factory.define(Workspace, ({ faker }) => ({ | 4 | export 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 @@ | |||
1 | import { BaseSchema } from '@adonisjs/lucid/schema' | 1 | import { BaseSchema } from '@adonisjs/lucid/schema'; |
2 | 2 | ||
3 | export default class extends BaseSchema { | 3 | export 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 @@ | |||
1 | import { BaseSchema } from '@adonisjs/lucid/schema' | 1 | import { BaseSchema } from '@adonisjs/lucid/schema'; |
2 | 2 | ||
3 | export default class extends BaseSchema { | 3 | export 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 @@ | |||
1 | import { BaseSchema } from '@adonisjs/lucid/schema' | 1 | import { BaseSchema } from '@adonisjs/lucid/schema'; |
2 | 2 | ||
3 | export default class extends BaseSchema { | 3 | export 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 @@ | |||
1 | import { BaseSchema } from '@adonisjs/lucid/schema' | 1 | import { BaseSchema } from '@adonisjs/lucid/schema'; |
2 | 2 | ||
3 | export default class extends BaseSchema { | 3 | export 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 @@ | |||
1 | import { BaseSchema } from '@adonisjs/lucid/schema' | 1 | import { BaseSchema } from '@adonisjs/lucid/schema'; |
2 | 2 | ||
3 | export default class extends BaseSchema { | 3 | export 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 @@ | |||
1 | import { BaseSchema } from '@adonisjs/lucid/schema' | 1 | import { BaseSchema } from '@adonisjs/lucid/schema'; |
2 | 2 | ||
3 | export default class extends BaseSchema { | 3 | export 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 @@ | |||
1 | import { BaseSchema } from '@adonisjs/lucid/schema' | 1 | import { BaseSchema } from '@adonisjs/lucid/schema'; |
2 | 2 | ||
3 | export default class extends BaseSchema { | 3 | export 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 @@ | |||
1 | import { BaseSchema } from '@adonisjs/lucid/schema' | 1 | import { BaseSchema } from '@adonisjs/lucid/schema'; |
2 | 2 | ||
3 | export default class JwtTokens extends BaseSchema { | 3 | export 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 | } |