hasura-auth icon indicating copy to clipboard operation
hasura-auth copied to clipboard

Start hasura-auth without an external SQL init script

Open msalehy opened this issue 2 years ago • 5 comments

Local docker for auth return below error for initiate migration for first time

yarn run v1.22.17

$ node ./dist/start.js

{"level":30,"time":1643888397013,"pid":28,"hostname":"1265cd3406a3","msg":"Hasura is not ready. Retry in 5 seconds."}

{"level":30,"time":1643888403082,"pid":28,"hostname":"1265cd3406a3","msg":"Hasura is not ready. Retry in 5 seconds."}

{"level":30,"time":1643888411152,"pid":28,"hostname":"1265cd3406a3","msg":"Hasura is not ready. Retry in 5 seconds."}

{"level":30,"time":1643888416174,"pid":28,"hostname":"1265cd3406a3","msg":"Hasura is ready"}

(node:28) UnhandledPromiseRejectionWarning: Error: Migration failed. Reason: An error occurred running 'create-migrations-table'. Rolled back this migration. No further migrations were run. Reason: schema "auth" does not exist

    at /app/node_modules/@djgrant/postgres-migrations/dist/migrate.js:63:27

    at processTicksAndRejections (internal/process/task_queues.js:95:5)

    at async /app/node_modules/@djgrant/postgres-migrations/dist/with-lock.js:24:28

    at async applyMigrations (/app/dist/migrations.js:16:9)

    at async start (/app/dist/server.js:37:5)

(Use `node --trace-warnings ...` to show where the warning was created)

(node:28) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)

(node:28) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Done in 20.67s.

msalehy avatar Feb 03 '22 11:02 msalehy

You may need to add this init script to your postgresql database

plmercereau avatar Feb 03 '22 14:02 plmercereau

Closing this issue for now. If you're still facing this issue I'll reopen

plmercereau avatar Mar 02 '22 13:03 plmercereau

@plmercereau please open. I think the first part of applyMigrations method call in hasura-auth should be

create schema is not exists auth

before trying to apply migrations. not everyone has accessible DB to start running the init script first

shiftlabs1 avatar May 01 '22 21:05 shiftlabs1

In some other cases, the postgres user is not allowed to create schemas. We could find a way to solve both cases

plmercereau avatar May 02 '22 06:05 plmercereau

Since we can not modify existing migrations, and this CRETE SCHEMA IF NOT EXISTS auth must happen before all migrations are executed here are a few solutions:

  1. State that the auth schema must be present before starting Hasura Auth. I.e. Hasura Auth is not responsible for creating the auth schema.
  2. Hasura Auth creates the auth schema via raw SQL (e.g. via /v2/query (Hasura)) before running migrations.
  3. Change migrations solution from @djgrant/postgres-migrations to a solution where we can modify old migrations. @djgrant/postgres-migrations hashes migration files and will not fail to start if a migration file has been applied and then modified.

Solution 1 feels clean. Solution 2 feels a bit hacky but kind of OK. Solution 3 feels hacky and time-consuming.

elitan avatar Jun 07 '22 06:06 elitan

Can you please add it in the docs that if you want to use the nhost/hasura-auth image then you have to setup the auth schema yourself? 🙏🏾

abdullah2993 avatar Sep 30 '22 14:09 abdullah2993

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 11 '23 15:05 stale[bot]