From 60a8e3ac7d6dba7166849a70ad7cdf6cb16b9a75 Mon Sep 17 00:00:00 2001 From: Georg Gadinger Date: Tue, 11 Jan 2022 23:16:56 +0100 Subject: [PATCH] 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` ...) --- Rakefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Rakefile b/Rakefile index 51594612..65f51123 100644 --- a/Rakefile +++ b/Rakefile @@ -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