blob: 54866577b1121bcf2272e8f5a0b36c208a4b1ed0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import BaseSchema from '@ioc:Adonis/Lucid/Schema';
export default class extends BaseSchema {
protected tableName = 'tokens';
public async up(): Promise<void> {
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');
table.foreign('user_id').references('users.id').onDelete('cascade');
});
}
public async down(): Promise<void> {
// Don't set it back withouth onDelete as the
// tests will break.
}
}
|