-
Notifications
You must be signed in to change notification settings - Fork 5
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
[db] Create migration scripts for DB #69
Comments
Important things to remember.
fyi @laghee |
Good run down of things to do for migration including remote migration on Heroku |
I've been looking at my weekly count data backup to see what the best migration plan might be. Since I have a It looks like I can pretty easily set up a postgres DB on pythonanywhere and run another script to load that up from the stored issue data. (My current data is a weekly count updated daily -- in a flagrantly terrible redundant way... I'm basically recounting all the issues every time 🙄.) Then I could dump that locally, run the migration, and push it to the heroku db. But I wonder if it might be simpler to write a temp script that makes a request to the existing apis for the older data and directly adds to the database? Obviously, we'll need to set up Alembic anyway in order to manage any migrations going forward, but I'm not sure it's necessary for this first step. @karlcow How are you currently storing the needsdiagnosis timeline on your api? Is it a json file that your script appends new data to, or do you have some kind of DB set up? |
no DB a json file. The core part looks like this: def main():
"""Core program."""
# Extract data from GitHub
url = urljoin(URL_REPO, NEEDSDIAGNOSIS)
json_response = get_remote_file(url)
# take only what we need
open_issues = extract_open_issues(json_response)
now = newtime(datetime.datetime.now().isoformat(timespec='seconds'))
# create an individual record
data = '{now} {open_issues}'.format(now=now, open_issues=open_issues)
# save it in a file
with open(FILEPATH, 'a') as f:
f.write('{data}\n'.format(data=data))
# Convert Data to JSON.
converted = convert(txt_data_path)
timeline = {'about': 'Hourly NeedsDiagnosis issues count', 'date_format': 'w3c'}
timeline['timeline'] = converted
# save the full file.
with open(json_data_path, 'w') as f:
f.write(json.dumps(timeline, sort_keys=True, indent=2))
# backup dance
copy2(json_timeline, json_timeline_bkp)
copy2(json_data_path, json_timeline) |
which is not optimum at all.
Probably. |
So to remember here. Every tutorial about flask + DB + Heroku says the same thing. Run LOCALLY
Then commit the results to the local git repo. Run on HEROKU
The reason is that there is no filesystem on heroku. |
This should be useful too. |
Heeeeeeelllllllllp. I decided that it was scandalous that I let this issue sit here so long, so I decided to jump in and tackle it, but it's driving me nuts. What I thought was going to be a simple "add a
...and then try to run the Hmmm. It occurs to me that maybe this is another app factory problem... Instead of
OK, slightly better (I guess?) error: So since we're just running the one file with no app context, I need to give it a Well, hot damn. 🎉 OK, this still needs some tweaks before pushing anything to Heroku. It should definitely have an app context that works in production, too -- "default" defaults to "development," which obviously isn't going to work live. From what I understand, I can either add the app context into Thoughts, @karlcow? |
@laghee understood. I put that on the todo list for wednesday. Thanks for the heads up. |
@karlcow Sleeping on it helped, and I was able to go back and successfully redo a migration I'm pushing the changes to |
That's super good news. :) |
Soon or later, migrating the DB will be required if we do not want to loose any data.
Alembic is a module using SQLAlchemy that we already use to manage migration.
https://alembic.zzzcomputing.com/en/latest/tutorial.html
The text was updated successfully, but these errors were encountered: