CREATE TABLE IF NOT EXISTS shared_view
(
  id BIGINT NOT NULL AUTO_INCREMENT,
  name VARCHAR(255) NOT NULL,
  description TEXT,
  link VARCHAR(255),
  view_payload TEXT,
  state VARCHAR(15),
  owner_id BIGINT NOT NULL,
  created_on DATETIME NOT NULL,
  token VARCHAR(255) UNIQUE,
  FOREIGN KEY (owner_id) REFERENCES user_account (id),
  PRIMARY KEY (id)
)
  ENGINE = InnoDB;

CREATE INDEX shared_view_INDEX_owner
  ON shared_view (owner_id);

CREATE TABLE IF NOT EXISTS shared_view_viewers
(
  shared_view_id BIGINT NOT NULL,
  viewers_id BIGINT NOT NULL,
  FOREIGN KEY (shared_view_id) REFERENCES shared_view (id),
  FOREIGN KEY (viewers_id) REFERENCES user_account (id)
)
  ENGINE = InnoDB;

CREATE INDEX shared_view_viewers_INDEX_shared_view
  ON shared_view_viewers (shared_view_id);

CREATE INDEX shared_view_viewers_INDEX_user_account
  ON shared_view_viewers (viewers_id);
