Skip to content

Commit 041be07

Browse files
authored
Merge pull request #183 from mapswipe/dev
fix NoneType because of no users in database
2 parents d7718f0 + 8f386a7 commit 041be07

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

mapswipe_workers/mapswipe_workers/firebase_to_postgres/update_data.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ def update_user_data(user_ids=None):
2020
ORDER BY created DESC
2121
LIMIT 1
2222
'''
23-
last_updated = pg_db.retr_query(pg_query)
24-
if not last_updated:
23+
last_updated = pg_db.retr_query(pg_query)[0][0]
24+
logger.info(f'got last updated timestamp: {last_updated}')
25+
26+
if last_updated is None:
2527
# No users in the Postgres database yet.
2628
# Get all users from Firebase.
2729
users = fb_ref.get()
2830
print(users)
2931
else:
3032
# Get only new users from Firebase.
31-
last_updated = last_updated[0][0]
3233
last_updated = last_updated.strftime('%Y-%m-%dT%H:%M:%S.%fZ')
3334
fb_query = fb_ref.order_by_child('created').start_at(last_updated)
3435
users = fb_query.get()

postgres/scripts/v1_to_v2/copy_groups_from_csv.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
CREATE TEMP TABLE v1_groups (
77
project_id varchar,
8-
group_id int,
8+
v1_group_id int,
9+
group_id varchar DEFAULT NULL,
910
number_of_tasks int,
1011
finished_count int,
1112
required_count int,
@@ -14,7 +15,7 @@ CREATE TEMP TABLE v1_groups (
1415
);
1516

1617
-- Has to be in one line otherwise syntax error
17-
\copy v1_groups(project_id, group_id, number_of_tasks, finished_count, required_count, project_type_specifics) FROM groups.csv WITH (FORMAT CSV, DELIMITER ',', HEADER TRUE);
18+
\copy v1_groups(project_id, v1_group_id, number_of_tasks, finished_count, required_count, project_type_specifics) FROM groups.csv WITH (FORMAT CSV, DELIMITER ',', HEADER TRUE);
1819

1920
-- (Convert old to new data structure).
2021
-- verification_count (old name for required_count) was static.

postgres/scripts/v1_to_v2/copy_tasks_from_csv.sql

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55

66
CREATE TEMP TABLE v1_tasks (
77
project_id varchar,
8-
group_id int,
8+
v1_group_id int,
9+
group_id varchar DEFAULT NULL,
910
task_id varchar,
1011
project_type_specifics json,
1112
geom geometry(MULTIPOLYGON,4326) DEFAULT NULL
1213
);
1314

1415
-- Has to be in one line otherwise syntax error
15-
\copy v1_tasks(project_id, group_id, task_id, project_type_specifics) FROM tasks.csv WITH (FORMAT CSV, DELIMITER ',', HEADER TRUE);
16+
\copy v1_tasks(project_id, v1_group_id, task_id, project_type_specifics) FROM tasks.csv WITH (FORMAT CSV, DELIMITER ',', HEADER TRUE);
17+
18+
UPDATE v1_tasks
19+
SET group_id = cast(v1_group_id as varchar);
1620

1721
/* Compute geometry of tasks from x, y tile coordinates and z zoom level stored in task id*/
1822
/* More details on the coordinates: */

postgres/scripts/v1_to_v2/copy_to_csv.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
-- Rename attributes to conform to v2.
33
\copy (SELECT archive, image, importkey as "import_id", isfeatured AS "is_featured", lookfor AS "look_for", name, progress, projectdetails AS "project_details", project_id, project_type, state AS "status", info AS "project_type_specifics" FROM projects WHERE project_id in (select project_id from results group by project_id) AND project_id = 5549) TO projects.csv WITH (FORMAT CSV, DELIMITER ",", HEADER TRUE);
44
\copy (SELECT i.import_id, i.info FROM imports i , projects p WHERE import_id in (select importkey as import_id from projects) AND p.project_id = 5549 AND p.importkey = i.import_id) TO imports.csv WITH (FORMAT CSV, DELIMITER ",", HEADER TRUE);
5-
\copy (SELECT project_id, group_id, count as "number_of_tasks", completedcount as "finished_count", verificationcount as "required_count", info as "project_type_specifics" FROM groups WHERE project_id in (select project_id from results group by project_id) AND project_id = 5549 ) TO groups.csv WITH (FORMAT CSV, DELIMITER ",", HEADER TRUE);
6-
\copy (SELECT project_id, group_id, task_id, info as "project_type_specifics" FROM tasks WHERE project_id in (select project_id from results group by project_id) AND project_id = 5549) TO tasks.csv WITH (FORMAT CSV, DELIMITER ",", HEADER TRUE);
5+
\copy (SELECT project_id, group_id as "v1_group_id", count as "number_of_tasks", completedcount as "finished_count", verificationcount as "required_count", info as "project_type_specifics" FROM groups WHERE project_id in (select project_id from results group by project_id) AND project_id = 5549 ) TO groups.csv WITH (FORMAT CSV, DELIMITER ",", HEADER TRUE);
6+
\copy (SELECT project_id, group_id as "v1_group_id", task_id, info as "project_type_specifics" FROM tasks WHERE project_id in (select project_id from results group by project_id) AND project_id = 5549) TO tasks.csv WITH (FORMAT CSV, DELIMITER ",", HEADER TRUE);

0 commit comments

Comments
 (0)