From 6e61cce1ece428731b1807ec0f02adbeffeee56a Mon Sep 17 00:00:00 2001 From: philipp Date: Sat, 22 Jul 2023 13:10:13 +0200 Subject: [PATCH] create db tables for logbook --- README.md | 40 +++++++++++--------------------------- migration.sql | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ seeds.sql | 13 +++++++++++++ 3 files changed, 78 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index d7e1002..d199a1f 100644 --- a/README.md +++ b/README.md @@ -6,47 +6,29 @@ ### Logbuch - Log with activities -#### Tables -- boats - - id - - name - - amount_seats -- session - - id - - ship_master (Schiffsführer) - - ship_master_only_steered (default: false) - - departure (Datetime) - - Option (Datetime) // None -> on water - - destination - - Option (prefilled from destination) - - comments - - type (normal, Wanderfahrt) -- rowers - - session_id - - user_id -- damages - - boat_id - - desc - - user_id_created - - created_at - - user_id_fixed - - fixed_at - - lock_boat (default: false), if true: noone can use this boat - ### Guest-Scheckbuch - guest_trip - guest_user_id - amount_trips - paid_to_user_id -- guest_trip_session +- guest_trip_logbook - guest_trip_id - - session_id + - logbook_id ### Bootsreservierungen - Confirmation required? - How long in advance is it possible? - Default reservations for some regular events (A+F, USI, ...)? +### Notifications +- notifcations + - id + - message + - category + - created_at + - read_at: Option + - user_id + ## Backlog (i.e. don't work on this now) ### Sync w/ nextcloud - remove most fields (names, ...) from users and add uid diff --git a/migration.sql b/migration.sql index 7fb8f45..479350d 100644 --- a/migration.sql +++ b/migration.sql @@ -65,3 +65,57 @@ CREATE TABLE IF NOT EXISTS "log" ( "created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP ); +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 +); + diff --git a/seeds.sql b/seeds.sql index 7c56b80..497ac8f 100644 --- a/seeds.sql +++ b/seeds.sql @@ -15,3 +15,16 @@ INSERT INTO "trip" (cox_id, trip_details_id) VALUES(4, 2); INSERT INTO "trip_type" (name, desc, question, icon) VALUES ('Regatta', 'Regatta!', 'Kein normales Event. Das ist eine Regatta! Willst du wirklich teilnehmen?', '🏅'); INSERT INTO "trip_type" (name, desc, question, icon) VALUES ('Lange Ausfahrt', 'Lange Ausfahrt!', 'Das ist eine lange Ausfahrt! Willst du wirklich teilnehmen?', '💪'); INSERT INTO "trip_type" (name, desc, question, icon) VALUES ('Wanderfahrt', 'Wanderfahrt!', 'Kein normales Event. Das ist eine Wanderfahrt! Bitte überprüfe ob du alle Anforderungen erfüllst. Willst du wirklich teilnehmen?', '⛱'); +INSERT INTO "location" (name) VALUES ('Linz'); +INSERT INTO "location" (name) VALUES ('Ottensheim'); +INSERT INTO "boat" (name, amount_seats, location_id) VALUES ('Haichenbach', 1, 1); +INSERT INTO "boat" (name, amount_seats, location_id, owner) VALUES ('private_boat_from_rower', 1, 1, 2); +INSERT INTO "boat" (name, amount_seats, location_id) VALUES ('Joe', 2, 1); +INSERT INTO "boat" (name, amount_seats, location_id) VALUES ('Kaputtes Boot :-(', 7, 1); +INSERT INTO "logbook_type" (name) VALUES ('Wanderfahrt'); +INSERT INTO "logbook_type" (name) VALUES ('Regatta'); +INSERT INTO "logbook" (boat_id, shipmaster, shipmaster_only_steering, departure) VALUES (2, 2, false, '2142-12-24 10:00'); +INSERT INTO "logbook" (boat_id, shipmaster, shipmaster_only_steering, departure, arrival, destination, distance_in_km) VALUES (1, 4, false, '2141-12-24 10:00', '2141-12-24 15:00', 'Ottensheim', 25); +INSERT INTO "logbook" (boat_id, shipmaster, shipmaster_only_steering, departure, arrival, destination, distance_in_km) VALUES (3, 4, false, '2142-12-24 10:00', '2142-12-24 11:30', 'Ottensheim + Regattastrecke', 29); +INSERT INTO "rower" (logbook_id, rower_id) VALUES(3,3); +INSERT INTO "boat_damage" (boat_id, desc, user_id_created, created_at) VALUES(4,'Dolle bei Position 2 fehlt', 5, '2142-12-24 15:02');