2024-11-05-Tuesday


created: <% tp.file.creation_date() %> tags: - daily-notes


<% moment(tp.file.title,'YYYY-MM-DD').format("dddd, MMMM DD, YYYY") %>

<< Timestamps/<% tp.date.now("YYYY", -1) %>/<% tp.date.now("MM-MMMM", -1) %>/<% tp.date.now("YYYY-MM-DD-dddd", -1) %>|Yesterday | Timestamps/<% tp.date.now("YYYY", 1) %>/<% tp.date.now("MM-MMMM", 1) %>/<% tp.date.now("YYYY-MM-DD-dddd", 1) %>|Tomorrow >>


🎯 Goal


🌟 Results


🌱 Next Time

  • Pick another issue to resolve and start working on it.

📝 Notes

I want to close out the postgreSQL integration issue so that I can have a working version of my production database on my local machine. Specifically, I want to find some way to copy the production database to my local machine, then make sure my Local Version of the DIMMiN App is configured to read from that snapshot.

First, I needed to refresh my credentials. I logged into Heroku from the Heroku CLI via

heroku login

First I wanted to make sure that my staging branch reflected the current version of the master (Production) branch. I checked out my staging branch, made it a copy of the master branch (after making sure my local version matched the master version), and pushed it to the staging branch to get a clean reset for that branch:

git checkout staging
git fetch origin
git reset --hard origin/master
git push origin staging --force

As a quick side note I made a new low priority Github Issue (available here) about changing the primary branch from master to production which would fit better with the staging branch. Low priority because I'm not sure if I'd have to change other configurations and it works well now, but a minor improvement that could help if any other developers join me for developing the DIMMiN App.

Then, I checked out a Git Branch to resolve this issue. I want to get into the habit of development around issues / get more used to using Git properly. I did so below:

git checkout -b issue-28-local-postgresql-integration

This checked out a branch to solve issue 28. Now I should be able to fix up only the Staging version. Then it was back to database development.

My Heroku Postgres database credentials are found here and are shifted continuously. In the Durability Section, I found a way to create a manual backup of the database. Following the requested reading, I was also able to create a backup using the following Heroku CLI:

heroku pg:backups:capture --app dimmin

I created a dimmin-staging app to add to my heroku dimmin pipeline, but unfortunately this would mean that if I deploy a Staging version of the app I would double the production cost of running my website. Instead, I may just continue to develop on my local then push to production. However, If I start using this website for business purposes, it makes sense to add on a Staging development environment to reduce points of failure. ChatGPT had a great take on it:

If your app has a high level of user interaction, frequent updates, or mission-critical components, a staging environment is likely worth the cost for the added stability and peace of mind.

So I'll continue to develop locally until I get some clients on board (or develop the site to the point where I'm trying to get clients on board). I can see my most recent backups by using

heroku pg:backups --app dimmin

Then I can identify the most recent snapshot of the data as the by its ID (in my case that's b006) and create a copy to my local via

heroku pg:backups:download b006 --app dimmin

which outputs a latest.dump file. I added latest.dump to my .gitignore file to make sure the changes wouldn't be pushed to github. I then need to use pg_restore from pgadmin, which I was able to do way back in 2023-11-27 to create backups at the following path:

C:\Users\Billy\Desktop\DIMMiN\database_stuff\bkups

Within pgadmin, I decided to create a new database called dimmin-staging to represent my development / Staging database. Then, I was able to load in the data from latest.dump into my dimmin-staging database via the following command:

pg_restore -h "localhost" -p "5432" -U "postgres" -d "dimmin-staging" -v "latest.dump"

Which I was able to open and see is exactly like my server via the SQL query:

SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public';

Within pgadmin on my new dimmin-staging database. Now I just needed to configure my Django App to interface with this specific PostgreSQL database. To do this I needed to adjust my config/settings.py file:

# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
# Use SQLlite during development
if DEBUG:
    # Use pgadmin Credentials for PostgreSQL in development
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql',
            'NAME': 'dimmin-staging', # Name of local database
            'USER': env.str("LOCAL_DATABASE_USERNAME"), # PostgreSQL username
            'PASSWORD': env.str("LOCAL_DATABASE_PASSWORD"), # PostgreSQL password
            'HOST': 'localhost', # Localhost
            'PORT': '5432', # Default PostgreSQL port
    }
}
# Use PostgreSQL in Production
else:
    DATABASES = {
        "default": dj_database_url.config(
            default=env.dj_db_url("DATABASE_URL"), 
            conn_max_age=600
        )
}

Then applied the necessary Database Migrations via

python manage.py migrate

and it worked! I now have an exact copy of my Production-level database available on my Local Version.

Now I can delete my local db.sqlite3 database and finally start using PostgreSQL. The last thing I needed to do was write up my solution and close out my ticket. I added my changes via

git add .

Then committed my changes to my feature Git Branch via

git commit -m "..."

With a long message detailing how the issue was resolved. Then I pushed that to GitHub via

git push origin issue-28-local-postgresql-integration

Then checked out the Staging branch and made sure I was up to date with the current version of the staging branch via

git checkout staging
git pull origin staging

And finally Git Merged with this new feature branch:

git merge issue-28-local-postgresql-integration

and pushed this to the staging branch

git push origin staging

At this point, I would probably deploy the staging branch to its own test site and run tests on it. However now I need to make the staging and master branches sync. I did the Pull Request on GitHub and seemed to have skipped some steps, so I manually closed Issue 28 with a link to the corresponding Pull Request. Finally, I pushed these changes to Production with

git checkout master
git push heroku master

Now it's time to un-do all my hacks. I'll remove the manually added <div> tags from the images in my previous posts to remove that hover effect on them.


Notes created today

List FROM "" WHERE file.cday = date("<%tp.date.now("YYYY-MM-DD")%>") SORT file.ctime asc

Notes last touched today

List FROM "" WHERE file.mday = date("<%tp.date.now("YYYY-MM-DD")%>") SORT file.mtime asc

(Template referenced from Dann Berg, can be found here)


Previous Note 2024-10-14-Monday Next Note 2024-11-06-Wednesday