# Before I write this myself, is there already an easier way?

**URL:** <https://www.ruby-forum.com/t/before-i-write-this-myself-is-there-already-an-easier-way/53164>\
**Category:** Rails\
**Created:** [January 27, 2006, 2:05am UTC](https://www.ruby-forum.com/t/before-i-write-this-myself-is-there-already-an-easier-way/53164 "2006-01-27T02:05:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [January 27, 2006, 2:05am UTC](https://www.ruby-forum.com/t/before-i-write-this-myself-is-there-already-an-easier-way/53164/1 "2006-01-27T02:05:24Z")

</div>

Recently I’ve wanted to be able to take the data I’ve painstakingly  
defined in my fixture files and slurp it up into my development database  
so I can play with my website (locally, in development mode) with the  
same data I use in my tests.

In a similar vein, I want to take the table definitions in the  
development\_structure.sql file and use it to re-define my development  
database schema. Unless I’m missing something obvious, when someone  
changes the db schema commits it into our subversion repository, I  
always have to hand-update my development db to match the new schema (if  
I don’t want to toast the data that’s already in there), or fire up my  
db tool, drop all the databases, then execute the \_structure.sql script  
(and lose all my data).

Is there already something in rails that can do one or both of these for  
me?

I guess I could take a whack at writing a couple of rake tasks, but I’m  
hoping that surely someone else has already written these already?

Thanks!  
Jeff

> **[Hey Daddio!](http://www.softiesonrails.com)**
>
> Home of Hey Daddio Software

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [January 27, 2006, 2:22am UTC](https://www.ruby-forum.com/t/before-i-write-this-myself-is-there-already-an-easier-way/53164/2 "2006-01-27T02:22:06Z")

</div>

On Fri, Jan 27, 2006 at 02:05:24AM +0100, Jeff C. wrote:

> I don’t want to toast the data that’s already in there), or fire up my  
> db tool, drop all the databases, then execute the \_structure.sql script  
> (and lose all my data).
> 
> Is there already something in rails that can do one or both of these for  
> me?
> 
> I guess I could take a whack at writing a couple of rake tasks, but I’m  
> hoping that surely someone else has already written these already?

rake db\_schema\_import

rake load\_fixtures

(all rake tasks are listed by running rake -T)

marcel

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [January 27, 2006, 5:40am UTC](https://www.ruby-forum.com/t/before-i-write-this-myself-is-there-already-an-easier-way/53164/3 "2006-01-27T05:40:57Z")

</div>

rake load\_fixtures

> (you lose any data in your development database however)

You do, but if your fixtures are set up properly, so what? Why would  
there  
be data in a development database that isn’t in the fixtures? If there  
is,  
then the time spent tip-toeing around your databasee is going to nickel  
and  
dime you until you’ve spent much more time doing things the hard way  
than  
just taking an hour and writing robust fixtures.

Worse, you’ll be less inclined to make data structure changes because of  
the  
extra work managing data, when a structure change really is the best  
choice  
for the project.

I recommend making the most out of tools like fixtures to manage your  
development environment. Your project will benefit from it in the long  
run.

matt

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [January 27, 2006, 2:25am UTC](https://www.ruby-forum.com/t/before-i-write-this-myself-is-there-already-an-easier-way/53164/4 "2006-01-27T02:25:07Z")

</div>

At 1/26/2006 08:05 PM, you wrote:

> Recently I’ve wanted to be able to take the data I’ve painstakingly  
> defined in my fixture files and slurp it up into my development database  
> so I can play with my website (locally, in development mode) with the  
> same data I use in my tests.

rake load\_fixtures  
(you lose any data in your development database however)

> In a similar vein, I want to take the table definitions in the  
> development\_structure.sql file and use it to re-define my development  
> database schema. Unless I’m missing something obvious, when someone  
> changes the db schema commits it into our subversion repository, I  
> always have to hand-update my development db to match the new schema (if  
> I don’t want to toast the data that’s already in there), or fire up my  
> db tool, drop all the databases, then execute the \_structure.sql script  
> (and lose all my data).

You need to learn about Migrations

> **[ActiveRecord::Migration](https://api.rubyonrails.org/classes/ActiveRecord/Migration.html)**
>
> Active Record Migrations Migrations can manage the evolution of a schema used by several physical databases.

but there’s more syntax explained with:  
[http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html](http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html)

> Is there already something in rails that can do one or both of these for  
> me?
> 
> I guess I could take a whack at writing a couple of rake tasks, but I’m  
> hoping that surely someone else has already written these already?
> 
> Thanks!  
> Jeff  
> [www.softiesonrails.com](http://www.softiesonrails.com)

You’re Welcome,  
-Rob

Rob B. removed\_email\_address@domain.invalid  
Agile Consulting LLC [http://agileconsultingllc.com](http://agileconsultingllc.com)  
513-295-4739

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [January 27, 2006, 4:16pm UTC](https://www.ruby-forum.com/t/before-i-write-this-myself-is-there-already-an-easier-way/53164/5 "2006-01-27T16:16:57Z")

</div>

Thanks everyone!

I did rake --tasks but obviously can’t read. 🙂

Jeff

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [January 27, 2006, 6:45pm UTC](https://www.ruby-forum.com/t/before-i-write-this-myself-is-there-already-an-easier-way/53164/6 "2006-01-27T18:45:53Z")

</div>

On Jan 26, 2006, at 8:38 PM, matthew clark wrote:

> more time doing things the hard way than just taking an hour and  
> matt
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

What about using this:

[http://nubyonrails.com/articles/2005/12/27/dump-or-slurp-yaml-](http://nubyonrails.com/articles/2005/12/27/dump-or-slurp-yaml-)  
reference-data

Cheers-  
-Ezra Z.  
Yakima Herald-Republic  
WebMaster

> **[yakimaherald.com | Yakima, Washington - We Tell Your Stories](https://www.yakimaherald.com/)**

509-577-7732  
removed\_email\_address@domain.invalid
