This repository has been archived by the owner on Dec 21, 2023. It is now read-only.
forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up the post deployment migration generator (mastodon#24233)
- Loading branch information
1 parent
3c7053a
commit a2a6630
Showing
6 changed files
with
62 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
17 changes: 17 additions & 0 deletions
17
lib/generators/post_deployment_migration/post_deployment_migration_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
8 changes: 8 additions & 0 deletions
8
lib/generators/post_deployment_migration/templates/migration.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
spec/generators/post_deployment_migration_generator_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |