create timestamp function + sequences on test schema loads too

This fixes a strange issue when running RSpec with changed migrations.

Basically: `ActiveRecord::Migration.maintain_test_schema!` drops the
database and wants to apply the schema from the `schema.rb` again, but
that fails at creating the `answers` table since it can't find the
postgres function `gen_timestamp_id`.

Internally it just calls `bin/rails db:test:load_schema`, so I just
hook it in the same way I do it for `db:schema:load` (used by
`db:setup` ...)
This commit is contained in:
Georg Gadinger 2022-01-11 23:16:56 +01:00
parent 452c71c128
commit 60a8e3ac7d

View file

@ -467,8 +467,12 @@ namespace :db do
# create timestampid before loading schema
Rake::Task['db:schema:load'].enhance ['db:schema:create_timestampid_function']
Rake::Task['db:test:load_schema'].enhance ['db:schema:create_timestampid_function']
# create id_sequences after loading schema
Rake::Task['db:schema:load'].enhance do
Rake::Task['db:schema:create_id_sequences'].invoke
end
Rake::Task['db:test:load_schema'].enhance do
Rake::Task['db:schema:create_id_sequences'].invoke
end
end