Skip to content

Commit

Permalink
refactor: relations and allow users to have multiple addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
aarbanas committed Sep 20, 2024
1 parent f858ac9 commit 1f81cb1
Show file tree
Hide file tree
Showing 6 changed files with 1,028 additions and 64 deletions.
50 changes: 50 additions & 0 deletions drizzle/0004_strong_hellion.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
DO $$ BEGIN
CREATE TYPE "public"."addresstype" AS ENUM('permanent_residence', 'temporary_residence', 'work', 'other');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "profile_address" (
"profile_id" uuid NOT NULL,
"address_id" uuid NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
CONSTRAINT "profile_address_profile_id_address_id_pk" PRIMARY KEY("profile_id","address_id")
);
--> statement-breakpoint
ALTER TABLE "profile" DROP CONSTRAINT "profile_size_id_profile_size_id_fk";
--> statement-breakpoint
ALTER TABLE "profile" DROP CONSTRAINT "profile_address_id_address_id_fk";
--> statement-breakpoint
ALTER TABLE "profile" DROP CONSTRAINT "profile_work_status_id_work_status_id_fk";
--> statement-breakpoint
ALTER TABLE "address" ADD COLUMN "type" "addresstype" NOT NULL;--> statement-breakpoint
ALTER TABLE "address" ADD COLUMN "is_primary" boolean DEFAULT false;--> statement-breakpoint
ALTER TABLE "profile_size" ADD COLUMN "profile_id" uuid;--> statement-breakpoint
ALTER TABLE "work_status" ADD COLUMN "profile_id" uuid;--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "profile_address" ADD CONSTRAINT "profile_address_profile_id_profile_id_fk" FOREIGN KEY ("profile_id") REFERENCES "public"."profile"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "profile_address" ADD CONSTRAINT "profile_address_address_id_address_id_fk" FOREIGN KEY ("address_id") REFERENCES "public"."address"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "profile_size" ADD CONSTRAINT "profile_size_profile_id_profile_id_fk" FOREIGN KEY ("profile_id") REFERENCES "public"."profile"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "work_status" ADD CONSTRAINT "work_status_profile_id_profile_id_fk" FOREIGN KEY ("profile_id") REFERENCES "public"."profile"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
ALTER TABLE "profile" DROP COLUMN IF EXISTS "size_id";--> statement-breakpoint
ALTER TABLE "profile" DROP COLUMN IF EXISTS "address_id";--> statement-breakpoint
ALTER TABLE "profile" DROP COLUMN IF EXISTS "work_status_id";
Loading

0 comments on commit 1f81cb1

Please sign in to comment.