Skip to content

Commit

Permalink
Disable troublesome migration
Browse files Browse the repository at this point in the history
Run code in a task instead avoid incompatibility with future code changes
  • Loading branch information
fumimowdan committed Sep 14, 2023
1 parent 723149f commit 2517e75
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ RUN bundle exec rake assets:precompile && \
rm -rf node_modules tmp

CMD bundle exec rails db:migrate && \
bundle exec rake set_app_settings && \
bundle exec rails server -b 0.0.0.0
8 changes: 8 additions & 0 deletions app/models/app_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,13 @@ def self.current
AppSettings.first_or_create!
end

def configured?
service_start_date.present? && service_end_date.present?
end

def to_s
"Start Date: #{service_start_date} --- End Date: #{service_end_date}"
end

private_class_method :new
end
5 changes: 1 addition & 4 deletions db/migrate/20230721082851_enable_opening_times.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
class EnableOpeningTimes < ActiveRecord::Migration[7.0]
def change
AppSettings.current.update!(
service_start_date: Time.zone.yesterday,
service_end_date: Time.zone.today + 1.year,
)
# Disable this migration and move code into task `rake set_app_settings`
end
end
25 changes: 25 additions & 0 deletions lib/tasks/app_setting.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
desc "sets app setting for environments different than production with no setting"
task set_app_settings: :environment do
if Rails.env.production?
msg = "Not changing production settings"
puts msg
Rails.logger.info(msg)
exit
end

current_setting = AppSettings.current
if current_setting.configured?
msg = "Keeping existing setting: #{current_setting}"
puts msg
Rails.logger.info(msg)
exit
end

current_setting.update!(
service_start_date: Time.zone.yesterday,
service_end_date: Time.zone.today + 1.year,
)
msg = "Updated settings to: #{current_setting}"
puts msg
Rails.logger.info(msg)
end

0 comments on commit 2517e75

Please sign in to comment.