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,
|
2024-09-10 23:25:26 +02:00
|
|
|
"user_token" TEXT NOT NULL DEFAULT (lower(hex(randomblob(16))))
|
2024-01-18 16:37:54 +01: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 12:39:23 +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 20:30:37 +00: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 20:30:37 +00: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 "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
|
|
|
);
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
);
|