Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions config/initializers/strong_migrations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,19 @@
# https://github.com/ankane/strong_migrations
StrongMigrations.start_after = 20260101000000 # rubocop:disable Style/NumericLiterals
StrongMigrations.target_postgresql_version = 16

# With preboot, the release phase runs before old web dynos stop, so old code
# serves against the new schema for ~3 minutes. Say so where the migration
# author will see it, next to the gem's `safety_assured` advice.
preboot_note = <<~TXT
Heroku preboot: this runs in the release phase before old web dynos stop,
so old code serves against the new schema for ~3 minutes after the deploy.
See AGENTS.md ("Migrations and Heroku preboot"). If the migration cannot
be made forward-compatible, disable preboot for this deploy.
TXT

%i[change_column change_column_with_not_null change_column_default
change_column_null rename_column rename_table rename_schema
rename_enum_value execute].each do |key|
StrongMigrations.error_messages[key] = "#{StrongMigrations.error_messages.fetch(key)}\n\n#{preboot_note}"
end
30 changes: 30 additions & 0 deletions spec/config/strong_migrations_config_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'StrongMigrations configuration' do # rubocop:disable RSpec/DescribeClass
describe 'destructive-operation messages' do
preboot_keys = %i[change_column change_column_with_not_null change_column_default
change_column_null rename_column rename_table rename_schema
rename_enum_value execute]

it 'appends the Heroku preboot note after the gem default' do
message = StrongMigrations.error_messages[:rename_column]

expect(message).to start_with("Renaming a column that's in use will cause errors")
expect(message).to end_with("disable preboot for this deploy.\n")
end

it 'carries the note exactly once on each destructive-operation message' do
counts = preboot_keys.index_with do |key|
StrongMigrations.error_messages.fetch(key).scan('disable preboot for this deploy').size
end

expect(counts.values).to all(eq(1))
end

it 'leaves messages for other checks unchanged' do
expect(StrongMigrations.error_messages[:add_index]).not_to include('Heroku preboot')
end
end
end
Loading