Skip to content

Commit

Permalink
Move index creation from baseline script to a 5.1.1 migration, so it …
Browse files Browse the repository at this point in the history
…will be applied in order (cannot create an older, out-of-order version as this would break migrations for everyone). #7256
  • Loading branch information
poikilotherm committed Nov 6, 2020
1 parent bf96722 commit 92e9609
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,2 @@
-- TODO: we still should add the real base line here, too. That would avoid conflicts between EclipseLink
-- trying to create new tables on existing databases. See https://github.com/IQSS/dataverse/issues/5871

-- This is unsupported by JPA, as it is PostgreSQL specific. Has to be done here, cannot be done in code.
-- (Only other option would be a lowercase copy of the data as a separate column, automatically filled py JPA)
CREATE UNIQUE INDEX IF NOT EXISTS dataverse_alias_unique_idx on dataverse (LOWER(alias));
CREATE UNIQUE INDEX IF NOT EXISTS index_authenticateduser_lower_email ON authenticateduser (lower(email));

-- Edit Dataset: Investigate and correct multiple draft issue: https://github.com/IQSS/dataverse/issues/2132
-- This unique index will prevent the multiple draft issue, yet it cannot be done in JPA code.
CREATE UNIQUE INDEX IF NOT EXISTS one_draft_version_per_dataset ON datasetversion (dataset_id) WHERE versionstate='DRAFT';
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- #5361 and #7256 is about faster deployments, especially during development, sitting on an empty database.
--
-- This script has been part of scripts/database/reference_data.sql that had to be executed manually on every new
-- deployment (manually in the sense of Flyway didn't, the outside installer or an admin took care of it).
--
-- While this is pretty old stuff and should have been done earlier (baseline...), it will be a nice migration
-- and behave like nothing happened if this is an existing installation. All new installation have an empty database
-- on first app boot and benefit from this Flyway-based management.

-- This is unsupported by JPA, as it is PostgreSQL specific. Has to be done here, cannot be done in code.
-- (Only other option would be a lowercase copy of the data as a separate column, automatically filled py JPA)
CREATE UNIQUE INDEX IF NOT EXISTS dataverse_alias_unique_idx on dataverse (LOWER(alias));
CREATE UNIQUE INDEX IF NOT EXISTS index_authenticateduser_lower_email ON authenticateduser (lower(email));

-- Edit Dataset: Investigate and correct multiple draft issue: https://github.com/IQSS/dataverse/issues/2132
-- This unique index will prevent the multiple draft issue, yet it cannot be done in JPA code.
CREATE UNIQUE INDEX IF NOT EXISTS one_draft_version_per_dataset ON datasetversion (dataset_id) WHERE versionstate='DRAFT';

0 comments on commit 92e9609

Please sign in to comment.