rowt/migration.sql

118 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-08-02 14:29:19 +02:00
"is_tech" boolean NOT NULL DEFAULT FALSE,
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,
2023-07-23 19:45:48 +02:00
"always_show" boolean NOT NULL default false,
2023-08-09 11:54:18 +02:00
"is_locked" boolean NOT NULL default false,
2023-08-05 16:27:51 +02:00
"trip_type_id" INTEGER REFERENCES trip_type(id) ON DELETE CASCADE
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,
2023-08-05 16:27:51 +02:00
"trip_details_id" INTEGER NOT NULL REFERENCES TRIP_details(id) ON DELETE CASCADE,
2023-08-05 16:29:58 +02:00
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP
2023-04-04 12:19:56 +02:00
);
2023-04-04 15:16:21 +02:00
CREATE TABLE IF NOT EXISTS "trip" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
2023-08-05 16:27:51 +02:00
"cox_id" INTEGER NOT NULL REFERENCES user(id),
"trip_details_id" INTEGER REFERENCES trip_details(id) ON DELETE CASCADE,
"planned_event_id" INTEGER REFERENCES planned_event(id) ON DELETE CASCADE,
2023-04-04 15:16:21 +02:00
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP,
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" (
2023-08-09 22:30:37 +02:00
"user_id" INTEGER REFERENCES user(id),
"user_note" text, -- only shown if user_id = none
2023-08-05 16:27:51 +02:00
"trip_details_id" INTEGER NOT NULL REFERENCES trip_details(id),
2023-08-09 22:30:37 +02:00
"created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP
2023-04-04 15:16:21 +02:00
);
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,
2023-07-31 09:10:26 +02:00
"created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
2023-04-18 12:10:11 +02:00
);
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 UNIQUE
2023-07-22 13:10:13 +02:00
);
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) DEFAULT 1,
2023-07-22 13:10:13 +02:00
"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 UNIQUE -- e.g. 'Wanderfahrt', 'Regatta'
2023-07-22 13:10:13 +02:00
);
CREATE TABLE IF NOT EXISTS "logbook" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"boat_id" INTEGER NOT NULL REFERENCES boat(id),
2023-10-26 20:37:48 +02:00
"shipmaster" INTEGER NOT NULL REFERENCES user(id),
2023-07-22 13:10:13 +02:00
"shipmaster_only_steering" boolean not null,
2023-08-05 15:58:17 +02:00
"departure" datetime not null,
"arrival" datetime, -- None -> ship is on water
2023-07-22 13:10:13 +02:00
"destination" text,
"distance_in_km" integer,
"comments" text,
2023-07-23 12:17:57 +02:00
"logtype" INTEGER REFERENCES logbook_type(id)
2023-07-22 13:10:13 +02:00
);
CREATE TABLE IF NOT EXISTS "rower" (
2023-08-05 16:27:51 +02:00
"logbook_id" INTEGER NOT NULL REFERENCES logbook(id) ON DELETE CASCADE,
2023-07-24 13:01:39 +02:00
"rower_id" INTEGER NOT NULL REFERENCES user(id),
2023-08-05 16:27:51 +02:00
CONSTRAINT unq UNIQUE (logbook_id, rower_id)
2023-07-22 13:10:13 +02:00
);
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),
2023-08-02 14:29:19 +02:00
"created_at" datetime not null default CURRENT_TIMESTAMP,
2023-07-22 13:10:13 +02:00
"user_id_fixed" INTEGER REFERENCES user(id), -- none: not fixed yet
2023-08-02 14:29:19 +02:00
"fixed_at" datetime,
2023-07-22 13:10:13 +02:00
"user_id_verified" INTEGER REFERENCES user(id),
2023-08-02 14:29:19 +02:00
"verified_at" datetime,
2023-07-22 13:10:13 +02:00
"lock_boat" boolean not null default false -- if true: noone can use the boat
);