Refs #1 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
26 lines
930 B
SQL
26 lines
930 B
SQL
-- +goose Up
|
|
CREATE TABLE users (
|
|
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
email citext NOT NULL UNIQUE CHECK (length(email) BETWEEN 3 AND 320),
|
|
display_name text NOT NULL DEFAULT '' CHECK (length(display_name) <= 200),
|
|
password_hash text,
|
|
disabled_at timestamptz,
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
updated_at timestamptz NOT NULL DEFAULT now()
|
|
);
|
|
|
|
CREATE TABLE memberships (
|
|
org_id uuid NOT NULL REFERENCES orgs (id) ON DELETE CASCADE,
|
|
user_id uuid NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
|
is_owner boolean NOT NULL DEFAULT false,
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
PRIMARY KEY (org_id, user_id)
|
|
);
|
|
|
|
CREATE INDEX memberships_user_idx ON memberships (user_id);
|
|
CREATE UNIQUE INDEX memberships_one_owner_idx ON memberships (org_id) WHERE is_owner;
|
|
|
|
-- +goose Down
|
|
DROP TABLE memberships;
|
|
DROP TABLE users;
|