
@COMMENT:Tworzenie wpisu wersji
^
INSERT INTO EAC_APP_VERSION (DB_VERSION, BIN_VERSION, UPGRADE_DATE, USER_NAME, IS_FINISHED) VALUES (7, '1.0.0.0', CURRENT_TIMESTAMP, 'ADMIN', 0);
^
@COMMENT:Tworzenie uprawnień aplikacji
^
INSERT INTO EAC_UPR_KONTEKSTY
VALUES (7, 'Import z KSeF');
^
INSERT INTO EAC_UPR_KONTEKSTY
VALUES (8, 'Eksport do KSeF');
^
INSERT INTO EAC_UPR
VALUES (20, 'Czytaj', 7);
^
INSERT INTO EAC_UPR
VALUES (21, 'Edytuj', 7);
^
INSERT INTO EAC_UPR
VALUES (22, 'Wykonaj', 7);
^
INSERT INTO EAC_UPR
VALUES (23, 'Czytaj', 8);
^
INSERT INTO EAC_UPR
VALUES (24, 'Edytuj', 8);
^
INSERT INTO EAC_UPR
VALUES (25, 'Wykonaj', 8);
^
INSERT INTO EAC_UPR_ROLI
VALUES (20, 1);
^
INSERT INTO EAC_UPR_ROLI
VALUES (21, 1);
^
INSERT INTO EAC_UPR_ROLI
VALUES (22, 1);
^
INSERT INTO EAC_UPR_ROLI
VALUES (23, 1);
^
INSERT INTO EAC_UPR_ROLI
VALUES (24, 1);
^
INSERT INTO EAC_UPR_ROLI
VALUES (25, 1);
^
@COMMENT:Tworzenie tabeli sesji KSeF
^
CREATE TABLE EAC_KSEF_SESJE (
    ID					INTEGER NOT NULL,
    NUMER_REF			VARCHAR(50) NOT NULL,
    TYP_SESJI			SMALLINT DEFAULT 1 NOT NULL,
    STATUS				SMALLINT NOT NULL,
    DATA_WAZNOSCI       TIMESTAMP NOT NULL,
    KOMENTARZ           VARCHAR(500),
	UTWORZYL            VARCHAR(15) NOT NULL,
    DATA_UTWORZENIA     TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
);
^
ALTER TABLE EAC_KSEF_SESJE ADD CONSTRAINT PK_EAC_KSEF_SESJE PRIMARY KEY (ID);
^
CREATE INDEX EAC_KSEF_SESJE_IDX1 ON EAC_KSEF_SESJE(NUMER_REF);
^
CREATE GENERATOR EAC_KSEF_SESJE_ID_GEN;
^
CREATE TRIGGER BI_EAC_KSEF_SESJE FOR EAC_KSEF_SESJE
ACTIVE BEFORE INSERT
POSITION 0
AS
BEGIN 
  IF (NEW.ID IS NULL) THEN
      NEW.ID = GEN_ID(EAC_KSEF_SESJE_ID_GEN, 1);
END
^
@COMMENT:Tworzenie tabeli statusów faktur sesji KSeF
^
CREATE TABLE EAC_KSEF_SESJE_FAKTURY (
    ID_FAKTURY			CHAR(36) NOT NULL,
    ID_SESJI			INTEGER NOT NULL,
    HASH_FAKTURY        VARCHAR(100),
    UPO_URL             VARCHAR(500),
    STATUS_KSEF			INTEGER,
    OPIS_STATUSU        VARCHAR(100)
);
^
ALTER TABLE EAC_KSEF_SESJE_FAKTURY ADD CONSTRAINT PK_EAC_KSEF_SESJE_FAKTURY PRIMARY KEY (ID_FAKTURY);
^
CREATE INDEX EAC_KSEF_SESJE_FAKTURY_IDX1 ON EAC_KSEF_SESJE_FAKTURY(ID_SESJI);
^
ALTER TABLE EAC_KSEF_SESJE_FAKTURY ADD CONSTRAINT FK_EAC_KSEF_SESJE_FAKTURY_1
    FOREIGN KEY (ID_FAKTURY)
    REFERENCES GM_KSEF (ID)
    ON DELETE CASCADE;
^
@COMMENT:Tworzenie tabeli upo faktur KSeF
^
CREATE TABLE EAC_KSEF_SESJE_FAKT_UPO (
    ID					CHAR(36) NOT NULL,
    DANE				BLOB SUB_TYPE BINARY
);
^
ALTER TABLE EAC_KSEF_SESJE_FAKT_UPO ADD CONSTRAINT PK_EAC_KSEF_SESJE_FAKT_UPO PRIMARY KEY (ID);
^
@COMMENT:Odblokowanie bazy danych
^
UPDATE EAC_APP_VERSION SET IS_FINISHED = 1 WHERE DB_VERSION = 7;