19 lines · 715 B
-- editor: squashed from 1100_editor_containers.sql.

-- Editor "Run in container" sessions: one row per container start, closed with its billed minutes.
CREATE TABLE editor_container_sessions (
  id TEXT PRIMARY KEY,
  account_id TEXT NOT NULL REFERENCES accounts(id) ON DELETE CASCADE,
  repo_id TEXT NOT NULL REFERENCES repos(id) ON DELETE CASCADE,
  branch TEXT NOT NULL,
  instance_type TEXT NOT NULL,
  started_at INTEGER NOT NULL,
  stopped_at INTEGER,
  minutes INTEGER,
  stop_reason TEXT
);

CREATE INDEX editor_container_sessions_account ON editor_container_sessions(account_id, started_at);

CREATE INDEX editor_container_sessions_open ON editor_container_sessions(stopped_at) WHERE stopped_at IS NULL;