简体   繁体   中英

How to ignore a file from GitHub repo when deploying to Heroku?

I have a Node.js app on Heroku linked with GitHub. The problem is that every time I deploy the master branch to Heroku, the whole app gets overwritten on Heroku.

Usually this is perfectly fine, however in the root folder there's a database file which constantly gets updated through a chat app, and on every deploy it gets reset. The SQLite database gets automatically generated if it does not exist when the main script is run.

My question is how do I make the SQLite database file be the only persistent file in the Heroku app, without getting overwritten on deploys from master branch on GitHub.

I have tried adding a .slugignore file and including database.sqlite there

To answer your question, as you've discovered, you can ignore files when deploying to Heroku using a .slugignore file .

However, this won't solve your problem. Heroku's filesystem is ephemeral . Any changes you make to it will be lost whenever your dyno restarts. This happens frequently (at least once per day). As a result, even if you add database.sqlite to your .slugignore , your data will be lost.

The solution is to use a client-server database instead of a file-based database like SQLite. Heroku Postgres is a fairly straightforward choice that has a free tier. If you don't want to use PosgreSQL you can choose another database .

Whatever database you choose, I urge you to also switch to the same database in development. Database systems aren't drop-in replacements for each other, and you don't want to discover the differences when you're trying to deploy to production.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM