Heroku Postgres database values resetting on deployment - postgresql

I am running a simple webapp on Heroku for splitting payments between housemates, and storing all payments to a Heroku PostgreSQL database.
The app works as expected while it is running, and the database is updated properly. However, after making changes to the code locally and pushing those to heroku, the database completely resets to a past instance, and all newly added rows are missing from the database.
Is this the intended behavior or am I doing something wrong?
More details:
The app is a python app using the Flask framework

If you have a working database on Heroku and want to seed it with some values, consider either using the seed file in the db folder of your Rails app or use heroku run rails c and then use the console to seed how you'd like.

Related

Using Neon.tech Postgres DB with a Strapi Application

I'm trying to setup up a deployed Strapi V4 application with Neon.tech's Postgres database. I set up the DATABASE_URL correctly and checked that all the environment variables were being read appropriately. However, the app crashes with a 500 status code every time I try to load my admin dashboard.
Is there something I'm missing that makes them incompatible?

EF Core migration to remote database

I have a working app and database locally. I want to setup a remote database for the remote application.
I thought forcing the environment variable would to it:
dotnet ef database update -- --environment Production
But it says "...The database is already up to date." Checking the remote database, it's still empty.
Now, the appsettings.json and appsettings.Development.json files appear to be working correctly. I confirmed my local application connects to my local database, and my remote application connects to my remote database.
Given that the connection strings are correct in the settings, how do I tell EF to do the thing again but for the other database? I feel like I'm missing something obvious.
So I was just using the wrong environment declaration. Run this before the update:
$env:ASPNETCORE_ENVIRONMENT = 'Production'

Accessing Postgresql Database on Heroku After doing git push heroku

Please I need your help.
I have a Django app that is running on heroku.
The Django app initially uses an sqlite3 database.
The local and the remote versions of the app worked fine.
I could access the sqlite3 database on my local machine. However, I have no idea, e.g. an interface, through which I could access the database version that is running on heroku.
Then, I changed the database to Postgresql.
The local version of the database worked fine with the application, as I could see the data being written into the local posgresql whenever I have a need to check the data in the database.
However, I need to be able to see how data is being written into the remote postgresql.
When I try to connect to the database on postgresql, I get an error as shown in the snapshot below.
Please, how can I connect to the database on heroku and see my database.
I am currently using a free heroku account. I hope that is also not a problem?
enter image description here

Heroku Postgres app works on local machine but not on Heroku

I built and deployed a Node.js Postgres app to Heroku and can not get to any of my endpoints via the Heroku site except the root GET route. Curiously, when I run Heroku local web ALL my endpoints behave exactly as they should. I can successfully perform CRUD on the app running via Heroku local web. However, when I try, for instance, to create a user using the Heroku URL, it returns an empty error message. Yet, when I check the associated database I find that the user was indeed created. Other than returning an empty error message when I try to either create a user or sign it, the app correctly responds with the different errors I programmed. For example, when I tweak my login details or try to register the same user I earlier tried to register it correctly says the user already exists!. Still, when I try to log in that same existing user I get a blank error message. Note that I created both the Heroku PostgreSQL database and my local PostgreSQL database from exactly the same queries. Please, can you help me through this bottleneck? I am using Postman to test my APIs.
Test to sign in user on Heroku app running on the local machine: success!
Same exact test with Heroku URL: cryptic error.
Ok, so after a lot of researching and fiddling around I discovered the solution. I did not add keys from my .env file to Heroku as config vars found under the settings tab of the Heroku User dashboard. Manually adding my environment variables resolved the matter. Now my app is working both on my local machine and via the Heroku URL.

Heroku Permanent Database Credentials

I've decided to save time on the ops side of things and move to Heroku. I'm planning to have a production dyno on Heroku with a postgres database AND another dyno that reads from the same database.
However when I opened the settings of postgres, it said:
Database Credentials
Get credentials for manual connections to this database.
Please note that these credentials are not permanent.
Heroku rotates credentials periodically and updates applications where this database is attached.
What's a good way to go about this?
From Heroku Documentation,
Credentials
Do not copy and paste database credentials to a separate environment or into your application’s code. The database URL is managed by Heroku and will change under some circumstances such as:
User initiated database credential rotations using heroku pg:credentials:rotate.
Catastrophic hardware failure leading to Heroku Postgres staff recovering your database on new hardware.
Automated failover events on HA enabled plans.
It is best practice to always fetch the database URL config var from the corresponding Heroku app when your application starts. For example, you may follow 12Factor application configuration principles by using the Heroku CLI and invoke your process like so:
DATABASE_URL=$(heroku config:get DATABASE_URL -a your-app-name) your_process
This way, you ensure your process or application always has correct database credentials.
May be attaching the same database to two heroku-apps will better suit you. In this way, pg creds will be auto-managed by heroku.
I am also using this technique. I have one client-facing app and another operation-app sharing the same database instance.
You can either do this using UI or via CLI
see Share database between 2 apps in Heroku