From ddcbb428d88935da04d6d78f7c16429e1f915d55 Mon Sep 17 00:00:00 2001 From: Adam Rauch Date: Sun, 14 Jun 2026 08:18:53 -0700 Subject: [PATCH] Migrate snprc_scheduler to PostgreSQL (#947) --- snprc_scheduler/module.properties | 4 +- .../snprc_scheduler-0.000-25.000.sql | 198 +++++ .../sqlserver/snprc_scheduler-0.00-18.21.sql | 5 - .../snprc_scheduler-0.000-25.000.sql | 756 ++++++++++++++++++ .../sqlserver/snprc_scheduler-18.21-18.22.sql | 276 ------- .../sqlserver/snprc_scheduler-18.22-18.23.sql | 120 --- .../sqlserver/snprc_scheduler-18.23-18.24.sql | 46 -- .../sqlserver/snprc_scheduler-18.24-18.25.sql | 13 - .../sqlserver/snprc_scheduler-18.25-18.26.sql | 16 - .../sqlserver/snprc_scheduler-18.26-18.27.sql | 7 - .../sqlserver/snprc_scheduler-18.27-18.28.sql | 77 -- .../sqlserver/snprc_scheduler-18.28-18.29.sql | 201 ----- .../sqlserver/snprc_scheduler-18.29-18.30.sql | 28 - .../sqlserver/snprc_scheduler-18.30-23.00.sql | 3 - .../SNPRC_schedulerModule.java | 10 +- 15 files changed, 964 insertions(+), 796 deletions(-) create mode 100644 snprc_scheduler/resources/schemas/dbscripts/postgresql/snprc_scheduler-0.000-25.000.sql delete mode 100644 snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-0.00-18.21.sql create mode 100644 snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-0.000-25.000.sql delete mode 100644 snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.21-18.22.sql delete mode 100644 snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.22-18.23.sql delete mode 100644 snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.23-18.24.sql delete mode 100644 snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.24-18.25.sql delete mode 100644 snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.25-18.26.sql delete mode 100644 snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.26-18.27.sql delete mode 100644 snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.27-18.28.sql delete mode 100644 snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.28-18.29.sql delete mode 100644 snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.29-18.30.sql delete mode 100644 snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.30-23.00.sql diff --git a/snprc_scheduler/module.properties b/snprc_scheduler/module.properties index 3d5fa7233..1b95bfa9d 100644 --- a/snprc_scheduler/module.properties +++ b/snprc_scheduler/module.properties @@ -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 diff --git a/snprc_scheduler/resources/schemas/dbscripts/postgresql/snprc_scheduler-0.000-25.000.sql b/snprc_scheduler/resources/schemas/dbscripts/postgresql/snprc_scheduler-0.000-25.000.sql new file mode 100644 index 000000000..84a902d0d --- /dev/null +++ b/snprc_scheduler/resources/schemas/dbscripts/postgresql/snprc_scheduler-0.000-25.000.sql @@ -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; diff --git a/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-0.00-18.21.sql b/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-0.00-18.21.sql deleted file mode 100644 index 197685052..000000000 --- a/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-0.00-18.21.sql +++ /dev/null @@ -1,5 +0,0 @@ - --- Create schema, tables, indexes, and constraints used for Snprc_scheduler module here --- All SQL VIEW definitions should be created in snprc_scheduler-create.sql and dropped in snprc_scheduler-drop.sql -CREATE SCHEMA snprc_scheduler; -GO \ No newline at end of file diff --git a/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-0.000-25.000.sql b/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-0.000-25.000.sql new file mode 100644 index 000000000..b5ab3c5e0 --- /dev/null +++ b/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-0.000-25.000.sql @@ -0,0 +1,756 @@ +-- Create schema, tables, indexes, and constraints used for Snprc_scheduler module here +-- All SQL VIEW definitions should be created in snprc_scheduler-create.sql and dropped in snprc_scheduler-drop.sql +CREATE SCHEMA snprc_scheduler; +GO + +/************************************************************************ +Create schema +Timeline, +TimelineItem, +Schedule, +TimelineAnimalJunction, +TimelinePojectItem + + +Do not have date bound reference from Timeline to TimelineAnimalJunction +Do not have date bound reference TimelineAnimalJunction to studyDataset_..._assignments + + +srr 10.30.18 + +Added qc and revisionNum columns +srr 11.01.2018 + +refactor keys, qcstate only in timeline. +pulled container from all tables + +Changed FK to snd.Projects back to composite. +Dropped ProjectObjectId from Timeline table. +srr 11.07.2018 + +************************************************************************/ + + + +/*==============================================================*/ +/* 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 nvarchar(255) null, + LeadTech nvarchar(50) null, + Notes nvarchar(Max) null, + SchedulerNotes nvarchar(500) null, + QcState int null, + Created datetime null, + CreatedBy int null, + Modified datetime null, + ModifiedBy int null, + ObjectId entityId not null +) +go +execute sp_addextendedproperty 'MS_Description', + 'Data Dict', + 'Schema', 'SNPRC_Scheduler', 'table', 'timeline' +go + +execute sp_addextendedproperty 'MS_Description', + 'Added during 9/17/18 meeting. Size TBD', + 'Schema', 'SNPRC_Scheduler', 'table', 'timeline', 'column', 'Notes' +go + +execute sp_addextendedproperty 'MS_Description', + 'Will handle isActive function', + 'Schema', 'SNPRC_Scheduler', 'table', 'timeline', 'column', 'qcstate' +go + + +alter table SNPRC_Scheduler.Timeline + add constraint PK_Timeline primary key nonclustered (TimelineId, RevisionNum) +go + +alter table SNPRC_Scheduler.Timeline + add constraint AK_TimelineObjectId unique (ObjectId) +go + + + +/*==============================================================*/ +/* Index: IDX_TimelineFK1 */ +/*==============================================================*/ +create clustered index IDX_TimelineFK1 on SNPRC_Scheduler.Timeline ( + ProjectObjectId ASC +); +go + +alter table SNPRC_Scheduler.Timeline + add constraint FK_Timeline_SNDProject foreign key (ProjectObjectId) +references snd.projects (Objectid); +go + + + + + +-- %% 111111111111 %%%%% end timeline + + +/*==============================================================*/ +/* Table: TimelineItem 2 */ +/*==============================================================*/ +create table SNPRC_Scheduler.TimelineItem ( + TimelineItemId int identity, + ProjectitemId int not null, + TimelineObjectId entityId not null, + StudyDay int null, + ScheduleDay int null, + Created datetime null, + CreatedBy int null, + Modified datetime null, + ModifiedBy int null, + ObjectId entityId not null +) + +go +alter table SNPRC_Scheduler.TimelineItem + add constraint PK_TimelineItem primary key nonclustered (TimelineItemId); + +go + +alter table SNPRC_Scheduler.TimelineItem + add constraint AK_TimelineItemObjectId unique (ObjectId); +go + + +/*==============================================================*/ +/* Index: IDXC_TimelineItemFK2 */ +/*==============================================================*/ +create clustered index IDXC_TimelineItemFK2 on SNPRC_Scheduler.TimelineItem ( + ProjectItemId ASC +); + +/*==============================================================*/ +/* Index: IDX_TimelineItemFK1 */ +/*==============================================================*/ +create index IDX_TimelineItemFK1 on SNPRC_Scheduler.TimelineItem ( + TimelineObjectId ASC +); +go + +alter table SNPRC_Scheduler.Timelineitem + add constraint FK_TimelineItem_Timeline foreign key (TimelineObjectId) +references SNPRC_Scheduler.Timeline (ObjectId); +go +alter table SNPRC_Scheduler.Timelineitem + add constraint FK_TimelineItem_SNDProjectItem foreign key (ProjectItemId) +references snd.ProjectItems (ProjectItemId); +go +-- %% 22222222222 %% end timelineItem + +/*==============================================================*/ +/* Table: Schedule 3 */ +/*==============================================================*/ +create table SNPRC_Scheduler.Schedule ( + ScheduleId int identity, + TimelineItemId int not null, + TargetDate datetime not null, + Created datetime null, + CreatedBy int null, + Modified datetime null, + ModifiedBy int null, + ObjectId EntityId not null +); + +go + +alter table SNPRC_Scheduler.Schedule + add constraint PK_Schedule primary key (ScheduleId); +go + + +/*==============================================================*/ +/* Index: IDX_ScheduleFK1 */ +/*==============================================================*/ +create index IDX_ScheduleFK1 on SNPRC_Scheduler.Schedule ( + TimelineItemId ASC +) + + +alter table SNPRC_Scheduler.Schedule + add constraint FK_ScheduleFK1 foreign key (TimelineItemId) +references SNPRC_Scheduler.TimelineItem (TimelineItemId) +go + + +-- %%% 333333 %%% end Schedule + +/*==============================================================*/ +/* Table: TimelineProjectItem 4 */ +/*==============================================================*/ +create table SNPRC_Scheduler.TimelineProjectItem ( + ProjectItemId int not null, + TimelineObjectId entityId not null, + TimelineId int not null, + TimelineRevisionNum int not null, + TimelineFootNotes nvarchar(100) null, + SortOrder int not null +) +go + +alter table SNPRC_Scheduler.TimelineProjectItem + add constraint PK_TimelineProjectItem primary key (TimelineObjectId, ProjectItemId) +go + +/*==============================================================*/ +/* Index: IDX_TimelineProjectItemFK1 */ +/*==============================================================*/ +create index IDX_TimelineProjectItemFK1 on SNPRC_Scheduler.TimelineProjectItem ( + TimelineObjectid ASC +) +go + +/*==============================================================*/ +/* Index: IDX_TimelineItemFK2 */ +/*==============================================================*/ +create index IDX_TimelineProjectItemFK2 on SNPRC_Scheduler.TimelineProjectItem ( + ProjectItemId ASC +) +go + +alter table SNPRC_Scheduler.TimelineProjectItem + add constraint FK_TimelineProjectItem_SndProject foreign key (ProjectItemId) +references snd.ProjectItems (ProjectitemId) +go + +alter table SNPRC_Scheduler.TimelineProjectItem + add constraint FK_TimelineProjectItem foreign key (TimelineObjectId) +references SNPRC_Scheduler.Timeline (ObjectId) +go + + + +-- %%%%%%% 4444444 %%%%%%%%%%%% end TimelineProjectItem + +/*==============================================================*/ +/* Table: timelineanimaljunction 5 */ +/*==============================================================*/ +create table SNPRC_Scheduler.TimelineAnimalJunction ( + RowId int identity, + AnimalId nvarchar(50) not null, + TimelineObjectId entityId null, + StartDate date null, + StopDate date null, + Created datetime null, + CreatedBy int null, + Modified datetime null, + ModifiedBy int null, + ObjectId entityId not null +) + +go + +alter table SNPRC_Scheduler.TimelineAnimalJunction + add constraint PK_TimelineAnimalJunction primary key nonclustered (RowId) +go + + +/*==============================================================*/ +/* Index: IDXC_TimelineAnimalJunctionFK1 */ +/*==============================================================*/ +create clustered index IDXC_TimelineAnimalJunctionFK1 on SNPRC_Scheduler.TimelineAnimalJunction ( + TimelineObjectId ASC +) +go + +/*==============================================================*/ +/* Index: IDX_TimelineAnimalJunctionFK2 */ +/*==============================================================*/ +create index IDX_TimelineAnimalJunctionFK2 on SNPRC_Scheduler.TimelineAnimalJunction ( + AnimalID ASC +) +go + + +alter table SNPRC_Scheduler.TimelineAnimalJunction + add constraint FK_TimelineJunction_Timeline foreign key (TimelineObjectId) +references SNPRC_Scheduler.Timeline (ObjectId) +go + +/****************************************************** + + rename snprc_scheduler.TimelineAnimalJunction.StopDate to EndDate + +srr 11.12.2018 +******************************************************/ +SET QUOTED_IDENTIFIER ON +SET ARITHABORT ON +SET NUMERIC_ROUNDABORT OFF +SET CONCAT_NULL_YIELDS_NULL ON +SET ANSI_NULLS ON +SET ANSI_PADDING ON +SET ANSI_WARNINGS ON + +GO +EXECUTE sp_rename N'snprc_scheduler.TimelineAnimalJunction.StopDate', N'Tmp_EndDate', 'COLUMN' +GO +EXECUTE sp_rename N'snprc_scheduler.TimelineAnimalJunction.Tmp_EndDate', N'EndDate', 'COLUMN' +GO +ALTER TABLE snprc_scheduler.TimelineAnimalJunction + DROP COLUMN StartDate +GO +-- END rename StopDate to EndDate + + + +/*####################################################################### +Change column: + ScheduleDay int +to + ScheduleDate date + + + + + +srr. 11.12.18 +####################################################################### */ + + + +ALTER TABLE [snprc_scheduler].[TimelineItem] DROP CONSTRAINT [FK_TimelineItem_Timeline]; +GO + +ALTER TABLE [snprc_scheduler].[TimelineItem] DROP CONSTRAINT [FK_TimelineItem_SNDProjectItem]; +GO + +ALTER TABLE [snprc_scheduler].[Schedule] DROP CONSTRAINT [FK_ScheduleFK1]; +GO + + +/****** Object: Table [snprc_scheduler].[TimelineItem] Script Date: 11/12/2018 11:42:24 AM ******/ +DROP TABLE [snprc_scheduler].[TimelineItem]; +GO + +/****** Object: Table [snprc_scheduler].[TimelineItem] Script Date: 11/12/2018 11:42:24 AM ******/ +SET ANSI_NULLS ON +GO + +SET QUOTED_IDENTIFIER ON +GO + + + +/**/ +/*==============================================================*/ +/* Table: TimelineItem 2 */ +/*==============================================================*/ +create table SNPRC_Scheduler.TimelineItem ( + TimelineItemId int identity, + ProjectitemId int not null, + TimelineObjectId entityId not null, + StudyDay int null, + ScheduleDate datetime null, + Created datetime null, + CreatedBy int null, + Modified datetime null, + ModifiedBy int null, + ObjectId entityId not null +) + + go +alter table SNPRC_Scheduler.TimelineItem + add constraint PK_TimelineItem primary key nonclustered (TimelineItemId) + +go + +alter table SNPRC_Scheduler.TimelineItem + add constraint AK_TimelineItemObjectId unique (ObjectId) +go + + +/*==============================================================*/ +/* Index: IDXC_TimelineItemFK2 */ +/*==============================================================*/ +create clustered index IDXC_TimelineItemFK2 on SNPRC_Scheduler.TimelineItem ( +ProjectItemId ASC +) + +/*==============================================================*/ +/* Index: IDX_TimelineItemFK1 */ +/*==============================================================*/ +create index IDX_TimelineItemFK1 on SNPRC_Scheduler.TimelineItem ( + TimelineObjectId ASC +) + go + +alter table SNPRC_Scheduler.Timelineitem + add constraint FK_TimelineItem_Timeline foreign key (TimelineObjectId) +references SNPRC_Scheduler.Timeline (ObjectId) +go +alter table SNPRC_Scheduler.Timelineitem + add constraint FK_TimelineItem_SNDProjectItem foreign key (ProjectItemId) +references snd.ProjectItems (ProjectItemId) +go + +alter table SNPRC_Scheduler.Schedule + add constraint FK_ScheduleFK1 foreign key (TimelineItemId) +references SNPRC_Scheduler.TimelineItem (TimelineItemId) +go + +/*********************************************** +Adding Created,Modified and ObjectId + +Populate ObjectId for current data, +set to NOT NULL + + +srr 11.28.2018 +srr 12.05.2018 Removed SETs +***********************************************/ +--BEGIN TRANSACTION +/* +SET QUOTED_IDENTIFIER ON +SET ARITHABORT ON +SET NUMERIC_ROUNDABORT OFF +SET CONCAT_NULL_YIELDS_NULL ON +SET ANSI_NULLS ON +SET ANSI_PADDING ON +SET ANSI_WARNINGS ON +*/ +--COMMIT +BEGIN TRANSACTION +GO +ALTER TABLE snprc_scheduler.TimelineProjectItem ADD + Created datetime NULL, +CreatedBy int NULL, +Modified datetime NULL, +ModifiedBy int NULL, +ObjectId dbo.ENTITYID NULL +GO +UPDATE snprc_scheduler.TimelineProjectItem +SET ObjectID = NEWID() +WHERE ObjectID IS null + GO +ALTER TABLE snprc_scheduler.TimelineProjectItem + DROP COLUMN TimelineId, TimelineRevisionNum +GO +ALTER TABLE snprc_scheduler.TimelineProjectItem + ALTER COLUMN ObjectId dbo.ENTITYID NOT NULL + + +ALTER TABLE snprc_scheduler.TimelineProjectItem SET (LOCK_ESCALATION = TABLE) +GO +if @@trancount = 1 +COMMIT +--select 'All is well' + +/*********************************************** +Table snprc_Scheduler.Schedule was refactored out +Dropping the table and FK + + +srr 11.30.2018 +***********************************************/ +ALTER TABLE [snprc_scheduler].[Schedule] DROP CONSTRAINT [FK_ScheduleFK1] +GO + +/****** Object: Table [snprc_scheduler].[Schedule] Script Date: 11/29/2018 11:16:22 AM ******/ +DROP TABLE [snprc_scheduler].[Schedule] +GO + +/******************************************* +TimelineObjectId should be NOT NULL +srr 12.04.2018 +*******************************************/ +DROP INDEX [IDXC_TimelineAnimalJunctionFK1] ON [snprc_scheduler].[TimelineAnimalJunction] WITH ( ONLINE = OFF ) +GO +-- set TimelineObjectId to NOT NULL +ALTER TABLE snprc_scheduler.TimelineAnimalJunction + ALTER COLUMN TimelineObjectId ENTITYID NOT NULL + + +CREATE CLUSTERED INDEX [IDXC_TimelineAnimalJunctionFK1] ON [snprc_scheduler].[TimelineAnimalJunction] +( +[TimelineObjectId] ASC +) +GO + +/******************************************* +Add RC to Timeline table +srr 01.08.2019 +*******************************************/ +ALTER TABLE snprc_scheduler.Timeline ADD + RC nvarchar(50) NULL +GO + +/******************************************* +Add AnimalAccount to Timeline table +Will hold a concated list of animal acccount +for this project. +NOTE: Reference only, not validated +srr 05.22.2019 +*******************************************/ +ALTER TABLE snprc_scheduler.Timeline + ADD AnimalAccount NVARCHAR(255) NULL; +GO +/****************************************** +Add alternate key to TimlelineItem +for reference to the new StudyDayNotes table +srr 05.22.2019 +*******************************************/ + +-- Reference is not to unique row +-- will handle integrity via a different mechanism +-- srr 05.28.2019 + +/* +ALTER TABLE snprc_scheduler.TimelineItem + ADD CONSTRAINT AK_AK_STUDYDAYNOTES_TIMELINE + UNIQUE ( + TimelineObjectId, + StudyDay + ); +GO +*/ +-- drop table if it exists +EXEC core.fn_dropifexists 'StudyDayNotes','snprc_scheduler', 'TABLE'; + + +/******************************************** +Create table to hold day specific study notes. + +C:\MySoftware\labkey\trunk\externalModules\snprcEHRModules +snprcEHRModules +srr 05.22.2019 +*********************************************/ +/*==============================================================*/ +/* Table: StudyDayNotes */ +/*==============================================================*/ +CREATE TABLE snprc_scheduler.StudyDayNotes +( + ObjectId ENTITYID NOT NULL, + TimelineObjectId UNIQUEIDENTIFIER NULL, + StudyDay INT NULL, + StudyDayNote NVARCHAR(MAX) NULL, + QcState INT NULL, + Created DATETIME NULL, + CreatedBy INT NULL, + Modified DATETIME NULL, + ModifiedBy INT NULL +); +GO + +ALTER TABLE snprc_scheduler.StudyDayNotes + ADD CONSTRAINT PK_STUDYDAYNOTES + PRIMARY KEY (ObjectId); +GO + +-- Reference is not to unique row +-- will handle integrity via a different mechanism +-- srr 05.24.2019 +/* +ALTER TABLE snprc_scheduler.StudyDayNotes + ADD CONSTRAINT FK_STUDYDAY_FK_TIMELI_TIMELINE + FOREIGN KEY ( + TimelineObjectId, + StudyDay + ) + REFERENCES snprc_scheduler.TimelineItem ( + TimelineObjectId, + StudyDay + ); +*/ + +/*************************************** +Integrity triggers + + + srr 05.28.2019 + **************************************/ + +/***************************** snprc_scheduler.tia_StudyDayNotes *****************************************/ + +/****** Object: Trigger [snprc_scheduler].[tia_StudyDayNotes] Script Date: 5/28/2019 10:50:47 AM ******/ + + +/* For referential integrity only. + Sole purpose is to prevent a note entry for (timeline-study day) that does not exists. + For INSERT and UPDATE + */ +CREATE TRIGGER snprc_scheduler.tiu_StudyDayNotes + ON snprc_scheduler.StudyDayNotes + FOR INSERT, UPDATE + AS +BEGIN +DECLARE @numrows INT, + @numnull INT, + @errno INT, + @errmsg VARCHAR(255); + +SELECT @numrows = @@rowcount; +IF @numrows = 0 + RETURN; +IF UPDATE(TimelineObjectId) + OR UPDATE(StudyDay) +BEGIN +IF +( + SELECT COUNT(*) + FROM snprc_scheduler.TimelineItem t + INNER JOIN INSERTED i + ON i.StudyDay = t.StudyDay + AND i.TimelineObjectId = t.TimelineObjectId +) < 1 +BEGIN +SELECT @errno = 50001, + @errmsg + = ' StudyDayNotes Trigger - TimelineObjectId - StudyDay pair do not exist SNPRC_Scheduler.Timelineitem. Cannot insert to SNPRC_Scheduler.StudyDayNotes'; +GOTO ERROR; +END; +END; + +-- Return if all is well +RETURN; + + /* Error handling */ +error: + RAISERROR('%d: %s', 16, 0, @errno, @errmsg); +-- LK will handle ROLLBACK TRANSACTION +END; +GO + +ALTER TABLE snprc_scheduler.StudyDayNotes ENABLE TRIGGER tiu_StudyDayNotes; +GO + +/***************************** snprc_scheduler.td_TimelineItem *****************************************/ + +CREATE TRIGGER [SNPRC_Scheduler].[td_TimelineItem] + ON [SNPRC_Scheduler].[TimelineItem] + FOR DELETE + AS +BEGIN +/***************************************************** + StudyDayNotes was an late addition to model. +This trigger’s sole purpose is to enforce referential integrity + between TimelineItem and StudyDayNotes tables +Each study day note requires one or more rows in the TimelineItem table. +This trigger used two table variables: +@Table_Notes holds rows that re required to have a matching row in the parent table. +@resultant uses EXCEPT operator to generate what the result of the delete will look like. +srr 06.07.19 + ****************************************************/ +DECLARE @numrows INT, + @numnull INT, + @errno INT, + @errmsg VARCHAR(255); + +-- No rows, nothing to do +SELECT @numrows = @@rowcount; +IF @numrows = 0 +RETURN; +-- No note rows for deleted items therefore nothing to do, exit +IF (SELECT COUNT(*) + FROM Deleted d + INNER JOIN SNPRC_Scheduler.StudyDayNotes n + ON n.StudyDay = d.StudyDay AND n.TimelineObjectId = d.TimelineObjectId) = 0 +RETURN; + + + +DECLARE @beforeCnt INT, + @afterCnt INT +-- table var to hold join columns +DECLARE @tbl_Notes TABLE( + StudyDay INT, + TimelineObjecId UNIQUEIDENTIFIER + ) +-- table var to hold resultant table +DECLARE @resultant TABLE( + StudyDay INT, + TimelineObjecId UNIQUEIDENTIFIER, + ProjectitemId int + ) + + -- these must exist in the post delete TimelineItem table +INSERT INTO @tbl_Notes(StudyDay, TimelineObjecId) +SELECT DISTINCT StudyDay, TimelineObjectId +FROM Deleted + -- EXCEPT used to generate the resultant table + INSERT INTO @resultant + ( + StudyDay, + TimelineObjecId, + ProjectitemId + ) +SELECT r.StudyDay, r.TimelineObjectId, r.ProjectitemId +FROM (-- new resultant table + SELECT b.TimelineItemId, b.ProjectitemId, b.TimelineObjectId, b.StudyDay + FROM SNPRC_Scheduler.TimelineItem b + INNER JOIN @tbl_Notes n + ON n.StudyDay = b.StudyDay AND n.TimelineObjecId = b.TimelineObjectId + EXCEPT + SELECT d.TimelineItemId, d.ProjectitemId, d.TimelineObjectId, d.StudyDay + FROM Deleted d + INNER JOIN @tbl_Notes n + ON n.StudyDay = d.StudyDay AND n.TimelineObjecId = d.TimelineObjectId + ) r + + + IF( SELECT COUNT(*) + --SELECT n.StudyDay, n.TimelineObjecId, r.StudyDay, r.TimelineObjecId + FROM @tbl_Notes n + LEFT OUTER JOIN @resultant r + ON r.StudyDay = n.StudyDay AND r.TimelineObjecId = n.TimelineObjecId + WHERE r.StudyDay IS NULL OR r.TimelineObjecId IS null) > 0 +BEGIN +SELECT @errno = 50001, + @errmsg + = ' Timeline Item Trigger - TimelineItem has a StudyDayNote and only item on Study day. Note must be deleted first. Data not modified.'; +GOTO ERROR; + +END; + + +-- Return if all is well +RETURN; + + /* Error handling */ +error: + RAISERROR('%d: %s', 16, 0, @errno, @errmsg); +-- LK will handle ROLLBACK TRANSACTION +END; +GO +ALTER TABLE snprc_scheduler.TimelineItem ENABLE TRIGGER td_TimelineItem; + +/******************************************/ +-- setting ProjectItemID to NOT NULL + + +ALTER TABLE snprc_scheduler.TimelineItem + ALTER COLUMN ProjectitemId INT NULL; + +--srr 05.29.19 +/*****************************************/ + +/****************************** +Added unique index to FK columns + to ensure no duplicate rows. + +srr 06.10.2019 +******************************/ + +/****** Object: Index [idx_u_FK_TimelineItem] Script Date: 6/10/2019 4:00:27 PM ******/ +CREATE UNIQUE NONCLUSTERED INDEX idx_u_FK_to_TimelineItem ON snprc_scheduler.StudyDayNotes +( + TimelineObjectId ASC, + StudyDay ASC +) +GO + +ALTER TABLE snprc_scheduler.StudyDayNotes + DROP COLUMN QcState +GO \ No newline at end of file diff --git a/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.21-18.22.sql b/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.21-18.22.sql deleted file mode 100644 index f011ece22..000000000 --- a/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.21-18.22.sql +++ /dev/null @@ -1,276 +0,0 @@ -/************************************************************************ -Create schema -Timeline, -TimelineItem, -Schedule, -TimelineAnimalJunction, -TimelinePojectItem - - -Do not have date bound reference from Timeline to TimelineAnimalJunction -Do not have date bound reference TimelineAnimalJunction to studyDataset_..._assignments - - -srr 10.30.18 - -Added qc and revisionNum columns -srr 11.01.2018 - -refactor keys, qcstate only in timeline. -pulled container from all tables - -Changed FK to snd.Projects back to composite. -Dropped ProjectObjectId from Timeline table. -srr 11.07.2018 - -************************************************************************/ - - - -/*==============================================================*/ -/* 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 nvarchar(255) null, - LeadTech nvarchar(50) null, - Notes nvarchar(Max) null, - SchedulerNotes nvarchar(500) null, - QcState int null, - Created datetime null, - CreatedBy int null, - Modified datetime null, - ModifiedBy int null, - ObjectId entityId not null -) -go -execute sp_addextendedproperty 'MS_Description', - 'Data Dict', - 'Schema', 'SNPRC_Scheduler', 'table', 'timeline' -go - -execute sp_addextendedproperty 'MS_Description', - 'Added during 9/17/18 meeting. Size TBD', - 'Schema', 'SNPRC_Scheduler', 'table', 'timeline', 'column', 'Notes' -go - -execute sp_addextendedproperty 'MS_Description', - 'Will handle isActive function', - 'Schema', 'SNPRC_Scheduler', 'table', 'timeline', 'column', 'qcstate' -go - - -alter table SNPRC_Scheduler.Timeline - add constraint PK_Timeline primary key nonclustered (TimelineId, RevisionNum) -go - -alter table SNPRC_Scheduler.Timeline - add constraint AK_TimelineObjectId unique (ObjectId) -go - - - -/*==============================================================*/ -/* Index: IDX_TimelineFK1 */ -/*==============================================================*/ -create clustered index IDX_TimelineFK1 on SNPRC_Scheduler.Timeline ( - ProjectObjectId ASC -) -go - -alter table SNPRC_Scheduler.Timeline - add constraint FK_Timeline_SNDProject foreign key (ProjectObjectId) -references snd.projects (Objectid) -go - - - - - --- %% 111111111111 %%%%% end timeline - - -/*==============================================================*/ -/* Table: TimelineItem 2 */ -/*==============================================================*/ -create table SNPRC_Scheduler.TimelineItem ( - TimelineItemId int identity, - ProjectitemId int not null, - TimelineObjectId entityId not null, - StudyDay int null, - ScheduleDay int null, - Created datetime null, - CreatedBy int null, - Modified datetime null, - ModifiedBy int null, - ObjectId entityId not null -) - -go -alter table SNPRC_Scheduler.TimelineItem - add constraint PK_TimelineItem primary key nonclustered (TimelineItemId) - -go - -alter table SNPRC_Scheduler.TimelineItem - add constraint AK_TimelineItemObjectId unique (ObjectId) -go - - -/*==============================================================*/ -/* Index: IDXC_TimelineItemFK2 */ -/*==============================================================*/ -create clustered index IDXC_TimelineItemFK2 on SNPRC_Scheduler.TimelineItem ( - ProjectItemId ASC -) - -/*==============================================================*/ -/* Index: IDX_TimelineItemFK1 */ -/*==============================================================*/ -create index IDX_TimelineItemFK1 on SNPRC_Scheduler.TimelineItem ( - TimelineObjectId ASC -) -go - -alter table SNPRC_Scheduler.Timelineitem - add constraint FK_TimelineItem_Timeline foreign key (TimelineObjectId) -references SNPRC_Scheduler.Timeline (ObjectId) -go -alter table SNPRC_Scheduler.Timelineitem - add constraint FK_TimelineItem_SNDProjectItem foreign key (ProjectItemId) -references snd.ProjectItems (ProjectItemId) -go --- %% 22222222222 %% end timelineItem - -/*==============================================================*/ -/* Table: Schedule 3 */ -/*==============================================================*/ -create table SNPRC_Scheduler.Schedule ( - ScheduleId int identity, - TimelineItemId int not null, - TargetDate datetime not null, - Created datetime null, - CreatedBy int null, - Modified datetime null, - ModifiedBy int null, - ObjectId EntityId not null -) - -go - -alter table SNPRC_Scheduler.Schedule - add constraint PK_Schedule primary key (ScheduleId) -go - - -/*==============================================================*/ -/* Index: IDX_ScheduleFK1 */ -/*==============================================================*/ -create index IDX_ScheduleFK1 on SNPRC_Scheduler.Schedule ( - TimelineItemId ASC -) - - -alter table SNPRC_Scheduler.Schedule - add constraint FK_ScheduleFK1 foreign key (TimelineItemId) -references SNPRC_Scheduler.TimelineItem (TimelineItemId) -go - - --- %%% 333333 %%% end Schedule - -/*==============================================================*/ -/* Table: TimelineProjectItem 4 */ -/*==============================================================*/ -create table SNPRC_Scheduler.TimelineProjectItem ( - ProjectItemId int not null, - TimelineObjectId entityId not null, - TimelineId int not null, - TimelineRevisionNum int not null, - TimelineFootNotes nvarchar(100) null, - SortOrder int not null -) -go - -alter table SNPRC_Scheduler.TimelineProjectItem - add constraint PK_TimelineProjectItem primary key (TimelineObjectId, ProjectItemId) -go - -/*==============================================================*/ -/* Index: IDX_TimelineProjectItemFK1 */ -/*==============================================================*/ -create index IDX_TimelineProjectItemFK1 on SNPRC_Scheduler.TimelineProjectItem ( - TimelineObjectid ASC -) -go - -/*==============================================================*/ -/* Index: IDX_TimelineItemFK2 */ -/*==============================================================*/ -create index IDX_TimelineProjectItemFK2 on SNPRC_Scheduler.TimelineProjectItem ( - ProjectItemId ASC -) -go - -alter table SNPRC_Scheduler.TimelineProjectItem - add constraint FK_TimelineProjectItem_SndProject foreign key (ProjectItemId) -references snd.ProjectItems (ProjectitemId) -go - -alter table SNPRC_Scheduler.TimelineProjectItem - add constraint FK_TimelineProjectItem foreign key (TimelineObjectId) -references SNPRC_Scheduler.Timeline (ObjectId) -go - - - --- %%%%%%% 4444444 %%%%%%%%%%%% end TimelineProjectItem - -/*==============================================================*/ -/* Table: timelineanimaljunction 5 */ -/*==============================================================*/ -create table SNPRC_Scheduler.TimelineAnimalJunction ( - RowId int identity, - AnimalId nvarchar(50) not null, - TimelineObjectId entityId null, - StartDate date null, - StopDate date null, - Created datetime null, - CreatedBy int null, - Modified datetime null, - ModifiedBy int null, - ObjectId entityId not null -) - -go - -alter table SNPRC_Scheduler.TimelineAnimalJunction - add constraint PK_TimelineAnimalJunction primary key nonclustered (RowId) -go - - -/*==============================================================*/ -/* Index: IDXC_TimelineAnimalJunctionFK1 */ -/*==============================================================*/ -create clustered index IDXC_TimelineAnimalJunctionFK1 on SNPRC_Scheduler.TimelineAnimalJunction ( - TimelineObjectId ASC -) -go - -/*==============================================================*/ -/* Index: IDX_TimelineAnimalJunctionFK2 */ -/*==============================================================*/ -create index IDX_TimelineAnimalJunctionFK2 on SNPRC_Scheduler.TimelineAnimalJunction ( - AnimalID ASC -) -go - - -alter table SNPRC_Scheduler.TimelineAnimalJunction - add constraint FK_TimelineJunction_Timeline foreign key (TimelineObjectId) -references SNPRC_Scheduler.Timeline (ObjectId) -go \ No newline at end of file diff --git a/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.22-18.23.sql b/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.22-18.23.sql deleted file mode 100644 index 0717d3745..000000000 --- a/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.22-18.23.sql +++ /dev/null @@ -1,120 +0,0 @@ -/****************************************************** - - rename snprc_scheduler.TimelineAnimalJunction.StopDate to EndDate - -srr 11.12.2018 -******************************************************/ -SET QUOTED_IDENTIFIER ON -SET ARITHABORT ON -SET NUMERIC_ROUNDABORT OFF -SET CONCAT_NULL_YIELDS_NULL ON -SET ANSI_NULLS ON -SET ANSI_PADDING ON -SET ANSI_WARNINGS ON - -GO -EXECUTE sp_rename N'snprc_scheduler.TimelineAnimalJunction.StopDate', N'Tmp_EndDate', 'COLUMN' -GO -EXECUTE sp_rename N'snprc_scheduler.TimelineAnimalJunction.Tmp_EndDate', N'EndDate', 'COLUMN' -GO -ALTER TABLE snprc_scheduler.TimelineAnimalJunction - DROP COLUMN StartDate -GO --- END rename StopDate to EndDate - - - -/*####################################################################### -Change column: - ScheduleDay int -to - ScheduleDate date - - - - - -srr. 11.12.18 -####################################################################### */ - - - -ALTER TABLE [snprc_scheduler].[TimelineItem] DROP CONSTRAINT [FK_TimelineItem_Timeline] -GO - -ALTER TABLE [snprc_scheduler].[TimelineItem] DROP CONSTRAINT [FK_TimelineItem_SNDProjectItem] -GO - -ALTER TABLE [snprc_scheduler].[Schedule] DROP CONSTRAINT [FK_ScheduleFK1] -GO - - -/****** Object: Table [snprc_scheduler].[TimelineItem] Script Date: 11/12/2018 11:42:24 AM ******/ -DROP TABLE [snprc_scheduler].[TimelineItem] -GO - -/****** Object: Table [snprc_scheduler].[TimelineItem] Script Date: 11/12/2018 11:42:24 AM ******/ -SET ANSI_NULLS ON -GO - -SET QUOTED_IDENTIFIER ON -GO - - - -/**/ -/*==============================================================*/ -/* Table: TimelineItem 2 */ -/*==============================================================*/ -create table SNPRC_Scheduler.TimelineItem ( - TimelineItemId int identity, - ProjectitemId int not null, - TimelineObjectId entityId not null, - StudyDay int null, - ScheduleDate datetime null, - Created datetime null, - CreatedBy int null, - Modified datetime null, - ModifiedBy int null, - ObjectId entityId not null -) - - go -alter table SNPRC_Scheduler.TimelineItem - add constraint PK_TimelineItem primary key nonclustered (TimelineItemId) - -go - -alter table SNPRC_Scheduler.TimelineItem - add constraint AK_TimelineItemObjectId unique (ObjectId) -go - - -/*==============================================================*/ -/* Index: IDXC_TimelineItemFK2 */ -/*==============================================================*/ -create clustered index IDXC_TimelineItemFK2 on SNPRC_Scheduler.TimelineItem ( -ProjectItemId ASC -) - -/*==============================================================*/ -/* Index: IDX_TimelineItemFK1 */ -/*==============================================================*/ -create index IDX_TimelineItemFK1 on SNPRC_Scheduler.TimelineItem ( - TimelineObjectId ASC -) - go - -alter table SNPRC_Scheduler.Timelineitem - add constraint FK_TimelineItem_Timeline foreign key (TimelineObjectId) -references SNPRC_Scheduler.Timeline (ObjectId) -go -alter table SNPRC_Scheduler.Timelineitem - add constraint FK_TimelineItem_SNDProjectItem foreign key (ProjectItemId) -references snd.ProjectItems (ProjectItemId) -go - -alter table SNPRC_Scheduler.Schedule - add constraint FK_ScheduleFK1 foreign key (TimelineItemId) -references SNPRC_Scheduler.TimelineItem (TimelineItemId) -go diff --git a/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.23-18.24.sql b/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.23-18.24.sql deleted file mode 100644 index a127ce96c..000000000 --- a/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.23-18.24.sql +++ /dev/null @@ -1,46 +0,0 @@ -/*********************************************** -Adding Created,Modified and ObjectId - -Populate ObjectId for current data, -set to NOT NULL - - -srr 11.28.2018 -srr 12.05.2018 Removed SETs -***********************************************/ ---BEGIN TRANSACTION -/* -SET QUOTED_IDENTIFIER ON -SET ARITHABORT ON -SET NUMERIC_ROUNDABORT OFF -SET CONCAT_NULL_YIELDS_NULL ON -SET ANSI_NULLS ON -SET ANSI_PADDING ON -SET ANSI_WARNINGS ON -*/ ---COMMIT -BEGIN TRANSACTION -GO -ALTER TABLE snprc_scheduler.TimelineProjectItem ADD - Created datetime NULL, -CreatedBy int NULL, -Modified datetime NULL, -ModifiedBy int NULL, -ObjectId dbo.ENTITYID NULL -GO -UPDATE snprc_scheduler.TimelineProjectItem -SET ObjectID = NEWID() -WHERE ObjectID IS null - GO -ALTER TABLE snprc_scheduler.TimelineProjectItem - DROP COLUMN TimelineId, TimelineRevisionNum -GO -ALTER TABLE snprc_scheduler.TimelineProjectItem - ALTER COLUMN ObjectId dbo.ENTITYID NOT NULL - - -ALTER TABLE snprc_scheduler.TimelineProjectItem SET (LOCK_ESCALATION = TABLE) -GO -if @@trancount = 1 -COMMIT ---select 'All is well' \ No newline at end of file diff --git a/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.24-18.25.sql b/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.24-18.25.sql deleted file mode 100644 index c573855be..000000000 --- a/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.24-18.25.sql +++ /dev/null @@ -1,13 +0,0 @@ -/*********************************************** -Table snprc_Scheduler.Schedule was refactored out -Dropping the table and FK - - -srr 11.30.2018 -***********************************************/ -ALTER TABLE [snprc_scheduler].[Schedule] DROP CONSTRAINT [FK_ScheduleFK1] -GO - -/****** Object: Table [snprc_scheduler].[Schedule] Script Date: 11/29/2018 11:16:22 AM ******/ -DROP TABLE [snprc_scheduler].[Schedule] -GO \ No newline at end of file diff --git a/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.25-18.26.sql b/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.25-18.26.sql deleted file mode 100644 index d280d5e38..000000000 --- a/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.25-18.26.sql +++ /dev/null @@ -1,16 +0,0 @@ -/******************************************* -TimelineObjectId should be NOT NULL -srr 12.04.2018 -*******************************************/ -DROP INDEX [IDXC_TimelineAnimalJunctionFK1] ON [snprc_scheduler].[TimelineAnimalJunction] WITH ( ONLINE = OFF ) -GO --- set TimelineObjectId to NOT NULL -ALTER TABLE snprc_scheduler.TimelineAnimalJunction - ALTER COLUMN TimelineObjectId ENTITYID NOT NULL - - -CREATE CLUSTERED INDEX [IDXC_TimelineAnimalJunctionFK1] ON [snprc_scheduler].[TimelineAnimalJunction] -( -[TimelineObjectId] ASC -) -GO \ No newline at end of file diff --git a/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.26-18.27.sql b/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.26-18.27.sql deleted file mode 100644 index 5f04f281c..000000000 --- a/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.26-18.27.sql +++ /dev/null @@ -1,7 +0,0 @@ -/******************************************* -Add RC to Timeline table -srr 01.08.2019 -*******************************************/ -ALTER TABLE snprc_scheduler.Timeline ADD - RC nvarchar(50) NULL -GO \ No newline at end of file diff --git a/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.27-18.28.sql b/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.27-18.28.sql deleted file mode 100644 index 042a66d69..000000000 --- a/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.27-18.28.sql +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************* -Add AnimalAccount to Timeline table -Will hold a concated list of animal acccount -for this project. -NOTE: Reference only, not validated -srr 05.22.2019 -*******************************************/ -ALTER TABLE snprc_scheduler.Timeline - ADD AnimalAccount NVARCHAR(255) NULL; -GO -/****************************************** -Add alternate key to TimlelineItem -for reference to the new StudyDayNotes table -srr 05.22.2019 -*******************************************/ - --- Reference is not to unique row --- will handle integrity via a different mechanism --- srr 05.28.2019 - -/* -ALTER TABLE snprc_scheduler.TimelineItem - ADD CONSTRAINT AK_AK_STUDYDAYNOTES_TIMELINE - UNIQUE ( - TimelineObjectId, - StudyDay - ); -GO -*/ --- drop table if it exists -EXEC core.fn_dropifexists 'StudyDayNotes','snprc_scheduler', 'TABLE'; - - -/******************************************** -Create table to hold day specific study notes. - -C:\MySoftware\labkey\trunk\externalModules\snprcEHRModules -snprcEHRModules -srr 05.22.2019 -*********************************************/ -/*==============================================================*/ -/* Table: StudyDayNotes */ -/*==============================================================*/ -CREATE TABLE snprc_scheduler.StudyDayNotes -( - ObjectId ENTITYID NOT NULL, - TimelineObjectId UNIQUEIDENTIFIER NULL, - StudyDay INT NULL, - StudyDayNote NVARCHAR(MAX) NULL, - QcState INT NULL, - Created DATETIME NULL, - CreatedBy INT NULL, - Modified DATETIME NULL, - ModifiedBy INT NULL -); -GO - -ALTER TABLE snprc_scheduler.StudyDayNotes - ADD CONSTRAINT PK_STUDYDAYNOTES - PRIMARY KEY (ObjectId); -GO - --- Reference is not to unique row --- will handle integrity via a different mechanism --- srr 05.24.2019 -/* -ALTER TABLE snprc_scheduler.StudyDayNotes - ADD CONSTRAINT FK_STUDYDAY_FK_TIMELI_TIMELINE - FOREIGN KEY ( - TimelineObjectId, - StudyDay - ) - REFERENCES snprc_scheduler.TimelineItem ( - TimelineObjectId, - StudyDay - ); -*/ \ No newline at end of file diff --git a/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.28-18.29.sql b/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.28-18.29.sql deleted file mode 100644 index 2d58c2ad6..000000000 --- a/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.28-18.29.sql +++ /dev/null @@ -1,201 +0,0 @@ -/*************************************** -Integrity triggers - - - srr 05.28.2019 - **************************************/ - -/***************************** snprc_scheduler.tia_StudyDayNotes *****************************************/ - -IF EXISTS -( - SELECT 1 - FROM sysobjects - WHERE id = OBJECT_ID('snprc_scheduler.tiu_StudyDayNotes') - AND type = 'TR' -) -DROP TRIGGER snprc_scheduler.tiu_StudyDayNotes; -GO - - -/****** Object: Trigger [snprc_scheduler].[tia_StudyDayNotes] Script Date: 5/28/2019 10:50:47 AM ******/ -/* -SET ANSI_NULLS ON -GO - -SET QUOTED_IDENTIFIER ON -GO -*/ - - -/* For referential integrity only. - Sole purpose is to prevent a note entry for (timeline-study day) that does not exists. - For INSERT and UPDATE - */ -CREATE TRIGGER snprc_scheduler.tiu_StudyDayNotes - ON snprc_scheduler.StudyDayNotes - FOR INSERT, UPDATE - AS -BEGIN -DECLARE @numrows INT, - @numnull INT, - @errno INT, - @errmsg VARCHAR(255); - -SELECT @numrows = @@rowcount; -IF @numrows = 0 - RETURN; -IF UPDATE(TimelineObjectId) - OR UPDATE(StudyDay) -BEGIN -IF -( - SELECT COUNT(*) - FROM snprc_scheduler.TimelineItem t - INNER JOIN INSERTED i - ON i.StudyDay = t.StudyDay - AND i.TimelineObjectId = t.TimelineObjectId -) < 1 -BEGIN -SELECT @errno = 50001, - @errmsg - = ' StudyDayNotes Trigger - TimelineObjectId - StudyDay pair do not exist SNPRC_Scheduler.Timelineitem. Cannot insert to SNPRC_Scheduler.StudyDayNotes'; -GOTO ERROR; -END; -END; - --- Return if all is well -RETURN; - - /* Error handling */ -error: - RAISERROR('%d: %s', 16, 0, @errno, @errmsg); --- LK will handle ROLLBACK TRANSACTION -END; -GO - -ALTER TABLE snprc_scheduler.StudyDayNotes ENABLE TRIGGER tiu_StudyDayNotes; - - - -/***************************** snprc_scheduler.td_TimelineItem *****************************************/ - - -IF EXISTS -( - SELECT 1 - FROM sysobjects - WHERE id = OBJECT_ID('snprc_scheduler.td_TimelineItem') - AND type = 'TR' -) -DROP TRIGGER snprc_scheduler.td_TimelineItem; -GO - - -CREATE TRIGGER [SNPRC_Scheduler].[td_TimelineItem] - ON [SNPRC_Scheduler].[TimelineItem] - FOR DELETE - AS -BEGIN -/***************************************************** - StudyDayNotes was an late addition to model. -This trigger’s sole purpose is to enforce referential integrity - between TimelineItem and StudyDayNotes tables -Each study day note requires one or more rows in the TimelineItem table. -This trigger used two table variables: -@Table_Notes holds rows that re required to have a matching row in the parent table. -@resultant uses EXCEPT operator to generate what the result of the delete will look like. -srr 06.07.19 - ****************************************************/ -DECLARE @numrows INT, - @numnull INT, - @errno INT, - @errmsg VARCHAR(255); - --- No rows, nothing to do -SELECT @numrows = @@rowcount; -IF @numrows = 0 -RETURN; --- No note rows for deleted items therefore nothing to do, exit -IF (SELECT COUNT(*) - FROM Deleted d - INNER JOIN SNPRC_Scheduler.StudyDayNotes n - ON n.StudyDay = d.StudyDay AND n.TimelineObjectId = d.TimelineObjectId) = 0 -RETURN; - - - -DECLARE @beforeCnt INT, - @afterCnt INT --- table var to hold join columns -DECLARE @tbl_Notes TABLE( - StudyDay INT, - TimelineObjecId UNIQUEIDENTIFIER - ) --- table var to hold resultant table -DECLARE @resultant TABLE( - StudyDay INT, - TimelineObjecId UNIQUEIDENTIFIER, - ProjectitemId int - ) - - -- these must exist in the post delete TimelineItem table -INSERT INTO @tbl_Notes(StudyDay, TimelineObjecId) -SELECT DISTINCT StudyDay, TimelineObjectId -FROM Deleted - -- EXCEPT used to generate the resultant table - INSERT INTO @resultant - ( - StudyDay, - TimelineObjecId, - ProjectitemId - ) -SELECT r.StudyDay, r.TimelineObjectId, r.ProjectitemId -FROM (-- new resultant table - SELECT b.TimelineItemId, b.ProjectitemId, b.TimelineObjectId, b.StudyDay - FROM SNPRC_Scheduler.TimelineItem b - INNER JOIN @tbl_Notes n - ON n.StudyDay = b.StudyDay AND n.TimelineObjecId = b.TimelineObjectId - EXCEPT - SELECT d.TimelineItemId, d.ProjectitemId, d.TimelineObjectId, d.StudyDay - FROM Deleted d - INNER JOIN @tbl_Notes n - ON n.StudyDay = d.StudyDay AND n.TimelineObjecId = d.TimelineObjectId - ) r - - - IF( SELECT COUNT(*) - --SELECT n.StudyDay, n.TimelineObjecId, r.StudyDay, r.TimelineObjecId - FROM @tbl_Notes n - LEFT OUTER JOIN @resultant r - ON r.StudyDay = n.StudyDay AND r.TimelineObjecId = n.TimelineObjecId - WHERE r.StudyDay IS NULL OR r.TimelineObjecId IS null) > 0 -BEGIN -SELECT @errno = 50001, - @errmsg - = ' Timeline Item Trigger - TimelineItem has a StudyDayNote and only item on Study day. Note must be deleted first. Data not modified.'; -GOTO ERROR; - -END; - - --- Return if all is well -RETURN; - - /* Error handling */ -error: - RAISERROR('%d: %s', 16, 0, @errno, @errmsg); --- LK will handle ROLLBACK TRANSACTION -END; -GO -ALTER TABLE snprc_scheduler.TimelineItem ENABLE TRIGGER td_TimelineItem; - -/******************************************/ --- setting ProjectItemID to NOT NULL - - -ALTER TABLE snprc_scheduler.TimelineItem - ALTER COLUMN ProjectitemId INT NULL; - ---srr 05.29.19 -/*****************************************/ \ No newline at end of file diff --git a/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.29-18.30.sql b/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.29-18.30.sql deleted file mode 100644 index 02a0c4a2a..000000000 --- a/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.29-18.30.sql +++ /dev/null @@ -1,28 +0,0 @@ -/****************************** -Added unique index to FK columns - to ensure no duplicate rows. - -srr 06.10.2019 -******************************/ - --- delete index if it exists -if exists (select 1 - from sysindexes - where id = object_id('snprc_scheduler.StudyDayNotes') - and name = 'idx_u_FK_to_TimelineItem' - - and indid > 0 - and indid < 255) -drop index idx_u_FK_to_TimelineItem ON snprc_scheduler.StudyDayNotes - -go - - - -/****** Object: Index [idx_u_FK_TimelineItem] Script Date: 6/10/2019 4:00:27 PM ******/ -CREATE UNIQUE NONCLUSTERED INDEX idx_u_FK_to_TimelineItem ON snprc_scheduler.StudyDayNotes -( - TimelineObjectId ASC, - StudyDay ASC -) -GO diff --git a/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.30-23.00.sql b/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.30-23.00.sql deleted file mode 100644 index 46f6655c8..000000000 --- a/snprc_scheduler/resources/schemas/dbscripts/sqlserver/snprc_scheduler-18.30-23.00.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE snprc_scheduler.StudyDayNotes - DROP COLUMN QcState -GO \ No newline at end of file diff --git a/snprc_scheduler/src/org/labkey/snprc_scheduler/SNPRC_schedulerModule.java b/snprc_scheduler/src/org/labkey/snprc_scheduler/SNPRC_schedulerModule.java index 5f904d793..f9b539cd2 100644 --- a/snprc_scheduler/src/org/labkey/snprc_scheduler/SNPRC_schedulerModule.java +++ b/snprc_scheduler/src/org/labkey/snprc_scheduler/SNPRC_schedulerModule.java @@ -44,7 +44,14 @@ public String getName() @Override public @Nullable Double getSchemaVersion() { - return 23.00; + return 26.000; + } + + @Override + public double getEarliestUpgradeVersion() + { + // Allow upgrades from 23.000+ + return 23.000; } @Override @@ -74,7 +81,6 @@ public SchedulerWebPart getWebPartView(@NotNull ViewContext portalCtx, @NotNull @Override protected void init() { - addController(SNPRC_schedulerController.NAME, SNPRC_schedulerController.class); ServiceRegistry.get().registerService(SNPRC_schedulerService.class, SNPRC_schedulerServiceImpl.INSTANCE);