Skip to content

Commit

Permalink
Use strong_migrations gem
Browse files Browse the repository at this point in the history
**Why**: `strong_migrations` is better maintained than
`zero_downtime_migrations` and seems to have better advice. The author
of the gem has written many other fantastic gems that are used in
production at Instacart, so they should be trustworthy.

The gem also comes with a handy rake task that will automatically
alphabetize the columns in `schema.rb`. This will eliminate issues
where after pulling the latest code and running recent migrations
locally, your schema.rb will change.
  • Loading branch information
monfresh committed Jan 15, 2019
1 parent f1ff53e commit 0e95d39
Show file tree
Hide file tree
Showing 6 changed files with 406 additions and 403 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Expand Up @@ -58,12 +58,12 @@ gem "sentry-raven"
gem "shoryuken", "3.1.11"
gem "sqlite3", platforms: [:ruby, :mswin, :mingw, :mswin, :x64_mingw]
gem "stringex", require: false
# catch problematic migrations at development/test time
gem "strong_migrations"
# execjs runtime
gem "therubyracer", platforms: :ruby
# Use Uglifier as compressor for JavaScript assets
gem "uglifier", ">= 1.3.0"
# catch problematic migrations at development/test time
gem "zero_downtime_migrations"

group :production, :staging, :ssh_forwarding, :development, :test do
# Oracle DB
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Expand Up @@ -464,6 +464,8 @@ GEM
sprockets (>= 3.0.0)
sqlite3 (1.3.13)
stringex (2.8.5)
strong_migrations (0.3.1)
activerecord (>= 3.2.0)
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
therubyracer (0.12.3)
Expand Down Expand Up @@ -496,8 +498,6 @@ GEM
nokogiri (~> 1.5)
xpath (3.0.0)
nokogiri (~> 1.8)
zero_downtime_migrations (0.0.7)
activerecord

PLATFORMS
ruby
Expand Down Expand Up @@ -567,11 +567,11 @@ DEPENDENCIES
sniffybara!
sqlite3
stringex
strong_migrations
therubyracer
timecop
tzinfo-data
uglifier (>= 1.3.0)
zero_downtime_migrations

BUNDLED WITH
1.17.2
2 changes: 2 additions & 0 deletions Rakefile
Expand Up @@ -7,3 +7,5 @@ require File.expand_path("config/application", __dir__)
Dir[Rails.root.join("lib/tasks/support/**/*.rb")].each { |f| require f }

Rails.application.load_tasks

task "db:schema:dump": "strong_migrations:alphabetize_columns"
1 change: 1 addition & 0 deletions config/initializers/strong_migrations.rb
@@ -0,0 +1 @@
StrongMigrations.start_after = 20190111000717
14 changes: 7 additions & 7 deletions db/migrate/20190110220936_make_hearing_views_polymorphic.rb
@@ -1,13 +1,13 @@
class MakeHearingViewsPolymorphic < ActiveRecord::Migration[5.1]
safety_assured

def change
add_column :hearing_views, :hearing_type, :string
remove_index :hearing_views, [:hearing_id, :user_id]
add_index :hearing_views, [:hearing_id, :user_id, :hearing_type], unique: true
safety_assured do
add_column :hearing_views, :hearing_type, :string
remove_index :hearing_views, [:hearing_id, :user_id]
add_index :hearing_views, [:hearing_id, :user_id, :hearing_type], unique: true

HearingView.find_each do |hearing_view|
hearing_view.update!(hearing_type: "LegacyHearing")
HearingView.find_each do |hearing_view|
hearing_view.update!(hearing_type: "LegacyHearing")
end
end
end
end

0 comments on commit 0e95d39

Please sign in to comment.