Is there a way to pass the database name in config/database.yml to a migration task such that the appropriate (test, development or production) DB is created by the initial migration? What I would like to do is to get this sort of thing to work: class RbacDataStructures < ActiveRecord::Migration def self.up create_database <<dbname from database.yml>> class :table_name < ActiveRecord::Base; end create_table :table_name do |t| t.column :column_1 :string ... end end def self.down drop_database <<dbname from database.yml>> end end Regards, Jim -- Posted via http://www.ruby-forum.com/.
James Byrne wrote:> Is there a way to pass the database name in config/database.yml to a > migration task such that the appropriate (test, development or > production) DB is created by the initial migration?You can use environment vartiables to get it in there, but migrations need the db to exist in order to execute, so creating it in the migratrion wont work. What you could do is create a new rake task, clean_migrate, which does the shell mysqladmin work and *then* calls migrate, A. -- Posted via http://www.ruby-forum.com/.
Alan Francis wrote:> > You can use environment vartiables to get it in there, but migrations > need the db to exist in order to execute, so creating it in the > migratrion wont work. > > > What you could do is create a new rake task, clean_migrate, which does > the shell mysqladmin work and *then* calls migrate, > > A.Just so. I have manually created the DBs and will proceed from there. I will revisit this later. Thank you. Jim -- Posted via http://www.ruby-forum.com/.