From 92e960934f739328c02e8845358ca79f18a99bbc Mon Sep 17 00:00:00 2001 From: Oliver Bertuch Date: Fri, 6 Nov 2020 16:40:39 +0100 Subject: [PATCH] Move index creation from baseline script to a 5.1.1 migration, so it will be applied in order (cannot create an older, out-of-order version as this would break migrations for everyone). #7256 --- .../db/migration/V1__flyway_schema_baseline.sql | 9 --------- .../V5.1.1.3__7256-purge-referencedata.sql | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 src/main/resources/db/migration/V5.1.1.3__7256-purge-referencedata.sql diff --git a/src/main/resources/db/migration/V1__flyway_schema_baseline.sql b/src/main/resources/db/migration/V1__flyway_schema_baseline.sql index 2ec219cd19e..d1caa63cd71 100644 --- a/src/main/resources/db/migration/V1__flyway_schema_baseline.sql +++ b/src/main/resources/db/migration/V1__flyway_schema_baseline.sql @@ -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'; \ No newline at end of file diff --git a/src/main/resources/db/migration/V5.1.1.3__7256-purge-referencedata.sql b/src/main/resources/db/migration/V5.1.1.3__7256-purge-referencedata.sql new file mode 100644 index 00000000000..176629f9abb --- /dev/null +++ b/src/main/resources/db/migration/V5.1.1.3__7256-purge-referencedata.sql @@ -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'; \ No newline at end of file