Skip to content

Commit

Permalink
Recover when the database hasn’t been set up yet
Browse files Browse the repository at this point in the history
Manually throw a MigrationPending exception if needed, or in cases where
app code begins executing before migration has run (eg worker instances
that override default Docker entrypoints) and there is no DB schema yet
(eg review apps) we get an error saying that the whole schema needs to
be put into the blocklist
  • Loading branch information
duncanjbrown committed Oct 4, 2022
1 parent 8a056b5 commit 97e3ddd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/dfe/analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def self.configure
end

def self.initialize!
ActiveRecord::Base.connection # cause an exception early if we can't connect
raise ActiveRecord::PendingMigrationError if ActiveRecord::Base.connection.migration_context.needs_migration?

DfE::Analytics::Fields.check!

entities_for_analytics.each do |entity|
Expand Down
5 changes: 5 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def name; end
# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!

config.around do |example|
ActiveRecord::Base.connection.migration_context.migrate
example.run
end

config.define_derived_metadata do |metadata|
metadata[:skip_analytics_init] = true unless metadata[:skip_analytics_init] == false
end
Expand Down

0 comments on commit 97e3ddd

Please sign in to comment.