Changes between Version 6 and Version 7 of BluePrint/Synchronisation
- Timestamp:
- 12/24/08 02:33:32 (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
BluePrint/Synchronisation
v6 v7 4 4 * http://wiki.sahana.lk/doku.php?id=doc:sync:english 5 5 6 This can be done in Web2Py using UUIDs (Universally Unique IDs) & CSV Export/Import: 6 The UUIDs have already been configured: 7 * DeveloperGuidelinesDatabaseSynchronization 8 9 We need to extend this by Exporting the tables (CSV is best-supported within Web2Py currently) 7 10 * http://groups.google.com/group/web2py/browse_thread/thread/c08d1b05ddda672c 11 * http://groups.google.com/group/web2py/browse_thread/thread/be927ccf4d9745d2/637e45ccc2cf2583 12 * http://groups.google.com/group/web2py/browse_thread/thread/55d923a51eca2c90 8 13 14 Initially this can be done using appadmin, but we want to make a user-friendly way of dumping all relevant tables. (Need clear list of which tables to include - e.g. not lookup lists which are the same across sites, not site-specific stuff such as gis_keys, etc) 15 16 Export tables as CSV (in Controller): 9 17 {{{ 10 import uuid 11 SQLField('uuid',default=str(uuid.uuid4())) 18 def export(): 19 s=StringIO.StringIO() 20 db.export_to_csv_file(s) 21 response.headers['Content-Type']='text/csv' 22 return s.getvalue() 12 23 }}} 13 24 14 CSV import/export threads: 15 * http://groups.google.com/group/web2py/browse_thread/thread/be927ccf4d9745d2/637e45ccc2cf2583 16 * http://groups.google.com/group/web2py/browse_thread/thread/55d923a51eca2c90 25 Import tables at the other end: 26 {{{ 27 def import_and_sync(): 28 form=FORM(INPUT(_type='file',_name='data'),INPUT(_type='submit')) 29 if form.accepts(request.vars): 30 db.import_from_csv_file(form.vars.data.file) 31 # for every table 32 for table in db.tables: 33 # for every uuid, delete all but the most recent 34 items=db(db[table].id>0).select(db[table].id,db[table].uuid,orderby=~db[table].modified_on,groupby=db[table].uuid) 35 for item in items: 36 db((db[table].uuid==item.uuid)&(db[table].id!=item.id)).delete() 37 return dict(form=form) 38 }}} 39 40 Create an index manually to make the search by uuid faster. 17 41 18 42 other related threads: