-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add documentation notes on sql migration gear
- Loading branch information
1 parent
a3ea5e2
commit a75d216
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# SQLalchemy database migration gear | ||
|
||
### apply migrations | ||
|
||
export the app script path as bash variable | ||
|
||
export FLASK_APP=chuck_norris_jokes_caller/app.py | ||
|
||
Initialize the db migration gear: it will create a folder at path `migrations`.<br> | ||
|
||
> [!TIP] | ||
> You should ignore the error in case a folder `migrations` is already present/versioned in the project. | ||
> [!NOTE] | ||
> In case you deleted migrations and you want to init the db again: | ||
> | ||
> sqlite3 chuck_norris_jokes_caller/chuck_norris_jokes_caller.sqlite | ||
> | ||
> delete from alembic_version; | ||
create migration required files | ||
|
||
flask db init | ||
|
||
save the changes to DB structure | ||
|
||
flask db migrate -m "< migration message here>" | ||
|
||
apply the changes to DB structure | ||
|
||
flask db upgrade | ||
|
||
> [!NOTE] | ||
> Every time the DB structure is changed, you have to run | ||
> | ||
> flask db migrate -m "< migration message here>" | ||
> | ||
> flask db upgrade | ||
> [!NOTE] | ||
> Every time you open a bash session or terminal and want to operate the migrations, you have to run | ||
> | ||
> export FLASK_APP=chuck_norris_jokes_caller/app.py | ||
|
||
> [!WARNING] | ||
> migrations do not affect changes in properties of field such as primary key, uniqueness, blankness, non-null ness... |