namespace :db do
desc "Create test database " task :create do # or createuser --interactive joe sh "sudo su postgres" sh "dropdb --if-exists northwind" sh "dropuser --if-exists northwind_user" sh "createdb northwind" puts 'The demo db is created.' end desc "Import data " task :import do cmds = %q{ psql northwind < ./test/integration/northwind/northwind.sql psql --no-psqlrc template1 -c "create user northwind_user;" psql --no-psqlrc template1 -c "alter user northwind_user password 'thewindisblowing';" psql --no-psqlrc template1 -c "grant all on DATABASE northwind to northwind_user;" psql --no-psqlrc northwind -c "GRANT ALL on ALL tables IN SCHEMA public to northwind_user" } sh cmds puts 'The northwind db is imported.' end desc "Drop test database " task :drop do sh "dropdb --if-exists northwind" sh "dropuser --if-exists northwind_user" puts 'The demo db is droped.' end
end