Changes between Version 6 and Version 7 of BluePrint/Synchronisation


Ignore:
Timestamp:
12/24/08 02:33:32 (13 years ago)
Author:
Fran Boon
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • BluePrint/Synchronisation

    v6 v7  
    44 * http://wiki.sahana.lk/doku.php?id=doc:sync:english
    55
    6 This can be done in Web2Py using UUIDs (Universally Unique IDs) & CSV Export/Import:
     6The UUIDs have already been configured:
     7* DeveloperGuidelinesDatabaseSynchronization
     8
     9We need to extend this by Exporting the tables (CSV is best-supported within Web2Py currently)
    710 * 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
    813
     14Initially 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
     16Export tables as CSV (in Controller):
    917{{{
    10 import uuid
    11 SQLField('uuid',default=str(uuid.uuid4()))
     18def export():
     19    s=StringIO.StringIO()
     20    db.export_to_csv_file(s)
     21    response.headers['Content-Type']='text/csv'
     22    return s.getvalue()
    1223}}}
    1324
    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
     25Import tables at the other end:
     26{{{
     27def 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
     40Create an index manually to make the search by uuid faster.
    1741
    1842other related threads: