Last active
October 9, 2023 23:45
-
-
Save samratshaw/b339a4a56ece34e9a3d15b2f29cafe03 to your computer and use it in GitHub Desktop.
Medium: Sequelize migrations with Typescript
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
# Read arguments passed to the script. | |
if [ -z "$1" ]; then | |
ENVIRONMENT='development' | |
else | |
ENVIRONMENT="$1" | |
fi | |
echo "" | |
echo "Migrating for environment: $ENVIRONMENT" | |
echo "" | |
echo " -> Step 1/4: Compiling migration scripts." | |
echo "" | |
for filename in ./src/db/migrations/*.ts; do | |
yarn tsc -t es2017 - module CommonJS - outDir ./build-migrations $filename | |
done | |
echo "" | |
echo " -> Compilation completed." | |
echo "" | |
echo "" | |
echo " -> Step 2/4: Copying resources required for migration." | |
cp -rf ./src/db/dump ./build-migrations/db/ | |
echo " -> Copying resources completed." | |
echo "" | |
echo "" | |
echo " -> Step 3/4: Starting migration." | |
echo "" | |
sequelize db:migrate - env $ENVIRONMENT | |
echo "" | |
echo " -> Migration completed." | |
echo "" | |
echo "" | |
echo " -> Step 4/4: Deleting generated files." | |
echo "" | |
rm -Rf ./build-migrations | |
mkdir ./build-migrations | |
echo "" | |
echo " -> Deletion completed." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment