-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
DropPrimaryKeyTask fails in SQL Server with newer versions of HAPI due to multipart primary keys #6650
Comments
Steps I used to reproduce: Install MSSQL in a local docker instance:
Connect to the local sql server DB using SQL Server Management Studio (SSMS) (free download). Create a database called 'hapi' in the SSMS ui. Start a HAPI 7.4.0 JPA instance connected to the Docker sql db to initialize the DB. Datasource setting in application.yaml:
Run the 7.6.0+ CLI: |
Heya! I notice you are using the default dialect, whereas HAPI-FHIR uses hapi-fhir/hapi-fhir-jpa/src/main/java/ca/uhn/fhir/jpa/model/dialect/HapiFhirSQLServerDialect.java Line 30 in 7090c3f
Are you able to replicate with this dialect? If so, let me know, as we internally are unable to replicate at the moment. For what its worth, either way, i think your fix is valid and we can likely get it merged, just wanted to check with you first for this replication. Cheers |
Hi @tadgh. I wiped out my SQL database (deleted the container and recreated it) and restarted a new HAPI JPA instance with the hapi sql dialect set to: I let it init the database, then stopped the FHIR server, then ran the CLI migrate - I still see the error. To be clear, when I'm running the CLI migrate utility, I am not specifying a dialect, only the "-d MSSQL_2012" parameter - which corresponds to the driver name, not the dialect. But I wouldn't think the dialect should affect this anyway. If the HFJ_RES_SEARCH_URL table has a multi part primary key defined, it looks like SQL Server will create two rows in the INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE table for it, which should lead to the error. FWIW, I did check an older version of a HAPI server (v7.0.2). and it does NOT have a multipart Pkey for 'HFJ_RES_SEARCH_URL', so I assume the partition_id column was added to that primary key fairly recently. In my error case the DB was initialized from a 7.4.0 HAPI JPA instance, and I'm trying to migrate to 7.6.0. Anyway, if the instance you are testing against returns 2 rows for the PKEY with this query, I'd think you should see the error: |
OK, thanks for doing the replication there. We are trying to replicate still via our closed source wrapper with no success, but I will try it with the jpaserver-starter wrapper. Maybe there's some discrepancy there. |
I was running from a fork, so I reset back to basics to double-check and still see the error. From the JPA starter, I pulled from master, then: Then: Then I'm taking the root.war and copying to a temp directory that has my application.yaml and running with: Anyway.. if that helps.. |
When running the CLI migrate on a HAPI 7.4.x instance, it looks like multipart primary keys have been added (at some point), which causes the generate primary key drop statement to fail.
The error generated from running the db migrate is:
This code appears to be the culprit:
hapi-fhir/hapi-fhir-sql-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropPrimaryKeyTask.java
Lines 126 to 129 in 251eee8
It appears to be unnecessarily joining the information_schema.constraint_column_usage table, which has two rows for this Primary key (partition_id and res_search_url) and thus gets 2 rows in the resultset instead of 1.
But if it just needs the primary key constraint name it shouldn't need to join to the constraint_column_usage table at all?
Here is what my database shows for these tables:
The text was updated successfully, but these errors were encountered: