Error during sql migration

Hi, I’ve been struggling trying to get database migration to work in Hydra. I’ve gone through the tutorials and can get everything working fine when configuring verbatim through the tutorial. What I’d like to do though is use a docker-compose file to pull all the pieces of hydra from docker hub, and will build our consent application separately.

I’ve modified the sample compose file from the git repository to pull images for postgresd:9.6 and oryd/hydra:latest (for hydra and hydra_migrate) before adding in the consent application. When running the migration, I’m getting an error I’ve seen around the forums, but don’t understand why I’m getting it. In the compose file, I have the same SYSTEM_SECRET in the environment section for both hydra-migrate, hydra, and postgresd. Below is the output:

postgresd_1 | LOG: database system was shut down at 2018-02-27 16:09:42 UTC
postgresd_1 | LOG: MultiXact member wraparound protections are now enabled
hydra-migrate_1 | time=“2018-02-27T16:11:07Z” level=info msg="Connecting with postgres://:@postgresd:5432/hydra?sslmode=disable"
postgresd_1 | LOG: database system is ready to accept connections
hydra-migrate_1 | time=“2018-02-27T16:11:07Z” level=info msg="Connected to SQL!"
hydra_1 | time=“2018-02-27T16:11:09Z” level=info msg="Connecting with postgres://:@postgresd:5432/hydra?sslmode=disable"
postgresd_1 | LOG: autovacuum launcher started
hydra-migrate_1 | Could not fetch signing key for OpenID Connect - did you forget to run “hydra migrate sql” or forget to set the SYSTEM_SECRET? Got error: pq: relation “hydra_jwk” does not exist
hydra_1 | time=“2018-02-27T16:11:09Z” level=info msg="Connected to SQL!"
postgresd_1 | ERROR: relation “hydra_jwk” does not exist at character 15
postgresd_1 | STATEMENT: SELECT * FROM hydra_jwk WHERE sid=$1 AND kid=$2
hydra_1 | Could not fetch signing key for OpenID Connect - did you forget to run “hydra migrate sql” or forget to set the SYSTEM_SECRET? Got error: pq: relation “hydra_jwk” does not exist
postgresd_1 | ERROR: relation “hydra_jwk” does not exist at character 15
postgresd_1 | STATEMENT: SELECT * FROM hydra_jwk WHERE sid=$1 AND kid=$2
postgresd_1 | ERROR: relation “hydra_jwk” does not exist at character 15
postgresd_1 | STATEMENT: SELECT * FROM hydra_jwk WHERE sid=$1 AND kid=$2
postgresd_1 | ERROR: relation “hydra_jwk” does not exist at character 15
postgresd_1 | STATEMENT: SELECT * FROM hydra_jwk WHERE sid=$1 AND kid=$2
postgresd_1 | ERROR: relation “hydra_jwk” does not exist at character 15
postgresd_1 | STATEMENT: SELECT * FROM hydra_jwk WHERE sid=$1 AND kid=$2
postgresd_1 | ERROR: relation “hydra_jwk” does not exist at character 15
postgresd_1 | STATEMENT: SELECT * FROM hydra_jwk WHERE sid=$1 AND kid=$2

  1. Is it a bad idea to be trying to use hydra images that are prebuilt instead of building them on my system?
  2. If this is an acceptable approach, does anyone know what could possibly be misconfigured? I’ll share more details if needed.

Thanks for any suggestions.

  1. Don’t use hydra:latest
  2. Did you run hydra migrate sql against the database you created?
  3. Please show the compose file
  4. Use the prebuilt images

Thanks for the quick reply! I’m new to both Hydra and Docker but did a lot of searching before I caved in and asked a question.

The command in the compose for hydra-migrate shows it should be running the migration (so it seems at least). I don’t see a good way to format or load a file, but I’m attaching the contents. If there’s a way to make it more legible I can change it.

###########################################################################
####### FOR DEMONSTRATION PURPOSES ONLY #######
###########################################################################

If you have not yet read the tutorial, do so now:

https://ory-am.gitbooks.io/hydra/content/tutorial.html

This set up is only for demonstration purposes. The login

endpoint can only be used if you follow the steps in the tutorial.

###########################################################################

version: ‘2’

services:

hydra-migrate:
image: oryd/hydra:latest
links:
- postgresd:postgresd
command:
migrate sql postgres://hydra:secret@postgresd:5432/hydra?sslmode=disable
environment:
- DATABASE_URL=postgres://hydra:secret@postgresd:5432/hydra?sslmode=disable
- SYSTEM_SECRET=ThisIsaDanGERousSecretANDmuSTbEChanged82
restart: on-failure

hydra:
image: oryd/hydra:latest
links:
- postgresd:postgresd

Uncomment the following line to use mysql instead.

- mysqld:mysqld

depends_on:
  - hydra-migrate
volumes:
  - hydravolume:/root
ports:
  - "4444:4444"
  - "4445:4445"
command:
  host --dangerous-auto-logon --dangerous-force-http --disable-telemetry
environment:
  - LOG_LEVEL=debug
  - ISSUER=http://localhost:4444
  - CONSENT_URL=http://localhost:3000
  - DATABASE_URL=postgres://hydra:secret@postgresd:5432/hydra?sslmode=disable
  - FORCE_ROOT_CLIENT_CREDENTIALS=admin:demo-password
  - SYSTEM_SECRET=ThisIsaDanGERousSecretANDmuSTbEChanged82
#restart: unless-stopped

postgresd:
image: postgres:9.6
ports:
- "5432:5432"
environment:
- POSTGRES_USER=hydra
- POSTGRES_PASSWORD=secret
- POSTGRES_DB=hydra
- SYSTEM_SECRET=ThisIsaDanGERousSecretANDmuSTbEChanged82

volumes:
hydravolume:
driver: local

Try tearing down and removing all docker images related to hydra and restart the build

Fantastic!! I changed image to oryd/hydra:v0.11.6-alpine, and deleted all images and containers, then the migration worked!! I had previously tried removing images and containers to no avail, so I suppose choosing a version of hydra made the difference.

Thank you so much for your help! I can’t believe how responsive you are to everyone’s queries.

Awesome, glad to be of help!

I deleted the latest tag so this doesn’t happen again

Thanks again. It was a rookie mistake on my part. Now, to get everything configured and secured!

No worries, glad I was able to help you resolve it so quickly :slight_smile: