lib/db/sync.rb in db-sync-0.0.12 vs lib/db/sync.rb in db-sync-0.0.13
- old
+ new
@@ -7,14 +7,15 @@
module Db
# Databse Sync
class Sync
include ActiveSupport::Configurable
- attr_accessor :sync_dir
+ attr_accessor :sync_dir, :custom_tables
- def initialize(sync_dir = nil)
+ def initialize(sync_dir = nil, tables = nil)
self.sync_dir = File.join((Rails.root || '.'), 'db', (sync_dir || 'data'))
+ self.custom_tables = tables
end
def log
@log ||= []
end
@@ -32,10 +33,11 @@
diff = Db::Sync::Diff.new(current_records, all_records, table_model.pkey)
delete_records(table, diff.deletes, commit)
update_records(table, diff.updates, commit)
insert_records(table, diff.inserts, commit)
+ # TODO: fix auto increments
end
end
def insert_records(table, inserts, commit = true)
inserts.each do |record|
@@ -110,10 +112,10 @@
table_model = data_model(table)
table_model.records
end
def working_tables
- config.tables || all_tables
+ custom_tables || config.tables || all_tables
end
def all_tables
ActiveRecord::Base.connection.tables.reject do |table|
%w(schema_info, schema_migrations).include?(table)