2023-11-28
Goal
Load in my Local Version of the PostgreSQL db to the DIMMiN App
Notes
Nuke it FR FR this time
I decided to kick things off today by restarting my computer. Then I got the credentials for my database:
heroku config:get DATABASE_URL --app dimmin
which gives the following information:
postgres://username:password@hostname:port/databasename
that was used in the following command:
pg_restore --verbose --clean --no-acl --no-owner -h hostname -U username -d databasename -p "C:\Users\Billy\Desktop\DIMMiN\database_stuff\bkups\20231127.dump"
The above command failed, but the following command from the docs requested my password which is a good sign:
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U username -d databasename "C:\Users\Billy\Desktop\DIMMiN\database_stuff\bkups\20231127.dump"
But I found out that this was just another way to load their backup file into my local PostgreSQL version. After scrolling down I found the way to actually import this database into Heroku by following their instructions to use an S3 bucket with a with a signed url. I decided to use a new bucket to make sure that my database remained private.
$ aws s3 presign s3://your-bucket-address/your-object
This gave me a nice long URL to reference when backing up the file. Then I was able to use this presigned URL in the pg:backups restore
command and decided to apply it to my Staging environment first:
heroku pg:backups:restore '<SIGNED URL>' DATABASE_URL --app dimmin-staging
For some reason, the presigned URL wasn't working so I made a temp folder in a public AWS bucket and ran the following command:
heroku pg:backups:restore https://dimmin.s3.us-west-1.amazonaws.com/temp-bkups/20231127.dump HEROKU_POSTGRESQL_AQUA_URL --app dimmin-staging
which finally says it uploaded successfully. Bizarrely enough though, while I was expecting to see my blog posts mimic those on the actual site I wasn't able to find them. Fuck it I'm just gonna nuke the app and see what happens. I ran the following commands:
heroku apps:destroy --app dimmin-staging
heroku apps:destroy --app dimmin
Re-build my web app
First I re-created the DIMMiN App in the Heroku web app, then connected it to github via
heroku git:remote -a dimmin
Then added all of the required Environment Variables:
heroku config:set DJANGO_LOG_LEVEL=INFO -a dimmin
heroku config:set SECRET_KEY=KEY -a dimmin
heroku config:set AWS_ACCESS_KEY_ID=KEY -a dimmin
heroku config:set AWS_SECRET_ACCESS_KEY=KEY -a dimmin
Then double-checked that they were all logged with
heroku config -a dimmin
I noticed that the only environment variable I was missing was DISABLE_COLLECTSTATIC=1
, I think that might have been why I was unable to re-compile my Static Files... goddammit.
Whatever, decided to build up the app via the good old fashioned
git push heroku master
but the site was still down because I needed to upload my database. So I ran my backups restore with fingers crossed:
heroku pg:backups:restore https://dimmin.s3.us-west-1.amazonaws.com/temp-bkups/20231127.dump DATABASE_URL --app dimmin
And it worked! I deleted the temp backup file, thankfully I now know how to backup my database from a local version. Now I just have to re-configure the SSL Certificate to get things back on track. Unfortunately the Taskmaster App is still not displaying properly!!! DAMN!
Thankfully though the users and whatnot are available. Also I finally figured out why dimmin.com
never worked in the past. It looks like I needed to add 'dimmin.com'
to my ALLOWED_HOSTS
parameter in my config's settings.py file. The reason it worked with 'www.dimmin.com'
was because that was the specific host that I had already included. I found this error by parsing the Heroku CLI logs using
heroku logs --tail
So it seems like I'm actually learning how to debug this stuff now. It finally works!!! Now I can focus on my idea for salvaging Taskmaster App.
Task App
So the task app is still not loading the correct CSS files. I'm thinking it might have something to do with how the files have been cached since the Git Reset. Therefore, I'm going to save the files in another folder, delete the current taskmaster app, then commit those changes to the site. Then, I'll add in the new CSS required and push those changes. Then we'll see if anything changes.
I pushed the changes to Production then re-created the app from scratch using
python manage.py startapp taskmaster
However this didn't work. In the end I actually ended up solving it by changing the names of the CSS and Javascript files then uploading them to the server. Looks like it was a Cache-ing issue all along. Dammit.
Anyways, at the expense of now having to be called style1.css
and script1.js
, we now have a working Taskmaster App! Hurray! Now what else was I going to do...?
Resetting by Timezone
Oh yeah that's right, adding a feature to auto-reset tasks at midnight! It looks like I already had the majority of it prepared and ready to go. I added a timezone feature to my custom user (defined in the Accounts App) and now have an AJAX command that can set the user's current timezone whenever they access the Taskmaster App.
Then I needed a way for the app to know to reset all tasks at midnight each night. I asked ChatGPT to help me set up Celery to help manage tasks. It said I also needed to download Redis so I did that with
pip install redis
Then I decided to wait until tomorrow to continue hahahahahaaaaaaaa.
Results
- Nuked app
- Fixed domain name (both for www.dimmin.com and dimmin.com, all with SSL Certificates)
- Fixed the damn Taskmaster App so that it has a working version
- Added a way for the user to auto-set their current timezone
- Un-Nuked the app
Next Time
- Learn about task scheduling with Celery