-- @block create table anwesenheit
CREATE TABLE "public"."anwesenheit" (
    "counter_id" SERIAL PRIMARY KEY,
    "timestamp" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
    "card_uid" varchar(255) COLLATE "pg_catalog"."default",
    "check_in_out" int2,
    "geraet_id" int2
);
COMMENT ON COLUMN "public"."anwesenheit"."check_in_out" IS '1=Check In 2=Check Out 255=Automatic Check Out';
COMMENT ON COLUMN "public"."anwesenheit"."geraet_id" IS 'ID des Lesegerätes';

-- @block create table personaldaten
CREATE TABLE "public"."personal_daten" (
    "personal_nummer" SERIAL PRIMARY KEY,
    "akiv_beschaeftig" bool,
    "vorname" varchar COLLATE "pg_catalog"."default",
    "nachname" varchar COLLATE "pg_catalog"."default",
    "geburtsdatum" date,
    "plz" varchar COLLATE "pg_catalog"."default",
    "adresse" varchar COLLATE "pg_catalog"."default",
    "geschlecht" numeric,
    "card_uid" varchar(255) COLLATE "pg_catalog"."default",
    "hauptbeschaeftigung_ort" int2
);
COMMENT ON COLUMN "public"."personal_daten"."akiv_beschaeftig" IS 'derzeit aktiv beschaeftigt : 1';
COMMENT ON COLUMN "public"."personal_daten"."geschlecht" IS 'w:1 m:2 div:3 kA:null ';
COMMENT ON COLUMN "public"."personal_daten"."card_uid" IS 'RFID-Karten-UID';
COMMENT ON COLUMN "public"."personal_daten"."hauptbeschaeftigung_ort" IS 'Chemnitz:1 Sayda:2';


-- @block drop tables
DROP TABLE IF EXISTS "public"."anwesenheit";
DROP TABLE IF EXISTS "public"."personal_daten";


-- @block insert into personal_daten
INSERT INTO personal_daten (
        personal_nummer,
        akiv_beschaeftig,
        vorname,
        nachname,
        geburtsdatum,
        plz,
        adresse,
        geschlecht,
        card_uid,
        hauptbeschaeftigung_ort
    )
VALUES (
        123,
        true,
        'Max',
        'Mustermann',
        now(),
        '00815',
        'Musterstrasse',
        1,
        'test_card',
        '1'
    );

-- @block select
SELECT *
FROM personal_daten;
