luckyframework / luckyframework/lucky_cli

Unhelpful error when the migrations table doesn't exist

Open
#737 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

improve error experience
Dominant language
HTML
Stars
92
Forks
48
PR merge metrics
No merged PRs in 30d

Description

This is the error message when a user boots a new lucky app with a correctly configured database url which points to an empty database (no migrations table):

2022-03-04 20:01:41.619 UTC [68] ERROR:  relation "migrations" does not exist at character 16
2022-03-04 20:01:41.619 UTC [68] STATEMENT:  SELECT id FROM migrations WHERE version = $1
web          | Unhandled exception: relation "migrations" does not exist (PQ::PQError)
web          | 
web          |                                              
web          |    🎉 App running at http://127.0.0.1:3001   
web          |                                              
web          | 

web          |   from lib/pg/src/pq/connection.cr:203:7 in 'handle_error'
web          |   from lib/pg/src/pq/connection.cr:186:7 in 'handle_async_frames'
web          |   from lib/pg/src/pq/connection.cr:162:7 in 'read'
web          |   from lib/pg/src/pq/connection.cr:157:7 in 'read'
web          |   from lib/pg/src/pq/connection.cr:414:31 in 'expect_frame'
web          |   from lib/pg/src/pq/connection.cr:413:5 in 'expect_frame'
web          |   from lib/pg/src/pg/statement.cr:18:5 in 'perform_query'
web          |   from lib/db/src/db/statement.cr:93:9 in 'perform_query_with_rescue'
web          |   from lib/db/src/db/statement.cr:80:7 in 'query:args'
web          |   from lib/db/src/db/pool_statement.cr:29:30 in 'query:args'
web          |   from lib/db/src/db/query_methods.cr:46:7 in 'query:args'
web          |   from lib/db/src/db/query_methods.cr:61:7 in 'query_one?:as'
web          |   from lib/avram/src/avram/migrator/migration.cr:67:7 in 'migrated?'
web          |   from lib/avram/src/avram/migrator/migration.cr:62:6 in 'pending?'
web          |   from lib/avram/src/avram/migrator/runner.cr:200:32 in 'pending_migrations'
web          |   from lib/avram/src/avram/migrator/runner.cr:172:9 in 'ensure_migrated!'
web          |   from src/start_server.cr:7:3 in '__crystal_main'
web          |   from /usr/share/crystal/src/crystal/main.cr:110:5 in 'main_user_code'
web          |   from /usr/share/crystal/src/crystal/main.cr:96:7 in 'main'
web          |   from /usr/share/crystal/src/crystal/main.cr:119:3 in 'main'
web          |   from __libc_start_main
web          |   from _start
web          |   from ???

As far as I can tell, that message comes from start_server.cr which is attempting to check to see that the database is up to date. Perhaps it should check to see if the migrations table exists before asking that question, and provide some helpful feedback if not.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at src/web_app_skeleton/src/start_server.cr.ecr and trace the migration check that produces the missing migrations-table error. Reproduce startup against an empty database, then define a more helpful failure message for that condition; done means the empty-database case no longer reports only the raw database error.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal, postgresql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.