Migrations and database creation

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 <>

class :table_name < ActiveRecord::Base; end
create_table :table_name do |t|
  t.column :column_1 :string
  ...
end

end

def self.down
drop_database <>
end
end

Regards,
Jim

James B. 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.

Alan F. 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs