fixing fixtures rake and adjusting the doc

Oleg committed May 30, 2011
commit 4eabc0597ec624ac9389262e085dea6a7e30ec33
Showing 2 changed files with 17 additions and 14 deletions
README.md +5 -3
@@ @@ -144,13 +144,15 @@ You can put this module in /config/initializers/comfortable\_mexican\_sofa.rb an
Working with Fixtures
---------------------
- Sofa allows you to build entire site using files instead of updating database via admin area. This significantly speeds up initial content population. To enable fixtures go to the initializer and set this: `config.enable_fixtures = true`. You may also change the folder that is used to store fixtures.
+ Sofa allows you to build entire site using files instead of updating database via admin area. This significantly speeds up initial content population. Go to the initializer and set this to enable fixtures in development environment: `config.enable_fixtures = Rails.env.development?`. You may also change the folder that is used to store fixtures.
- If you run `rails g cms` you should find an example set of fixtures in [/db/cms\_fixtures](https://github.com/twg/comfortable-mexican-sofa/blob/master/db/cms_fixtures). If you run multiple sites, each set of fixtures should be inside a folder named as the hostname of the site. It's optional if you only have one site.
+ If you run `rails g cms` you should find an example set of fixtures in [/db/cms\_fixtures](https://github.com/twg/comfortable-mexican-sofa/blob/master/db/cms_fixtures).
When fixtures are enabled, database is updated with each request, but only if fixture file is newer than the database entry. Database is also purged of items that are not defined in fixtures. So be careful not to clear out your database by mistake.
- When deploying to a production server don't forget to turn off fixtures. To load them into the database just run this rake task: `rake comfortable_mexican_sofa:fixtures:import`. When running multiple sites specify which one by passing argument like this: `SITE=example.com`.
+ To load fixtures into the database just run this rake task: `rake comfortable_mexican_sofa:fixtures:import FROM=example.local TO=example.com`. `from` indicates folder the fixtures are in and `to` is the Site hostname you have defined in the database.
+
+ If you need to dump database contents into fixture files run: `rake comfortable_mexican_sofa:fixtures:import FROM=example.com TO=example.local`. This will create example.local folder and dump all content from example.com Site.
Active Components
-----------------
tasks/comfortable_mexican_sofa.rake b/lib/tasks/comfortable_mexican_sofa.rake +12 -11
@@ @@ -6,24 +6,25 @@ end
namespace :comfortable_mexican_sofa do
namespace :fixtures do
- desc 'Import Fixture data into database (options: FOLDER=example.local SITE=example.com)'
+ desc 'Import Fixture data into database (options: FROM=example.local TO=example.com)'
task :import => :environment do |task, args|
- hostname = args[:site] || args[:folder]
- site = Cms::Site.find_by_hostname(hostname)
- abort "Site with hostname [#{hostname}] not found. Aborting." if !site
+ to = args[:to] || args[:from]
+ from = args[:from]
- puts "Importing for #{site.hostname}"
- ComfortableMexicanSofa::Fixtures.import_all(site.hostname, (args[:site] || site.hostname))
+ abort "Site with hostname [#{to}] not found. Aborting." if !Cms::Site.find_by_hostname(to)
+ puts "Importing from Folder [#{from}] to Site [#{to}] ..."
+ ComfortableMexicanSofa::Fixtures.import_all(to, from)
puts 'Done!'
end
- desc 'Export database data into Fixtures (options: SITE=example.com FOLDER=example.local)'
+ desc 'Export database data into Fixtures (options: FROM=example.com TO=example.local)'
task :export => :environment do |task, args|
- site = Cms::Site.find_by_hostname(args[:folder])
- abort "Site with hostname [#{hostname}] not found. Aborting." if !site
+ to = args[:to] || args[:from]
+ from = args[:from]
- puts "Exporting for #{site.hostname}"
- ComfortableMexicanSofa::Fixtures.export_all((args[:site] || site.hostname), site.hostname)
+ abort "Site with hostname [#{from}] not found. Aborting." if !Cms::Site.find_by_hostname(from)
+ puts "Exporting from Site [#{from}] to Folder [#{to}] ..."
+ ComfortableMexicanSofa::Fixtures.export_all(from, to)
puts 'Done!'
end
end