You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It appears that yaml_db doesn't dump empty tables, which means that it doesn't know to truncate them when loading. This was definitely unexpected. It is fairly easy to resolve, but before I create a pull request (including extending the test suite to validate the behavior), I'd like to know if there's a consensus that this behavior should be changed. In case anyone else wants my monkey-patch in the interim, here is my monkey patch for 0.2.3:
module SerializationHelper
class Load
def self.load_records(table, column_names, records)
if column_names.nil?
return
end
columns = column_names.map{|cn| ActiveRecord::Base.connection.columns(table).detect{|c| c.name == cn}}
quoted_column_names = column_names.map { |column| ActiveRecord::Base.connection.quote_column_name(column) }.join(',')
quoted_table_name = SerializationHelper::Utils.quote_table(table)
(records || []).each do |record|
quoted_values = record.zip(columns).map{|c| ActiveRecord::Base.connection.quote(c.first, c.last)}.join(',')
ActiveRecord::Base.connection.execute("INSERT INTO #{quoted_table_name} (#{quoted_column_names}) VALUES (#{quoted_values})")
end
end
end
class Dump
def self.dump_table(io, table)
dump_table_columns(io, table)
dump_table_records(io, table)
end
end
end
The modification to SerializationHelper::Load::load_records is to substitute an empty array for records if the latter is missing. The modification to SerializationHelper::Dump.dump_table is to eliminate the first line that returns if the table has no records.
The text was updated successfully, but these errors were encountered:
It appears that
yaml_db
doesn't dump empty tables, which means that it doesn't know to truncate them when loading. This was definitely unexpected. It is fairly easy to resolve, but before I create a pull request (including extending the test suite to validate the behavior), I'd like to know if there's a consensus that this behavior should be changed. In case anyone else wants my monkey-patch in the interim, here is my monkey patch for 0.2.3:The modification to
SerializationHelper::Load::load_records
is to substitute an empty array forrecords
if the latter is missing. The modification toSerializationHelper::Dump.dump_table
is to eliminate the first line that returns if the table has no records.The text was updated successfully, but these errors were encountered: