Skip to content

Commit

Permalink
Move index creation from reference_data.sql into Flyway baseline. #7256
Browse files Browse the repository at this point in the history
  • Loading branch information
poikilotherm committed Oct 23, 2020
1 parent 1a122d4 commit fc3dbb6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
13 changes: 0 additions & 13 deletions scripts/database/reference_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,6 @@ INSERT INTO guestbook(
VALUES ( false, true, false, now(),
'Default', false, false, null);

-- TODO: Remove if http://stackoverflow.com/questions/25743191/how-to-add-a-case-insensitive-jpa-unique-constraint
-- gets an answer. See also https://github.com/IQSS/dataverse/issues/2598#issuecomment-158219334
CREATE UNIQUE INDEX dataverse_alias_unique_idx on dataverse (LOWER(alias));
CREATE UNIQUE INDEX index_authenticateduser_lower_email ON authenticateduser (lower(email));
-- CREATE UNIQUE INDEX index_authenticateduser_lower_useridentifier ON authenticateduser (lower(useridentifier));
-- this field has been removed from builtinuser; CREATE UNIQUE INDEX index_builtinuser_lower_email ON builtinuser (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
CREATE UNIQUE INDEX one_draft_version_per_dataset ON datasetversion
(dataset_id) WHERE versionstate='DRAFT';


INSERT INTO worldmapauth_tokentype
( name,
created,
Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/db/migration/V1__flyway_schema_baseline.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- 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';

0 comments on commit fc3dbb6

Please sign in to comment.