-
Notifications
You must be signed in to change notification settings - Fork 3
Migrate snprc_scheduler to PostgreSQL #947
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
02eb218
Consolidate snprc_scheduler upgrade scripts into 0.000-25.000.sql
labkey-adam 831e61e
Bit o' cleanup
labkey-adam f8415a9
Load-bearing GO
labkey-adam 005a62d
Override getEarliestUpgradeVersion()
labkey-adam 519b8ee
PostgreSQL script
labkey-adam ef1e983
Fix
labkey-adam 7d0ca80
Clean up the script
labkey-adam ef55405
Bump to 26.000 to appease test
labkey-adam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| ModuleClass: org.labkey.snprc_scheduler.SNPRC_schedulerModule | ||
| Label: SNPRC EHR Procedure scheduling module | ||
| Description: The SNPRC scheduler provides timeline and procedure scheduling for snprc_ehr module. | ||
| SupportedDatabases: mssql | ||
| SupportedDatabases: mssql, pgsql | ||
| License: Apache 2.0 | ||
| LicenseURL: http://www.apache.org/licenses/LICENSE-2.0 | ||
| ManageVersion: false | ||
| ManageVersion: true |
198 changes: 198 additions & 0 deletions
198
snprc_scheduler/resources/schemas/dbscripts/postgresql/snprc_scheduler-0.000-25.000.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| CREATE SCHEMA snprc_scheduler; | ||
|
|
||
| /*==============================================================*/ | ||
| /* Table: Timeline */ | ||
| /*==============================================================*/ | ||
| CREATE TABLE snprc_scheduler.Timeline ( | ||
| TimelineId int not null, | ||
| RevisionNum int not null, | ||
| ProjectObjectId ENTITYID not null, | ||
| StartDate date null, | ||
| EndDate date null, | ||
| Description varchar(255) null, | ||
| LeadTech varchar(50) null, | ||
| Notes text null, | ||
| SchedulerNotes varchar(500) null, | ||
| QcState int null, | ||
| Created timestamp null, | ||
| CreatedBy int null, | ||
| Modified timestamp null, | ||
| ModifiedBy int null, | ||
| ObjectId ENTITYID not null, | ||
| RC varchar(50) null, | ||
| AnimalAccount varchar(255) null, | ||
| CONSTRAINT PK_Timeline PRIMARY KEY (TimelineId, RevisionNum), | ||
| CONSTRAINT AK_TimelineObjectId UNIQUE (ObjectId), | ||
| CONSTRAINT FK_Timeline_SNDProject FOREIGN KEY (ProjectObjectId) REFERENCES snd.projects (Objectid) | ||
| ); | ||
|
|
||
| COMMENT ON TABLE snprc_scheduler.Timeline IS 'Data Dict'; | ||
| COMMENT ON COLUMN snprc_scheduler.Timeline.Notes IS 'Added during 9/17/18 meeting. Size TBD'; | ||
| COMMENT ON COLUMN snprc_scheduler.Timeline.QcState IS 'Will handle isActive function'; | ||
|
|
||
| CREATE INDEX IDX_TimelineFK1 ON snprc_scheduler.Timeline ( | ||
| ProjectObjectId ASC | ||
| ); | ||
|
|
||
|
|
||
| /*==============================================================*/ | ||
| /* Table: TimelineItem */ | ||
| /*==============================================================*/ | ||
| CREATE TABLE snprc_scheduler.TimelineItem ( | ||
| TimelineItemId integer GENERATED BY DEFAULT AS IDENTITY, | ||
| ProjectitemId int null, | ||
| TimelineObjectId ENTITYID not null, | ||
| StudyDay int null, | ||
| ScheduleDate timestamp null, | ||
| Created timestamp null, | ||
| CreatedBy int null, | ||
| Modified timestamp null, | ||
| ModifiedBy int null, | ||
| ObjectId ENTITYID not null, | ||
| CONSTRAINT PK_TimelineItem PRIMARY KEY (TimelineItemId), | ||
| CONSTRAINT AK_TimelineItemObjectId UNIQUE (ObjectId), | ||
| CONSTRAINT FK_TimelineItem_Timeline FOREIGN KEY (TimelineObjectId) REFERENCES snprc_scheduler.Timeline (ObjectId), | ||
| CONSTRAINT FK_TimelineItem_SNDProjectItem FOREIGN KEY (ProjectItemId) REFERENCES snd.ProjectItems (ProjectItemId) | ||
| ); | ||
|
|
||
| CREATE INDEX IDXC_TimelineItemFK2 ON snprc_scheduler.TimelineItem ( | ||
| ProjectItemId ASC | ||
| ); | ||
|
|
||
| CREATE INDEX IDX_TimelineItemFK1 ON snprc_scheduler.TimelineItem ( | ||
| TimelineObjectId ASC | ||
| ); | ||
|
|
||
|
|
||
| /*==============================================================*/ | ||
| /* Table: TimelineProjectItem */ | ||
| /*==============================================================*/ | ||
| CREATE TABLE snprc_scheduler.TimelineProjectItem ( | ||
| ProjectItemId int not null, | ||
| TimelineObjectId ENTITYID not null, | ||
| TimelineFootNotes varchar(100) null, | ||
| SortOrder int not null, | ||
| Created timestamp null, | ||
| CreatedBy int null, | ||
| Modified timestamp null, | ||
| ModifiedBy int null, | ||
| ObjectId ENTITYID not null, | ||
| CONSTRAINT PK_TimelineProjectItem PRIMARY KEY (TimelineObjectId, ProjectItemId), | ||
| CONSTRAINT FK_TimelineProjectItem_SndProject FOREIGN KEY (ProjectItemId) REFERENCES snd.ProjectItems (ProjectitemId), | ||
| CONSTRAINT FK_TimelineProjectItem FOREIGN KEY (TimelineObjectId) REFERENCES snprc_scheduler.Timeline (ObjectId) | ||
| ); | ||
|
|
||
| CREATE INDEX IDX_TimelineProjectItemFK1 ON snprc_scheduler.TimelineProjectItem ( | ||
| TimelineObjectId ASC | ||
| ); | ||
|
|
||
| CREATE INDEX IDX_TimelineProjectItemFK2 ON snprc_scheduler.TimelineProjectItem ( | ||
| ProjectItemId ASC | ||
| ); | ||
|
|
||
|
|
||
| /*==============================================================*/ | ||
| /* Table: TimelineAnimalJunction */ | ||
| /*==============================================================*/ | ||
| CREATE TABLE snprc_scheduler.TimelineAnimalJunction ( | ||
| RowId integer GENERATED BY DEFAULT AS IDENTITY, | ||
| AnimalId varchar(50) not null, | ||
| TimelineObjectId ENTITYID not null, | ||
| EndDate date null, | ||
| Created timestamp null, | ||
| CreatedBy int null, | ||
| Modified timestamp null, | ||
| ModifiedBy int null, | ||
| ObjectId ENTITYID not null, | ||
| CONSTRAINT PK_TimelineAnimalJunction PRIMARY KEY (RowId), | ||
| CONSTRAINT FK_TimelineJunction_Timeline FOREIGN KEY (TimelineObjectId) REFERENCES snprc_scheduler.Timeline (ObjectId) | ||
| ); | ||
|
|
||
| CREATE INDEX IDXC_TimelineAnimalJunctionFK1 ON snprc_scheduler.TimelineAnimalJunction ( | ||
| TimelineObjectId ASC | ||
| ); | ||
|
|
||
| CREATE INDEX IDX_TimelineAnimalJunctionFK2 ON snprc_scheduler.TimelineAnimalJunction ( | ||
| AnimalId ASC | ||
| ); | ||
|
|
||
|
|
||
| /*==============================================================*/ | ||
| /* Table: StudyDayNotes */ | ||
| /*==============================================================*/ | ||
| CREATE TABLE snprc_scheduler.StudyDayNotes ( | ||
| ObjectId ENTITYID not null, | ||
| TimelineObjectId UNIQUEIDENTIFIER null, | ||
| StudyDay int null, | ||
| StudyDayNote text null, | ||
| Created timestamp null, | ||
| CreatedBy int null, | ||
| Modified timestamp null, | ||
| ModifiedBy int null, | ||
| CONSTRAINT PK_StudyDayNotes PRIMARY KEY (ObjectId) | ||
| ); | ||
|
|
||
| -- Using NULLS NOT DISTINCT (PostgreSQL 15+) to match SQL Server behavior for unique constraints with NULLs | ||
| CREATE UNIQUE INDEX idx_u_FK_to_TimelineItem ON snprc_scheduler.StudyDayNotes ( | ||
| TimelineObjectId ASC, | ||
| StudyDay ASC | ||
| ) NULLS NOT DISTINCT; | ||
|
|
||
|
|
||
| /*==============================================================*/ | ||
| /* Triggers & Integrity Functions */ | ||
| /*==============================================================*/ | ||
|
|
||
| -- Trigger Function: tiu_StudyDayNotes_fn | ||
| CREATE OR REPLACE FUNCTION snprc_scheduler.tiu_StudyDayNotes_fn() | ||
| RETURNS TRIGGER AS $$ | ||
| BEGIN | ||
| IF NOT EXISTS ( | ||
| SELECT 1 | ||
| FROM snprc_scheduler.TimelineItem t | ||
| WHERE t.StudyDay = NEW.StudyDay | ||
| AND t.TimelineObjectId = NEW.TimelineObjectId | ||
| ) THEN | ||
| RAISE EXCEPTION 'StudyDayNotes Trigger - TimelineObjectId - StudyDay pair do not exist SNPRC_Scheduler.Timelineitem. Cannot insert to SNPRC_Scheduler.StudyDayNotes'; | ||
| END IF; | ||
| RETURN NEW; | ||
| END; | ||
| $$ LANGUAGE plpgsql; | ||
|
|
||
| -- Trigger: tiu_StudyDayNotes | ||
| CREATE TRIGGER tiu_StudyDayNotes | ||
| BEFORE INSERT OR UPDATE | ||
| ON snprc_scheduler.StudyDayNotes | ||
| FOR EACH ROW | ||
| EXECUTE FUNCTION snprc_scheduler.tiu_StudyDayNotes_fn(); | ||
|
|
||
| ALTER TABLE snprc_scheduler.StudyDayNotes ENABLE TRIGGER tiu_StudyDayNotes; | ||
|
|
||
|
|
||
| -- Trigger Function: td_TimelineItem_fn | ||
| CREATE OR REPLACE FUNCTION snprc_scheduler.td_TimelineItem_fn() | ||
| RETURNS TRIGGER AS $$ | ||
| BEGIN | ||
| IF EXISTS ( | ||
| SELECT 1 | ||
| FROM snprc_scheduler.StudyDayNotes n | ||
| WHERE n.StudyDay = OLD.StudyDay AND n.TimelineObjectId = OLD.TimelineObjectId | ||
| ) AND NOT EXISTS ( | ||
| SELECT 1 | ||
| FROM snprc_scheduler.TimelineItem t | ||
| WHERE t.StudyDay = OLD.StudyDay AND t.TimelineObjectId = OLD.TimelineObjectId | ||
| ) THEN | ||
| RAISE EXCEPTION 'Timeline Item Trigger - TimelineItem has a StudyDayNote and only item on Study day. Note must be deleted first. Data not modified.'; | ||
| END IF; | ||
| RETURN OLD; | ||
| END; | ||
| $$ LANGUAGE plpgsql; | ||
|
|
||
| -- Trigger: td_TimelineItem | ||
| CREATE TRIGGER td_TimelineItem | ||
| AFTER DELETE | ||
| ON snprc_scheduler.TimelineItem | ||
| FOR EACH ROW | ||
| EXECUTE FUNCTION snprc_scheduler.td_TimelineItem_fn(); | ||
|
|
||
| ALTER TABLE snprc_scheduler.TimelineItem ENABLE TRIGGER td_TimelineItem; | ||
5 changes: 0 additions & 5 deletions
5
snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-0.00-18.21.sql
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be fine. I don't see any reason they would migrate to anything below pg 15. @labkey-mohara we'll have to make sure this is conveyed to them.