Skip to content

Commit

Permalink
Merge pull request #8 from Peter-512/fix-migrations
Browse files Browse the repository at this point in the history
[DX-23] fixed migrations
  • Loading branch information
Peter-512 authored Sep 17, 2023
2 parents fa7094c + 558023b commit 008ad3d
Showing 1 changed file with 44 additions and 10 deletions.
54 changes: 44 additions & 10 deletions supabase/migrations/20230915154915_projects.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,41 @@ create table if not exists "public"."skills" (
"color" text
);

-- alter table "public"."skills" add column "color" text;
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'skills' AND column_name = 'color') THEN
alter table "public"."skills" add column "color" text;
END IF;
END $$;

DO $$
BEGIN
IF NOT EXISTS (
SELECT constraint_name
FROM information_schema.table_constraints
WHERE table_name = 'your_table_name'
WHERE table_name = 'skills'
AND constraint_type = 'PRIMARY KEY'
) THEN
ALTER TABLE your_table_name
ADD CONSTRAINT pk_your_table_name PRIMARY KEY (column_name);
ALTER TABLE ONLY "public"."skills"
ADD CONSTRAINT "skills_pkey" PRIMARY KEY ("id");
END IF;
END $$;

DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'skills' AND column_name = 'color') THEN
alter table "public"."skills" add column "color" text;
END IF;
END $$;

DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_policy
WHERE polrelid = (SELECT oid FROM pg_class WHERE relname = 'skills')
) THEN
CREATE POLICY "Enable read access for all users" ON "public"."skills" FOR SELECT USING (true);
END IF;
END $$;

alter table "public"."skills" enable row level security;


create table "public"."team_members" (
"id" bigint generated by default as identity not null,
"name" text not null,
Expand All @@ -90,6 +101,29 @@ create table if not exists "public"."testimonials" (
"quote" text not null
);

DO $$
BEGIN
IF NOT EXISTS (
SELECT constraint_name
FROM information_schema.table_constraints
WHERE table_name = 'testimonials'
AND constraint_type = 'PRIMARY KEY'
) THEN
ALTER TABLE ONLY "public"."testimonials"
ADD CONSTRAINT "testimonials_pkey" PRIMARY KEY ("slug");
END IF;
END $$;

DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_policy
WHERE polrelid = (SELECT oid FROM pg_class WHERE relname = 'testimonials')
) THEN
CREATE POLICY "Enable read access for all users" ON "public"."testimonials" FOR SELECT USING (true);
END IF;
END $$;

alter table "public"."testimonials" enable row level security;

Expand Down

0 comments on commit 008ad3d

Please sign in to comment.