Add a source field to keep track of the source of the reports
This commit is contained in:
parent
903ad14bbc
commit
20dd75b152
43
scripts/migrations/0.4.py
Normal file
43
scripts/migrations/0.4.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
"""
|
||||||
|
Database migration from < 0.3 to 0.3 version.
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import peewee
|
||||||
|
|
||||||
|
SCRIPT_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
sys.path.append(os.path.abspath(os.path.join(SCRIPT_DIRECTORY, '..', '..')))
|
||||||
|
|
||||||
|
from playhouse.migrate import *
|
||||||
|
|
||||||
|
from server.models import db, Report
|
||||||
|
from server.tools import UTC_now
|
||||||
|
|
||||||
|
|
||||||
|
def run_migration():
|
||||||
|
if type(db) == peewee.SqliteDatabase:
|
||||||
|
migrator = SqliteMigrator(db)
|
||||||
|
elif type(db) == peewee.MySQLDatabase:
|
||||||
|
migrator = MySQLMigrator(db)
|
||||||
|
elif type(db) == peewee.PostgresqlDatabase:
|
||||||
|
migrator = PostgresqlMigrator(db)
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
|
migrate(
|
||||||
|
migrator.add_column(
|
||||||
|
'report', 'source',
|
||||||
|
peewee.CharField(max_length=255)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
query = Report.select()
|
||||||
|
for report in query:
|
||||||
|
report.source = 'unknown'
|
||||||
|
report.save()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
db.connect()
|
||||||
|
run_migration()
|
@ -50,6 +50,7 @@ class Report(BaseModel):
|
|||||||
expiration_datetime = peewee.DateTimeField(null=True)
|
expiration_datetime = peewee.DateTimeField(null=True)
|
||||||
upvotes = peewee.IntegerField(default=0)
|
upvotes = peewee.IntegerField(default=0)
|
||||||
downvotes = peewee.IntegerField(default=0)
|
downvotes = peewee.IntegerField(default=0)
|
||||||
|
source = peewee.CharField(max_length=255)
|
||||||
|
|
||||||
def to_json(self):
|
def to_json(self):
|
||||||
return {
|
return {
|
||||||
|
@ -140,6 +140,7 @@ def post_report():
|
|||||||
"upvotes": 0,
|
"upvotes": 0,
|
||||||
"lng": 2.385234797066081,
|
"lng": 2.385234797066081,
|
||||||
"type": "pothole",
|
"type": "pothole",
|
||||||
|
"source": "survey"
|
||||||
…
|
…
|
||||||
},
|
},
|
||||||
"type": "reports",
|
"type": "reports",
|
||||||
@ -168,7 +169,8 @@ def post_report():
|
|||||||
r = Report(
|
r = Report(
|
||||||
type=payload['type'],
|
type=payload['type'],
|
||||||
lat=payload['lat'],
|
lat=payload['lat'],
|
||||||
lng=payload['lng']
|
lng=payload['lng'],
|
||||||
|
source=payload.get('source', 'unknown')
|
||||||
)
|
)
|
||||||
# Handle expiration
|
# Handle expiration
|
||||||
if r.type in ['accident', 'gcum']:
|
if r.type in ['accident', 'gcum']:
|
||||||
|
@ -12,6 +12,7 @@ export function saveReport(type, lat, lng) {
|
|||||||
type,
|
type,
|
||||||
lat,
|
lat,
|
||||||
lng,
|
lng,
|
||||||
|
source: 'survey',
|
||||||
}),
|
}),
|
||||||
headers: AUTHORIZATION_HEADERS,
|
headers: AUTHORIZATION_HEADERS,
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user