diff options
Diffstat (limited to 'database/migrations/1658076326250_correct_token_relations.ts')
-rw-r--r-- | database/migrations/1658076326250_correct_token_relations.ts | 16 |
1 files changed, 7 insertions, 9 deletions
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 @@ | |||
1 | import BaseSchema from '@ioc:Adonis/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( | 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> { |