...I've had to build a lot of fixtures using extant data from a MySQL database. I don't want the whole database in my fixtures... just a subset, based on some examples I use in my specs.
So I run a query to get the subset I want, being sure to grab all the contents from a given table (and ONLY one table). Something like this:
Then:
...If that makes sense, you'll find it's a huge time-saver. Unless you're copying entire tables, in which case you can use Dmitry's script.
So I run a query to get the subset I want, being sure to grab all the contents from a given table (and ONLY one table). Something like this:
SELECT st.*
FROM a_fancy_table ft
JOIN some_table st ON (ft.id = st.a_fancy_table_id)
WHERE ft.id IN (1, 2, 3)\G
The \G is essential, here. I then copy the output of that to the some_table.yml file, created with vim.FROM a_fancy_table ft
JOIN some_table st ON (ft.id = st.a_fancy_table_id)
WHERE ft.id IN (1, 2, 3)\G
Then:
- <ap multiple times, until everything is left-justified, then
- >ap once, so that it's all indented 1 level, then
- :%s/ \*\+ \(\d\+\). row \*\+/^Msome_prefix_\1:
- finally, rename any of those that are really significant.
...If that makes sense, you'll find it's a huge time-saver. Unless you're copying entire tables, in which case you can use Dmitry's script.
No comments:
Post a Comment