Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration Issue: Missing migration script / PostGres DB / Version 3.12.6 to 4.2.2 #7976

Open
rime1014 opened this issue Apr 24, 2024 · 0 comments

Comments

@rime1014
Copy link

Describe the bug
A PSQL exception appears in the log file when executing the database migration from GN 3.12.6 to GN 4.2.2 for the matadatastatus table.

DEBUG [org.hibernate.SQL] - alter table if exists geonetwork.MetadataStatus add constraint FKtih0k768u8kuwxsp8dnm9kru3 foreign key (relatedMetadataStatusId) references geonetwork.MetadataStatus
WARN  [org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl] - GenerationTarget encountered exception accepting command : Error executing DDL "alter table if exists geonetwork.MetadataStatus add constraint FKtih0k768u8kuwxsp8dnm9kru3 foreign key (relatedMetadataStatusId) references geonetwork.MetadataStatus" via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table if exists geonetwork.MetadataStatus add constraint FKtih0k768u8kuwxsp8dnm9kru3 foreign key (relatedMetadataStatusId) references geonetwork.MetadataStatus" via JDBC Statement
...
Caused by: org.postgresql.util.PSQLException: FEHLER: Anzahl der Quell- und Zielspalten im Fremdschlüssel stimmt nicht überein

Warning

Number of source and target columns in foreign key does not match.
The database migration does not stop.
Consequences during operation may be possible.

To Reproduce
Steps to reproduce the behavior:

  1. Increase loglevel to DEBUG for org.hibernate.SQL and org.hibernate
  2. Start GeoNetwork migration from version 3.12.6 to version 4.2.2
  3. Check the logfile for "org.hibernate"

Expected behavior
No PSQL exception should appear. The metadatastatus table should look the same after migration to GN 4.2.2 as if GN 4.2.2 was set up from scratch.

Log file

DEBUG [org.hibernate.SQL] - alter table if exists geonetwork.MetadataStatus add constraint FKtih0k768u8kuwxsp8dnm9kru3 foreign key (relatedMetadataStatusId) references geonetwork.MetadataStatus
WARN  [org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl] - GenerationTarget encountered exception accepting command : Error executing DDL "alter table if exists geonetwork.MetadataStatus add constraint FKtih0k768u8kuwxsp8dnm9kru3 foreign key (relatedMetadataStatusId) references geonetwork.MetadataStatus" via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table if exists geonetwork.MetadataStatus add constraint FKtih0k768u8kuwxsp8dnm9kru3 foreign key (relatedMetadataStatusId) references geonetwork.MetadataStatus" via JDBC Statement
...
Caused by: org.postgresql.util.PSQLException: FEHLER: Anzahl der Quell- und Zielspalten im Fremdschlüssel stimmt nicht überein

Desktop (please complete the following information):

  • GeoNetwork Version: Migrated 4.2.2
  • Server Application Tomcat 8

Additional context
The error message results from necessary changes to the metadatastatus table, which were not taken into account in the migration scripts during the database migration. When comparing the migrated GN 4.2.2 instance with a bare new GN 4.2.2 instance, the differences are recognizable:

  • The Primary Key (PK) is no longer composed of the columns changedate, metadataid, statusid & userid. Instead, the PK is defined by the ID column
  • A new Foreign Key (FK) is created, which refers to the PK of the same table. The creation of the FK has so far failed (see error message)

Possible Solution: Adding a migration script
Proposal for rectification (PostGres DB)

ALTER TABLE IF EXISTS geonetwork.metadatastatus
ALTER COLUMN id SET NOT NULL;
  
ALTER TABLE IF EXISTS geonetwork.metadatastatus
ALTER COLUMN owner SET NOT NULL;
  
ALTER TABLE IF EXISTS geonetwork.metadatastatus DROP CONSTRAINT IF EXISTS metadatastatus_pkey;
  
ALTER TABLE IF EXISTS geonetwork.metadatastatus
    ADD CONSTRAINT metadatastatus_pkey PRIMARY KEY (id);
  
ALTER TABLE IF EXISTS geonetwork.metadatastatus
    ADD CONSTRAINT fktih0k768u8kuwxsp8dnm9kru3 FOREIGN KEY (relatedmetadatastatusid)
    REFERENCES geonetwork.metadatastatus (id) MATCH SIMPLE
    ON UPDATE NO ACTION
       ON DELETE NO ACTION;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant