diff --git a/.gitignore b/.gitignore index e7c242b..11a8757 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ DB/pg_data .vscode node_modules +atlas.hcl diff --git a/DB/initdb/01_create_tables.sql b/DB/initdb/01_schema.sql similarity index 77% rename from DB/initdb/01_create_tables.sql rename to DB/initdb/01_schema.sql index 0c90c86..c987aef 100644 --- a/DB/initdb/01_create_tables.sql +++ b/DB/initdb/01_schema.sql @@ -98,16 +98,3 @@ CREATE TABLE "s_abwesenheit_typen" ( -- Adds crypto extension CREATE EXTENSION IF NOT EXISTS pgcrypto; - --- ---------------------------- --- Insert example data --- ---------------------------- - -INSERT INTO "s_personal_daten" ("personal_nummer", "aktiv_beschaeftigt", "vorname", "nachname", "geburtsdatum", "plz", "adresse", "geschlecht", "card_uid", "hauptbeschaeftigungs_ort", "arbeitszeit_per_tag", "arbeitszeit_min_start", "arbeitszeit_max_ende", "vorgesetzter_pers_nr") VALUES -(123, 't', 'Max', 'Mustermann', '2003-02-01', '08963', 'Altenburger Str. 44A', 1, 'acde-edca', 1, 7.5, '07:00:00', '20:00:00', 0); - -INSERT INTO "user_password" ("personal_nummer", "pass_hash") VALUES -(123, crypt('max_pass', gen_salt('bf'))); - -INSERT INTO "s_anwesenheit_typen" ("anwesenheit_id", "anwesenheit_name") VALUES (1, 'Büro'); -INSERT INTO "s_abwesenheit_typen" ("abwesenheit_id", "abwesenheit_name") VALUES (1, 'Urlaub'), (2, 'Krank'), (3, 'Kurzarbeit'); diff --git a/DB/initdb/03_sample_data.sql b/DB/initdb/03_sample_data.sql new file mode 100644 index 0000000..6d84496 --- /dev/null +++ b/DB/initdb/03_sample_data.sql @@ -0,0 +1,8 @@ +INSERT INTO "s_personal_daten" ("personal_nummer", "aktiv_beschaeftigt", "vorname", "nachname", "geburtsdatum", "plz", "adresse", "geschlecht", "card_uid", "hauptbeschaeftigungs_ort", "arbeitszeit_per_tag", "arbeitszeit_min_start", "arbeitszeit_max_ende", "vorgesetzter_pers_nr") VALUES +(123, 't', 'Max', 'Mustermann', '2003-02-01', '08963', 'Altenburger Str. 44A', 1, 'acde-edca', 1, 7.5, '07:00:00', '20:00:00', 0); + +INSERT INTO "user_password" ("personal_nummer", "pass_hash") VALUES +(123, crypt('max_pass', gen_salt('bf'))); + +INSERT INTO "s_anwesenheit_typen" ("anwesenheit_id", "anwesenheit_name") VALUES (1, 'Büro'); +INSERT INTO "s_abwesenheit_typen" ("abwesenheit_id", "abwesenheit_name") VALUES (1, 'Urlaub'), (2, 'Krank'), (3, 'Kurzarbeit'); diff --git a/Docker/.env.example b/Docker/.env.example index 8eea0f3..256e380 100644 --- a/Docker/.env.example +++ b/Docker/.env.example @@ -1,7 +1,7 @@ POSTGRES_USER=root POSTGRES_PASSWORD=very_secure -POSTGRES_API_USER=api_nuter -POSTGRES_API_PASSWORD=password +POSTGRES_API_USER=api_nutzer +POSTGRES_API_PASS=password POSTGRES_PATH=../DB POSTGRES_DB=arbeitszeitmessung EXPOSED_PORT=8000 diff --git a/atlas.hcl b/example.atlas.hcl similarity index 61% rename from atlas.hcl rename to example.atlas.hcl index ebc39a6..7e69ee9 100644 --- a/atlas.hcl +++ b/example.atlas.hcl @@ -1,10 +1,10 @@ # The "dev" environment represents our local testings. env "local" { - url = "postgres://root:very_secure@:5432/arbeitszeitmessung?search_path=public&sslmode=disable" + url = "postgres://user:password@:5432/database?search_path=public&sslmode=disable" migration { dir = "file://migrations" format = golang-migrate } dev = "docker://postgres/16/dev?search_path=public" - src = "file://schema.sql" + src = "file://DB/initdb/01_schema.sql" } diff --git a/migrations/20250802065143_initial.down.sql b/migrations/20250802065143_initial.down.sql new file mode 100644 index 0000000..1f8630e --- /dev/null +++ b/migrations/20250802065143_initial.down.sql @@ -0,0 +1,16 @@ +-- reverse: create "wochen_report" table +DROP TABLE "wochen_report"; +-- reverse: create "user_password" table +DROP TABLE "user_password"; +-- reverse: set comment to column: "geschlecht" on table: "personal_daten" +COMMENT ON COLUMN "personal_daten"."geschlecht" IS NULL; +-- reverse: create "personal_daten" table +DROP TABLE "personal_daten"; +-- reverse: set comment to column: "geraet_id" on table: "anwesenheit" +COMMENT ON COLUMN "anwesenheit"."geraet_id" IS NULL; +-- reverse: set comment to column: "check_in_out" on table: "anwesenheit" +COMMENT ON COLUMN "anwesenheit"."check_in_out" IS NULL; +-- reverse: create "anwesenheit" table +DROP TABLE "anwesenheit"; +-- reverse: create "abwesenheit" table +DROP TABLE "abwesenheit"; diff --git a/schema.sql b/migrations/20250802065143_initial.up.sql similarity index 82% rename from schema.sql rename to migrations/20250802065143_initial.up.sql index 55dcecd..5144756 100644 --- a/schema.sql +++ b/migrations/20250802065143_initial.up.sql @@ -1,4 +1,4 @@ --- Create "abwesenheit" table +-- create "abwesenheit" table CREATE TABLE "abwesenheit" ( "counter_id" bigserial NOT NULL, "card_uid" character varying(255) NULL, @@ -6,21 +6,20 @@ CREATE TABLE "abwesenheit" ( "datum" timestamptz NULL DEFAULT (now())::date, PRIMARY KEY ("counter_id") ); --- Create "anwesenheit" table +-- create "anwesenheit" table CREATE TABLE "anwesenheit" ( "counter_id" bigserial NOT NULL, "timestamp" timestamptz NULL DEFAULT CURRENT_TIMESTAMP, "card_uid" character varying(255) NULL, "check_in_out" smallint NULL, - "anwesenheit_type" smallint NULL, "geraet_id" smallint NULL, PRIMARY KEY ("counter_id") ); --- Set comment to column: "check_in_out" on table: "anwesenheit" +-- set comment to column: "check_in_out" on table: "anwesenheit" COMMENT ON COLUMN "anwesenheit"."check_in_out" IS '1=Check In 2=Check Out , 3=Check in Manuell, 4=Check out manuell255=Automatic Check Out'; --- Set comment to column: "geraet_id" on table: "anwesenheit" +-- set comment to column: "geraet_id" on table: "anwesenheit" COMMENT ON COLUMN "anwesenheit"."geraet_id" IS 'ID des Lesegerätes'; --- Create "personal_daten" table +-- create "personal_daten" table CREATE TABLE "personal_daten" ( "personal_nummer" integer NOT NULL, "aktiv_beschaeftigt" boolean NULL, @@ -38,16 +37,16 @@ CREATE TABLE "personal_daten" ( "vorgesetzter_pers_nr" integer NULL, PRIMARY KEY ("personal_nummer") ); --- Set comment to column: "geschlecht" on table: "personal_daten" +-- set comment to column: "geschlecht" on table: "personal_daten" COMMENT ON COLUMN "personal_daten"."geschlecht" IS '1==weiblich, 2==maennlich, 3==divers'; --- Create "user_password" table +-- create "user_password" table CREATE TABLE "user_password" ( "personal_nummer" integer NOT NULL, "pass_hash" text NULL, "zuletzt_geandert" timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY ("personal_nummer") ); --- Create "wochen_report" table +-- create "wochen_report" table CREATE TABLE "wochen_report" ( "id" serial NOT NULL, "personal_nummer" integer NULL, diff --git a/migrations/20250802075213_control_tables.down.sql b/migrations/20250802075213_control_tables.down.sql new file mode 100644 index 0000000..f8eef8a --- /dev/null +++ b/migrations/20250802075213_control_tables.down.sql @@ -0,0 +1,10 @@ +-- reverse rename "s_personal_daten" table +ALTER TABLE "s_personal_daten" RENAME TO "personal_daten"; + +DROP TABLE "s_personal_daten"; +-- reverse: create "s_anwesenheit_typen" table +DROP TABLE "s_anwesenheit_typen"; +-- reverse: create "s_abwesenheit_typen" table +DROP TABLE "s_abwesenheit_typen"; +-- reverse: modify "anwesenheit" table +ALTER TABLE "anwesenheit" DROP COLUMN "manuelle_buchung"; diff --git a/migrations/20250802075213_control_tables.up.sql b/migrations/20250802075213_control_tables.up.sql new file mode 100644 index 0000000..d372a37 --- /dev/null +++ b/migrations/20250802075213_control_tables.up.sql @@ -0,0 +1,16 @@ +-- modify "anwesenheit" table +ALTER TABLE "anwesenheit" ADD COLUMN "manuelle_buchung" boolean NULL; +-- create "s_abwesenheit_typen" table +CREATE TABLE "s_abwesenheit_typen" ( + "abwesenheit_id" smallint NOT NULL, + "abwesenheit_name" character varying(255) NULL, + PRIMARY KEY ("abwesenheit_id") +); +-- create "s_anwesenheit_typen" table +CREATE TABLE "s_anwesenheit_typen" ( + "anwesenheit_id" smallint NOT NULL, + "anwesenheit_name" character varying(255) NULL, + PRIMARY KEY ("anwesenheit_id") +); +-- create "s_personal_daten" table +ALTER TABLE "personal_daten" RENAME TO "s_personal_daten"; diff --git a/migrations/atlas.sum b/migrations/atlas.sum new file mode 100644 index 0000000..58b1ee2 --- /dev/null +++ b/migrations/atlas.sum @@ -0,0 +1,3 @@ +h1:5gPDmrcQS12KjKLuwN1ycTBHtbHbkzd7rUIj01uJrhA= +20250802065143_initial.up.sql h1:9cUWduWgONRfI5LV+b3nFvei6DKDqPxcNryKVg1xo80= +20250802075213_control_tables.up.sql h1:5vQLBHMM2Sa1FErP5gQUUHAoSiV2RQ0cOlMEEDFcoKA=