jdtornow / challah

User authorization and session management in Rails.
MIT License
18 stars 7 forks source link

Fix running migrations on empty database #27

Closed philtr closed 8 years ago

philtr commented 8 years ago

Good afternoon @jdtornow!

I couldn't run migrations on an empty database in Rails 5.

Running rails db:migrate gave me this error:

ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "admin_users" does not exist
LINE 8:                WHERE a.attrelid = '"admin_users"'::regclass
                                          ^
:               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                     pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
             (SELECT c.collname FROM pg_collation c, pg_type t
               WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation),
                     col_description(a.attrelid, a.attnum) AS comment
                FROM pg_attribute a LEFT JOIN pg_attrdef d
                  ON a.attrelid = d.adrelid AND a.attnum = d.adnum
               WHERE a.attrelid = '"admin_users"'::regclass
                 AND a.attnum > 0 AND NOT a.attisdropped
               ORDER BY a.attnum

Commenting out include Challah::Userable fixed the issue, as well as the code attached to this pull request (does not exist is for postgres, could not find table is for sqlite).

I'm not married to this approach, but this was the offending code. If you have a better idea, I'd be happy to implement it.

Cheers!

jdtornow commented 8 years ago

Great find. Thanks a ton @philtr!