Forum: Ruby on Rails migrations and database creation

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
James B. (Guest)
on 2006-04-27 00:03
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
Alan F. (Guest)
on 2006-04-27 00:08
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.
James B. (Guest)
on 2006-04-27 00:32
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 topic is locked and can not be replied to.