Seemingly crazy catch 22 Dspace DB migration loop question!!!

452 views
Skip to first unread message

S. T.

unread,
Oct 13, 2021, 5:47:46 PM10/13/21
to DSpace Technical Support
We are trying to upgrade our system from 6 to 7, we are following all the steps.

We get this message on DB migration:
Migration V5.7_2017.04.11__DS-3563_Index_metadatavalue_resource_type_id_column.sql failed

When we attempt to update the DB, if fails right there, because it is (?) trying to create a field WHICH APPARENTLY DOES NOT EXIST in 6.x or 7.x from a previous field THAT NEVER EXISTED ON OUR 6.x install.

This script, which is part of the Flyway DB upgrade auto process

org/dspace/storage/rdbms/sqlmigration/postgres/V5.7_2017.04.11__DS-3563_Index_metadatavalue_resource_type_id_column.sql

Contents are:
DROP INDEX IF EXISTS metadatavalue_resource_type_id_idx; CREATE INDEX metadatavalue_resource_type_id_idx ON metadatavalue (resource_type_id);

However, WE started with V 6.0. So, (1) that column did not exist in the 6.0 schema. (2) Furthermore, the field it is trying to create USING the value from that 5.7 field, also DOES NOT EXIST in the schema for 6.xx OR 7.xx.

So, the migration script seems to be trying to alter the metadatavalue table using a column which doesn't exist to create a column that doesn't apparently exist in anyone's backend. 

 Can anyone who either knows migrations very well, or the Dspace backend care to comment or assist? This is so super frustrating and confusing. What are we missing?

Thanks so much

Steven Turner

Joel R

unread,
Oct 14, 2021, 8:56:24 AM10/14/21
to DSpace Technical Support
Steven,

I claim to be no expert, but maybe you (and another post from September) stumbled upon a bug? Can you share the results of the following commands?

[dspace]/bin/dspace database validate
[dspace]/bin/dspace database info

It's suspicious that you started on version 6 and the Flyaway migration is attempting to issue a patch for something that existed in version 5.7.

Just for fun, you might want to try this, too, if you haven't already.

[dspace]/bin/dspace database repair

--Joel



S. T.

unread,
Oct 14, 2021, 11:47:36 AM10/14/21
to DSpace Technical Support
Thanks Joel, I appreciate the help. I guess I should search the Jira for Dspace on their github repo, and / or submit this bug. I am assuming they have a Jira and a github repo.Let me run those commands, and I will share.

S. T.

unread,
Oct 14, 2021, 11:57:53 AM10/14/21
to DSpace Technical Support
"It's suspicious that you started on version 6 and the Flyaway migration is attempting to issue a patch for something that existed in version 5.7." _ I agree, it makes no sense that the migration is attempting to create fixes for past versions. I don't think this is normally what software engineers / companies do, unless there is a zero-day bug or something like that. Normally I expect patches to older software items / packages to be in later releases, otherwise it becomes ridiculously confusing. I also think this may be a bug. One workaround may be just to remove the code in scripts that ask for this to occur. Or to create the column, and then delete the finished result at the end of the migration. Unsure.

Tim Donohue

unread,
Oct 14, 2021, 12:04:30 PM10/14/21
to S. T., DSpace Technical Support
Hi Steven,

What does your "dspace database info" command return?  
We'd need more information here to help debug it.  This seems like a very odd error to me as well, as that migration was initially added in 5.7 and ported to 6.1... so, if you were already running 6.1 or above, this migration should have already run for you​. 

That said, it's possible your "dspace database info" command would provide us with additional hints.​  I'm assuming that somehow this migration may not have ever been applied to your 6.x site....and now that you are updating to 7.x, it's causing issues.

Tim

From: dspac...@googlegroups.com <dspac...@googlegroups.com> on behalf of S. T. <sjtu...@gmail.com>
Sent: Thursday, October 14, 2021 10:47 AM
To: DSpace Technical Support <dspac...@googlegroups.com>
Subject: [dspace-tech] Re: Seemingly crazy catch 22 Dspace DB migration loop question!!!
 
--
All messages to this mailing list should adhere to the Code of Conduct: https://www.lyrasis.org/about/Pages/Code-of-Conduct.aspx
---
You received this message because you are subscribed to the Google Groups "DSpace Technical Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dspace-tech...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dspace-tech/6fe30d91-4b79-48c6-aa30-2e13ce040132n%40googlegroups.com.

S. T.

