.db file from Heroku app does not sync with github repository [duplicate] - github

This question already has answers here:
Does heroku automatically update the repository?
(1 answer)
Heroku via Github, where is my JSON files updated?
(2 answers)
Closed last month.
I have this app on Heroku that deploys code from a GitHub repository. In this GitHub repository, there is this database file "something.db", which has all the necessary fields but empty of any records. When I build the app on Heroku and deploy it, it pulls the code from the GitHub repository, including the "something.db" database file. When people access the website, when they register a user account for example, the app inserts a new record to the database "something.db". However, I have some a concern about this:
How would I be able to sync this "something.db" database file from the Heroku app back to the GitHub repository? I.e. How can the GitHub repository be able to see the data changes in the "something.db" database file once I create a new user on the website.
I am asking this question in the context that every time I need to push code onto that GitHub repository, I would need to redeploy the app from heroku, which will then also deploy the empty "something.db" database file, which I do not want, since I want to retain the data that was previously added while the website was live.
I know this method of storing data in a .db file is not professional, but I would like to keep things as simple as possible since this website is small scale and does not hold that much data.
The app that I am using is a python Flask app, and the database is using flask alchemy (sqlite).
I tried looking online for some answers on how to push the changes from Heroku back to the GitHub pipeline but could not find anything about it. All I saw was how to deploy an app FROM GitHub to Heroku, but not push code FROM Heroku back to the GitHub repository.

Related

GitHub Actions: auto-PR on some files update?

I'm very new to GitHub Actions/CI/CD, and I want to know whether it is possible to automate the following scenario:
I have a local script that makes use of some APIs to download some files onto my local machine. My current status is that: I have to run the script every day to check whether the content of these files is updated or not. If some of those files got updated then I need to add those changes into a new branch and push it to a repository as a PR.
My trying: My idea is that since it's possible to compare the hash of the downloaded files to know whether any of those got updated. The next thing to do is to make this into an event to trigger some action?
If it's possible could you share some resources/tutorials about how to do it?
I tested something similar on GitHub to understand how the CI/CD GitHub actions works.
the script is based on an SQLite DataBase which is updated automatically each time (automatic git push). And it uses Github Secrets to store encrypted Tokens/Passwords.
You can find my scheduler in the follow link: https://github.com/noweh/project-marvel-memories/blob/master/.github/workflows/run-schedule.yml.
you can find more information directly in the github documentation.
Here for the Github actions: https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows.
And here for the Github encrypted secrets: https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-an-environment

Heroku manual deploy keeps switching to Master

In Heroku, connected to Git. I want to deploy my Dev branch, and can select it.
When I manually deploy it does it's thing (deploys my website to Heroku). But my website has Master branch code. I go back to Heroku and it's on Master.
If I select Dev as the branch for either Manual or Automatic, then reload the page, it switches back to Master. Below is a screenshot of me setting the branch to dev. If I do a browser refresh, it resets to Master.
I tried reconnecting Github. Not sure what else it could be.
Deploying Dev was working up until yesterday.
Here is a screenshot of how I manually deploy (as opposed to auto deploy) from the Heroku Deployment tab.
Edit: I should also add, I happily was on Dev, and could deploy Dev updates up until recently. I deployed Master by mistake, bat can't go back to Dev.
I ended up having a corrupt Collection / DB record. I was tipped on another forum that the symptoms I was seeing (Nighscout web app not displaying some data, not the Heroku deploy I was attempting to work around that issue) could be caused by that. So as a last resort I dropped the entire Mongo Collection and I can now deploy Master and Dev, and it sticks in Heroku.
I don't know the significance since the data should be separate from the web app source code itself.
The whole reason I wanted to try Dev was for a fix for parts of the app not working. After initialising the Mongo DB Collection, I can use Master, so Dev (and the fix it contained) is not needed.
I know this isn't the exact root cause, but I'll leave this here in case someone comes across it and hasn't thought to look at the data.

How to share Discord.py code with Github without exposing code, while still having your bot run on Heroku

So I host my Discord.py bot on Heroku. I also want to continue updating the source code on Github. Whenever I want to update the source code, I have to remove my .env file with the token in it so I can upload it to Github, then I would have to add the file again to push it to Heroku. Is there any way to have the bot run on Heroku without having to add the file to Git before doing so?
You can store your token as a config variable in Heroku and it will automatically set it as an environment variable in your Dyno, you do not need your .env file at all.
See: https://devcenter.heroku.com/articles/config-vars

Why meteor database(mongo db) contents is not uploaded in the github repo?

I uploaded a meteor project on github repository. Once I finished uploading, I downloaded the zip file to check if it is functioning properly. The project runs, however, there is not even a single collection in mongodb. (Note my meteor version is 1.8)
Can someone please help me get why the database collections are not stored/uploaded in the github repo and how can they be stored on github repo?
That is the designed behaviour of classic 3 tier web apps architecture. Your app code is separated from your app data.
Technically, the MongoDB data of your Meteor project in dev mode (i.e. when you start it with meteor run) is in your Meteor project .meteor/local folder, which is correctly excluded from version control by .gitignore.
Note that in production (i.e. when you use your app after doing meteor build) you will have to provide a MONGO_URL environment variable to specify where your MongoDB can be reached, since your local dev data will not be shipped with the built app.
Now you can backup your data (e.g. mongodump) and use the dump to fill up your new MongoDB. You can also do it automatically, typically in your Meteor server startup, if you find empty collections.

Regarding the database in Pythonanywhere

I am following the Djangogirls tutorial according to which I added new posts in the blog on the Django admin. I created a template using Django templates to display this Dynamic data. I checked it by opening 127.0.0.1:8000 in browser and I was able to see the data. Then for deploying this site on Pythonanywhere, I pushed the data to github from my local rep using git push and did git pull on Pythonanywhere from github.All the files including the db.sqlite3(database) file were updated properly in pythonanywhere but still I could not the see the data after running my webapp on pythonanywhere.Then , I manually removed the db.sqlite3 file from pythonanywhere and uploaded the same file from my local desktop and it worked. Why did this work? and is there an alternative for this?
That's kind of odd; if the SQLite DB was in the git repository, and was uploaded correctly, I'd expect it to work. Perhaps the database is in a different directory? On PythonAnywhere, the working directory of your running web app might be (actually, probably is) different to your local machine. And if you're specifying the database using a relative path (which you probably are) then that might mean that the one you created locally is somewhere different to where it is on PythonAnywhere.
BTW, from my memories of the Django Girls tutorial (I coached for one session a few months ago) you're not actually expected to put the database in your Git repository. It's not how websites are normally managed. You'd normally have one database locally, for testing, where you'd be able to put random testing data, and then a completely different one on your live site, with posts for public consumption.