@COMMENT:Tworzenie struktury bazy danych wersji 1
^
CREATE TABLE EAC_APP_VERSION (
  ID INTEGER NOT NULL,
  DB_VERSION INTEGER NOT NULL,
  BIN_VERSION VARCHAR(50) CHARACTER SET WIN1250 NOT NULL COLLATE PXW_PLK,
  UPGRADE_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
  USER_NAME VARCHAR(20) CHARACTER SET WIN1250 NOT NULL COLLATE PXW_PLK,
  IS_FINISHED SMALLINT DEFAULT 0 NOT NULL);
^
ALTER TABLE EAC_APP_VERSION ADD PRIMARY KEY (ID);
^
CREATE GENERATOR EAC_APP_VERSION_ID_GEN;
^
CREATE TRIGGER BI_EAC_APP_VERSION_ID FOR EAC_APP_VERSION
ACTIVE BEFORE INSERT
POSITION 0
AS
BEGIN
  IF (NEW.ID IS NULL) THEN
      NEW.ID = GEN_ID(EAC_APP_VERSION_ID_GEN, 1);
END
^
@COMMENT:Tworzenie wpisu wersji
^
INSERT INTO EAC_APP_VERSION (DB_VERSION, BIN_VERSION, UPGRADE_DATE, USER_NAME, IS_FINISHED) VALUES (1, '1.0.0.0', CURRENT_TIMESTAMP, 'ADMIN', 0);
^

CREATE TABLE EAC_GENERATORY (
  ID INTEGER NOT NULL,
  DATA DATE,
  NAZWA VARCHAR(100) CHARACTER SET WIN1250 NOT NULL COLLATE PXW_PLK,
  WARTOSC INTEGER DEFAULT 0 NOT NULL,
  OKRES VARCHAR(1) CHARACTER SET WIN1250 NOT NULL COLLATE WIN1250,
  MASKA VARCHAR(30) CHARACTER SET WIN1250 COLLATE PXW_PLK);
^
ALTER TABLE EAC_GENERATORY ADD CONSTRAINT PK_EAC_GENERATORY PRIMARY KEY (ID);

^
CREATE TABLE EAC_UPR_KONTEKSTY (
  ID INTEGER NOT NULL,
  NAZWA VARCHAR(100) CHARACTER SET WIN1250 NOT NULL COLLATE PXW_PLK);
^
ALTER TABLE EAC_UPR_KONTEKSTY ADD CONSTRAINT PK_EAC_UPR_KONTEKSTY PRIMARY KEY (ID);
^
CREATE GENERATOR EAC_UPR_KONTEKSTY_ID_GEN;
^
CREATE TRIGGER BI_EAC_UPR_KONTEKSTY_ID FOR EAC_UPR_KONTEKSTY
ACTIVE BEFORE INSERT
POSITION 0
AS
BEGIN
  IF (NEW.ID IS NULL) THEN
      NEW.ID = GEN_ID(EAC_UPR_KONTEKSTY_ID_GEN, 1);
END
^

CREATE TABLE EAC_UPR (
  ID INTEGER NOT NULL,
  NAZWA VARCHAR(50) CHARACTER SET WIN1250 NOT NULL COLLATE PXW_PLK,
  ID_KONTEKSTU INTEGER NOT NULL);
^
ALTER TABLE EAC_UPR ADD CONSTRAINT PK_EAC_UPR PRIMARY KEY (ID);
^
ALTER TABLE EAC_UPR ADD CONSTRAINT UQ_EAC_UPR UNIQUE (NAZWA,ID_KONTEKSTU);
^
CREATE GENERATOR EAC_UPR_ID_GEN;
^
CREATE TRIGGER BI_EAC_UPR_ID FOR EAC_UPR
ACTIVE BEFORE INSERT
POSITION 0
AS
BEGIN
  IF (NEW.ID IS NULL) THEN
      NEW.ID = GEN_ID(EAC_UPR_ID_GEN, 1);
END
^

CREATE TABLE EAC_ROLE (
  ID INTEGER NOT NULL,
  NAZWA VARCHAR(50) CHARACTER SET WIN1250 NOT NULL COLLATE PXW_PLK);
^
ALTER TABLE EAC_ROLE ADD CONSTRAINT PK_EAC_ROLE PRIMARY KEY (ID);
^
ALTER TABLE EAC_ROLE ADD CONSTRAINT UQ_EAC_ROLE UNIQUE (NAZWA);
^
CREATE GENERATOR EAC_ROLE_ID_GEN;
^
CREATE TRIGGER BI_EAC_ROLE_ID FOR EAC_ROLE
ACTIVE BEFORE INSERT
POSITION 0
AS
BEGIN
  IF (NEW.ID IS NULL) THEN
      NEW.ID = GEN_ID(EAC_ROLE_ID_GEN, 1);
END
^

CREATE TABLE EAC_UPR_ROLI (
  ID_UPR INTEGER NOT NULL,
  ID_ROLI INTEGER NOT NULL);
^
ALTER TABLE EAC_UPR_ROLI ADD CONSTRAINT PK_EAC_UPR_ROLI PRIMARY KEY (ID_UPR,ID_ROLI);
^

CREATE TABLE EAC_UZYTKOWNICY (
  ID INTEGER NOT NULL,
  NAZWA VARCHAR(40) CHARACTER SET WIN1250 NOT NULL COLLATE PXW_PLK,
  NAZWA_WYSWIETLANA VARCHAR(100) CHARACTER SET WIN1250 NOT NULL COLLATE PXW_PLK,
  HASLO VARCHAR(50) CHARACTER SET WIN1250 NOT NULL COLLATE PXW_PLK,
  UTWORZYL VARCHAR(40) CHARACTER SET WIN1250 NOT NULL COLLATE PXW_PLK,
  DATA_UTWORZENIA TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
  ZMIENIL VARCHAR(40) CHARACTER SET WIN1250 COLLATE PXW_PLK,
  DATA_ZMIANY TIMESTAMP,
  STATUS SMALLINT DEFAULT 1 NOT NULL,
  ID_KONTAKTU INTEGER,
  ID_POJAZDU INTEGER);
^
ALTER TABLE EAC_UZYTKOWNICY ADD CONSTRAINT PK_EAC_UZYTKOWNICY PRIMARY KEY (ID);
^
ALTER TABLE EAC_UZYTKOWNICY ADD CONSTRAINT UQ_EAC_UZYTKOWNICY UNIQUE (NAZWA);
^
CREATE GENERATOR EAC_UZYTKOWNICY_ID_GEN;
^
CREATE TRIGGER BI_EAC_UZYTKOWNICY_ID FOR EAC_UZYTKOWNICY
ACTIVE BEFORE INSERT
POSITION 0
AS
BEGIN
  IF (NEW.ID IS NULL) THEN
      NEW.ID = GEN_ID(EAC_UZYTKOWNICY_ID_GEN, 1);
END
^

CREATE TABLE EAC_UPR_UZYTKOWNIKA (
  ID_UPR INTEGER NOT NULL,
  ID_UZYTKOWNIKA INTEGER NOT NULL,
  TYP SMALLINT DEFAULT 0 NOT NULL);
^
ALTER TABLE EAC_UPR_UZYTKOWNIKA ADD CONSTRAINT PK_EAC_UPR_UZYTKOWNIKA PRIMARY KEY (ID_UPR,ID_UZYTKOWNIKA);
^

CREATE TABLE EAC_UZYTKOWNICY_ROLE (
  ID_ROLI INTEGER NOT NULL,
  ID_UZYTKOWNIKA INTEGER NOT NULL);
^
ALTER TABLE EAC_UZYTKOWNICY_ROLE ADD CONSTRAINT PK_EAC_UZYTKOWNICY_ROLE PRIMARY KEY (ID_ROLI,ID_UZYTKOWNIKA);
^

CREATE TABLE EAC_BLOKADY (
  ID BIGINT NOT NULL,
  SESJA VARCHAR(40) CHARACTER SET WIN1250 NOT NULL COLLATE PXW_PLK,
  DATA_ZAL TIMESTAMP NOT NULL,
  DATA_WYG TIMESTAMP NOT NULL,
  HOST VARCHAR(100) CHARACTER SET WIN1250 NOT NULL COLLATE PXW_PLK,
  IP VARCHAR(20) CHARACTER SET WIN1250 NOT NULL COLLATE PXW_PLK,
  UZYTKOWNIK VARCHAR(30) CHARACTER SET WIN1250 NOT NULL COLLATE PXW_PLK,
  KONTEKST VARCHAR(50) CHARACTER SET WIN1250 NOT NULL COLLATE PXW_PLK,
  ID_WIERSZA INTEGER NOT NULL);
^
ALTER TABLE EAC_BLOKADY ADD CONSTRAINT PK_EAC_BLOKADY PRIMARY KEY (ID);
^
ALTER TABLE EAC_BLOKADY ADD CONSTRAINT UQ_EAC_BLOKADY UNIQUE (KONTEKST,ID_WIERSZA);
^
CREATE GENERATOR EAC_BLOKADY_ID_GEN;
^
CREATE TRIGGER BI_EAC_BLOKADY_ID FOR EAC_BLOKADY
ACTIVE BEFORE INSERT
POSITION 0
AS
BEGIN
  IF (NEW.ID IS NULL) THEN
      NEW.ID = GEN_ID(EAC_BLOKADY_ID_GEN, 1);
END
^
CREATE TABLE EAC_GLOBAL_SETTINGS (
  ID INTEGER NOT NULL,
  PARAM_NAME VARCHAR(50) CHARACTER SET WIN1250 NOT NULL COLLATE PXW_PLK,
  PARAM_VALUE VARCHAR(1000) CHARACTER SET WIN1250 COLLATE PXW_PLK);
^
ALTER TABLE EAC_GLOBAL_SETTINGS ADD CONSTRAINT PK_EAC_GLOBAL_SETTINGS PRIMARY KEY (ID);
^
ALTER TABLE EAC_GLOBAL_SETTINGS ADD CONSTRAINT UQ_EAC_GLOBAL_SETTINGS UNIQUE (PARAM_NAME);
^
CREATE GENERATOR EAC_GLOBAL_SETTINGS_ID_GEN;
^
CREATE TRIGGER BI_EAC_GLOBAL_SETTINGS_ID FOR EAC_GLOBAL_SETTINGS
ACTIVE BEFORE INSERT
POSITION 0
AS
BEGIN
  IF (NEW.ID IS NULL) THEN
      NEW.ID = GEN_ID(EAC_GLOBAL_SETTINGS_ID_GEN, 1);
END
^
INSERT INTO EAC_GLOBAL_SETTINGS (PARAM_NAME, PARAM_VALUE)
VALUES ('ATTACHMENT_VFS', 'baza_danych');