this also needs cascades

This commit is contained in:
Evert Prants 2022-09-14 21:08:08 +03:00
parent eb5f66e4cd
commit 70fd84dd0f
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
2 changed files with 37 additions and 2 deletions

View File

@ -0,0 +1,35 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class cascadeauthorization1663178807737 implements MigrationInterface {
name = 'cascadeauthorization1663178807737';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`o_auth2_client_authorization\` DROP FOREIGN KEY \`FK_8227110f58510b7233f3db90cfb\``,
);
await queryRunner.query(
`ALTER TABLE \`o_auth2_client_authorization\` ADD CONSTRAINT \`FK_8227110f58510b7233f3db90cfb\` FOREIGN KEY (\`userId\`) REFERENCES \`user\`(\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE \`o_auth2_client_authorization\` DROP FOREIGN KEY \`FK_9ca9ebb654e7ce71954d5fdb281\``,
);
await queryRunner.query(
`ALTER TABLE \`o_auth2_client_authorization\` ADD CONSTRAINT \`FK_9ca9ebb654e7ce71954d5fdb281\` FOREIGN KEY (\`clientId\`) REFERENCES \`o_auth2_client\`(\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`o_auth2_client_authorization\` DROP FOREIGN KEY \`FK_8227110f58510b7233f3db90cfb\``,
);
await queryRunner.query(
`ALTER TABLE \`o_auth2_client_authorization\` DROP FOREIGN KEY \`FK_9ca9ebb654e7ce71954d5fdb281\``,
);
await queryRunner.query(
`ALTER TABLE \`o_auth2_client_authorization\` ADD CONSTRAINT \`FK_8227110f58510b7233f3db90cfb\` FOREIGN KEY (\`userId\`) REFERENCES \`user\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE \`o_auth2_client_authorization\` ADD CONSTRAINT \`FK_9ca9ebb654e7ce71954d5fdb281\` FOREIGN KEY (\`clientId\`) REFERENCES \`o_auth2_client\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
}
}

View File

@ -22,9 +22,9 @@ export class OAuth2ClientAuthorization {
@CreateDateColumn() @CreateDateColumn()
public created_at: Date; public created_at: Date;
@ManyToOne(() => OAuth2Client) @ManyToOne(() => OAuth2Client, { onDelete: 'CASCADE' })
public client: OAuth2Client; public client: OAuth2Client;
@ManyToOne(() => User) @ManyToOne(() => User, { onDelete: 'CASCADE' })
public user: User; public user: User;
} }