rowt/migration.sql

176 lines
5.8 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-05-10 08:57:20 +02:00
"deleted" boolean NOT NULL DEFAULT FALSE,
2023-11-02 12:25:13 +01:00
"last_access" DATETIME,
"dob" text,
"weight" text,
"sex" text,
"dirty_thirty" text,
2023-12-30 21:21:30 +01:00
"dirty_dozen" text,
"member_since_date" text,
"birthdate" text,
"mail" text,
"nickname" text,
"notes" text,
"phone" text,
2024-01-18 16:37:54 +01:00
"address" text,
2024-03-20 20:59:41 +01:00
"family_id" INTEGER REFERENCES family(id),
"membership_pdf" BLOB
2024-01-18 16:37:54 +01:00
);
CREATE TABLE IF NOT EXISTS "family" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT
2023-03-26 14:40:56 +02:00
);
2023-04-04 12:19:56 +02:00
CREATE TABLE IF NOT EXISTS "role" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" text NOT NULL UNIQUE
);
CREATE TABLE IF NOT EXISTS "user_role" (
"user_id" INTEGER NOT NULL REFERENCES user(id),
"role_id" INTEGER NOT NULL REFERENCES role(id),
CONSTRAINT unq UNIQUE (user_id, role_id)
);
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,
2023-11-09 08:58:09 +01:00
"default_destination" text,
2023-07-22 13:10:13 +02:00
"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-10-29 18:42:12 +01:00
"steering_person" 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
);
2024-03-08 13:13:20 +01:00
CREATE TABLE IF NOT EXISTS "boathouse" (
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
"boat_id" INTEGER NOT NULL REFERENCES boat(id),
"aisle" TEXT NOT NULL CHECK (aisle in ('water', 'middle', 'mountain')),
"side" TEXT NOT NULL CHECK(side IN ('mountain', 'water')),
"level" INTEGER NOT NULL CHECK(level BETWEEN 0 AND 11),
2024-03-08 13:13:20 +01:00
CONSTRAINT unq UNIQUE (aisle, side, level) -- only 1 boat allowed to rest at each space
);
CREATE TABLE IF NOT EXISTS "notification" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"user_id" INTEGER NOT NULL REFERENCES user(id),
"message" TEXT NOT NULL,
"read_at" DATETIME,
"created_at" DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
"category" TEXT NOT NULL,
"link" TEXT
);
2024-03-30 01:36:37 +01:00
CREATE TABLE IF NOT EXISTS "boat_reservation" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"boat_id" INTEGER NOT NULL REFERENCES boat(id),
"start_date" DATE NOT NULL,
"end_date" DATE NOT NULL,
"time_desc" TEXT NOT NULL,
"usage" TEXT NOT NULL,
"user_id_applicant" INTEGER NOT NULL REFERENCES user(id),
"user_id_confirmation" INTEGER REFERENCES user(id),
"created_at" datetime not null default CURRENT_TIMESTAMP
);