From 001486ba3391e6205f3fa4de474f0282b3b82fc0 Mon Sep 17 00:00:00 2001 From: Alex Koval Date: Sun, 18 Aug 2024 23:21:03 +0400 Subject: [PATCH] add strong migrations --- Gemfile | 2 ++ Gemfile.lock | 3 +++ Rakefile | 1 + config/initializers/strong_migrations.rb | 26 ++++++++++++++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 config/initializers/strong_migrations.rb diff --git a/Gemfile b/Gemfile index 9785db0..54afcb5 100644 --- a/Gemfile +++ b/Gemfile @@ -21,6 +21,8 @@ gem "turbo-rails" gem "sidekiq" gem "sidekiq-scheduler" +gem "strong_migrations" + group :development, :test do gem "bullet", "~> 7.1.3" gem "debug" diff --git a/Gemfile.lock b/Gemfile.lock index 5dbb963..d0eeb2a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -328,6 +328,8 @@ GEM stimulus-rails (1.3.0) railties (>= 6.0.0) stringio (3.0.9) + strong_migrations (2.0.0) + activerecord (>= 6.1) tailwindcss-rails (2.0.32-x86_64-linux) railties (>= 6.0.0) thor (1.3.0) @@ -388,6 +390,7 @@ DEPENDENCIES sprockets-rails standard stimulus-rails + strong_migrations tailwindcss-rails (~> 2.0) turbo-rails web-console diff --git a/Rakefile b/Rakefile index d2a78aa..c458068 100644 --- a/Rakefile +++ b/Rakefile @@ -6,3 +6,4 @@ require_relative "config/application" Rails.application.load_tasks +task "db:schema:dump": "strong_migrations:alphabetize_columns" diff --git a/config/initializers/strong_migrations.rb b/config/initializers/strong_migrations.rb new file mode 100644 index 0000000..98b3868 --- /dev/null +++ b/config/initializers/strong_migrations.rb @@ -0,0 +1,26 @@ +# Mark existing migrations as safe +StrongMigrations.start_after = 20240818191740 + +# Set timeouts for migrations +# If you use PgBouncer in transaction mode, delete these lines and set timeouts on the database user +StrongMigrations.lock_timeout = 10.seconds +StrongMigrations.statement_timeout = 1.hour + +# Analyze tables after indexes are added +# Outdated statistics can sometimes hurt performance +StrongMigrations.auto_analyze = true + +# Set the version of the production database +# so the right checks are run in development +# StrongMigrations.target_version = 10 + +# Add custom checks +# StrongMigrations.add_check do |method, args| +# if method == :add_index && args[0].to_s == "users" +# stop! "No more indexes on the users table" +# end +# end + +# Make some operations safe by default +# See https://github.com/ankane/strong_migrations#safe-by-default +# StrongMigrations.safe_by_default = true