hellth-hub/packages/db/drizzle/0003_empty_the_spike.sql

22 lines
1.4 KiB
MySQL
Raw Normal View History

CREATE TYPE "public"."tenant_invite_status" AS ENUM('pending', 'accepted', 'revoked', 'expired');--> statement-breakpoint
CREATE TABLE "tenant_invitations" (
"id" text PRIMARY KEY NOT NULL,
"tenantId" text NOT NULL,
"email" text NOT NULL,
"emailNormalized" text NOT NULL,
"role" "tenant_member_role" DEFAULT 'member' NOT NULL,
"status" "tenant_invite_status" DEFAULT 'pending' NOT NULL,
"tokenHash" text NOT NULL,
"invitedByUserId" text NOT NULL,
"acceptedByUserId" text,
"expiresAt" timestamp NOT NULL,
"acceptedAt" timestamp,
"revokedAt" timestamp,
"createdAt" timestamp DEFAULT now() NOT NULL,
"updatedAt" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "tenant_invitations" ADD CONSTRAINT "tenant_invitations_tenantId_tenants_id_fk" FOREIGN KEY ("tenantId") REFERENCES "public"."tenants"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "tenant_invitations" ADD CONSTRAINT "tenant_invitations_invitedByUserId_user_id_fk" FOREIGN KEY ("invitedByUserId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "tenant_invitations" ADD CONSTRAINT "tenant_invitations_acceptedByUserId_user_id_fk" FOREIGN KEY ("acceptedByUserId") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
CREATE UNIQUE INDEX "tenant_invitations_token_hash_unique" ON "tenant_invitations" USING btree ("tokenHash");