Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

ci(migrations): add diesel migrations validations (#1056)

Sampras Lopes56d12ce5eb92
diff --git a/.github/workflows/migration-check.yaml b/.github/workflows/migration-check.yaml
new file mode 100644
index 0000000000..b913949d6c
--- /dev/null
+++ b/.github/workflows/migration-check.yaml
@@ -0,0 +1,66 @@
+name: Migration Consistency Tests
+
+on:
+ pull_request:
+
+ merge_group:
+ types:
+ - checks_requested
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: true
+
+env:
+ # Allow more retries for network requests in cargo (downloading crates) and
+ # rustup (installing toolchains). This should help to reduce flaky CI failures
+ # from transient network timeouts or other issues.
+ CARGO_NET_RETRY: 10
+ RUSTUP_MAX_RETRIES: 10
+ # Use cargo's sparse index protocol
+ CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
+
+jobs:
+ migration_verify:
+ name: Verify consistency of migrations with `schema.rs` file
+ runs-on: ubuntu-latest
+
+ services:
+ postgres:
+ image: postgres
+ env:
+ POSTGRES_PASSWORD: postgres
+ options: >-
+ --health-cmd pg_isready
+ --health-interval 10s
+ --health-timeout 5s
+ --health-retries 5
+ ports:
+ - 5432:5432
+
+ steps:
+ - name: Checkout repository
+ uses: actions/[email protected]
+
+ - name: Install Rust
+ uses: dtolnay/rust-toolchain@master
+ with:
+ toolchain: stable
+
+ - uses: Swatinem/[email protected]
+
+ - name: Install diesel_cli
+ shell: bash
+ run: cargo install diesel_cli --no-default-features --features postgres
+
+ - name: Verify `diesel migration run`
+ shell: bash
+ env:
+ DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
+ run: diesel migration run --locked-schema
+
+ - name: Verify `diesel migration redo`
+ shell: bash
+ env:
+ DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
+ run: diesel migration redo -a --locked-schema
diff --git a/crates/storage_models/src/merchant_account.rs b/crates/storage_models/src/merchant_account.rs
index f92f742d71..c34f67705d 100644
--- a/crates/storage_models/src/merchant_account.rs
+++ b/crates/storage_models/src/merchant_account.rs
@@ -35,9 +35,9 @@ pub struct MerchantAccount {
pub routing_algorithm: Option<serde_json::Value>,
pub primary_business_details: serde_json::Value,
pub api_key: Option<StrongSecret<String>>,
+ pub intent_fulfillment_time: Option<i64>,
pub created_at: time::PrimitiveDateTime,
pub modified_at: time::PrimitiveDateTime,
- pub intent_fulfillment_time: Option<i64>,
}
#[derive(Clone, Debug, Default, Insertable, router_derive::DebugAsDisplay)]
diff --git a/crates/storage_models/src/schema.rs b/crates/storage_models/src/schema.rs
index ebe2129156..3f50d83732 100644
--- a/crates/storage_models/src/schema.rs
+++ b/crates/storage_models/src/schema.rs
@@ -247,9 +247,9 @@ diesel::table! {
routing_algorithm -> Nullable<Json>,
primary_business_details -> Json,
api_key -> Nullable<Varchar>,
+ intent_fulfillment_time -> Nullable<Int8>,
created_at -> Timestamp,
modified_at -> Timestamp,
- intent_fulfillment_time -> Nullable<Int8>,
}
}
diff --git a/migrations/2023-01-20-113235_add_attempt_id_to_payment_intent/down.sql b/migrations/2023-01-20-113235_add_attempt_id_to_payment_intent/down.sql
index dd47bba7b5..f6777dd65a 100644
--- a/migrations/2023-01-20-113235_add_attempt_id_to_payment_intent/down.sql
+++ b/migrations/2023-01-20-113235_add_attempt_id_to_payment_intent/down.sql
@@ -2,4 +2,4 @@
DROP INDEX payment_attempt_payment_id_merchant_id_index;
CREATE UNIQUE INDEX payment_attempt_payment_id_merchant_id_index ON payment_attempt (payment_id, merchant_id);
DROP INDEX payment_attempt_payment_id_merchant_id_attempt_id_index;
-ALTER TABLE PAYMENT_INTENT DROP COLUMN attempt_id;
\ No newline at end of file
+ALTER TABLE PAYMENT_INTENT DROP COLUMN active_attempt_id;
diff --git a/migrations/2023-02-28-072631_ang-currency/down.sql b/migrations/2023-02-28-072631_ang-currency/down.sql
index e69de29bb2..e0ac49d1ec 100644
--- a/migrations/2023-02-28-072631_ang-currency/down.sql
+++ b/migrations/2023-02-28-072631_ang-currency/down.sql
@@ -0,0 +1 @@
+SELECT 1;
diff --git a/migrations/2023-02-28-112730_add_refund_webhook_types/down.sql b/migrations/2023-02-28-112730_add_refund_webhook_types/down.sql
index e69de29bb2..e0ac49d1ec 100644
--- a/migrations/2023-02-28-112730_add_refund_webhook_types/down.sql
+++ b/migrations/2023-02-28-112730_add_refund_webhook_types/down.sql
@@ -0,0 +1 @@
+SELECT 1;