| 13 | Here is a process that works, although is a bit cumbersome, so we should look to automate as much as possible & improve: |
| 14 | 1. Get a spreadsheet of good Data together (e.g. using Google Docs) |
| 15 | 2. Save as CSV |
| 16 | 3. Open in Open Office (MS Excel destroys data - do NOT use!) |
| 17 | 4. Export copies of the tables you wish to import to in CSV format, e.g.: |
| 18 | * /gis/location.csv |
| 19 | * /hms/hospital.csv |
| 20 | 5. Plan how you are going to deal with duplicates between these datasets. |
| 21 | * e.g. copy exported data into Spreadsheet & then clear table: {{{db.module_resource.truncate()}}} |
| 22 | 6. Plan the order of imports: |
| 23 | * Need to import referenced tables before those which refer to them, e.g.: |
| 24 | * pr_person, gis_location, or_organisation, or_office, or_contact |
| 25 | 7. Copy the data from the datasheet into the one with the column headers |
| 26 | * NB All column headers need to be present, named correctly, in the correct order |
| 27 | * No blank rows in the sheet |
| 28 | 8. Upload the file to the server: /home/haiti/web2py |
| 29 | 9. Do a Test Import on Dev |
| 30 | * Check that data looks good |
| 31 | 10. Repeat on Prod: |
14 | | cd /path/to/web2py |
15 | | python web2py.py -S sahana -M -N |
16 | | db.import_from_csv_file(open('db.csv','rb')) |
17 | | db.or_organisation.import_from_csv_file(open('orgs.csv','rb')) |
| 33 | vim /etc/crontab |
| 34 | #0-59/1 * * * * www-data cd /home/haiti/web2py/ && python web2py.py -C -D 1 >> /tmp/cron.output 2>&1 |
| 35 | vim /home/haiti/prod/models/00_db.py |
| 36 | migrate=True |
| 37 | rm /etc/apache2/sites-enabled/prod-ssl |
| 38 | /etc/init.d/apache2 force-reload |
| 39 | /home/haiti/update-prod |
| 40 | /home/haiti/shell-prod |
| 41 | db(db.gis_location.id>0).select().last().id |
| 42 | db.gis_location.import_from_csv_file(open('hospital_locations.csv','rb')) |
| 43 | rows = db(db.gis_location.id>0).select() |
| 44 | for row in rows: |
| 45 | if row.lon and row.lat and not row.wkt: |
| 46 | db.gis_location[row.id] = dict(wkt = 'POINT(%f %f)' % (row.lon, row.lat)) |
| 47 | if not row.deleted: |
| 48 | db.gis_location[row.id] = dict(deleted = False) |
| 49 | if not row.created_on: |
| 50 | db.gis_location[row.id] = dict(created_on = request.utcnow) |
| 51 | if not row.modified_on: |
| 52 | db.gis_location[row.id] = dict(modified_on = request.utcnow) |
| 53 | |
| 56 | Set the initial ID in import sheet to be the last+1 & then continue on |
| 57 | /home/haiti/shell-prod |
| 58 | db.hms_hospital.import_from_csv_file(open('hospitals_import.csv','rb')) |
| 59 | rows = db(db.hms_hospital.id>0).select() |
| 60 | for row in rows: |
| 61 | if not row.deleted: |
| 62 | db.hms_hospital[row.id] = dict(deleted = False) |
| 63 | if not row.created_on: |
| 64 | db.hms_hospital[row.id] = dict(created_on = request.utcnow) |
| 65 | if not row.modified_on: |
| 66 | db.hms_hospital[row.id] = dict(modified_on = request.utcnow) |
| 67 | |
| 68 | db.commit() |
| 69 | Ctrl+D |
| 70 | ln -s /etc/apache2/sites-available/prod-ssl /etc/apache2/sites-enabled |
| 71 | /etc/init.d/apache2 force-reload |
| 72 | vim /home/haiti/prod/models/00_db.py |
| 73 | migrate=False |
| 74 | vim /etc/crontab |
| 75 | 0-59/1 * * * * www-data cd /home/haiti/web2py/ && python web2py.py -C -D 1 >> /tmp/cron.output 2>&1 |