featurehub-io / featurehub

FeatureHub - cloud native feature flags, A/B testing and remote configuration service. Real-time streaming feature updates. Provided with Java, JavaScript, React, Python, Go, .Net, Ruby, Android, Swift and Flutter SDKs.
https://www.featurehub.io
Other
315 stars 31 forks source link

management failed to upgrade from 1.7.0 to 1.8.0 due to DB migration error #1182

Open chkp-liordan opened 2 months ago

chkp-liordan commented 2 months ago

management repository got an error while migration.

Featurehub running on k8s with RDS PostgreSQL. currently 1.7.0 and upgrading to 1.8.0. edge and dacha got ready but mr got on crash loop

here the :

"message":"failed","priority":"ERROR","path":"io.featurehub.Application","thread":"main","stack_trace":"java.lang.RuntimeException: java.sql.SQLException: Error executing stmt[alter table fh_celog add constraint fk_fh_celog_fk_org foreign key (fk_org) references fh_organization (id) on delete restrict on update restrict] error[ERROR: there is no unique constraint matching given keys for referenced table \"fh_organization\"]\n\tio.ebean.migration.MigrationRunner.run(MigrationRunner.java:120) ~[ebean-migration-13.7.0.jar:13.7.0]\n\tio.ebean.migration.MigrationRunner.run(MigrationRunner.java:72) ~[ebean-migration-13.7.0.jar:13.7.0]\n\tio.ebean.migration.MigrationRunner.run(MigrationRunner.java:65) ~[ebean-migration-13.7.0.jar:13.7.0]\n\tio.featurehub.app.db.utils.CommonDbFeature.configure(CommonDbFeature.kt:160) ~[common-db-1.1-SNAPSHOT.jar:?]\n\torg.glassfish.jersey.model.internal.CommonConfig.configureFeatures(CommonConfig.java:728) ~[jersey-common-3.1.1.jar:?]\n\torg.glassfish.jersey.model.internal.CommonConfig.configureFeatures(CommonConfig.java:736) ~[jersey-common-3.1.1.jar:?]\n\torg.glassfish.jersey.model.internal.CommonConfig.configureMetaProviders(CommonConfig.java:647) ~[jersey-common-3.1.1.jar:?]\n\torg.glassfish.jersey.server.ResourceConfig.configureMetaProviders(ResourceConfig.java:832) ~[jersey-server-3.1.1.jar:?]\n\torg.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:345) ~[jersey-server-3.1.1.jar:?]\n\torg.glassfish.jersey.server.ApplicationHandler.lambda$initialize$1(ApplicationHandler.java:310) ~[jersey-server-3.1.1.jar:?]\n\torg.glassfish.jersey.internal.Errors.process(Errors.java:292) ~[jersey-common-3.1.1.jar:?]\n\torg.glassfish.jersey.internal.Errors.process(Errors.java:274) ~[jersey-common-3.1.1.jar:?]\n\torg.glassfish.jersey.internal.Errors.processWithException(Errors.java:232) ~[jersey-common-3.1.1.jar:?]\n\torg.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:309) ~[jersey-server-3.1.1.jar:?]\n\torg.glassfish.jersey.server.ApplicationHandler.(ApplicationHandler.java:274) ~[jersey-server-3.1.1.jar:?]\n\torg.glassfish.jersey.server.ApplicationHandler.(ApplicationHandler.java:261) ~[jersey-server-3.1.1.jar:?]\n\torg.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.(GrizzlyHttpContainer.java:310) ~[jersey-container-grizzly2-http-3.1.1.jar:?]\n\torg.glassfish.jersey.grizzly2.httpserver.HttpGrizzlyContainer$Companion.makeHandler(HttpGrizzlyContainer.kt:9) ~[common-web-1.1-SNAPSHOT.jar:?]\n\tio.featurehub.jersey.FeatureHubJerseyHost.start(FeatureHubJerseyHost.kt:99) ~[common-web-1.1-SNAPSHOT.jar:?]\n\tio.featurehub.jersey.FeatureHubJerseyHost.start(FeatureHubJerseyHost.kt:62) ~[common-web-1.1-SNAPSHOT.jar:?]\n\tio.featurehub.Application.run(Application.java:60) ~[mr-1.1-SNAPSHOT.jar:?]\n\tio.featurehub.Application.main(Application.java:31) [mr-1.1-SNAPSHOT.jar:?]\n\tjdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]\n\tjdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:?]\n\tjdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:?]\n\tjava.lang.reflect.Method.invoke(Unknown Source) ~[?:?]\n\tbathe.BatheBooter.tryMainMethod(BatheBooter.java:149) [bathe-booter-3.2.jar:?]\n\tbathe.BatheBooter.exec(BatheBooter.java:166) [bathe-booter-3.2.jar:?]\n\tbathe.BatheBooter.runWithLoader(BatheBooter.java:125) [bathe-booter-3.2.jar:?]\n\tbathe.BatheBooter.run(BatheBooter.java:115) [bathe-booter-3.2.jar:?]\n\tbathe.BatheBooter.main(BatheBooter.java:37) [bathe-booter-3.2.jar:?]\n\tCaused by: java.sql.SQLException: Error executing stmt[alter table fh_celog add constraint fk_fh_celog_fk_org foreign key (fk_org) references fh_organization (id) on delete restrict on update restrict] error[ERROR: there is no unique constraint matching given keys for referenced table \"fh_organization\"]\n\tio.ebean.ddlrunner.DdlRunner.runStatement(DdlRunner.java:105) ~[ebean-ddl-runner-2.2.jar:2.2]\n\tio.ebean.ddlrunner.DdlRunner.runStatements(DdlRunner.java:71) ~[ebean-ddl-runner-2.2.jar:2.2]\n\tio.ebean.ddlrunner.DdlRunner.runAll(DdlRunner.java:54) ~[ebean-ddl-runner-2.2.jar:2.2]\n\tio.ebean.migration.runner.MigrationScriptRunner.runScript(MigrationScriptRunner.java:34) ~[ebean-migration-13.7.0.jar:13.7.0]\n\tio.ebean.migration.runner.MigrationTable.executeMigration(MigrationTable.java:411) ~[ebean-migration-13.7.0.jar:13.7.0]\n\tio.ebean.migration.runner.MigrationTable.executeMigration(MigrationTable.java:389) ~[ebean-migration-13.7.0.jar:13.7.0]\n\tio.ebean.migration.runner.MigrationTable.runMigration(MigrationTable.java:316) ~[ebean-migration-13.7.0.jar:13.7.0]\n\tio.ebean.migration.runner.MigrationTable.shouldRun(MigrationTable.java:284) ~[ebean-migration-13.7.0.jar:13.7.0]\n\tio.ebean.migration.runner.MigrationTable.runAll(MigrationTable.java:505) ~[ebean-migration-13.7.0.jar:13.7.0]\n\tio.ebean.migration.MigrationRunner.runMigrations(MigrationRunner.java:143) ~[ebean-migration-13.7.0.jar:13.7.0]\n\tio.ebean.migration.MigrationRunner.run(MigrationRunner.java:107) ~[ebean-migration-13.7.0.jar:13.7.0]\n\tCaused by: org.postgresql.util.PSQLException: ERROR: there is no unique constraint matching given keys for referenced table \"fh_organization\"\n\torg.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2713) ~[postgresql-42.6.0.jar:42.6.0]\n\torg.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2401) ~[postgresql-42.6.0.jar:42.6.0]\n\torg.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:368) ~[postgresql-42.6.0.jar:42.6.0]\n\torg.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:498) ~[postgresql-42.6.0.jar:42.6.0]\n\torg.postgresql.jdbc.PgStatement.execute(PgStatement.java:415) ~[postgresql-42.6.0.jar:42.6.0]\n\torg.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:190) ~[postgresql-42.6.0.jar:42.6.0]\n\torg.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:177) ~[postgresql-42.6.0.jar:42.6.0]\n\tio.ebean.datasource.pool.ExtendedPreparedStatement.execute(ExtendedPreparedStatement.java:103) ~[ebean-datasource-8.5.jar:8.5]\n\tio.ebean.ddlrunner.DdlRunner.runStatement(DdlRunner.java:100) ~[ebean-ddl-runner-2.2.jar:2.2]\n\tio.ebean.ddlrunner.DdlRunner.runStatements(DdlRunner.java:71) ~[ebean-ddl-runner-2.2.jar:2.2]\n\tio.ebean.ddlrunner.DdlRunner.runAll(DdlRunner.java:54) ~[ebean-ddl-runner-2.2.jar:2.2]\n\tio.ebean.migration.runner.MigrationScriptRunner.runScript(MigrationScriptRunner.java:34) ~[ebean-migration-13.7.0.jar:13.7.0]\n\tio.ebean.migration.runner.MigrationTable.executeMigration(MigrationTable.java:411) ~[ebean-migration-13.7.0.jar:13.7.0]\n\tio.ebean.migration.runner.MigrationTable.executeMigration(MigrationTable.java:389) ~[ebean-migration-13.7.0.jar:13.7.0]\n\tio.ebean.migration.runner.MigrationTable.runMigration(MigrationTable.java:316) ~[ebean-migration-13.7.0.jar:13.7.0]\n\tio.ebean.migration.runner.MigrationTable.shouldRun(MigrationTable.java:284) ~[ebean-migration-13.7.0.jar:13.7.0]\n\tio.ebean.migration.runner.MigrationTable.runAll(MigrationTable.java:505) ~[ebean-migration-13.7.0.jar:13.7.0]\n\tio.ebean.migration.MigrationRunner.runMigrations(MigrationRunner.java:143) ~[ebean-migration-13.7.0.jar:13.7.0]\n\tio.ebean.migration.MigrationRunner.run(MigrationRunner.java:107) ~[ebean-migration-13.7.0.jar:13.7.0]","host":"featurehub-management-repository-757f44c8c9-kpltd"}

rvowles commented 2 months ago

Has your fh_organization table lost its primary key? Can you check? I cannot see how this would be possible.

The error appears to be saying that the fh_organization has no primary key or unique field called "id" - which is most definitely does!

chkp-liordan commented 2 months ago

apparently, fh_organization and fh_person table has no constraint in my DB. i start from 1.6.0 and upgrade to 1.7.0 and now to 1.8.0, and it seams that there was no constraint.

fixing that by running the next commands:

ALTER TABLE fh_organization ADD CONSTRAINT pk_fh_organization_id PRIMARY KEY (id);

ALTER TABLE fh_organization ADD CONSTRAINT uq_fh_organization_id UNIQUE (id);

ALTER TABLE fh_person ADD CONSTRAINT pk_fh_person_id PRIMARY KEY (id);

ALTER TABLE fh_person ADD CONSTRAINT uq_fh_person_id UNIQUE (id);