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
3 changes: 2 additions & 1 deletion lib/data_migrate/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ def config
end

class Config
attr_accessor :data_migrations_path, :data_template_path, :db_configuration, :spec_name
attr_accessor :data_migrations_path, :data_migrations_gen_path, :data_template_path, :db_configuration, :spec_name

DEFAULT_DATA_TEMPLATE_PATH = "data_migration.rb"

def initialize
@data_migrations_path = "db/data/"
@data_migrations_gen_path = "db/data"
@data_template_path = DEFAULT_DATA_TEMPLATE_PATH
@db_configuration = nil
@spec_name = nil
Expand Down
2 changes: 1 addition & 1 deletion lib/data_migrate/data_migrator_five.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
module DataMigrate
class DataMigrator < ActiveRecord::Migrator
def self.migrations_paths
[DataMigrate.config.data_migrations_path]
Array.wrap(DataMigrate.config.data_migrations_path)
end

def self.assure_data_schema_table
Expand Down
10 changes: 6 additions & 4 deletions lib/data_migrate/data_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ def migrated

def versions
@versions ||= begin
versions = []
Dir.foreach(DataMigrate::DataMigrator.full_migrations_path) do |file|
match_data = DataMigrate::DataMigrator.match(file)
versions << match_data[1].to_i if match_data
versions = Set.new
DataMigrate::DataMigrator.migrations_paths.each do |path|

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this might be changing the list from an expanded path to a relative path. It might be an issue if running the data_migrate command from somewhere other than Rails.root ? Pretty edge case, would not consider this a blocker for deployment, but maybe something the upstream folks will be concerned about 😸

Dir.foreach(path) do |file|
match_data = DataMigrate::DataMigrator.match(file)
versions << match_data[1].to_i if match_data
end
end
versions

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set and Array have pretty different methods available. If it doesn't break anything, I think changing to Set here is an improvement since it removes duplicates. But if we wanted to minimize changes to method signatures, we could put a .to_a here so the method returns the same type as it did before.

end
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/data_migration/data_migration_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def data_migrations_file_path
end

def data_migrations_path
DataMigrate.config.data_migrations_path
DataMigrate.config.data_migrations_gen_path || DataMigrate.config.data_migrations_path
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

context 'when custom data migrations path has a trailing slash' do
before do
DataMigrate.config.data_migrations_path = 'abc/'
DataMigrate.config.data_migrations_gen_path = 'abc/'
end

it 'returns correct file path' do
Expand All @@ -50,7 +50,7 @@

context 'when custom data migrations path does not have a trailing slash' do
before do
DataMigrate.config.data_migrations_path = 'abc'
DataMigrate.config.data_migrations_gen_path = 'abc'
end

it 'returns correct file path' do
Expand Down