From 020884cf6cd0f7efeb210963aba67196e43e32a5 Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Fri, 18 Oct 2024 10:27:52 +0100 Subject: [PATCH 1/2] fix: Pre-quesnalia gin index declarations Included a migrations file to run pre-quesnalia migrations. This ensures that any systems coming from Poppy or before with sufficiently large license descriptions can upgrade to Q. Any systems who have _already_ upgraded to Q will have the "wrong" index on license description, and we recommend implementors manage the adding of the correct indexes manually ERM-3387 --- .../correct-gin-indices-pre-quesnalia.groovy | 57 +++++++++++++++++++ .../migrations/module-tenant-changelog.groovy | 1 + 2 files changed, 58 insertions(+) create mode 100644 service/grails-app/migrations/correct-gin-indices-pre-quesnalia.groovy diff --git a/service/grails-app/migrations/correct-gin-indices-pre-quesnalia.groovy b/service/grails-app/migrations/correct-gin-indices-pre-quesnalia.groovy new file mode 100644 index 0000000..a9b62bb --- /dev/null +++ b/service/grails-app/migrations/correct-gin-indices-pre-quesnalia.groovy @@ -0,0 +1,57 @@ +databaseChangeLog = { + /* GIN Indexes have been added in update-mod-licenses-5-1.groovy + * These can cause issues when the underlying data passes a certain limit + * due to trigram operator not being used and the postgres token size growing + * + * It is a little unorthodox, however these index creations are conditional on + * "CREATE IF NOT EXISTS". We will make use of that to insert indices on those + * fields _before_ they are set up by upgrading/new implementors. For any tenants + * who already managed to upgrade, these new changesets will be ignored, but it + * it _recommended_ that an operational task be undertaken to bring those schemas + * in line with the indices in place on new instances of mod-agreements + */ + + // The first two of these shouldn't be impacted by the bug outlined in ERM-3387, but we bring them in line anyway + changeSet(author: "EFreestone (manual)", id: "2024-10-17-ERM-3387-quesnalia-1") { + preConditions (onFail: 'MARK_RAN', onError: 'WARN') { + not { + indexExists(tableName: 'alternate_name', columnNames: 'an_name') + } + } + // Gin indexes need to be done via scripting. + grailsChange { + change { + def cmd = "CREATE INDEX alternate_name_name_idx ON ${database.defaultSchemaName}.alternate_name USING gin (an_name, gin_trgm_ops);".toString() + sql.execute(cmd); + } + } + } + + changeSet(author: "EFreestone (manual)", id: "2024-10-17-ERM-3387-quesnalia-2") { + preConditions (onFail: 'MARK_RAN', onError: 'WARN') { + not { + indexExists(tableName: 'license', columnNames: 'lic_name') + } + } + grailsChange { + change { + def cmd = "CREATE INDEX license_name_idx ON ${database.defaultSchemaName}.license USING gin (lic_name, gin_trgm_ops);".toString() + sql.execute(cmd); + } + } + } + + changeSet(author: "EFreestone (manual)", id: "2024-10-17-ERM-3387-quesnalia-3") { + preConditions (onFail: 'MARK_RAN', onError: 'WARN') { + not { + indexExists(tableName: 'license', columnNames: 'lic_description') + } + } + grailsChange { + change { + def cmd = "CREATE INDEX license_description_idx ON ${database.defaultSchemaName}.license USING gin (lic_description, gin_trgm_ops);".toString() + sql.execute(cmd); + } + } + } +} \ No newline at end of file diff --git a/service/grails-app/migrations/module-tenant-changelog.groovy b/service/grails-app/migrations/module-tenant-changelog.groovy index 92fe103..5df9f3b 100644 --- a/service/grails-app/migrations/module-tenant-changelog.groovy +++ b/service/grails-app/migrations/module-tenant-changelog.groovy @@ -21,5 +21,6 @@ databaseChangeLog = { include file: 'wtk/hidden-appsetting.feat.groovy' include file: 'update-mod-license-4-2.groovy' include file: 'wtk/multi-value-custprops.feat.groovy' + include file: 'correct-gin-indices-pre-quesnalia.groovy' include file: 'update-mod-license-5-1.groovy' } From 0d6a99bf4b44a9d977d33e3fd53897e652ddf397 Mon Sep 17 00:00:00 2001 From: Ethan Freestone Date: Fri, 18 Oct 2024 10:41:18 +0100 Subject: [PATCH 2/2] fix: Syntax error Accidentally included a comma, that causes broken migrations. Also realised that `"2024-10-17-ERM-3387-quesnalia-1"` and `"2024-10-17-ERM-3387-quesnalia-2"` are not currently running due to preconditions, which likely means the "wrong" gin index definitions are also not running even on systems which successfully upgraded to Q, so the license description really is the only one which matters ERM-3387 --- .../migrations/correct-gin-indices-pre-quesnalia.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/service/grails-app/migrations/correct-gin-indices-pre-quesnalia.groovy b/service/grails-app/migrations/correct-gin-indices-pre-quesnalia.groovy index a9b62bb..a0a9794 100644 --- a/service/grails-app/migrations/correct-gin-indices-pre-quesnalia.groovy +++ b/service/grails-app/migrations/correct-gin-indices-pre-quesnalia.groovy @@ -21,7 +21,7 @@ databaseChangeLog = { // Gin indexes need to be done via scripting. grailsChange { change { - def cmd = "CREATE INDEX alternate_name_name_idx ON ${database.defaultSchemaName}.alternate_name USING gin (an_name, gin_trgm_ops);".toString() + def cmd = "CREATE INDEX alternate_name_name_idx ON ${database.defaultSchemaName}.alternate_name USING gin (an_name gin_trgm_ops);".toString() sql.execute(cmd); } } @@ -35,7 +35,7 @@ databaseChangeLog = { } grailsChange { change { - def cmd = "CREATE INDEX license_name_idx ON ${database.defaultSchemaName}.license USING gin (lic_name, gin_trgm_ops);".toString() + def cmd = "CREATE INDEX license_name_idx ON ${database.defaultSchemaName}.license USING gin (lic_name gin_trgm_ops);".toString() sql.execute(cmd); } } @@ -49,7 +49,7 @@ databaseChangeLog = { } grailsChange { change { - def cmd = "CREATE INDEX license_description_idx ON ${database.defaultSchemaName}.license USING gin (lic_description, gin_trgm_ops);".toString() + def cmd = "CREATE INDEX license_description_idx ON ${database.defaultSchemaName}.license USING gin (lic_description gin_trgm_ops);".toString() sql.execute(cmd); } }