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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ Further, there are tasks db:dump and db:load which do the entire database (the e

In addition, we have plugins whereby you can export your database to/from various formats. We only deal with yaml and csv right now, but you can easily write tools for your own formats (such as Excel or XML). To use another format, just load setting the "class" parameter to the class you are using. This defaults to "YamlDb::Helper" which is a refactoring of the old yaml_db code. We'll shorten this to use class nicknames in a little bit.

## Optional parameters

dir='some_directory_name' -> Specify the name of the target dump directory
exclude="table_1,table_2" -> Specify tables in comma delimited format to exclude

## Examples

One common use would be to switch your data from one database backend to another. For example, let's say you wanted to switch from SQLite to MySQL. You might execute the following steps:
Expand Down
4 changes: 3 additions & 1 deletion lib/yaml_db/serialization_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ def self.after_table(io, table)
end

def self.tables
ActiveRecord::Base.connection.tables.reject { |table| ['schema_info', 'schema_migrations'].include?(table) }
response = ActiveRecord::Base.connection.tables.reject { |table| ['schema_info', 'schema_migrations'].include?(table) }
excludes = ( ENV["exclude"] || "" ).split(",")
return (response - excludes)
end

def self.dump_table(io, table)
Expand Down
5 changes: 5 additions & 0 deletions spec/yaml_db/serialization_helper_dump_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ module SerializationHelper
Dump.dump_table(@io, 'mytable')
end

it 'does not dump table that is excluded' do
stub_const('ENV', 'exclude' => "mytable")
expect(Dump.tables).to eq([])
end

end
end
end