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),
|
2024-09-10 23:25:26 +02:00
|
|
|
"membership_pdf" BLOB,
|
|
|
|
"user_token" TEXT NOT NULL DEFAULT (lower(hex(randomblob(16))))
|
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
|
|
|
|
2023-12-23 21:27:52 +01:00
|
|
|
CREATE TABLE IF NOT EXISTS "role" (
|
|
|
|
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
2024-10-11 11:20:58 +02:00
|
|
|
"name" text NOT NULL UNIQUE,
|
|
|
|
"cluster" text
|
2023-12-23 21:27:52 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
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,
|
2023-04-29 18:57:01 +02:00
|
|
|
"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,
|
2023-07-22 15:51:20 +02:00
|
|
|
"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,
|
2023-07-22 13:57:17 +02:00
|
|
|
"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,
|
2024-04-24 09:37:45 +02:00
|
|
|
"convert_handoperated_possible" 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
|
2024-04-17 13:18:35 +02:00
|
|
|
"external" boolean default false NOT NULL, -- false => owned by different club
|
|
|
|
"deleted" boolean NOT NULL DEFAULT FALSE
|
2023-07-22 13:10:13 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS "logbook_type" (
|
|
|
|
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
2023-07-22 15:51:20 +02:00
|
|
|
"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')),
|
2024-03-20 13:58:42 +01:00
|
|
|
"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
|
|
|
|
);
|
|
|
|
|
2024-03-20 16:19:12 +01:00
|
|
|
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,
|
2024-05-21 19:41:00 +02:00
|
|
|
"action_after_reading" TEXT,
|
2024-03-20 16:19:12 +01:00
|
|
|
"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
|
|
|
|
);
|
|
|
|
|
2024-04-30 11:59:33 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS "waterlevel" (
|
|
|
|
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
|
|
"day" DATE NOT NULL,
|
|
|
|
"time" TEXT NOT NULL,
|
|
|
|
"max" INTEGER NOT NULL,
|
|
|
|
"min" INTEGER NOT NULL,
|
|
|
|
"mittel" INTEGER NOT NULL,
|
|
|
|
"tumax" INTEGER NOT NULL,
|
|
|
|
"tumin" INTEGER NOT NULL,
|
|
|
|
"tumittel" INTEGER NOT NULL
|
|
|
|
);
|
2024-05-16 14:41:15 +02:00
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS "weather" (
|
|
|
|
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
|
|
"day" DATE NOT NULL,
|
|
|
|
"max_temp" FLOAT NOT NULL,
|
|
|
|
"wind_gust" FLOAT NOT NULL,
|
|
|
|
"rain_mm" FLOAT NOT NULL
|
|
|
|
);
|
2024-06-10 19:43:59 +02:00
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS "trailer" (
|
|
|
|
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
|
|
"name" text NOT NULL UNIQUE
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS "trailer_reservation" (
|
|
|
|
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
2024-06-16 20:00:44 +02:00
|
|
|
"trailer_id" INTEGER NOT NULL REFERENCES trailer(id),
|
2024-06-10 19:43:59 +02:00
|
|
|
"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
|
|
|
|
);
|
|
|
|
|
2024-08-18 20:21:59 +02:00
|
|
|
CREATE TABLE IF NOT EXISTS "distance" (
|
|
|
|
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
|
|
"destination" text NOT NULL,
|
|
|
|
"distance_in_km" integer NOT NULL
|
|
|
|
);
|
|
|
|
|
2024-10-11 11:20:58 +02:00
|
|
|
|
|
|
|
CREATE TRIGGER IF NOT EXISTS prevent_multiple_roles_same_cluster
|
|
|
|
BEFORE INSERT ON user_role
|
|
|
|
BEGIN
|
|
|
|
SELECT CASE
|
|
|
|
WHEN EXISTS (
|
|
|
|
SELECT 1
|
|
|
|
FROM user_role ur
|
|
|
|
JOIN role r1 ON ur.role_id = r1.id
|
|
|
|
JOIN role r2 ON r1."cluster" = r2."cluster"
|
|
|
|
WHERE ur.user_id = NEW.user_id
|
|
|
|
AND r2.id = NEW.role_id
|
|
|
|
AND r1.id != NEW.role_id
|
|
|
|
)
|
|
|
|
THEN RAISE(ABORT, 'User already has a role in this cluster')
|
|
|
|
END;
|
|
|
|
END;
|