Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add migrations for Practitioner and Organization tables to add server_version date_created/edited timestamps #143

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- // add practitioner and orgs columns date created date edited server version
-- Migration SQL that makes the change goes here.

-- Add date created and date edited columns
ALTER TABLE team.practitioner ADD COLUMN IF NOT EXISTS date_created timestamp DEFAULT NOW();
ALTER TABLE team.practitioner ADD COLUMN IF NOT EXISTS date_edited timestamp DEFAULT NOW();
ALTER TABLE team.organization ADD COLUMN IF NOT EXISTS date_created timestamp DEFAULT NOW();
ALTER TABLE team.organization ADD COLUMN IF NOT EXISTS date_edited timestamp DEFAULT NOW();

-- Add server version columns
ALTER TABLE team.practitioner ADD COLUMN IF NOT EXISTS server_version bigint;
ALTER TABLE team.organization ADD COLUMN IF NOT EXISTS server_version bigint;


-- //@UNDO
-- SQL to undo the change goes here.

ALTER TABLE team.practitioner DROP COLUMN date_created;
ALTER TABLE team.practitioner DROP COLUMN date_edited;
ALTER TABLE team.organization DROP COLUMN date_created;
ALTER TABLE team.organization DROP COLUMN date_edited;

ALTER TABLE team.organization DROP COLUMN server_version;
ALTER TABLE team.organization DROP COLUMN server_version;


Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- // add practitioner and organization sequences
-- Migration SQL that makes the change goes here.
--Create Sequences
CREATE SEQUENCE IF NOT EXISTS team.practitioner_server_version_seq;
CREATE SEQUENCE IF NOT EXISTS team.organization_server_version_seq;

--populate sequences with Max server versions
SELECT setval('team.practitioner_server_version_seq',(SELECT max(server_version )+1 FROM team.practitioner));
SELECT setval('team.organization_server_version_seq',(SELECT max(server_version )+1 FROM team.organization));


-- //@UNDO
-- SQL to undo the change goes here.
DROP SEQUENCE IF EXISTS team.practitioner_server_version_seq;
DROP SEQUENCE IF EXISTS team.organization_server_version_seq;

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- // add server versions for existing practitioners and organizations
-- Migration SQL that makes the change goes here.


-- Update server version
update team.practitioner set server_version = nextval('team.practitioner_server_version_seq')
where server_version IS NULL;

update team.organization set server_version = nextval('team.organization_server_version_seq')
where server_version IS NULL;


-- //@UNDO
-- SQL to undo the change goes here.

update team.practitioner set server_version = NULL
where server_version IS NOT NULL;

update team.organization set server_version = NULL
where server_version IS NOT NULL;