Changes between Version 15 and Version 16 of BluePrint/Synchronisation


Ignore:
Timestamp:
02/14/09 14:25:44 (16 years ago)
Author:
Fran Boon
Comment:

Update for current

Legend:

Unmodified
Added
Removed
Modified
  • BluePrint/Synchronisation

    v15 v16  
    44 * http://wiki.sahana.lk/doku.php?id=doc:sync:english
    55
    6 The UUIDs have already been configured: DeveloperGuidelinesDatabaseSynchronization
     6All tables have UUID fields: DeveloperGuidelinesDatabaseSynchronization
    77
    8 We need to extend this by Exporting the tables (CSV is best-supported within Web2Py currently)[[BR]]
     8We can Export the tables - CSV is best-supported within Web2Py currently[[BR]]
    99"complete database backup/restore with db.export_to_csv_file(..),db.import_from_csv_file(...),[[BR]]
    1010reimporting optionally fixes references without need for uuid"
     
    1313 * http://groups.google.com/group/web2py/browse_thread/thread/55d923a51eca2c90
    1414
    15 Initially this can be done using appadmin, but we want to make a user-friendly way of dumping all relevant tables.[[BR]]
     15This 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
    1620Need clear list of which tables to include:
    1721 * not lookup lists which are the same across sites
    1822  * e.g. !OpenStreetMap/Google Layers (but WMS/SOS Layers Yes. Shapefiles Layers Yes if uploads copied across as well)
    1923 * 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 table
    37         for table in db.tables:
    38         # for every uuid, delete all but the most recent
    39             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 }}}
    4424
    4525Create an index manually to make the search by uuid faster.