On Thu, Apr 2, 2009 at 4:07 PM, Yassen Damyanov <[email protected]> wrote:
>
> On Thu, Apr 2, 2009, Maxim Khitrov <[email protected]> wrote:
>>
>> If using SQLAlchemy to create these dump files directly is not
>> possible, what about using reflection to load the schema for a given
>> database, recreating that schema in a temporary database, loading
>> required data, and then generating the SQL dump?
>>
>> I can do the first part of that like so:
>>
>> engine = create_engine('mysql://root:<password>@localhost/caffeine_gum2')
>> meta = MetaData()
>> meta.reflect(bind=engine)
>
> Sounds good (although I am not familiar with reflection in SA :( )
>
>> Once I have the metadata, how can I create a temporary database and
>> reload the table structure there? I suppose I'll need to use some
>> other tool for generating the dump once the data is inserted, but
>> that's fine. As long as I'm not modifying the live data I'll be happy.
>
> How about 'mysqldump database' ? You can use the '--compatible' option
> to generate an SQL dump that is compatible with mysql323, mysql40,
> postgresql, oracle, mssql, db2, maxdb.
> Y.

I'll need to use mysqldump on the temporary database, but there I was
asking about creating that database from metadata. The following seems
to work well:

engine = create_engine(dsn)

url = engine.url
url.database = 'temp'

meta = MetaData()
meta.reflect(bind=engine)

conn = engine.connect()
conn.execute('DROP DATABASE IF EXISTS temp')
conn.execute('CREATE DATABASE temp')
conn.close()

engine = create_engine(url)

meta.bind = engine
meta.create_all()

- Max

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to