I want to dump a subsection of a database. I've found this 
<http://docs.sqlalchemy.org/en/rel_1_0/faq/metadata_schema.html#how-can-i-get-the-create-table-drop-table-output-as-a-string>
 in 
the SQLA documentation to dump schemata, and found this SO answer 
<http://stackoverflow.com/questions/135835/limiting-the-number-of-records-from-mysqldump>
 to 
indiscriminately dump the first n rows of one or more tables, but that 
doesn't guarantee that all related objects will 'come along'--there's a 
decent chance, for example, that relevant rows in many-to-many tables won't 
get included. Is there a way to do something like (using SQLAlchemy 1.0.9 
with MySQL)

my_objects = session.query(MyTable).filter(MyTable.created_at >= some_date).
all()
with open('my_objects_dump.sql', 'w') as dump_file:
    do_some_magic_with(my_objects, dump_file)

...


$ mysql my_database < my_objects_dump.sql

and then have my_database contain my_objects AND their related objects? I'm 
perfectly happy wrangling schemata and data separately.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to