1

I have this small project that specifies sqlite as the database choice.

For this particular project, the framework is Django, and the server is hosted by Heroku. In order for the database to work, it must be set up with migration commands and credentials whenever the project is deployed to continuous integration tools or development site.

The question is, that many of these environments do not actually use the my_project.sqlite3 file that comes with the source repository, which we version control with git. How do I incorporate changes to the deployed database? Is a script that set up the database suitable for this scenario? Meanwhile, it is worth notice that there are security credentials that should not appear in a script in unencrypted ways, which makes the situation tricky.

1 Answer 1

1

that many of these environments do not actually use the my_project.sqlite3 file that comes with the source repository

If your deployment platform does not support your chosen database, then your development environment should probably be moved to using one of the databases they do support. It is possible to run different databases in development and production, but just seems like the source of headaches.

I have found a number of articles that state that Heroku just doesn't support SQLite in production and instead recommends Postgres.

How do I incorporate changes to the deployed database? Is a script that set up the database suitable for this scenario?

I assume that you are just extracting data from one database to give to another, so yes,as long as that script is a one time batch operation each time the code is updated, then it should be fine. You will want something else if you are adding/manipulating data in production and then exporting it to your git.

Meanwhile, it is worth notice that there are security credentials that should not appear in a script in unencrypted ways

An environment variable should solve that. You set your host machine to have environment variables with your credentials and then just retrieve them within the script. You are looking to have something like this:

# Set environment vars
os.environ['USER'] = 'username'
os.environ['PASSWORD'] = 'password'

# Get environment vars
USER = os.getenv('USER')
PASSWORD = os.environ.get('PASSWORD')
Sign up to request clarification or add additional context in comments.

4 Comments

Yeah, I read on both Heroku and Django, Postgres is preferred. But for the project we are having, it has to be SQLite for a while, which is just tedious.
When I was talking about credentials, I was thinking about for example tokens for OAuth. How do I store them to be safe?
@jackxujh supporting that is going to have annoyingly more glue than should be needed
@jackxujh can you just encrypt them based on a password? It really depends on your use case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.