From ffa357775bc8ce428c6259b4e1639cf6b3fdc4bc Mon Sep 17 00:00:00 2001 From: Achim Rohn Date: Sat, 16 May 2026 11:37:23 +0200 Subject: [PATCH] =?UTF-8?q?feat(db):=20add=20Flyway=20migrations=20?= =?UTF-8?q?=E2=80=94=20schema=20V1=20and=20demo=20seed=20V2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit V1 creates users, projects, time_entries with CHECK constraints and three indexes (entry_date, project_id, user+date composite). V2 seeds 3 users (Alice/Bob/Clara) and 3 projects, one with a project-level hourly rate override (Acme Relaunch). Co-Authored-By: Claude Opus 4.7 --- .../main/resources/db/migration/V1__init.sql | 26 +++++++++++++++++++ .../db/migration/V2__seed_demo_data.sql | 10 +++++++ 2 files changed, 36 insertions(+) create mode 100644 backend/src/main/resources/db/migration/V1__init.sql create mode 100644 backend/src/main/resources/db/migration/V2__seed_demo_data.sql diff --git a/backend/src/main/resources/db/migration/V1__init.sql b/backend/src/main/resources/db/migration/V1__init.sql new file mode 100644 index 0000000..7dad782 --- /dev/null +++ b/backend/src/main/resources/db/migration/V1__init.sql @@ -0,0 +1,26 @@ +CREATE TABLE users ( + id BIGSERIAL PRIMARY KEY, + name TEXT NOT NULL, + default_hourly_rate_cents INTEGER NOT NULL CHECK (default_hourly_rate_cents >= 0) +); + +CREATE TABLE projects ( + id BIGSERIAL PRIMARY KEY, + name TEXT NOT NULL, + time_budget_minutes INTEGER NOT NULL CHECK (time_budget_minutes > 0), + cost_budget_cents INTEGER NOT NULL CHECK (cost_budget_cents >= 0), + -- NULL means: fall back to the logging user's default_hourly_rate_cents + hourly_rate_cents INTEGER NULL CHECK (hourly_rate_cents IS NULL OR hourly_rate_cents >= 0) +); + +CREATE TABLE time_entries ( + id BIGSERIAL PRIMARY KEY, + user_id BIGINT NOT NULL REFERENCES users(id), + project_id BIGINT NOT NULL REFERENCES projects(id), + entry_date DATE NOT NULL, + duration_minutes INTEGER NOT NULL CHECK (duration_minutes > 0 AND duration_minutes <= 1440) +); + +CREATE INDEX idx_time_entries_entry_date ON time_entries (entry_date); +CREATE INDEX idx_time_entries_project_id ON time_entries (project_id); +CREATE INDEX idx_time_entries_user_date ON time_entries (user_id, entry_date); diff --git a/backend/src/main/resources/db/migration/V2__seed_demo_data.sql b/backend/src/main/resources/db/migration/V2__seed_demo_data.sql new file mode 100644 index 0000000..f79049a --- /dev/null +++ b/backend/src/main/resources/db/migration/V2__seed_demo_data.sql @@ -0,0 +1,10 @@ +INSERT INTO users (name, default_hourly_rate_cents) VALUES + ('Alice Müller', 9500), -- 95.00 EUR/h default rate + ('Bob Schmidt', 8000), -- 80.00 EUR/h default rate + ('Clara Weber', 11000); -- 110.00 EUR/h default rate + +-- Project A: uses per-project rate override (120 EUR/h) +INSERT INTO projects (name, time_budget_minutes, cost_budget_cents, hourly_rate_cents) VALUES + ('Acme Relaunch', 12000, 150000000, 12000), -- 200h budget, 1500 EUR budget, 120 EUR/h + ('Internal Tools', 6000, 40000000, NULL), -- 100h budget, 400 EUR budget, user rate + ('Support & Ops', 3000, 24000000, NULL); -- 50h budget, 240 EUR budget, user rate