Database build failing

80 views
Skip to first unread message

Tom Hanstra

unread,
Jan 26, 2018, 3:14:32 PM1/26/18
to keywhiz-users
I've been able to get Keywhiz running using the docker container. But the instructions for (and evidently the underlying config file related to) building the database is not working.

When I run the migrate command on the build, instead of creating the database in /data directory, it creates it in files in /tmp/h2_data.  When I later try to add a user or do anything with the server, things die on trying to get to the data base:

Exception in thread "main" org.jooq.exception.DataAccessException: SQL [insert into USERS (USERNAME, PASSWORD_HASH, CREATED_AT, UPDATED_AT) values (cast(? as varchar), cast(? as varchar), cast(? as timestamp), cast(? as timestamp))]; Unique index or primary key violation: "PRIMARY_KEY_4 ON PUBLIC.USERS(USERNAME) VALUES ('keywhizadmin', 1)"; SQL statement:
insert into USERS (USERNAME, PASSWORD_HASH, CREATED_AT, UPDATED_AT) values (cast(? as varchar), cast(? as varchar), cast(? as timestamp), cast(? as timestamp)) [23505-187]
at org.jooq_3.10.2.H2.debug(Unknown Source)
at org.jooq.impl.Tools.translate(Tools.java:2194)
at org.jooq.impl.DefaultExecuteContext.sqlException(DefaultExecuteContext.java:701)
at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:358)
at org.jooq.impl.AbstractDelegatingQuery.execute(AbstractDelegatingQuery.java:124)
at keywhiz.service.daos.UserDAO.createUserAt(UserDAO.java:50)
at keywhiz.service.daos.UserDAO.createUser(UserDAO.java:54)
at keywhiz.commands.AddUserCommand.run(AddUserCommand.java:45)
at keywhiz.commands.AddUserCommand.run(AddUserCommand.java:29)
at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:76)
at io.dropwizard.cli.Cli.run(Cli.java:70)
at io.dropwizard.Application.run(Application.java:73)
at keywhiz.KeywhizService.main(KeywhizService.java:72)
Caused by: org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "PRIMARY_KEY_4 ON PUBLIC.USERS(USERNAME) VALUES ('keywhizadmin', 1)"; SQL statement:
insert into USERS (USERNAME, PASSWORD_HASH, CREATED_AT, UPDATED_AT) values (cast(? as varchar), cast(? as varchar), cast(? as timestamp), cast(? as timestamp)) [23505-187]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:179)
at org.h2.message.DbException.get(DbException.java:155)
at org.h2.index.BaseIndex.getDuplicateKeyException(BaseIndex.java:102)
at org.h2.mvstore.db.MVSecondaryIndex.checkUnique(MVSecondaryIndex.java:233)
at org.h2.mvstore.db.MVSecondaryIndex.add(MVSecondaryIndex.java:191)
at org.h2.mvstore.db.MVTable.addRow(MVTable.java:638)
at org.h2.command.dml.Insert.insertRows(Insert.java:156)
at org.h2.command.dml.Insert.update(Insert.java:114)
at org.h2.command.CommandContainer.update(CommandContainer.java:78)
at org.h2.command.Command.executeUpdate(Command.java:254)
at org.h2.jdbc.JdbcPreparedStatement.execute(JdbcPreparedStatement.java:198)
at org.jooq.tools.jdbc.DefaultPreparedStatement.execute(DefaultPreparedStatement.java:206)
at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:426)
at org.jooq.impl.AbstractDMLQuery.execute(AbstractDMLQuery.java:449)
at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:344)
... 9 more

Where is the right config file that will allow me to create the database properly?  The migrate command is not building things properly.

Tom Hanstra

unread,
Jan 26, 2018, 3:26:27 PM1/26/18
to keywhiz-users
Here is a more clear list of what is happening:

docker run -v keywhiz-db-devel:/data ndlib/kw-dev migrate
------------------------------------------------------------------------
---    No configuration file specified, using development config!    ---
--- Use the KEYWHIZ_CONFIG environment variable to set a config file ---
------------------------------------------------------------------------
INFO  [2018-01-26 20:22:07,969] org.flywaydb.core.internal.util.VersionPrinter: Flyway 4.2.0 by Boxfuse
INFO  [2018-01-26 20:22:08,233] org.flywaydb.core.internal.dbsupport.DbSupportFactory: Database: jdbc:h2:/tmp/h2_data/keywhizdb_development (H2 1.4)
INFO  [2018-01-26 20:22:08,368] org.flywaydb.core.internal.command.DbValidate: Successfully validated 32 migrations (execution time 00:00.048s)
INFO  [2018-01-26 20:22:08,387] org.flywaydb.core.internal.metadatatable.MetaDataTableImpl: Creating Metadata table: "PUBLIC"."schema_version"
INFO  [2018-01-26 20:22:08,431] org.flywaydb.core.internal.command.DbMigrate: Current version of schema "PUBLIC": << Empty Schema >>
INFO  [2018-01-26 20:22:08,440] org.flywaydb.core.internal.command.DbMigrate: Migrating schema "PUBLIC" to version 1 - create tables
INFO  [2018-01-26 20:22:08,502] org.flywaydb.core.internal.command.DbMigrate: Migrating schema "PUBLIC" to version 1.1 - create unique secrets index
... lots more INFO about database initializaton
Found constraint (REFERENTIAL, CONSTRAINT_32, SECRETS_CONTENT) - Dropped it.
Found constraint (REFERENTIAL, CONSTRAINT_D3E, MEMBERSHIPS) - Dropped it.
Found constraint (REFERENTIAL, CONSTRAINT_24, ACCESSGRANTS) - Dropped it.
Found constraint (REFERENTIAL, CONSTRAINT_241, ACCESSGRANTS) - Dropped it.
Found constraint (REFERENTIAL, CONSTRAINT_D3, MEMBERSHIPS) - Dropped it.
INFO  [2018-01-26 20:22:09,182] org.flywaydb.core.internal.command.DbMigrate: Migrating schema "PUBLIC" to version 4 - alter secret content to add hmac
INFO  [2018-01-26 20:22:09,198] org.flywaydb.core.internal.command.DbMigrate: Migrating schema "PUBLIC" to version 5 - add index current to secrets
INFO  [2018-01-26 20:22:09,204] org.flywaydb.core.internal.command.DbMigrate: Migrating schema "PUBLIC" to version 6 - drop unique constraint on secret name
INFO  [2018-01-26 20:22:09,216] org.flywaydb.core.internal.command.DbMigrate: Successfully applied 32 migrations to schema "PUBLIC" (execution time 00:00.831s)


docker run -v keywhiz-db-devel:/data ndlib/kw-dev server
------------------------------------------------------------------------
---    No configuration file specified, using development config!    ---
--- Use the KEYWHIZ_CONFIG environment variable to set a config file ---
------------------------------------------------------------------------
INFO  [2018-01-26 20:23:47,970] org.eclipse.jetty.util.log: Logging initialized @1941ms
INFO  [2018-01-26 20:23:48,900] keywhiz.service.config.Templates: Reading configuration value from file server/src/main/resources/dev_and_test_cookiekey.base64
INFO  [2018-01-26 20:23:50,089] keywhiz.service.config.KeyStoreConfig: Opening keystore at resource path jar:file:/usr/src/app/server/target/keywhiz-server-0.8.1-SNAPSHOT-shaded.jar!/derivation.jceks
INFO  [2018-01-26 20:23:50,241] org.flywaydb.core.internal.util.VersionPrinter: Flyway 4.2.0 by Boxfuse
INFO  [2018-01-26 20:23:50,254] org.flywaydb.core.internal.dbsupport.DbSupportFactory: Database: jdbc:h2:/tmp/h2_data/keywhizdb_development (H2 1.4)
Exception in thread "main" org.flywaydb.core.api.FlywayException: Validate failed: Detected resolved migration not applied to database: 1
at org.flywaydb.core.Flyway.doValidate(Flyway.java:1065)
at org.flywaydb.core.Flyway.access$100(Flyway.java:72)
at org.flywaydb.core.Flyway$2.execute(Flyway.java:1038)
at org.flywaydb.core.Flyway$2.execute(Flyway.java:1035)
at org.flywaydb.core.Flyway.execute(Flyway.java:1464)
at org.flywaydb.core.Flyway.validate(Flyway.java:1035)
at keywhiz.KeywhizService.validateDatabase(KeywhizService.java:170)
at keywhiz.KeywhizService.run(KeywhizService.java:158)
at keywhiz.KeywhizService.run(KeywhizService.java:65)
at io.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:42)
at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:76)
at io.dropwizard.cli.Cli.run(Cli.java:70)
at io.dropwizard.Application.run(Application.java:73)
at keywhiz.KeywhizService.main(KeywhizService.java:72)


The server command above looks for the database here:
Database: jdbc:h2:/tmp/h2_data/keywhizdb_development (H2 1.4) 

which is not what it did the migration on.  Why?  How can I fix this?



Alok Menghrajani

unread,
Jan 26, 2018, 4:19:09 PM1/26/18
to keywhiz-users
docker/keywhiz-config.tpl configures /data/keywhizdb_development but
keywhiz-development.yaml.h2 uses /tmp/h2_data/keywhizdb_development

That might explain why things don't work.

Alok

--
You received this message because you are subscribed to the Google Groups "keywhiz-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keywhiz-users+unsubscribe@googlegroups.com.
To post to this group, send email to keywhi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/keywhiz-users/db0113ef-306e-4e71-b8a5-b4973ceafdea%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages