Skip to content

Commit

Permalink
We don't need to run Merb environment for sequel tasks. It can be als…
Browse files Browse the repository at this point in the history
…o quite problematic when some sequel plugins tries to get info about tables. The :sequel_env is the most minimalistic environment needed for Sequel tasks to run properly.
  • Loading branch information
pk committed Feb 17, 2009
1 parent 0aaecd3 commit df886e5
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions merb_sequel/lib/merb_sequel/merbtasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,29 @@

namespace :sequel do

task :merb_start do
Merb.start :adapter => 'runner',
:environment => ENV['MERB_ENV'] || 'development'
desc "Minimalistic Sequel environment"
task :sequel_env do
Merb::Orms::Sequel.connect
end

namespace :db do

desc "Perform migration using migrations in schema/migrations"
task :migrate => :merb_start do
task :migrate => :sequel_env do
Sequel::Migrator.apply(Sequel::Model.db, "schema/migrations", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
end

desc "Truncate all tables in database"
task :truncate => :sequel_env do
db = Sequel::Model.db
db << "TRUNCATE #{db.tables.join(', ')} CASCADE;"
end
end

namespace :sessions do

desc "Creates session migration"
task :create => :merb_start do
task :create => :sequel_env do
migration_exists = Dir[File.join(Merb.root,"schema", "migrations", "*.rb")].detect{ |f| f =~ /database_sessions\.rb/ }
if migration_exists
puts "\nThe Session Migration File already exists\n\n"
Expand All @@ -29,10 +34,9 @@
end

desc "Clears sessions"
task :clear => :merb_start do
task :clear => :sequel_env do
table_name = ((Merb::Plugins.config[:sequel] || {})[:session_table_name] || "sessions")

Merb::Orms::Sequel.connect.execute("DELETE FROM #{table_name}")
Model.db.connect.execute("DELETE FROM #{table_name}")
end

end
Expand Down

0 comments on commit df886e5

Please sign in to comment.