<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Hello happy pony users and devs !<br>
<br>
I do an import from old db to a new one, driven by pony orm. Import
iterates over records of customers and their related licences,
fetched from an old DB. So we have to fill two tables in new DB:
Customers table and Licence table with records, which have one2many
relations (one Customer can have many Licences, by PK). PK is an
autoincrementing integer in both tables.<br>
<br>
Within <b>each iteration</b> of import i need to write one Customer
record and its Licences records to new DB. Licence records should
have customer_id fields filled up with corresponding Customer PKs.
Here we have a problem:<br>
<br>
If we create an object of an entity Customers : <font
face="FreeMono">cust =
Customers(name='GazMyas',city='Chelyabinsk')</font> , it wont be
recorded to a DB exactly at this moment and we wont able to use its
ID (pk of the record) to bind Licence records to it. In other words
there is no 'cust.id' element at this moment.<br>
<br>
We can do a 'commit()' each time we create a Customer object. After
that 'cust.id' comes ready. But in case of monstrous imports with
over 20 000 records committing every record to hdd slows down the
import process to hours. And hangs up your server hard drive.
Anyway, it's a bad practice to commit every record walking the huge
array of incoming data.<br>
<br>
So, by now, I fill up two dicts with Customers records, incrementing
their ID's manually (customer_id += 1) and Licences records bound to
this pre-calculated ID's. When dicts are ready, I write them to a
new DB walking through them.<br>
<br>
Is there a better way to complete a data import without filling up
transition dicts and calculating autoincrement IDs by hand ? Can I
somehow use PKs of the records before committing them to DB ?<br>
</body>
</html>