From d9e9dc0ab7e5c13ba31bb46c41a33765515e1e40 Mon Sep 17 00:00:00 2001 From: Christoph <34290975+Soliseum@users.noreply.github.com> Date: Wed, 1 Oct 2025 16:24:25 -0500 Subject: [PATCH] Generate Migration based off Drift Generate Migration scripts to deploy to lower environments based off Drift. With and without snapshots. --- Drift/Drift_GenerateMigration.ps1 | 15 +++++++++++++++ Drift/Drift_GenerateMigration_Snapshot.ps1 | 3 +++ 2 files changed, 18 insertions(+) create mode 100644 Drift/Drift_GenerateMigration.ps1 create mode 100644 Drift/Drift_GenerateMigration_Snapshot.ps1 diff --git a/Drift/Drift_GenerateMigration.ps1 b/Drift/Drift_GenerateMigration.ps1 new file mode 100644 index 0000000..ba18b8a --- /dev/null +++ b/Drift/Drift_GenerateMigration.ps1 @@ -0,0 +1,15 @@ +# Compare Target Database To schemaModel and apply drift to schemaModel +# Use case: Compare a live environment (e.g., QA) against the schema model to check for drift. +# Helpful for identifying differences before deploying migrations. + +flyway diff model -diff.source=qa -environments.qa.url="jdbc:postgresql://127.0.0.1:5432/qa" -environments.qa.user="flyway_qa" "-environments.qa.password=Flyway123" -diff.target=schemaModel -environments.qa.schemas="mySchema" +# Note: Ensure that the 'qa' environment is properly configured in your Flyway configuration file or command line. + +# Generate Migrations +# Use case: Automatically generate versioned and undo migrations after drift is detected. +# Useful for developers to create migration scripts based on schema changes. + +flyway generate "-generate.types=versioned,undo" "-generate.description=dev_updates" + +# generate to a specific location +flyway generate -X -generate.types=versioned,undo -generate.description=dev_updates -generate.location=./outputs/drift \ No newline at end of file diff --git a/Drift/Drift_GenerateMigration_Snapshot.ps1 b/Drift/Drift_GenerateMigration_Snapshot.ps1 new file mode 100644 index 0000000..9802b6b --- /dev/null +++ b/Drift/Drift_GenerateMigration_Snapshot.ps1 @@ -0,0 +1,3 @@ +flyway snapshot "-source=development" "-filename=C:\Projects\AdventureWorks\snapshots\snapshot.json" +flyway diff "-source=snapshot:.\snapshots\snapshot.json" "-target=schemaModel" model diffText +flyway generate -X "-generate.types=versioned,undo" "-generate.description=dev_updates" "-generate.location=./outputs/drift" \ No newline at end of file