Migration for delete cascade
This commit is contained in:
parent
a539a82640
commit
3d67b3c1e8
|
@ -0,0 +1,19 @@
|
|||
import {MigrationInterface, QueryRunner} from "typeorm";
|
||||
|
||||
export class default1570719082786 implements MigrationInterface {
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.query(`ALTER TABLE "event_information" DROP CONSTRAINT "FK_863d4c38d8fd413a088f4d74013"`);
|
||||
await queryRunner.query(`ALTER TABLE "event_occurrence" DROP CONSTRAINT "FK_88f92a74a42d782cb5caa3993f5"`);
|
||||
await queryRunner.query(`ALTER TABLE "event_information" ADD CONSTRAINT "FK_863d4c38d8fd413a088f4d74013" FOREIGN KEY ("eventId") REFERENCES "event"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
|
||||
await queryRunner.query(`ALTER TABLE "event_occurrence" ADD CONSTRAINT "FK_88f92a74a42d782cb5caa3993f5" FOREIGN KEY ("eventId") REFERENCES "event"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.query(`ALTER TABLE "event_occurrence" DROP CONSTRAINT "FK_88f92a74a42d782cb5caa3993f5"`);
|
||||
await queryRunner.query(`ALTER TABLE "event_information" DROP CONSTRAINT "FK_863d4c38d8fd413a088f4d74013"`);
|
||||
await queryRunner.query(`ALTER TABLE "event_occurrence" ADD CONSTRAINT "FK_88f92a74a42d782cb5caa3993f5" FOREIGN KEY ("eventId") REFERENCES "event"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
await queryRunner.query(`ALTER TABLE "event_information" ADD CONSTRAINT "FK_863d4c38d8fd413a088f4d74013" FOREIGN KEY ("eventId") REFERENCES "event"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
}
|
||||
|
||||
}
|
|
@ -138,7 +138,9 @@ export class EventInformation {
|
|||
title: string
|
||||
@Column({nullable: true})
|
||||
description: string
|
||||
@ManyToOne(type => Event, event => event.infos)
|
||||
@ManyToOne(type => Event, event => event.infos, {
|
||||
onDelete: "CASCADE"
|
||||
})
|
||||
event: Event
|
||||
}
|
||||
|
||||
|
@ -147,7 +149,10 @@ export class EventOccurrence extends BaseEntity {
|
|||
@PrimaryGeneratedColumn("uuid")
|
||||
id: number
|
||||
|
||||
@ManyToOne(type => Event, event => event.occurrences, { nullable: false })
|
||||
@ManyToOne(type => Event, event => event.occurrences, {
|
||||
nullable: false,
|
||||
onDelete: "CASCADE"
|
||||
})
|
||||
event: Promise<Event>
|
||||
|
||||
@Column({type: "tstzrange", nullable: true})
|
||||
|
|
|
@ -156,11 +156,9 @@ const resolvers: ResolverMap = {
|
|||
throw Error("Only the owner can delete this event")
|
||||
}
|
||||
|
||||
const deleteResult = await Event.delete(id)
|
||||
if (deleteResult.affected !== 1) {
|
||||
throw new Error(`Error deleting event. Row affected: ${deleteResult.affected}`)
|
||||
}
|
||||
|
||||
console.log('will try to remove event now', event.id)
|
||||
const removeEventResult = await Event.remove(event)
|
||||
console.log('removeEventResult', JSON.stringify(removeEventResult))
|
||||
return context.user
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
import {PostgresConnectionOptions} from "typeorm/driver/postgres/PostgresConnectionOptions"
|
||||
import { PostgresConnectionOptions } from "typeorm/driver/postgres/PostgresConnectionOptions";
|
||||
|
||||
const config: PostgresConnectionOptions = {
|
||||
type: 'postgres',
|
||||
host: process.env.POSTGRES_HOST || 'localhost',
|
||||
type: "postgres",
|
||||
host: process.env.POSTGRES_HOST || "localhost",
|
||||
port: Number(process.env.POSTGRES_PORT || 5432),
|
||||
database: process.env.POSTGRES_DB || 'qpa-dev',
|
||||
database: process.env.POSTGRES_DB || "qpa-dev",
|
||||
username: process.env.DB_USER || null,
|
||||
password: process.env.DB_PASSWORD || null,
|
||||
entities: ["**/*.entity.ts", "**/*.entity.js"],
|
||||
migrations: ["migrations/*.js"],
|
||||
migrations: ["migrations/*.js", "migrations/*.ts"],
|
||||
logging: true,
|
||||
synchronize: process.env.NODE_ENV === 'development',
|
||||
logger: 'debug',
|
||||
synchronize: !!process.env.TYPEORM_SYNCHRONIZE,
|
||||
logger: "debug",
|
||||
cli: {
|
||||
migrationsDir: "migrations"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export = config
|
||||
export = config;
|
||||
|
|
Loading…
Reference in New Issue