-- CreateTable
CREATE TABLE `Alapertek` (
    `szervizes` INTEGER NOT NULL,
    `mérnöki` INTEGER NOT NULL,
    `szervizesx2` INTEGER NOT NULL,
    `mérnökix2` INTEGER NOT NULL,

    PRIMARY KEY (`szervizes`, `mérnöki`, `szervizesx2`, `mérnökix2`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Aru_nev` (
    `ID` INTEGER NOT NULL AUTO_INCREMENT,
    `Nev` TEXT NOT NULL,
    `Megjegyzes` TEXT NOT NULL,
    `Image1` LONGBLOB NOT NULL,
    `Image2` LONGBLOB NOT NULL,
    `Image3` LONGBLOB NOT NULL,
    `barcode` TEXT NULL,

    UNIQUE INDEX `ID`(`ID`),
    PRIMARY KEY (`ID`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Bank` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `Kulcs` TEXT NOT NULL,
    `Munkaszam` TEXT NOT NULL,
    `Netto` INTEGER NOT NULL,
    `Brutto` INTEGER NOT NULL,
    `Esedekes` DATE NOT NULL,
    `Beerkezett` DATE NOT NULL,
    `MRC_szam` TEXT NOT NULL,
    `Megjegyzes` TEXT NOT NULL,
    `Munka_neve` TEXT NOT NULL,
    `Penznem` TEXT NULL DEFAULT 'HUF',

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Beszerzes` (
    `Kulcs` INTEGER NOT NULL AUTO_INCREMENT,
    `R_datum` DATE NOT NULL,
    `Project_kod` TEXT NOT NULL,
    `Be_tetel_neve` TEXT NOT NULL,
    `Mennyiseg` DECIMAL(11, 1) NOT NULL,
    `Me` TEXT NOT NULL,
    `E_ar` INTEGER NOT NULL,
    `Netto_ossz` INTEGER NOT NULL,
    `Brutto_ossz` INTEGER NOT NULL,
    `Fiz_mod` TEXT NOT NULL,
    `Be_ceg` TEXT NOT NULL,
    `R_azonositoja` TEXT NOT NULL,
    `Be_datum` DATE NOT NULL DEFAULT ('0000-00-00'),
    `Ellenorzo` TEXT NOT NULL,
    `Megjegyzes` TEXT NULL,

    UNIQUE INDEX `Kulcs`(`Kulcs`),
    PRIMARY KEY (`Kulcs`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Ceg_nev` (
    `ID` INTEGER NOT NULL AUTO_INCREMENT,
    `Nev` TEXT NOT NULL,
    `Cim` TEXT NOT NULL,
    `Megjegyzes` TEXT NOT NULL,

    UNIQUE INDEX `ID`(`ID`),
    PRIMARY KEY (`ID`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Dokument` (
    `kulcs` INTEGER NOT NULL AUTO_INCREMENT,
    `Project_kod` TEXT NOT NULL,
    `File_nev` TEXT NOT NULL,
    `Tipus` TEXT NOT NULL,
    `Datum` DATE NOT NULL,
    `Eleresi_ut` TEXT NOT NULL,

    UNIQUE INDEX `kulcs`(`kulcs`),
    PRIMARY KEY (`kulcs`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Hazi_penztar` (
    `ID` INTEGER NOT NULL AUTO_INCREMENT,
    `Datum` DATE NOT NULL,
    `Megnevezes` TEXT NOT NULL,
    `Bevetel` INTEGER NOT NULL,
    `Kiadas` INTEGER NOT NULL,
    `Projekt_kod` TEXT NOT NULL,
    `Megjegyzes` TEXT NOT NULL,

    UNIQUE INDEX `ID`(`ID`),
    PRIMARY KEY (`ID`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Kezelo` (
    `Azonosito` INTEGER NOT NULL AUTO_INCREMENT,
    `User_name` TEXT NOT NULL,
    `PW` TEXT NOT NULL,
    `Teljes_nev` TEXT NOT NULL,
    `Jogosult` TEXT NOT NULL,
    `szg` TEXT NOT NULL,
    `imei` TEXT NULL,

    UNIQUE INDEX `Azonosito`(`Azonosito`),
    PRIMARY KEY (`Azonosito`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Kiszallasok` (
    `kiszallasid` INTEGER NOT NULL AUTO_INCREMENT,
    `megnevezes` TEXT NOT NULL,
    `osszeg` INTEGER NOT NULL,

    PRIMARY KEY (`kiszallasid`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Munkak` (
    `Munka_kod` INTEGER NOT NULL AUTO_INCREMENT,
    `Megnevezes` TEXT NOT NULL,
    `Datum_kezd` DATE NOT NULL,
    `Datum_vege` DATE NOT NULL,
    `Felelos` TEXT NOT NULL,
    `Letrehozo` TEXT NOT NULL,
    `Ar_netto` INTEGER NOT NULL,
    `Szamlazott_netto` INTEGER NOT NULL,
    `Kiadasok_ossz` INTEGER NOT NULL,
    `Allapota` TEXT NOT NULL,
    `Megjegyzes` TEXT NOT NULL,
    `Nev_rovid` TEXT NOT NULL,
    `Fiz_modja` TEXT NOT NULL,
    `Esedekes` DATE NULL,
    `Beker` INTEGER NOT NULL,
    `Kiszallas` VARCHAR(45) NULL,
    `Munkaora` VARCHAR(45) NULL,
    `customer_id` INTEGER NULL,
    `project_folder` TEXT NULL,

    UNIQUE INDEX `Munka_kod`(`Munka_kod`),
    INDEX `customer_id`(`customer_id`),
    PRIMARY KEY (`Munka_kod`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Munkalap` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `project_kod` VARCHAR(15) NOT NULL,
    `munkalapszam` INTEGER NOT NULL,
    `leiras` TEXT NOT NULL,
    `anyagok` TEXT NOT NULL,
    `munkatvegzok` TEXT NOT NULL,
    `munkatelvegzo` TEXT NOT NULL,
    `igazolo` TEXT NOT NULL,
    `datum` DATE NOT NULL,
    `sign_path` TEXT NOT NULL,
    `pdf_path` TEXT NOT NULL,
    `email` TEXT NOT NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Rovid_nev` (
    `ID` INTEGER NOT NULL AUTO_INCREMENT,
    `Nev` VARCHAR(11) NOT NULL,

    UNIQUE INDEX `ID`(`ID`),
    PRIMARY KEY (`ID`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `alembic_version` (
    `version_num` VARCHAR(32) NOT NULL,

    PRIMARY KEY (`version_num`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `customers` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `name` TEXT NOT NULL,
    `address` TEXT NOT NULL,
    `tax_num` TEXT NULL,
    `phone_num` TEXT NULL,
    `contact_name` TEXT NULL,
    `contact_email` TEXT NULL,
    `contact_phone_num` TEXT NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `worksheet_validation_links` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `value` VARCHAR(80) NOT NULL,
    `created` DATETIME(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
    `worksheet_id` INTEGER NOT NULL,

    INDEX `worksheet_id`(`worksheet_id`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `worksheets` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `project_id` INTEGER NULL,
    `description` TEXT NOT NULL,
    `workers` LONGTEXT NOT NULL,
    `date` DATE NOT NULL,
    `creation_date` DATETIME(0) NOT NULL,
    `validation_date` DATETIME(0) NULL,
    `created_by` TEXT NOT NULL,
    `signed_by` TEXT NOT NULL,
    `signers_emails` TEXT NULL,
    `items` LONGTEXT NOT NULL,
    `signature` LONGTEXT NULL,
    `status` TEXT NOT NULL,

    INDEX `project_id`(`project_id`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `Munkak` ADD CONSTRAINT `Munkak_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customers`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;

-- AddForeignKey
ALTER TABLE `worksheet_validation_links` ADD CONSTRAINT `worksheet_validation_links_ibfk_1` FOREIGN KEY (`worksheet_id`) REFERENCES `worksheets`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;

-- AddForeignKey
ALTER TABLE `worksheets` ADD CONSTRAINT `worksheets_ibfk_1` FOREIGN KEY (`project_id`) REFERENCES `Munkak`(`Munka_kod`) ON DELETE RESTRICT ON UPDATE RESTRICT;
