-
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.
- Loading branch information
Showing
19 changed files
with
239 additions
and
43 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
2 changes: 1 addition & 1 deletion
2
...ranslations_for_mobility_table_backend.rb → ..._dietary_requirement_name_translations.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
2 changes: 1 addition & 1 deletion
2
...ranslations_for_mobility_table_backend.rb → ...institution_name_and_city_translations.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
2 changes: 1 addition & 1 deletion
2
...ranslations_for_mobility_table_backend.rb → ...tation_title_and_abstract_translations.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
2 changes: 1 addition & 1 deletion
2
...ranslations_for_mobility_table_backend.rb → ...tion_attachment_type_name_translations.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
2 changes: 1 addition & 1 deletion
2
...ranslations_for_mobility_table_backend.rb → ...es_presentation_type_name_translations.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
2 changes: 1 addition & 1 deletion
2
...ranslations_for_mobility_table_backend.rb → ..._room_building_and_number_translations.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
2 changes: 1 addition & 1 deletion
2
...ranslations_for_mobility_table_backend.rb → ...nferences_conference_name_translations.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
2 changes: 1 addition & 1 deletion
2
...ranslations_for_mobility_table_backend.rb → ..._conferences_session_name_translations.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
2 changes: 1 addition & 1 deletion
2
...ranslations_for_mobility_table_backend.rb → ..._description_and_location_translations.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
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
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,81 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'active_support/concern' | ||
|
||
module Spina | ||
module Admin | ||
module Conferences | ||
module Migration | ||
module Renaming | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
@stale_migrations ||= [] | ||
@migrations_path ||= nil | ||
end | ||
|
||
class_methods do | ||
def rename_migration(name, to:) | ||
config.after_initialize do | ||
migration = {} | ||
migration[:old] = migration_hash(name) | ||
migration[:new] = migration_hash(to) | ||
if [migration[:old], migration[:new]].pluck(:file).all?(&:present?) | ||
@stale_migrations << migration | ||
end | ||
end | ||
end | ||
|
||
def raise_on_duplicate_migrations! | ||
raise DuplicateMigrationsError.new(@stale_migrations) if @stale_migrations.any? | ||
end | ||
|
||
private | ||
|
||
attr_reader :duplicate_migrations | ||
|
||
class DuplicateMigrationsError < ::StandardError | ||
def initialize(migrations) | ||
messages = migrations.collect { |migration| generate_message(migration) } | ||
super(messages.join("\n")) | ||
end | ||
|
||
private | ||
|
||
MIGRATION_REGEXP = /([0-9]+)_.+\.(spina(_admin)?_conferences).rb$/ | ||
|
||
def generate_message(migration) | ||
old_version, old_scope = parse_filename(migration[:old][:file]) | ||
messages = [] | ||
messages << "#{File.basename(migration[:new][:file])} is a renamed version of #{File.basename(migration[:old][:file])}." | ||
messages << "Rename #{File.basename(migration[:old][:file])} to #{old_version}_#{migration[:new][:name]}.#{old_scope}.rb " \ | ||
"and delete #{File.basename(migration[:new][:file])}." | ||
messages.join("\n") | ||
end | ||
|
||
def parse_filename(filename) | ||
filename.scan(MIGRATION_REGEXP).first | ||
end | ||
end | ||
|
||
def migration_hash(name) | ||
{ name: name, file: detect_migration(name) } | ||
end | ||
|
||
def migrations_path | ||
@migrations_path || ActiveRecord::Tasks::DatabaseTasks.migrations_paths.first | ||
end | ||
|
||
def engine_migration_glob(name) | ||
"#{migrations_path}/**/*_#{name}.spina{_admin,}_conferences.rb" | ||
end | ||
|
||
def detect_migration(name) | ||
Dir[engine_migration_glob(name)].first | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
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,34 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spina/admin/conferences/migration/renaming' | ||
|
||
module Spina | ||
module Admin | ||
module Conferences | ||
class Railtie < Rails::Railtie | ||
include Migration::Renaming | ||
|
||
rename_migration 'create_spina_conferences_dietary_requirement_name_translations_for_mobility_table_backend', | ||
to: 'create_spina_conferences_dietary_requirement_name_translations' | ||
rename_migration 'create_spina_conferences_institution_name_and_city_translations_for_mobility_table_backend', | ||
to: 'create_spina_conferences_institution_name_and_city_translations' | ||
rename_migration 'create_spina_conferences_presentation_attachment_type_name_translations_for_mobility_table_backend', | ||
to: 'create_spina_conferences_presentation_attachment_type_name_translations' | ||
rename_migration 'create_spina_conferences_presentation_type_name_translations_for_mobility_table_backend', | ||
to: 'create_spina_conferences_presentation_type_name_translations' | ||
rename_migration 'create_spina_conferences_room_building_and_number_translations_for_mobility_table_backend', | ||
to: 'create_spina_conferences_room_building_and_number_translations' | ||
rename_migration 'create_spina_conferences_conference_name_translations_for_mobility_table_backend', | ||
to: 'create_spina_conferences_conference_name_translations' | ||
rename_migration 'create_spina_conferences_session_name_translations_for_mobility_table_backend', | ||
to: 'create_spina_conferences_session_name_translations' | ||
rename_migration 'create_spina_conferences_event_name_description_and_location_translations_for_mobility_table_backend', | ||
to: 'create_spina_conferences_event_name_description_and_location_translations' | ||
|
||
config.after_initialize do | ||
raise_on_duplicate_migrations! | ||
end | ||
end | ||
end | ||
end | ||
end |
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ module Spina | |
module Admin | ||
module Conferences | ||
# Version number. | ||
VERSION = '1.3.2' | ||
VERSION = '1.3.3' | ||
end | ||
end | ||
end |
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
5 changes: 5 additions & 0 deletions
5
test/fixtures/files/migrations/fresh/00000000000000_old_name.spina_conferences.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,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class Foo < ActiveRecord::Migration[6.0] # :nodoc: | ||
def change; end | ||
end |
5 changes: 5 additions & 0 deletions
5
test/fixtures/files/migrations/stale/00000000000000_new_name.spina_admin_conferences.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,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class Foo < ActiveRecord::Migration[6.0] # :nodoc: | ||
def change; end | ||
end |
5 changes: 5 additions & 0 deletions
5
test/fixtures/files/migrations/stale/00000000000000_old_name.spina_conferences.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,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class Foo < ActiveRecord::Migration[6.0] # :nodoc: | ||
def change; end | ||
end |
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,65 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
module Spina | ||
module Admin | ||
module Conferences | ||
module Migration | ||
class RenamingTest < ActiveSupport::TestCase | ||
setup do | ||
@dummy_class = Class.new(Rails::Railtie) do | ||
class << self | ||
attr_accessor :stale_migrations | ||
attr_accessor :migrations_path | ||
end | ||
end | ||
end | ||
|
||
test 'initializes stale migrations array' do | ||
assert_nil @dummy_class.stale_migrations | ||
@dummy_class.include(Renaming) | ||
assert_equal [], @dummy_class.stale_migrations | ||
end | ||
|
||
test 'adds stale migrations when declared' do | ||
@dummy_class.migrations_path = file_fixture('migrations/stale').to_path | ||
@dummy_class.include(Renaming) | ||
assert_empty @dummy_class.stale_migrations | ||
@dummy_class.rename_migration 'old_name', to: 'new_name' | ||
assert_not_empty @dummy_class.stale_migrations | ||
end | ||
|
||
test 'does not add fresh migrations when declared' do | ||
@dummy_class.migrations_path = file_fixture('migrations/fresh').to_path | ||
@dummy_class.include(Renaming) | ||
assert_empty @dummy_class.stale_migrations | ||
@dummy_class.rename_migration 'old_name', to: 'new_name' | ||
assert_empty @dummy_class.stale_migrations | ||
end | ||
|
||
test 'raises on duplicate migrations' do | ||
@dummy_class.include(Renaming) | ||
@dummy_class.stale_migrations = [ | ||
{ | ||
old: { name: 'old_name', file: '00000000000000_old_name.spina_conferences.rb' }, | ||
new: { name: 'new_name', file: '00000000000000_new_name.spina_conferences.rb' } | ||
} | ||
] | ||
assert_raises Renaming::DuplicateMigrationsError do | ||
@dummy_class.raise_on_duplicate_migrations! | ||
end | ||
end | ||
|
||
test 'does not raise on empty migrations' do | ||
@dummy_class.include(Renaming) | ||
@dummy_class.stale_migrations = [] | ||
assert_nothing_raised do | ||
@dummy_class.raise_on_duplicate_migrations! | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |