rowt/migration.sql

122 lines
4.1 KiB
MySQL
Raw Normal View History

2023-03-26 14:40:56 +02:00
CREATE TABLE IF NOT EXISTS "user" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" text NOT NULL UNIQUE,
2023-04-04 10:44:14 +02:00
"pw" text,
2023-03-26 14:40:56 +02:00
"is_cox" boolean NOT NULL DEFAULT FALSE,
"is_admin" boolean NOT NULL DEFAULT FALSE,
2023-04-28 19:29:20 +02:00
"is_guest" boolean NOT NULL DEFAULT TRUE,
2023-05-10 08:57:20 +02:00
"deleted" boolean NOT NULL DEFAULT FALSE,
"last_access" DATETIME
2023-03-26 14:40:56 +02:00
);
2023-04-04 12:19:56 +02:00
2023-04-28 21:30:13 +02:00
CREATE TABLE IF NOT EXISTS "trip_type" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" text NOT NULL UNIQUE,
"desc" text NOT NULL,
"question" text NOT NULL,
"icon" text NOT NULL
);
2023-04-04 12:19:56 +02:00
CREATE TABLE IF NOT EXISTS "trip_details" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"planned_starting_time" text NOT NULL,
"max_people" INTEGER NOT NULL,
"day" TEXT NOT NULL,
"allow_guests" boolean NOT NULL default false,
2023-04-28 21:18:50 +02:00
"notes" TEXT,
"trip_type_id" INTEGER,
FOREIGN KEY(trip_type_id) REFERENCES trip_type(id)
2023-04-04 12:19:56 +02:00
);
CREATE TABLE IF NOT EXISTS "planned_event" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" text NOT NULL,
"planned_amount_cox" INTEGER unsigned NOT NULL,
"trip_details_id" INTEGER NOT NULL,
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
2023-05-14 09:38:45 +02:00
"always_show" boolean NOT NULL default false,
2023-04-04 12:19:56 +02:00
FOREIGN KEY(trip_details_id) REFERENCES trip_details(id) ON DELETE CASCADE
);
2023-04-04 15:16:21 +02:00
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
);
2023-04-18 12:10:11 +02:00
CREATE TABLE IF NOT EXISTS "log" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"msg" text NOT NULL,
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP
);
2023-04-28 21:18:50 +02:00
2023-07-22 13:10:13 +02:00
CREATE TABLE IF NOT EXISTS "location" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" text NOT NULL
);
CREATE TABLE IF NOT EXISTS "boat" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" text NOT NULL UNIQUE,
"amount_seats" integer NOT NULL,
"location_id" INTEGER NOT NULL REFERENCES location(id),
"owner" INTEGER REFERENCES user(id), -- null: club is owner
"year_built" INTEGER,
"boatbuilder" TEXT,
"default_shipmaster_only_steering" boolean default false not null,
"skull" boolean default true NOT NULL, -- false => riemen
"external" boolean default false NOT NULL -- false => owned by different club
);
CREATE TABLE IF NOT EXISTS "logbook_type" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" text NOT NULL -- e.g. 'Wanderfahrt', 'Regatta'
);
CREATE TABLE IF NOT EXISTS "logbook" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"boat_id" INTEGER NOT NULL REFERENCES boat(id),
"shipmaster" INTEGER NOT NULL REFERENCES user(id), -- null: club is owner
"shipmaster_only_steering" boolean not null,
"departure" text not null,
"arrival" text, -- None -> ship is on water
"destination" text,
"distance_in_km" integer,
"comments" text,
"type" INTEGER REFERENCES logbook_type(id)
);
CREATE TABLE IF NOT EXISTS "rower" (
"logbook_id" INTEGER NOT NULL REFERENCES logbook(id),
"rower_id" INTEGER NOT NULL REFERENCES user(id)
);
CREATE TABLE IF NOT EXISTS "boat_damage" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"boat_id" INTEGER NOT NULL REFERENCES boat(id),
"desc" text not null,
"user_id_created" INTEGER NOT NULL REFERENCES user(id),
"created_at" text not null,
"user_id_fixed" INTEGER REFERENCES user(id), -- none: not fixed yet
"fixed_at" text,
"user_id_verified" INTEGER REFERENCES user(id),
"verified_at" text,
"lock_boat" boolean not null default false -- if true: noone can use the boat
);