jeudi 23 juin 2016

copy rails table with changed data in migrations

I have a table Pizza linked to mystery that currently looks like this

|pizza_id|mystery_id|name|description|
|1       |1         |fun |really fun |
|2       |1         |car |it is fast |
|3       |1         |hou |i live!    |
|4       |1         |air |breathy    |

and after my migration I would like it to look like this:

|pizza_id|mystery_id|name|description|
|1       |1         |fun |really fun |
|2       |1         |car |it is fast |
|3       |1         |hou |i live!    |
|4       |1         |air |breathy    |
|5       |2         |fun |really fun |
|6       |2         |car |it is fast |
|7       |2         |hou |i live!    |
|8       |2         |air |breathy    |

Basically i just want to copy the table's data, and paste it back into the same table, but slightly different. To make matters worse, I SUCK at ruby on rails.

I tried, but I just cant figure out the syntax to copy a table, then paste a table back with changed data. To make matters worse my test site is in sqlite, and my production server is in MYSQL. So I cannot just write one or the other it has to use ruby migration syntax.

This stackoverflow question looks helpful, but it is copying into another table, and it uses just ruby not ruby migrations is that legal in a migration? Any help would be appreciated.

Aucun commentaire:

Enregistrer un commentaire