# Creating a DB in the schema import process

**URL:** <https://www.ruby-forum.com/t/creating-a-db-in-the-schema-import-process/61096>\
**Category:** Rails\
**Created:** [January 11, 2006, 10:15pm UTC](https://www.ruby-forum.com/t/creating-a-db-in-the-schema-import-process/61096 "2006-01-11T22:15:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bradeck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7cd45c/32.png) [@bradeck](https://www.ruby-forum.com/u/bradeck)\
**Post date:** [January 11, 2006, 10:15pm UTC](https://www.ruby-forum.com/t/creating-a-db-in-the-schema-import-process/61096/1 "2006-01-11T22:15:43Z")

</div>

I’ve got a bunch of table creations in the schema.rb file and all is  
well. However, I have to manually go and create the db first. Is there a  
way (something like a create\_database method) to get this to work?  
(execute “create database …” didn’t seem to cut it either.)

* * *

Brad Eck  
Sr. Software Engineer  
Pelco  
3500 Pelco Way  
Clovis, CA 93612  
Office - 800-289-9100  
Email - removed\_email\_address@domain.invalid BLOCKED::mailto:removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![bradeck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7cd45c/32.png) [@bradeck](https://www.ruby-forum.com/u/bradeck)\
**Post date:** [January 11, 2006, 11:17pm UTC](https://www.ruby-forum.com/t/creating-a-db-in-the-schema-import-process/61096/2 "2006-01-11T23:17:17Z")

</div>

Brad Eck wrote:

> I’ve got a bunch of table creations in the schema.rb file and all is  
> well. However, I have to manually go and create the db first. Is there a  
> way (something like a create\_database method) to get this to work?  
> (execute “create database …” didn’t seem to cut it either.)

$ rake db\_schema\_import

should create the database accoring to the config/database.yml file.

$rake db\_schema\_dump will create the db/schema.rb file from your current  
database.

Also, look into migrations.

> * * *
> 
> Brad Eck  
> Sr. Software Engineer  
> Pelco  
> 3500 Pelco Way  
> Clovis, CA 93612  
> Office - 800-289-9100  
> Email - removed\_email\_address@domain.invalid BLOCKED::mailto:removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![bradeck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7cd45c/32.png) [@bradeck](https://www.ruby-forum.com/u/bradeck)\
**Post date:** [January 12, 2006, 1:14am UTC](https://www.ruby-forum.com/t/creating-a-db-in-the-schema-import-process/61096/3 "2006-01-12T01:14:39Z")

</div>

Brad Eck wrote:

> I’ve got a bunch of table creations in the schema.rb file and all is  
> well. However, I have to manually go and create the db first. Is there a  
> way (something like a create\_database method) to get this to work?  
> (execute “create database …” didn’t seem to cut it either.)

Brad,

Which database are you using? Which version of Rails?

I am using Rails 1.0.0 with mySQL 4.1 on Mac OS X.

I created a migration:

script/generate migration CreateDatabase

in my ‘up’ method, I put  
create\_database :foo

in my ‘down’ method, I put:  
drop\_database :foo

rake migrate

‘foo’ is there

rake migrate VERSION=0

‘foo’ is not there

Of course, you can’t connect to this database with settings in  
database.yml until it is already created. Secondly, I am using the root  
user on mysql which has CREATE TABLE permissions.

But if you are wanting to create some other database, it should work  
just fine (depending on which db and Rails version you are using).

-damon

> **[Damon Clinkscales](https://damonc.onuniverse.com/)**
>
> Damon Clinkscales
