CREATE TABLE TASKS (
  id INTEGER PRIMARY KEY AUTO_INCREMENT,
  text varchar(64) NOT NULL,
  disabled BOOL DEFAULT(false)
);

CREATE TABLE AVAILABILITIES (
  id INTEGER PRIMARY KEY AUTO_INCREMENT,
  text varchar(32) NOT NULL,
  disabled BOOL DEFAULT(false)
);

CREATE TABLE USERS (
  id INTEGER PRIMARY KEY AUTO_INCREMENT,
  name varchar(64) NOT NULL,
  password binary(60) NOT NULL,
  admin BOOL NOT NULL DEFAULT(false)
);

CREATE TABLE EVENTS (
  id INTEGER PRIMARY KEY AUTO_INCREMENT,
  date DATETIME NOT NULL,
  description TEXT DEFAULT("")
);

CREATE TABLE USER_AVAILABILITIES (
  userID INTEGER NOT NULL,
  eventID INTEGER NOT NULL,
  availabilityID INTEGER NOT NULL,
  PRIMARY KEY (userID, eventID),
  FOREIGN KEY (userID) REFERENCES USERS(id) ON DELETE CASCADE,
  FOREIGN KEY (eventID) REFERENCES EVENTS(id) ON DELETE CASCADE,
  FOREIGN KEY (avaibID) REFERENCES AVAILABILITIES(id) ON DELETE RESTRICT,
);

CREATE TABLE USER_ASSIGNMENTS (
  eventID INTEGER NOT NULL,
  taskID INTEGER NOT NULL,
  userID INTEGER NOT NULL,
  PRIMARY KEY (eventID, taskID),
  FOREIGN KEY (userID) REFERENCES USERS(id) ON DELETE CASCADE,
  FOREIGN KEY (taskID) REFERENCES TASKS(id) ON DELETE RESTRICT,
  FOREIGN KEY (eventID) REFERENCES EVENTS(id) ON DELETE CASCADE
);