Skip to content

Commit

Permalink
Resolves Mismatch in pathway_event_cohort DDL (#1419)
Browse files Browse the repository at this point in the history
* WebAPI-975 Extract Cohort Characterization analysis to external package

* fixes SQL injection vulnerability

* Resolves Mismatch in pathway_event_cohort DDL between sql server and postgresql.
  • Loading branch information
wivern authored Jan 23, 2020
1 parent fe45fc6 commit a721214
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ CREATE TABLE ${ohdsiSchema}.pathway_event_cohort
name VARCHAR(255) NOT NULL,
cohort_definition_id INTEGER NOT NULL,
pathway_analysis_id INTEGER NOT NULL,
is_deleted INTEGER DEFAULT 0,
CONSTRAINT [PK_pathway_event_cohort] PRIMARY KEY (id),

This comment has been minimized.

Copy link
@chrisknoll

chrisknoll Jan 28, 2021

Collaborator

@wivern: this should not have been deleted from the migration script. if we want to drop a column later, we should do it in a new migration, not rewrite history.

The issue was raised here: https://forums.ohdsi.org/t/error-deploying-webapi-2-8-0/13031/9, and I believe what happend was that someone did a fresh install (ie, did not upgrade from 2.6) ... and I think we tried to handle this with a 'if exists' statement, but the IF EXISTS syntax does not work until SQL Server 2016 (which not everyone is running on that version).

CONSTRAINT FK_pec_cd_id
FOREIGN KEY (cohort_definition_id)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- at first removing default value
declare @command nvarchar(1000)
select @command = 'ALTER TABLE ${ohdsiSchema}.pathway_event_cohort DROP CONSTRAINT IF EXISTS ' + d.name
from sys.tables t
join sys.default_constraints d on d.parent_object_id = t.object_id
join sys.columns c on c.object_id = t.object_id and c.column_id = d.parent_column_id
where
t.name = 'pathway_event_cohort'
and t.schema_id = schema_id('${ohdsiSchema}')
and c.name = 'is_deleted';
execute (@command)

ALTER TABLE ${ohdsiSchema}.pathway_event_cohort DROP COLUMN IF EXISTS is_deleted;

0 comments on commit a721214

Please sign in to comment.