Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

Commit

Permalink
chore: add back cascade (#2062)
Browse files Browse the repository at this point in the history
To more easily delete applications.
  • Loading branch information
asdfryan authored Dec 13, 2023
1 parent 8529206 commit d2f3981
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-- DropForeignKey
ALTER TABLE "connections" DROP CONSTRAINT "connections_customer_id_fkey";

-- DropForeignKey
ALTER TABLE "connections" DROP CONSTRAINT "connections_provider_id_fkey";

-- DropForeignKey
ALTER TABLE "object_syncs" DROP CONSTRAINT "object_syncs_connection_id_fkey";

-- DropForeignKey
ALTER TABLE "object_syncs" DROP CONSTRAINT "object_syncs_entity_id_fkey";

-- DropForeignKey
ALTER TABLE "object_syncs" DROP CONSTRAINT "object_syncs_sync_config_id_fkey";

-- DropForeignKey
ALTER TABLE "replay_ids" DROP CONSTRAINT "replay_ids_connection_id_fkey";

-- AddForeignKey
ALTER TABLE "connections" ADD CONSTRAINT "connections_customer_id_fkey" FOREIGN KEY ("customer_id") REFERENCES "customers"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "connections" ADD CONSTRAINT "connections_provider_id_fkey" FOREIGN KEY ("provider_id") REFERENCES "providers"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "object_syncs" ADD CONSTRAINT "object_syncs_entity_id_fkey" FOREIGN KEY ("entity_id") REFERENCES "entities"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "object_syncs" ADD CONSTRAINT "object_syncs_connection_id_fkey" FOREIGN KEY ("connection_id") REFERENCES "connections"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "object_syncs" ADD CONSTRAINT "object_syncs_sync_config_id_fkey" FOREIGN KEY ("sync_config_id") REFERENCES "sync_configs"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "replay_ids" ADD CONSTRAINT "replay_ids_connection_id_fkey" FOREIGN KEY ("connection_id") REFERENCES "connections"("id") ON DELETE CASCADE ON UPDATE CASCADE;
12 changes: 6 additions & 6 deletions packages/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ model Connection {
providerName String @map("provider_name")
status String // available | added | authorized | callable
credentials Bytes // encrypted, {type, access_token, refresh_token, expires_at, raw}
customer Customer @relation(fields: [customerId], references: [id])
customer Customer @relation(fields: [customerId], references: [id], onDelete: Cascade)
customerId String @map("customer_id")
instanceUrl String @default("") @map("instance_url")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
replayIds ReplayId[]
provider Provider @relation(fields: [providerId], references: [id])
provider Provider @relation(fields: [providerId], references: [id], onDelete: Cascade)
providerId String @map("provider_id")
schemaMappingsConfig Json? @map("schema_mappings_config")
entityMappings Json? @map("entity_mappings")
Expand Down Expand Up @@ -162,14 +162,14 @@ model Sync {
object String?
// set `entityId` if type is `entity`
entityId String? @map("entity_id")
entity Entity? @relation(fields: [entityId], references: [id])
entity Entity? @relation(fields: [entityId], references: [id], onDelete: Cascade)
state Json
strategy Json
connectionId String @map("connection_id")
connection Connection @relation(fields: [connectionId], references: [id])
connection Connection @relation(fields: [connectionId], references: [id], onDelete: Cascade)
paused Boolean @default(false)
syncConfigId String @map("sync_config_id")
syncConfig SyncConfig @relation(fields: [syncConfigId], references: [id])
syncConfig SyncConfig @relation(fields: [syncConfigId], references: [id], onDelete: Cascade)
argsForNextRun Json? @map("args_for_next_run")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
Expand Down Expand Up @@ -209,7 +209,7 @@ model SyncRun {

model ReplayId {
connectionId String @map("connection_id")
connection Connection @relation(fields: [connectionId], references: [id])
connection Connection @relation(fields: [connectionId], references: [id], onDelete: Cascade)
eventType String @map("event_type")
replayId String @map("replay_id")
createdAt DateTime @default(now()) @map("created_at")
Expand Down

0 comments on commit d2f3981

Please sign in to comment.