feat(store): add users and org memberships with single owner per org

Refs #1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-21 23:48:02 +01:00
1 parent c615c21af1
commit 95da376ac1
9 files changed
+356

No files matched your search

@@ -0,0 +1,25 @@
-- +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;