taMERB_ROOT = Dir.pwd desc "Setup the Merb Environment by requiring merb and loading your merb_init.rb" task :merb_env do require 'rubygems' require 'merb' load MERB_ROOT+'/dist/conf/merb_init.rb' end namespace :db do desc "Migrate the database through scripts in dist/schema/migrate. Target specific version with VERSION=x" task :migrate => :merb_env do ActiveRecord::Migrator.migrate("dist/schema/migrations/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil) Rake::Task["db:schema:dump"].invoke end namespace :schema do desc "Create a db/schema.rb file that can be portably used against any DB supported by AR" task :dump => :merb_env do require 'active_record/schema_dumper' File.open(ENV['SCHEMA'] || "dist/schema/schema.rb", "w") do |file| ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file) end end desc "Load a schema.rb file into the database" task :load => :merb_env do file = ENV['SCHEMA'] || "dist/schema/schema.rb" load(file) end end namespace :sessions do desc "Creates a sessions table for use with CGI::Session::ActiveRecordStore" task :create => :merb_env do raise "Task unavailable to this database (no migration support)" unless ActiveRecord::Base.connection.supports_migrations? require 'rails_generator' require 'rails_generator/scripts/generate' Rails::Generator::Scripts::Generate.new.run(["session_migration", ENV["MIGRATION"] || "AddSessions"]) end desc "Clear the sessions table" task :clear => :merb_env do session_table = 'session' session_table = Inflector.pluralize(session_table) if ActiveRecord::Base.pluralize_table_names ActiveRecord::Base.connection.execute "DELETE FROM #{session_table}" end end end def session_table_name ActiveRecord::Base.pluralize_table_names ? :sessions : :session end