Skip to content
Snippets Groups Projects
Commit 5a7bda9a authored by Michael Kyriakou's avatar Michael Kyriakou
Browse files

Modified ".bat" scripts to be ".sh" scripts. Updated README.

parent 917c833c
No related branches found
No related tags found
No related merge requests found
......@@ -115,7 +115,7 @@ Notes
## Running a Migration
The "migrations" directory contains the following scripts you'll need to use: `RunDowngradeMigration.bat` and `RunUpgradeMigration.bat`.
The "migrations" directory contains the following scripts you'll need to use: `RunDowngradeMigration.sh` and `RunUpgradeMigration.sh`.
When you run an "upgrade" migration for the first time subdirectories `migrations/dev` and `migrations/prod` should be constructed.
......@@ -135,7 +135,7 @@ Flask migrate will automatically generate a migration script based on the differ
2. It is very useful for rows in a database to have a `created_at` attribute so you know when the row was first inserted. Comment out the new under the TODO, and remove the TODO.
3. Navigate and edit the file: `migrations/RunUpgradeMigration.bat`
3. Navigate and edit the file: `migrations/RunUpgradeMigration.sh`
4. Change the value of the 3rd argument to either `dev` or `prod`.
......@@ -156,7 +156,7 @@ Flask migrate will automatically generate a migration script based on the differ
### Tutorial: running an "downgrade" migration script
Example: you performed an "upgrade" migration but realize that it wasn't what you wanted, or could improve the column definition, for example you realize "phone_number" should not be a column part of "Person" but rather a separate table called "PhoneNumber" with a 1-many relation.
1. Edit `migrations/RunDowngradeMigration.bat`.
1. Edit `migrations/RunDowngradeMigration.sh`.
2. Change the value of the 3rd argument to either `dev` or `prod`.
......@@ -168,3 +168,7 @@ Example: you performed an "upgrade" migration but realize that it wasn't what yo
### Consistency violation, cannot find version
Delete/drop the `alembic` table from the database, and delete the associated migration directory for this table only.
### Migration script says "No changes in schema detected"
This is perfectly fine, this is just Flask Migrate checking for a migration. If you just want to downgrade from a previously run migration just ignore the output, it'll take the HEAD of the migration scripts applied, and call the "downgrade" method, then move the HEAD down to the next version.
Likewise, if you ran "RunUpgradeMigration" but cancelled before continuing with the autogenerated migration script created, you can ignore the output and continue; it'll take the HEAD of the migration scripts applied, and call the "upgrade" method, then move the HEAD to that script version.
\ No newline at end of file
RunMigration.bat downgrade dev first_db
\ No newline at end of file
#!/bin/bash -e
sh RunMigration.sh downgrade dev first_db
set ENV=%2
set FLASK_APP=../app.py
set FLASK_DB_BINDING_TO_MIGRATE=%3
set migrations_dir_path=%ENV%/%FLASK_DB_BINDING_TO_MIGRATE%
flask db init --directory %migrations_dir_path%
flask db migrate -m "In this migration we did..." --directory %migrations_dir_path%
ECHO "Press enter 2 times to confirm and %1 the migration..."
pause
pause
flask db %1 --directory %migrations_dir_path%
pause
\ No newline at end of file
#!/bin/bash -e
action=$1
export ENV=$2
export FLASK_APP=../app.py
export FLASK_DB_BINDING_TO_MIGRATE=$3
migrations_dir_path="$ENV/$FLASK_DB_BINDING_TO_MIGRATE"
flask db init --directory $migrations_dir_path
flask db migrate -m "In this migration we did..." --directory $migrations_dir_path
input_prompt="Press any key to confirm and $action the migration..."
read -p "$input_prompt"
read -p "$input_prompt"
flask db $action --directory $migrations_dir_path
read -p "Press any key to exit."
RunMigration.bat upgrade dev first_db
\ No newline at end of file
#!/bin/bash -e
sh RunMigration.sh upgrade dev first_db
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment