hanami db prepare command and empty schema.sql

Created on 1 Dec 2020  路  5Comments  路  Source: hanami/hanami

Hi! Following getting started guides I encountered an error in output on database setup. When running hanami db prepare the output of this command showed following snippet:

[hanami] [INFO] (0.000211s) SET standard_conforming_strings = ON
[hanami] [INFO] (0.000154s) SET client_min_messages = 'WARNING'
[hanami] [INFO] (0.000166s) SET DateStyle = 'ISO'
[hanami] [ERROR] PG::UndefinedTable: ERROR:  relation "schema_migrations" does not exist
LINE 1: SELECT NULL AS "nil" FROM "schema_migrations" LIMIT 1
                                  ^: SELECT NULL AS "nil" FROM "schema_migrations" LIMIT 1
[hanami] [INFO] (0.013304s) CREATE TABLE "schema_migrations" ("filename" text PRIMARY KEY)
[hanami] [ERROR] PG::UndefinedTable: ERROR:  relation "schema_info" does not exist
LINE 1: SELECT NULL AS "nil" FROM "schema_info" LIMIT 1
                                  ^: SELECT NULL AS "nil" FROM "schema_info" LIMIT 1
[hanami] [INFO] (0.000649s) SELECT "filename" FROM "schema_migrations" ORDER BY "filename"

This is related to empty db/schema.sql file which is included in new application and being read by hanami model in this line.

I wonder if db/schema.sql is needed in basic setup.

Hanami version: 1.3.3

bug

Most helpful comment

@hedselu I've spent some time investigating this issue and I believe the problem is actually related to the absence of schema_migrations or schema_info when sequel tries to create it, the Sequel source itself verifies if the table exists and creates it if that's not true. So, although Sequel creates the table successfully we're logging out the message regarding its absence.

My points:

The schema_migrations table does not exist yet, that's a fact, should we force it to be created before invoking Sequel?
_I've not convinced myself about this option once the Sequel is already handling the situation_

Should be just a matter of omitting the error for schema_migrations absence considering it'll be created by Sequel?
_Seems reasonable even though I may be missing something_ :thinking:

What do you guys think? I'm planning to work on a fix for the problem.

All 5 comments

Sorry you're running into this issue! I was able to reproduce it, not upon the initial hanami db prepare as I first tried but when there are migrations present. It seems like the migrations still work, though I agree this error shouldn't be displayed. Is that right?

Hi @cllns, that is right. Migrations work, but error is confusing that they might actually not.

@hedselu I've spent some time investigating this issue and I believe the problem is actually related to the absence of schema_migrations or schema_info when sequel tries to create it, the Sequel source itself verifies if the table exists and creates it if that's not true. So, although Sequel creates the table successfully we're logging out the message regarding its absence.

My points:

The schema_migrations table does not exist yet, that's a fact, should we force it to be created before invoking Sequel?
_I've not convinced myself about this option once the Sequel is already handling the situation_

Should be just a matter of omitting the error for schema_migrations absence considering it'll be created by Sequel?
_Seems reasonable even though I may be missing something_ :thinking:

What do you guys think? I'm planning to work on a fix for the problem.

The schema_migrations table does not exist yet, that's a fact, should we force it to be created before invoking Sequel?

I agree with you that this is probably the wrong course of action, and might not even work if so. If we force created the table, we'd have to handle a different error for the conflict.

Should be just a matter of omitting the error for schema_migrations absence considering it'll be created by Sequel?

I'd probably do this.

Do we know if this is specific to the Postgres adapter?

It isn't tight to Postgres only @adam12, I could achieve the same behavior using SQLite.

Was this page helpful?
0 / 5 - 0 ratings