0016_org_invitations.sql 1.1 KB

1234567891011121314151617181920212223242526
  1. -- org_invitations — pending invites to a team org. Mirrors the
  2. -- project_invitations table shape but scoped to an org id and
  3. -- carrying an org role (owner/admin/developer/viewer) instead of
  4. -- a project-member role.
  5. CREATE TABLE IF NOT EXISTS "org_invitations" (
  6. "id" text PRIMARY KEY NOT NULL,
  7. "org_id" text NOT NULL REFERENCES "organizations"("id") ON DELETE CASCADE,
  8. "email" text NOT NULL,
  9. "role" text NOT NULL DEFAULT 'developer',
  10. "token_hash" text NOT NULL,
  11. "invited_by" text REFERENCES "users"("id"),
  12. "expires_at" timestamp with time zone NOT NULL,
  13. "accepted_at" timestamp with time zone,
  14. "revoked_at" timestamp with time zone,
  15. "created_at" timestamp with time zone DEFAULT now() NOT NULL
  16. );
  17. -- One pending invite per (org, email) at a time. A second invite to the
  18. -- same address replaces the prior one (handled at the service layer with
  19. -- an INSERT … ON CONFLICT … DO UPDATE).
  20. CREATE UNIQUE INDEX IF NOT EXISTS "org_invitations_org_email_idx"
  21. ON "org_invitations" USING btree ("org_id", "email");
  22. CREATE UNIQUE INDEX IF NOT EXISTS "org_invitations_token_idx"
  23. ON "org_invitations" USING btree ("token_hash");