Skip to content

Commit

Permalink
fixes to postgres migrations to prevent primary key collisions (#160)…
Browse files Browse the repository at this point in the history
…; fixes to migrations to remove renaming lint
  • Loading branch information
michaelquigley committed Jan 17, 2023
1 parent 8ef5225 commit 8f51787
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions controller/store/sql/postgresql/003_v0_3_0_service_modes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ alter table services rename backend to backend_proxy_endpoint;
alter table services rename name to token;

alter table services rename to services_old;
alter sequence services_id_seq rename to services_id_seq_old;

create table services (
id serial primary key,
Expand All @@ -41,4 +42,6 @@ create table services (
insert into services (id, environment_id, z_id, token, share_mode, backend_mode, frontend_selection, frontend_endpoint, backend_proxy_endpoint, created_at, updated_at)
select id, environment_id, z_id, token, share_mode, backend_mode, frontend_selection, frontend_endpoint, backend_proxy_endpoint, created_at, updated_at from services_old;

select setval('services_id_seq', (select max(id) from services));

drop table services_old;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-- +migrate Up

alter table services rename to shares;
alter sequence services_id_seq1 rename to shares_id_seq1;
alter index services_pkey1 rename to shares_pkey1;
alter sequence services_id_seq rename to shares_id_seq;
alter index services_pkey1 rename to shares_pkey;
alter index services_token_key rename to shares_token_key;
alter index services_z_id_key1 rename to shares_z_id_key1;
alter index services_z_id_key1 rename to shares_z_id_key;
alter table shares rename constraint services_environment_id_fkey to shares_environment_id_fkey;
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- +migrate Up

alter table accounts rename to accounts_old;
alter sequence accounts_id_seq rename to accounts_id_seq_old;

create table accounts (
id serial primary key,
Expand All @@ -19,7 +20,13 @@ create table accounts (
insert into accounts(id, email, password, token, created_at, updated_at)
select id, email, password, token, created_at, updated_at from accounts_old;

select setval('accounts_id_seq', (select max(id) from accounts));

alter table environments drop constraint fk_accounts_id;
alter table environments add constraint fk_accounts_id foreign key (account_id) references accounts(id);

drop table accounts_old;
drop table accounts_old;

alter index accounts_pkey1 rename to accounts_pkey;
alter index accounts_email_key1 rename to accounts_email_key;
alter index accounts_token_key1 rename to accounts_token_key;

0 comments on commit 8f51787

Please sign in to comment.