Skip to content
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ You can override this setting in `config/initializers/data_migrate.rb`

```ruby
DataMigrate.configure do |config|
config.data_migrations_table_name = 'my_migrations_database_name'
config.data_migrations_path = 'db/awesomepath/'
config.data_template_path = Rails.root.join("lib", "awesomepath", "custom_data_migration.rb")
config.db_configuration = {
Expand Down
3 changes: 2 additions & 1 deletion lib/data_migrate/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ def config
end

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

DEFAULT_DATA_TEMPLATE_PATH = "data_migration.rb"

def initialize
@data_migrations_table_name = "data_migrations"
@data_migrations_path = "db/data/"
@data_template_path = DEFAULT_DATA_TEMPLATE_PATH
@db_configuration = nil
Expand Down
4 changes: 2 additions & 2 deletions lib/data_migrate/data_schema_migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class DataSchemaMigration < ActiveRecord::SchemaMigration
# So we only load the appropriate methods depending on Rails version.
if DataMigrate::RailsHelper.rails_version_equal_to_or_higher_than_7_1
def table_name
ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix
ActiveRecord::Base.table_name_prefix + DataMigrate.config.data_migrations_table_name + ActiveRecord::Base.table_name_suffix
end

def primary_key
Expand All @@ -13,7 +13,7 @@ def primary_key
else
class << self
def table_name
ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix
ActiveRecord::Base.table_name_prefix + DataMigrate.config.data_migrations_table_name + ActiveRecord::Base.table_name_suffix
end

def primary_key
Expand Down
42 changes: 42 additions & 0 deletions spec/data_migrate/data_schema_migration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@
it "returns correct table name" do
expect(subject.table_name).to eq("data_migrations")
end

describe "when data migrations table name configured" do
let(:data_migrations_table_name) { "my_app_data_template_migrations"}

before do
@before = DataMigrate.config.data_migrations_table_name
DataMigrate.configure do |config|
config.data_migrations_table_name = data_migrations_table_name
end
end

after do
DataMigrate.configure do |config|
config.data_migrations_table_name = @before
end
end

it "returns correct table name" do
expect(subject.table_name).to eq(data_migrations_table_name)
end
end
end

describe :index_name do
Expand All @@ -22,6 +43,27 @@
it "returns correct table name" do
expect(subject.table_name).to eq("data_migrations")
end

describe "when data migrations table name configured" do
let(:data_migrations_table_name) { "my_app_data_template_migrations"}

before do
@before = DataMigrate.config.data_migrations_table_name
DataMigrate.configure do |config|
config.data_migrations_table_name = data_migrations_table_name
end
end

after do
DataMigrate.configure do |config|
config.data_migrations_table_name = @before
end
end

it "returns correct table name" do
expect(subject.table_name).to eq(data_migrations_table_name)
end
end
end

describe :index_name do
Expand Down
Loading