unread,
Oct 14, 2021, 12:20:06 PM10/14/21
to DSpace Technical Support
Hi Tim - yes, agreed. We were running 6.0. The ignore command was in operation for our migration, and it claims it is not needed, and so it is ignored. Except it is not ignored, and the DB fails on request. Additionally, I am not sure what you are saying because this field doesn't exist in the 7/xx DB schema for that table. SO what gives? Is it created, and then migrated through additional SQL migration scripts to another table, this index it is trying to create? Because it doesn't not exist in 7, so why is the script desperately trying to make it so? 

S. T.

unread,
Oct 14, 2021, 1:17:22 PM10/14/21
to DSpace Technical Support
Hi folks; here is our info dump 6.3 with 6.0 DB

you can see the ignored line for the metadata value index down there at the bottom, that is where the install fails, of course. Because the column it is looking for doesnt' exist. 

However, nobody has answered the question as to why is this even part of the migration process? Where is this index in 7.0? Or in 6.xx? It is not in that table. Is it moved by other migration scripts to another table? That index does exist in several other tables, but not this one, according to both schemas.

Database URL: jdbc:postgresql://localhost:5432/dspace
Migrating database to latest version AND running previously "Ignored" migrations... (Check logs for details)
Migration exception:
java.sql.SQLException: Flyway migration error occurred
        at org.dspace.storage.rdbms.DatabaseUtils.updateDatabase(DatabaseUtils.java:673)
        at org.dspace.storage.rdbms.DatabaseUtils.main(DatabaseUtils.java:187)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.dspace.app.launcher.ScriptLauncher.runOneCommand(ScriptLauncher.java:229)
        at org.dspace.app.launcher.ScriptLauncher.main(ScriptLauncher.java:81)
Caused by: org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException:
Migration V5.7_2017.04.11__DS-3563_Index_metadatavalue_resource_type_id_column.sql failed
-----------------------------------------------------------------------------------------
SQL State  : 42703
Error Code : 0
Message    : ERROR: column "resource_type_id" does not exist
Location   : org/dspace/storage/rdbms/sqlmigration/postgres/V5.7_2017.04.11__DS-3563_Index_metadatavalue_resource_type_id_column.sql (/srv/dspace63/bin/file:/srv/dspace63/lib/dspace-api-6.3.jar!/org/dspace/storage/rdbms/sqlmigration/postgres/V5.7_2017.04.11__DS-3563_Index_metadatavalue_resource_type_id_column.sql)
Line       : 16
Statement  : CREATE INDEX metadatavalue_resource_type_id_idx ON metadatavalue (resource_type_id)

        at org.flywaydb.core.internal.dbsupport.SqlScript.execute(SqlScript.java:117)
        at org.flywaydb.core.internal.resolver.sql.SqlMigrationExecutor.execute(SqlMigrationExecutor.java:71)
        at org.flywaydb.core.internal.command.DbMigrate.doMigrate(DbMigrate.java:352)
        at org.flywaydb.core.internal.command.DbMigrate.access$1100(DbMigrate.java:47)
        at org.flywaydb.core.internal.command.DbMigrate$4.doInTransaction(DbMigrate.java:308)
        at org.flywaydb.core.internal.util.jdbc.TransactionTemplate.execute(TransactionTemplate.java:72)
        at org.flywaydb.core.internal.command.DbMigrate.applyMigration(DbMigrate.java:305)
        at org.flywaydb.core.internal.command.DbMigrate.access$1000(DbMigrate.java:47)
        at org.flywaydb.core.internal.command.DbMigrate$2.doInTransaction(DbMigrate.java:230)
        at org.flywaydb.core.internal.command.DbMigrate$2.doInTransaction(DbMigrate.java:173)
        at org.flywaydb.core.internal.util.jdbc.TransactionTemplate.execute(TransactionTemplate.java:72)
        at org.flywaydb.core.internal.command.DbMigrate.migrate(DbMigrate.java:173)
        at org.flywaydb.core.Flyway$1.execute(Flyway.java:959)
        at org.flywaydb.core.Flyway$1.execute(Flyway.java:917)
        at org.flywaydb.core.Flyway.execute(Flyway.java:1373)
        at org.flywaydb.core.Flyway.migrate(Flyway.java:917)
        at org.dspace.storage.rdbms.DatabaseUtils.updateDatabase(DatabaseUtils.java:662)
        ... 7 more
Caused by: org.postgresql.util.PSQLException: ERROR: column "resource_type_id" does not exist
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2422)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2167)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:306)
        at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
        at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
        at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:307)
        at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:293)
        at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:270)
        at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:266)
        at org.apache.commons.dbcp2.DelegatingStatement.execute(DelegatingStatement.java:291)
        at org.apache.commons.dbcp2.DelegatingStatement.execute(DelegatingStatement.java:291)
        at org.flywaydb.core.internal.dbsupport.JdbcTemplate.executeStatement(JdbcTemplate.java:238)
        at org.flywaydb.core.internal.dbsupport.SqlScript.execute(SqlScript.java:114)
        ... 23 more

S. T.

unread,
Oct 14, 2021, 2:33:56 PM10/14/21
to DSpace Technical Support
Hey folks, or anyone interested - here is the log of the DB repair function on our 6.0 DB. We did get a single table repair, but it was not the table in question. We are attempting to run the migration script again, to see what happens. Thanks again to everyone who has attempted to help. It is much appreciated.

2021-10-14 12:41:13,206 INFO  org.dspace.importer.external.service.ImportService @ Loading 1 import sources.
2021-10-14 12:41:14,032 INFO  org.dspace.core.LoggerServiceImpl @ Using dspace provided log configuration (log.init.config)
2021-10-14 12:41:14,032 INFO  org.dspace.core.LoggerServiceImpl @ Loading: /srv/dspace63/config/log4j.properties
2021-10-14 12:41:14,183 INFO  org.dspace.storage.rdbms.DatabaseUtils @ Loading Flyway DB migrations from: filesystem:/srv/dspace63/etc/postgres, classpath:org.dspace.storage.rdbms.sqlmigration.postgres, classpath:org.dspace.storage.rdbms.migration
2021-10-14 12:41:14,186 INFO  org.flywaydb.core.internal.util.VersionPrinter @ Flyway 4.0.3 by Boxfuse
2021-10-14 12:41:14,196 INFO  org.flywaydb.core.internal.dbsupport.DbSupportFactory @ Database: jdbc:postgresql://localhost:5432/dspace (PostgreSQL 9.4)
2021-10-14 12:41:14,241 INFO  org.flywaydb.core.internal.metadatatable.MetaDataTableImpl @ Repair of failed migration in metadata table "public"."schema_version" not necessary. No failed migration detected.
2021-10-14 12:41:14,268 INFO  org.flywaydb.core.internal.command.DbRepair @ Successfully repaired metadata table "public"."schema_version" (execution time 00:00.030s).

S. T.

unread,
Oct 14, 2021, 2:36:33 PM10/14/21
to DSpace Technical Support
Notice - in the db repair log - how it said NOTHING about NOT having the oddball column that was to be created by the 5.7 script, eg, it's not there, and the db repair script made no mention of that fact. So, to me, I think we may be looking a bug in the migration process, in these DB scripts.

S. T.

unread,
Oct 14, 2021, 2:46:33 PM10/14/21
to DSpace Technical Support
Joel, the DB repair did not affect the migration issues, unfortunately. Is there a way to remove the XML/Cocoon config line that is requiring this script? How would that affect future upgrade processes.

On Thursday, October 14, 2021 at 7:56:24 AM UTC-5 caju...@gmail.com wrote:

S. T.

unread,
Oct 14, 2021, 4:09:11 PM10/14/21
to DSpace Technical Support
Hi Tim - did you see the returned DB info data? Do you have any suggestions? We are running into a brick wall over here, and so far, we are unable to resolve any issues brought about by upgrading using the 'ignored' flag. We are not only stopped at this issue, but also at other multiple issues involving DB modification using an index. I commented out the 5.7 db fix, and the script ran fine, but failed on another, similar issue.

So, to me, this says that we have an unexpected or non-standard table structure? There is no reason why our table structure/indexes should be non-standard and unexpected, we have done nothing custom to the database.

Any suggestions?

On Thursday, October 14, 2021 at 11:04:30 AM UTC-5 Tim Donohue wrote:

Tim Donohue

unread,
Oct 15, 2021, 10:39:21 AM10/15/21
to S. T., DSpace Technical Support
Hi Steven,

I apologize, but I haven't had time to get back to this yet.  It is definitely an odd error to be occurring, as I would have expected this migration to have run before​ you attempted an upgrade to 7.0.

One option might be to go back to your 6.x site and run the "dspace database migrate ignored" script there (using the 6.x codebase). If it works there, it might be enough to get your database past​ that migration (once it is run, it never runs again).  Then you could attempt the upgrade to 7.0.

You may be correct that there's a migration bug at play here... I honestly haven't had time to see if I can replicate this elsewhere.  The expectation though is that ideally all pre-7.0 migrations should have already been run on your database (even those which are returned as "ignored")....as many upgrades involve running that "dspace database migrate ignored" command (which should have previously triggered those ignored migrations to run).   

The oddity​ here is that somehow you (and a few others on this list) have an older 5.7 migration that wasn't triggered until the 7.0 upgrade...that's unexpected to me as well.  Generally, we expect 5.x migrations to trigger during 5.x minor upgrades or, at worst, during an upgrade from 5.x to 6.x.  The fact that it was never triggered before is very odd, as it's obviously no longer a valid migration as you move to 7.x -- it only worked on a 5.x style database.

I'll see if I can get back to this sometime next week...apologies though, as this comes during a very busy couple of weeks.  I'll also see if I can ask around to find another developer with time to debug what could be going on here.

Thanks again for reporting this...hopefully we can find a way to workaround this soon.

Tim

Sent: Thursday, October 14, 2021 3:09 PM

To: DSpace Technical Support <dspac...@googlegroups.com>
Subject: Re: [dspace-tech] Re: Seemingly crazy catch 22 Dspace DB migration loop question!!!
 

S. T.

unread,
Oct 18, 2021, 11:52:41 AM10/18/21
to DSpace Technical Support
Thank so much Tim,

At no time during the 6.x versions does it tell you to run "database migrate ignored".  All of the instructions ignore the fact that someone that started with version 6.x will not have had those migrations run, and yet are forced to do so to upgrade to 7.x, where they will fail.This gives me hope though that skipping them may yield a completely workable 7.x system.  So I'm going to try to skip the other 5.x migration that's now holding us up since we skipped the other.  (we modified the 5.7 DB script called by the cocoon files,  that creates the un-needed index, to basically have a null output) 

I can also try upgrading through the 6.x versions, but I see no reason this will succeed, only a slower path to get us to where we are (it failed with 6.2 and 6.3, I only haven't tried 6.1).

Any other suggestions form today? I apologize for taking up so much of your time. I have a schedule of 'upgrade DB to 7' for end of October, so I am actively pursuing a solution.

Another idea was to perform some sort of WP-style export of the data, then re-import to individual table on a clean 7 install. Dspace does not have that many data tables, so it's possible, but unwieldy and very far from ideal, or maybe even no possible.

Tim Donohue

unread,
Oct 18, 2021, 1:26:38 PM10/18/21
to S. T., DSpace Technical Support
Hi Steven,

Ok, I understand the frustration. Honestly, I've very confused how this migration was never triggered earlier...as there was a time (in 5.x days) when it was not​ "ignored" / out of order and it should have been triggered by a simple "dspace database migrate" at that time.

One other option here, and I would recommend BACKING UP FIRST or trying it on a test database (as it could be dangerous & I've not tested this).  As you may have already figured out, our entire "dspace database" script just runs FlywayDB.org behind the scenes. So...

You could manually modify the Flyway "schema_version" table for that specific migration entry, setting the "success" column to "t" (true).  

In other words, after the migration failure, you should already have a row in the "schema_version" table for "script" named "V5.7_2017.04.11__DS-3563_Index_metadatavalue_resource_type_id_column.sql".  Currently, that row's "success" column will say "f" (false).  Setting it to true will "fool" Flyway into thinking your previous run was successful.  Since, this migration script is obviously no longer needed in 7.x, that's an OK fix in this scenario.   

After this manual change, I think your "./dspace database migrate info" script will show it as "Out of Order" (which means successful, but not run in order)

After that change, you can try to run "./dspace database migrate ignored" again to see if it gets passed that migration.  If you end up with a warning/failure saying that Flyway's validation process failed, you can try first a "./dspace database repair" and then try the "migrate ignored" again.

This sort of modification to the Flyway "schema_version" table is obviously NOT RECOMMENDED in most scenarios, as you are bypassing the Flyway database upgrade process.  But, in this odd scenario, it's worth a try, since this old migration is quite obviously no longer valid...and there's no easier way to "skip" a migration in Flyway unfortunately. 

Please let us know on this list if you decide to go this route & what steps work for you. I've not been able to yet figure out a way to reproduce this scenario locally, so it's difficult to list the exact steps above...but I'm hoping this should at least get you passed that migration.

Tim


Sent: Monday, October 18, 2021 10:52 AM

To: DSpace Technical Support <dspac...@googlegroups.com>

S. T.

unread,
Oct 18, 2021, 1:40:08 PM10/18/21
to DSpace Technical Support
Tim, that is great advice, and sort of what we are already doing, so we will continue down this path, and report back. Thanks again!

euler

unread,
Jul 5, 2022, 11:20:16 PM7/5/22
to DSpace Technical Support

Hi Steven,

Did you manage to solve your issue? I am also experiencing the same issue where the version used to install DSpace was 6.0. Right now it is running on version 6.3. Hoping you can share your steps on fixing this migration issue so that others who have started from version 6 can apply your fix.

Thanks in advance and best regards,
euler

Tim Donohue

unread,
Jul 11, 2022, 11:41:35 AM7/11/22
to euler, DSpace Technical Support
Hi Euler,

Hmm... that's confusing to me that this issue has triggered for you when you started your DSpace site from 6.0.

One approach that should work is to:
  1. Delete the migration file from dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V5.7_2017.04.11__DS-3563_Index_metadatavalue_resource_type_id_column.sql
  2. Rebuild DSpace backend ("mvn clean package") and redeploy ("ant update")
  3. Run "./dspace database repair" (this will tell Flyway to ignore that deleted migration file which you removed in step 1)
  4. Try to migrate again. Run "./dspace database migrate ignored"
If this works for you, please report back.  It seems that there's something strange going on with this particular migration file...and I'm still trying to determine the root cause.  So, if we can at least document a known "workaround", that'd be very useful to everyone who encounters this issue.

Tim

From: dspac...@googlegroups.com <dspac...@googlegroups.com> on behalf of euler <esn...@seafdec.org.ph>
Sent: Tuesday, July 5, 2022 10:20 PM
Message has been deleted
Message has been deleted

Tim Donohue

unread,
Jul 31, 2023, 11:40:51 AM7/31/23
to euler, DSpace Technical Support
Hi Euler,

This 5.7 migration is obsolete & it has caused issues with others as well.  See this old dspace-tech mailing list thread: https://groups.google.com/g/dspace-tech/c/PlOA1WMvd4M/m/eBVE5RfhBgAJ

The solution is to use the new "./dspace database skip" command provided as of DSpace 7.5 and skip this problematic migration by running:

./dspace database skip "5.7.2017.04.11"

This is safe to do because the migration is obsolete​. 

Tim

Sent: Monday, July 31, 2023 6:05 AM

To: DSpace Technical Support <dspac...@googlegroups.com>
Subject: Re: [dspace-tech] Re: Seemingly crazy catch 22 Dspace DB migration loop question!!!
 
Hi Tim,

Apologies for not reporting back sooner. As per your suggestion, I removed the SQL you mentioned, performed 'mvn clean package', and 'ant update'. I did not receive any errors when running 'dspace database repair', but when I run 'dspace database migrate ignored', the console returned a lot of errors too long to post here. Please see the attached text file from the output of my console. I will try to restore this repository in a local instance with the latest 6x version and try to run 'dspace database migrate ignored' from there. I suspect there is something wrong with this particular instance because when I run the command 'dspace database migrate ignored' on this repository which is running version 6.3, it returned this error:

Database URL: jdbc:postgresql://localhost:5432/dspace
Migrating database to latest version AND running previously "Ignored" migrations... (Check logs for details)
Migration exception:
java.sql.SQLException: Flyway migration error occurred
at org.dspace.storage.rdbms.DatabaseUtils.updateDatabase(DatabaseUtils.java:673)
at org.dspace.storage.rdbms.DatabaseUtils.main(DatabaseUtils.java:187)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)

at org.dspace.app.launcher.ScriptLauncher.runOneCommand(ScriptLauncher.java:229)
at org.dspace.app.launcher.ScriptLauncher.main(ScriptLauncher.java:81)
Caused by: org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException:
Migration V5.7_2017.04.11__DS-3563_Index_metadatavalue_resource_type_id_column.sql failed
-----------------------------------------------------------------------------------------
SQL State  : 42703
Error Code : 0
Message    : ERROR: column "resource_type_id" does not exist
Location   : org/dspace/storage/rdbms/sqlmigration/postgres/V5.7_2017.04.11__DS-3563_Index_metadatavalue_resource_type_id_column.sql (c:\DSpace\file:\C:\DSpace\lib\dspace-api-6.3.jar!\org\dspace\storage\rdbms\sqlmigration\postgres\V5.7_2017.04.11__DS-3563_Index_metadatavalue_resource_type_id_column.sql)
Line       : 16
Statement  : CREATE INDEX metadatavalue_resource_type_id_idx ON metadatavalue (resource_type_id)

Please note that the original version of DSpace that I used to install in this instance was version 6.0, so I wonder why it is complaining about scripts from version 5.7.

Hoping this can be resolved so that I can successfully migrate it to version 7.6

Thanks in advance and best regards,
euler
Reply all
Reply to author
Forward
0 new messages