# How to maintain data while using migration

**URL:** <https://www.ruby-forum.com/t/how-to-maintain-data-while-using-migration/53387>\
**Category:** Rails\
**Created:** [February 3, 2006, 2:47pm UTC](https://www.ruby-forum.com/t/how-to-maintain-data-while-using-migration/53387 "2006-02-03T14:47:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ror-user](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/22d042/32.png) [@ror-user](https://www.ruby-forum.com/u/ror-user)\
**Post date:** [February 3, 2006, 2:47pm UTC](https://www.ruby-forum.com/t/how-to-maintain-data-while-using-migration/53387/1 "2006-02-03T14:47:46Z")

</div>

hi all  
started using migration , gr8 stuff  
but how can i maintain old data , or import it alongwith schema with  
same easiness,  
as in migration we only import schema ?  
thanks  
rohit

---

<div class="post-metadata">

**Author:** ![ror-user](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/22d042/32.png) [@ror-user](https://www.ruby-forum.com/u/ror-user)\
**Post date:** [February 3, 2006, 2:53pm UTC](https://www.ruby-forum.com/t/how-to-maintain-data-while-using-migration/53387/2 "2006-02-03T14:53:48Z")

</div>

You can write all kinds of ruby code in a migration…So everything is  
actually possible…

---

<div class="post-metadata">

**Author:** ![ror-user](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/22d042/32.png) [@ror-user](https://www.ruby-forum.com/u/ror-user)\
**Post date:** [February 5, 2006, 9:40pm UTC](https://www.ruby-forum.com/t/how-to-maintain-data-while-using-migration/53387/3 "2006-02-05T21:40:34Z")

</div>

rohit mehra \<rohitm2010@…\> writes:

> hi all started using migration , gr8 stuff but how can i maintain old data  
> , or import it alongwith schema with same easiness, as in migration we  
> only  
> import schema ? thanks rohit

Well, I don’t pretend to stay database agnostic in my migrations so I  
use strictly execute() calls to run whatever sql I want. For example,  
you could create a temp table, copy the data into it, and copy it back.  
In postgres, temp tables are automatically dropped at the end of the  
transaction.

As another said, you can also use whatever ruby code you what instead  
of using SQL.

---

<div class="post-metadata">

**Author:** ![ror-user](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/22d042/32.png) [@ror-user](https://www.ruby-forum.com/u/ror-user)\
**Post date:** [February 4, 2006, 4:27pm UTC](https://www.ruby-forum.com/t/how-to-maintain-data-while-using-migration/53387/4 "2006-02-04T16:27:53Z")

</div>

When using migration, you probably will be using Alter , add\_columns etc  
to  
ur old table. That should not affect the data that are already there

–  
Rgds,  
–Siva J.  
[http://www.varcasa.com/](http://www.varcasa.com/)  
My First Rails Project.  
Education Through Collabration
