CREATE TABLE IF NOT EXISTS "activities" (
    "id" VARCHAR NOT NULL UNIQUE,
    "description" VARCHAR NOT NULL,
    "time_spent" NUMERIC(3, 3) NOT NULL,
    "date_start" DATETIME NOT NULL,
    "date_end" DATETIME,
    "is_tracked" BOOLEAN NOT NULL DEFAULT false,
    "vetro_project_id" VARCHAR NOT NULL,
    "tag_id" VARCHAR NOT NULL,
    "project_id" VARCHAR NOT NULL,
    PRIMARY KEY("id"),
    FOREIGN KEY ("tag_id") REFERENCES "tags"("id") ON UPDATE NO ACTION ON DELETE NO ACTION,
    FOREIGN KEY ("vetro_project_id") REFERENCES "vetro_projects"("id") ON UPDATE NO ACTION ON DELETE NO ACTION
);

CREATE TABLE IF NOT EXISTS "tags" (
    "id" VARCHAR NOT NULL UNIQUE,
    "title" VARCHAR NOT NULL,
    PRIMARY KEY("id")
);

CREATE TABLE IF NOT EXISTS "vetro_projects" (
    "id" VARCHAR NOT NULL UNIQUE,
    "title" VARCHAR NOT NULL,
    PRIMARY KEY("id")
);
                            
CREATE TABLE IF NOT EXISTS "activity_types" (
    "id" INTEGER NOT NULL UNIQUE,
    "title" VARCHAR NOT NULL,
    PRIMARY KEY("id")
);

CREATE TABLE IF NOT EXISTS "time_entry" (
    "id" INTEGER PRIMARY KEY,
    "date" DATETIME NOT NULL,
    "description" VARCHAR NOT NULL,
    "activity_id" VARCHAR NOT NULL,
    "time_spent" NUMERIC(3, 3) NOT NULL,
    "task_id" INTEGER NOT NULL,
    "activity_type_id" INTEGER NOT NULL,
    FOREIGN KEY ("activity_id") REFERENCES "activities"("id") ON UPDATE NO ACTION ON DELETE NO ACTION,
    FOREIGN KEY ("task_id") REFERENCES "activities"("id") ON UPDATE NO ACTION ON DELETE NO ACTION,
    FOREIGN KEY ("activity_type_id") REFERENCES "activity_types"("id") ON UPDATE NO ACTION ON DELETE NO ACTION
);