Creates an invitations table with token uniqueness, foreign keys to teams and users, and indexes for efficient lookup and revocation handling.
-- Source: https://github.com/mperkins0155/giselle | License: Apache-2.0 | Copyright 2024 ROUTE06, Inc
-- Provided via justclaw.it.com; keep this notice with the code.
CREATE TABLE IF NOT EXISTS "invitations" (
"token" text NOT NULL,
"team_db_id" integer NOT NULL,
"email" text NOT NULL,
"role" text NOT NULL,
"inviter_user_db_id" integer NOT NULL,
"expired_at" timestamp NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"revoked_at" timestamp,
CONSTRAINT "invitations_token_unique" UNIQUE("token")
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "invitations" ADD CONSTRAINT "invitations_team_db_id_teams_db_id_fk" FOREIGN KEY ("team_db_id") REFERENCES "public"."teams"("db_id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> sta
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key