Database setup and development

In the SaaS Forge boilerplate we use PostgreSQL. You can install it on your computer or create a database in the cloud for free, for example with ElephantSQL. As a ORM system we use SQLAlchemy. We use the "code-first" approach and update the database with Alembic.

The boilerplate is delivered with pre-created models that will create database tables when you run the init script. The tables are:

  • user
  • role
  • account
  • account_history.

The models Python files can be found in src/shared/db_models. The Alembic code that updates the database can be found in src/shared/utils/db_scaffold.

When you run the init script for the first time it creates tables and 2 roles "Admin" and "User".

When you want to add a new table, or field in the existing tables, just create the corresponding code and run the following command:

flask dbupdate

If you experience any problem, please refer this document: "Updating database"

When Alembic updates the database it creates the corresponding code file containing the current changes. All the files are stored in src/migrations folder.