Skip to content
Browse files

Fix di un problema con l'auto_update del datamapper ed aggiunti due r…

…ake task veloci per creare e droppare il db in sviluppo! Credenziali hardcoded... vergogna Paolo... trova un rimedio
  • Loading branch information...
1 parent 867e733 commit bcd2e6eb213bb54eb5ea12725f3c6c41f0ae6c7b @thesp0nge thesp0nge committed Mar 10, 2011
Showing with 42 additions and 7 deletions.
  1. +1 −1 config.ru
  2. +37 −5 lib/tasks/setup.rb
  3. +4 −1 rubyday.rb
View
2 config.ru
@@ -1,6 +1,6 @@
require './rubyday.rb'
-set :environment, :development
+set :env, (ENV['RACK_ENV'] ? ENV['RACK_ENV'].to_sym : :development)
set :run, false
run Sinatra::Application
View
42 lib/tasks/setup.rb
@@ -1,8 +1,40 @@
-require 'dm-migrations'
+require 'mysql'
-namespace :setup do
- desc "Perform automigration"
- task :migrate do
- DataMapper.auto_migrate!
+namespace :db do
+
+ desc "Create database"
+ task :create do
+ m = Mysql.init
+ m.connect('localhost', 'root')
+ if (m.list_dbs.find_index("rubyday").nil?)
+ m.query("CREATE DATABASE rubyday")
+ else
+ puts 'rubyday DATABASE already there. Use rake db:purge to delete it'
+ end
+ m.close
+ end
+
+ desc "Drop database"
+ task :drop do
+ m = Mysql.init
+ m.connect('localhost', 'root')
+ if (! m.list_dbs.find_index("rubyday").nil?)
+ m.query("DROP DATABASE rubyday")
+ else
+ puts 'rubyday DATABASE does not exists. Use rake db:create to delete it'
+ end
+ m.close
+ end
+
+ desc "Check database for existant"
+ task :check do
+ m = Mysql.init
+ m.connect('localhost', 'root')
+ if (! m.list_dbs.find_index("rubyday").nil?)
+ puts 'rubyday db is in place'
+ else
+ puts 'rubyday db does not exists'
+ end
+ m.close
end
end
View
5 rubyday.rb
@@ -20,6 +20,7 @@
configure :development do
DataMapper::Logger.new(STDOUT, :debug)
+
DataMapper.setup(:default, {
:adapter => 'mysql',
:host => 'localhost',
@@ -29,7 +30,7 @@
- DataMapper.auto_upgrade!
+
end
configure :production do
@@ -41,6 +42,7 @@
:database => 'sinatra_production'})
end
+
class Subscriber
include DataMapper::Resource
@@ -51,6 +53,7 @@ class Subscriber
end
+DataMapper.auto_upgrade!
helpers do
include Sinatra::Authorization

0 comments on commit bcd2e6e

Please sign in to comment.
Something went wrong with that request. Please try again.