Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not attempt initialization when the user is changing the database #81

Merged
merged 1 commit into from
Jun 30, 2023

Conversation

duncanjbrown
Copy link
Contributor

db:* rake commands are often useful to bring the database into line with what DfE::Analytics expects, so it can be painful not to be able to run them when the config is inconsistent. Allow these commands at all times - full checks will run on app or test boot anyway.

I couldn't think of a reasonable way to test this!

db:* rake commands are often useful to bring the database into line with
what DfE::Analytics expects, so it can be painful not to be able to run
them when the config is inconsistent. Allow these commands at all times -
full checks will run on app or test boot anyway.
@@ -34,7 +34,15 @@ class Railtie < Rails::Railtie
config.after_initialize do
# internal gem tests will sometimes suppress this so they can test the
# init process
DfE::Analytics.initialize! unless ENV['SUPPRESS_DFE_ANALYTICS_INIT']
if running_db_rake_task? || ENV['SUPPRESS_DFE_ANALYTICS_INIT']
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

db: commands can also be invoked using rails, so possibly need to cater for rails invocation also.

@duncanjbrown
Copy link
Contributor Author

duncanjbrown commented Jun 29, 2023 via email

end

def running_db_rake_task?
defined?(Rake) && Rake.application.top_level_tasks.any? { |t| t.start_with?('db:') }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to see if there was a way we could look at the namespace of the tasks rather than looking at what it starts with, but couldn't work out a nice way of doing it, so this seems fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's a bit ick. But it does seem to work

@duncanjbrown duncanjbrown merged commit 8a6da94 into main Jun 30, 2023
@duncanjbrown duncanjbrown deleted the allow-db-operations branch June 30, 2023 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants