--- channel-thread-members

CREATE TABLE channel_thread_members (
  id         BIGINT IDENTITY (1,1) PRIMARY KEY,
  thread_id  BIGINT      NOT NULL REFERENCES channel_threads (id),
  user_id    BIGINT      NOT NULL REFERENCES users (id),
  inviter_id BIGINT REFERENCES users (id),
  state      VARCHAR(64)     NOT NULL,
  created_at DATETIMEOFFSET NOT NULL DEFAULT SYSDATETIMEOFFSET(),
  updated_at DATETIMEOFFSET
);

CREATE UNIQUE INDEX channel_thread_members_thread_id_user_id_uniq
  ON channel_thread_members (thread_id, user_id);

-- channel-threads

ALTER TABLE channel_threads
  ADD total_members INTEGER NOT NULL DEFAULT 0;
