-- -*- mode:sql sql-product:sqlite -*-

-- CREATE TABLE abilityscores (
--   abilityscores_id INTEGER PRIMARY KEY,
--   flag_rep INTEGER NOT NULL,
--   short_name TEXT NOT NULL UNIQUE,
--   long_name TEXT NOT NULL UNIQUE
-- );


CREATE TABLE damagecategories (
  damagecategories_id INTEGER PRIMARY KEY,
  "name" TEXT NOT NULL UNIQUE,
  descr TEXT,
);

CREATE TABLE damagetypes (
  damagetypes_id INTEGER PRIMARY KEY,
  damagecategories_id INTEGER NOT NULL,
  "abbr" TEXT,
  "name" TEXT NOT NULL UNIQUE,
  FOREIGN KEY (damagecategories_id) REFERENCES damagecategories(damagecategories_id),
);

-- Joining table --
CREATE TABLE damagecategories_sourceentries (
	 id INTEGER PRIMARY KEY
  ,damagecategories_id INTEGER NOT NULL
  ,sourceentry_id INTEGER NOT NULL
  ,UNIQUE (id, damagecategories_id, sourceentry_id)
  ,FOREIGN KEY (damagecategories_id) REFERENCES damagecategories(damagecategories_id)
  ,FOREIGN KEY (sourceentry_id) REFERENCES sourceentries(sourceentry_id)
);

-- Joining table --
CREATE TABLE damagetypes_sourceentries (
	 id INTEGER PRIMARY KEY
  ,damagetypes_id INTEGER NOT NULL
  ,sourceentry_id INTEGER NOT NULL
  ,UNIQUE (id, damagetypes_id, sourceentry_id)
  ,FOREIGN KEY (damagetypes_id) REFERENCES damagetypes(damagetypes_id)
  ,FOREIGN KEY (sourceentry_id) REFERENCES sourceentries(sourceentry_id)
);