Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Clean up the post deployment migration generator (mastodon#24233)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski authored Apr 11, 2023
1 parent 3c7053a commit a2a6630
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 25 deletions.
10 changes: 10 additions & 0 deletions lib/generators/post_deployment_migration/USAGE
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Description:
Generate a Rails migration in the db/post_migrate/ dir.

Interacts with the post_deployment_migrations initializer.

Example:
bin/rails generate post_deployment_migration IsolateChanges

Creates a migration in db/post_migrate/<timestamp>_isolate_changes.rb
which will have `disable_ddl_transaction!` and a `change` method included.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require 'rails/generators/active_record'

class PostDeploymentMigrationGenerator < Rails::Generators::NamedBase
source_root File.expand_path('templates', __dir__)

include Rails::Generators::Migration

def create_post_deployment_migration
migration_template 'migration.erb', "db/post_migrate/#{file_name}.rb"
end

def self.next_migration_number(path)
ActiveRecord::Generators::Base.next_migration_number(path)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
disable_ddl_transaction!

def change
end
end
17 changes: 0 additions & 17 deletions lib/generators/post_deployment_migration_generator.rb

This file was deleted.

8 changes: 0 additions & 8 deletions lib/templates/rails/post_deployment_migration/migration.rb

This file was deleted.

27 changes: 27 additions & 0 deletions spec/generators/post_deployment_migration_generator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require 'rails_helper'
require 'rails/generators/testing/behaviour'
require 'rails/generators/testing/assertions'

require 'generators/post_deployment_migration/post_deployment_migration_generator'

describe PostDeploymentMigrationGenerator, type: :generator do
include Rails::Generators::Testing::Behaviour
include Rails::Generators::Testing::Assertions
include FileUtils

tests described_class
destination File.expand_path('../../tmp', __dir__)
before { prepare_destination }
after { rm_rf(destination_root) }

describe 'the migration' do
it 'generates expected file' do
run_generator %w(Changes)

assert_migration('db/post_migrate/changes.rb', /disable_ddl/)
assert_migration('db/post_migrate/changes.rb', /change/)
end
end
end

0 comments on commit a2a6630

Please sign in to comment.