-
-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
database update script #648
Conversation
…311-data into 625-BACK-UpdateScript
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks great. Diagnostic endpoints are 👍
resource.getrlimit(getattr(resource, kind)) | ||
)) | ||
|
||
return {kind: report(kind) for kind in [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't even know what most of these resources are but this seems like a really useful util, particularly if we decide to test out different backend hosting options.
# fix North Westwood | ||
res = exec_sql(f""" | ||
UPDATE stage | ||
SET nc = 127 | ||
WHERE nc = 0 AND ncname = 'NORTH WESTWOOD NC' | ||
""") | ||
log(f'\tFixed nc code for North Westwood NC: {res.rowcount} rows') | ||
|
||
# fix Historic Cultural North | ||
res = exec_sql(f""" | ||
UPDATE stage | ||
SET nc = 128 | ||
WHERE nc = 0 AND ncname = 'HISTORIC CULTURAL NORTH NC' | ||
""") | ||
log(f'\tFixed nc code for Historic Cultural North NC: {res.rowcount} rows') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I wasn't aware of this.
Fixes #625
This enhances our ingestion process with an update script. Instead of resetting the database and downloading all of the Socrata data every night, we can just update the DB with the new stuff from Socrata. The update should take a few minutes, and the server will continue to function normally while the DB is updating.
I was going to run this as a cron job every night, but it turns out Heroku automatically restarts our app every 24 hours, so I tied the update script to the restart. Whenever the server starts, it will check to see if it's been at least 24 hours since the last update, and if so, it will run the update in the background.
The same check will be run locally, so our local DBs will stay up to date with Socrata as well.
I changed the structure of the DB a little bit, so unfortunately everyone's going to need to repopulate their local DBs. But I included a temporary migration script that will do that automatically when you run docker-compose for the first time after merging this code. The migration only includes 2020, which I figure is enough for dev purposes and doesn't take too long.
UPDATE 5/26:
I refactored the ingestion code into a proper database module that handles db operations with a clean api, for example:
This makes it possible to add years individually rather than in a multi-hour script. Also provides useful info about the current contents of the db.
There are also two new diagnostic endpoints that will be helpful in monitoring our production environment:
Finally, there are a bunch of little cleanup things -- removing old endpoints, deleting unused functions and files, etc.
dev
branchAny questions? See the getting started guide