-
Notifications
You must be signed in to change notification settings - Fork 1
DB Init
We have three enviornments for the project, which are: dev, prod and test. So we will create three databases respectively, each for one envrionment.
The dev enviornment is the most frequently used environment during our devlopment process. Issue #89 implemented an auto generated script when statring the app in the dev environment. It works as the following flow chart shown.
flowchart TD
A[Start] --> B{Does dev db exsit?}
B -->|Yes| C1{Does dev db need migrations?}
C1 -->|Yes| D1[Flask Migrate to the head version]
D1 --> End[End]
C1 -->|No| End
B -->|No| C2[Create a new dev db]
C2 --> D2[Execute backup SQL]
D2 --> E2[Update dev version to head]
E2 --> End
Check create_dev_db() and migrate_dev_db() in /app/__init__.py.
The mandatory data is maintained under /sql/dev.backup.sql. It will be executed every time when the app recreates the new dev db. Alternatively, you can insert it into your existing dev db manually.
The test environment is used only for testing, especially for unit testing.
The test db will be created every time you run a test under /tests.
It is implemented in /tests/config.py; check it for details.
- Generally speaking, the db will be created using
db.create_all()after the app instance is created. - Then, the seed data in
tests/seedswill be inserted into the test db in theTestBase.setUp()process, which occurs after the app instance is created and before your test code is executed. - When your test is finished, the data will be cleaned up in
tearDown(), which happens after your test code has been executed.
All the test data is organized under /tests/seeds; create your seed data based on the db model.
The prod environment is used for deploying the website online, visit here.
For now, the prod db will be updated manually, so there's no need to worry about it.
@ 2024