Renamed helpers to correspond to renamed Controller classes.
[merb_radiant.git] / lib / tasks / .svn / text-base / database.rake.svn-base
blob1e8e4954038221e1308cb22b0d4b7de6e695f33b
1 namespace :db do
2   desc "Migrate schema to version 0 and back up again. WARNING: Destroys all data in tables!!"
3   task :remigrate => :environment do
4     require 'highline/import'
5     if ENV['OVERWRITE'].to_s.downcase == 'true' or agree("This task will destroy any data in the database. Are you sure you want to \ncontinue? [yn] ")
6       
7       # Migrate downward
8       ActiveRecord::Migrator.migrate("#{RADIANT_ROOT}/db/migrate/", 0)
9     
10       # Migrate upward 
11       Rake::Task["db:migrate"].invoke
12       
13       # Dump the schema
14       Rake::Task["db:schema:dump"].invoke
15     else
16       say "Task cancelled."
17       exit
18     end
19   end
20   
21   desc "Bootstrap your database for Radiant."
22   task :bootstrap => :remigrate do
23     require 'radiant/setup'
24     Radiant::Setup.bootstrap(
25       :admin_name => ENV['ADMIN_NAME'],
26       :admin_username => ENV['ADMIN_USERNAME'],
27       :admin_password => ENV['ADMIN_PASSWORD'],
28       :database_template => ENV['DATABASE_TEMPLATE']
29     )
30   end
31   
32   #
33   # The following tasks are only needed by Scenarios until Rails 2
34   #
35   
36   desc 'Drops the database for the current RAILS_ENV'
37   task :drop => :environment do
38     config = ActiveRecord::Base.configurations[RAILS_ENV]
39     case config['adapter']
40     when 'mysql'
41       ActiveRecord::Base.connection.drop_database config['database']
42     when /^sqlite/
43       FileUtils.rm_f(File.join(RAILS_ROOT, config['database']))
44     when 'postgresql'
45       `dropdb "#{config['database']}"`
46     end
47   end
48     
49   desc 'Create the database defined in config/database.yml for the current RAILS_ENV'
50   task :create => :environment do
51     config = ActiveRecord::Base.configurations[RAILS_ENV]
52     begin
53       ActiveRecord::Base.establish_connection(config)
54       ActiveRecord::Base.connection
55     rescue
56       case config['adapter']
57       when 'mysql'
58         `mysqladmin #{config['password'].nil? ? '' : "-p #{config['password']}"} -u #{config['username']} create #{config['database']}`
59       when 'postgresql'
60         `createdb "#{config['database']}" -E utf8`
61       when 'sqlite'
62         `sqlite "#{config['database']}"`
63       when 'sqlite3'
64         `sqlite3 "#{config['database']}"`
65       end
66     else
67       p "#{config['database']} already exists"
68     end
69   end
70   
71   desc "Drops and recreates the database from db/schema.rb for the current environment."
72   task :reset => ['db:drop', 'db:create', 'db:schema:load']
73 end