CREATE TABLE IF NOT EXISTS "invite_codes" ( "token" varchar(8) PRIMARY KEY NOT NULL, "user_id" integer, "granted" timestamp NOT NULL, "expires" timestamp DEFAULT '1970-01-01 00:00:00.000' ); --> statement-breakpoint DO $$ BEGIN ALTER TABLE "invite_codes" ADD CONSTRAINT "invite_codes_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; EXCEPTION WHEN duplicate_object THEN null; END $$;