Changes between Version 15 and Version 16 of BluePrint/Synchronisation
- Timestamp:
- 02/14/09 14:25:44 (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
BluePrint/Synchronisation
v15 v16 4 4 * http://wiki.sahana.lk/doku.php?id=doc:sync:english 5 5 6 The UUIDs have already been configured: DeveloperGuidelinesDatabaseSynchronization6 All tables have UUID fields: DeveloperGuidelinesDatabaseSynchronization 7 7 8 We need to extend this by Exporting the tables (CSV is best-supported within Web2Py currently)[[BR]]8 We can Export the tables - CSV is best-supported within Web2Py currently[[BR]] 9 9 "complete database backup/restore with db.export_to_csv_file(..),db.import_from_csv_file(...),[[BR]] 10 10 reimporting optionally fixes references without need for uuid" … … 13 13 * http://groups.google.com/group/web2py/browse_thread/thread/55d923a51eca2c90 14 14 15 Initially this can be done using appadmin, but we want to make a user-friendly way of dumping all relevant tables.[[BR]] 15 This can be done using appadmin, but we have started work on a user-friendly way of dumping all relevant tables: 16 * {{{controllers/default.py}}} 17 * {{{views/default/export_data.html}}} 18 * {{{views/default/import_data.html}}} 19 16 20 Need clear list of which tables to include: 17 21 * not lookup lists which are the same across sites 18 22 * e.g. !OpenStreetMap/Google Layers (but WMS/SOS Layers Yes. Shapefiles Layers Yes if uploads copied across as well) 19 23 * not site-specific stuff such as system_config, gis_keys, etc 20 21 Export tables as CSV (in Controller):22 {{{23 def export():24 s=StringIO.StringIO()25 db.export_to_csv_file(s)26 response.headers['Content-Type']='text/csv'27 return s.getvalue()28 }}}29 30 Import tables at the other end:31 {{{32 def import_and_sync():33 form=FORM(INPUT(_type='file',_name='data'),INPUT(_type='submit'))34 if form.accepts(request.vars):35 db.import_from_csv_file(form.vars.data.file)36 # for every table37 for table in db.tables:38 # for every uuid, delete all but the most recent39 items=db(db[table].id>0).select(db[table].id,db[table].uuid,orderby=~db[table].modified_on,groupby=db[table].uuid)40 for item in items:41 db((db[table].uuid==item.uuid)&(db[table].id!=item.id)).delete()42 return dict(form=form)43 }}}44 24 45 25 Create an index manually to make the search by uuid faster.