-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #161 from lil-lab/recnet-api/create-migration-down
[recnet-api] Create migration down
- Loading branch information
Showing
4 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
apps/recnet-api/prisma/migrations/20240306064817_init/down.sql
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,39 @@ | ||
-- DropForeignKey | ||
ALTER TABLE "FollowingRecord" DROP CONSTRAINT "FollowingRecord_userId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "FollowingRecord" DROP CONSTRAINT "FollowingRecord_followerId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Recommendation" DROP CONSTRAINT "Recommendation_userId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "Recommendation" DROP CONSTRAINT "Recommendation_articleId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "InviteCode" DROP CONSTRAINT "InviteCode_ownerId_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "InviteCode" DROP CONSTRAINT "InviteCode_usedById_fkey"; | ||
|
||
-- DropTable | ||
DROP TABLE "User"; | ||
|
||
-- DropTable | ||
DROP TABLE "FollowingRecord"; | ||
|
||
-- DropTable | ||
DROP TABLE "Recommendation"; | ||
|
||
-- DropTable | ||
DROP TABLE "Article"; | ||
|
||
-- DropTable | ||
DROP TABLE "InviteCode"; | ||
|
||
-- DropEnum | ||
DROP TYPE "Provider"; | ||
|
||
-- DropEnum | ||
DROP TYPE "Role"; | ||
|
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
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
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,32 @@ | ||
#!/bin/bash | ||
|
||
PRISMA_SCHEMA="apps/recnet-api/prisma/schema.prisma" | ||
PRISMA_MIGRATIONS_DIR="apps/recnet-api/prisma/migrations" | ||
|
||
MIGRATION_NAME="$1" | ||
|
||
perform_migration_up() { | ||
pnpx prisma migrate dev --name $MIGRATION_NAME --schema="$PRISMA_SCHEMA" | ||
} | ||
|
||
perform_migration_down() { | ||
npx prisma migrate diff \ | ||
--from-schema-datamodel $PRISMA_SCHEMA \ | ||
--to-schema-datasource $PRISMA_SCHEMA \ | ||
--script > down.sql | ||
} | ||
|
||
move_down_sql_file() { | ||
DIRECTORY=$(find $PRISMA_MIGRATIONS_DIR -type d -name "*$MIGRATION_NAME*" | tail -n 1) | ||
mv down.sql $DIRECTORY/down.sql | ||
} | ||
|
||
echo "Migrating database to $MIGRATION_NAME" | ||
echo "Performing migration down" | ||
perform_migration_down | ||
|
||
echo "Performing migration up" | ||
perform_migration_up | ||
|
||
echo "Moving down.sql to migration directory" | ||
move_down_sql_file |