PRAGMA journal_mode=WAL;
PRAGMA foreign_keys=on;

CREATE TABLE "mosservers" (
  "mosId" INTEGER PRIMARY KEY AUTOINCREMENT,
  "mosServer" TEXT
);

-- Default values ... might be omitted later?
INSERT INTO "mosservers" ("mosServer") VALUES
  ("Material.n24test.intern.mos"),
  ("StudioA.n24test.intern.mos"),
  ("Material.n24prod.intern.mos"),
  ("StudioA.n24prod.intern.mos")
;

CREATE TABLE "mosstatus" (
  "statusId" INTEGER PRIMARY KEY AUTOINCREMENT,
  "status" TEXT
);

INSERT INTO "mosstatus" ("status") VALUES
  ("NEW"),
  ("UPDATED"),
  ("MOVED")
;

CREATE TABLE "mosair" (
  "airId" INTEGER PRIMARY KEY AUTOINCREMENT,
  "objAir" TEXT
);

INSERT INTO "mosair" ("objAir") VALUES
  ("READY"),
  ("NOT READY")
;

CREATE TABLE "mosgroups" (
  "groupId" INTEGER PRIMARY KEY AUTOINCREMENT,
  "objGroup" TEXT
);

CREATE TABLE "mosusers" (
  "userId" INTEGER PRIMARY KEY AUTOINCREMENT,
  "name" TEXT,
  "email" TEXT
);

CREATE TABLE "mosobjects" (
  "objId" TEXT PRIMARY KEY,
  "mosId" INTEGER REFERENCES "mosservers" ("mosId"),
  "statusId" INTEGER REFERENCES "mosstatus" ("statusId"),
  "isDeleted" INTEGER,  -- 0/1 (boolean)
  "objSlug" TEXT,
  "objPath" TEXT,
  "objProxyPath" TEXT,
  "objAir" INTEGER REFERENCES "mosair" ("airId"),
  "created" INTEGER,
  "createdBy" INTEGER REFERENCES "mosusers" ("userId"),
  "changed" INTEGER,
  "changedBy" INTEGER REFERENCES "mosusers" ("userId"),
  "description" TEXT,
  "objDur" INTEGER,
  "groupId" INTEGER REFERENCES "mosgroups" ("groupId")
);

CREATE TABLE "mosobjlinks" (
    "objId" TEXT PRIMARY KEY REFERENCES "mosobjects" ("objId") ON DELETE CASCADE,
    "planningId" TEXT
);

CREATE TABLE "moslufs" (
    "objId" TEXT PRIMARY KEY REFERENCES "mosobjects" ("objId") ON DELETE CASCADE,
    "lufs" REAL,
    "lra" REAL,
    "ldiff" REAL
);

