This commit is contained in:
2023-04-04 15:16:21 +02:00
parent 0bdd073d7f
commit cedaba5709
10 changed files with 453 additions and 28 deletions

View File

@ -24,3 +24,24 @@ CREATE TABLE IF NOT EXISTS "planned_event" (
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY(trip_details_id) REFERENCES trip_details(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS "trip" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"cox_id" INTEGER NOT NULL,
"trip_details_id" INTEGER,
"planned_event_id" INTEGER,
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY(cox_id) REFERENCES user(id),
FOREIGN KEY(trip_details_id) REFERENCES trip_details(id) ON DELETE CASCADE,
FOREIGN KEY(planned_event_id) REFERENCES planned_event(id) ON DELETE CASCADE,
CONSTRAINT unq UNIQUE (cox_id, planned_event_id) -- allow cox to participate only once for each planned event
);
CREATE TABLE IF NOT EXISTS "user_trip" (
"user_id" INTEGER NOT NULL,
"trip_details_id" INTEGER NOT NULL,
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY(user_id) REFERENCES user(id),
FOREIGN KEY(trip_details_id) REFERENCES trip_details(id),
CONSTRAINT unq UNIQUE (user_id, trip_details_id) -- allow user to participate only once for each trip
);