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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
ci: add API and database Schema validation workflow (#9710)
Harshvardhan Bahukhandidea49def59b2
diff --git a/.github/api-migration-compatibility/.oasdiff-severity-levels.yaml b/.github/api-migration-compatibility/.oasdiff-severity-levels.yamlnew file mode 100644index 0000000000..29fc3042eb--- /dev/null+++ b/.github/api-migration-compatibility/.oasdiff-severity-levels.yaml@@ -0,0 +1,61 @@+api-path-removed-without-deprecation: ERR+api-path-removed-before-sunset: ERR+api-removed-without-deprecation: ERR+api-removed-before-sunset: ERR+api-operation-id-removed: ERR+api-tag-removed: WARN+request-body-became-enum: ERR+request-body-became-optional: INFO+request-body-became-required: ERR+request-body-max-length-decreased: ERR+request-body-max-length-increased: INFO+request-body-min-length-increased: ERR+request-body-min-length-decreased: INFO+request-body-type-changed: ERR+request-property-became-not-nullable: ERR+request-property-became-nullable: INFO+request-property-became-optional: INFO+request-property-became-required: ERR+request-property-default-value-changed: WARN+request-property-enum-value-removed: ERR+request-property-enum-value-added: INFO+request-property-max-decreased: ERR+request-property-max-increased: INFO+request-property-max-length-decreased: ERR+request-property-max-length-increased: INFO+request-property-min-increased: ERR+request-property-min-decreased: INFO+request-property-min-length-increased: ERR+request-property-min-length-decreased: INFO+request-property-pattern-changed: ERR+request-property-pattern-removed: INFO+request-property-removed: ERR+request-property-type-changed: ERR+request-property-x-extensible-enum-value-removed: ERR+response-header-became-optional: ERR+response-property-default-value-changed: WARN+response-property-enum-value-added: INFO+response-property-pattern-changed: ERR+response-property-pattern-removed: INFO+response-property-type-changed: ERR+request-parameter-became-optional: INFO+request-parameter-became-required: ERR+request-parameter-default-value-changed: WARN+request-parameter-enum-value-removed: ERR+request-parameter-enum-value-added: INFO+request-parameter-max-decreased: ERR+request-parameter-max-increased: INFO+request-parameter-max-length-decreased: ERR+request-parameter-max-length-increased: INFO+request-parameter-min-increased: ERR+request-parameter-min-decreased: INFO+request-parameter-min-length-increased: ERR+request-parameter-min-length-decreased: INFO+request-parameter-pattern-changed: ERR+request-parameter-pattern-removed: INFO+request-parameter-type-changed: ERR+request-parameter-x-extensible-enum-value-removed: ERR+request-parameter-deprecated: WARN+api-schema-removed: INFO+endpoint-deprecated: WARN+endpoint-reactivated: INFOdiff --git a/.github/api-migration-compatibility/.oasdiff-warn-ignore.yaml b/.github/api-migration-compatibility/.oasdiff-warn-ignore.yamlnew file mode 100644index 0000000000..4cd529aa15--- /dev/null+++ b/.github/api-migration-compatibility/.oasdiff-warn-ignore.yaml@@ -0,0 +1,14 @@+response-property-max-length-increased+response-property-min-length-decreased+response-property-max-increased+response-property-min-decreased+request-parameter-max-length-increased+request-parameter-min-length-decreased+request-parameter-max-increased+request-parameter-min-decreased+api-tag-added+response-property-enum-value-added+request-property-enum-value-added+request-parameter-enum-value-added+response-media-type-added+request-body-media-type-addeddiff --git a/.github/api-migration-compatibility/migration-rules.yaml b/.github/api-migration-compatibility/migration-rules.yamlnew file mode 100644index 0000000000..b217b62da3--- /dev/null+++ b/.github/api-migration-compatibility/migration-rules.yaml@@ -0,0 +1,108 @@+# Migration Rules Configuration+# This file defines SQL patterns that are considered breaking changes or warnings+# for database migrations, with folder-specific rule application.++# Define reusable rule patterns+rule_patterns:+ drop_table:+ pattern: 'DROP\s+TABLE\s+'+ description: "Dropping a table removes data and breaks existing queries"++ drop_column:+ pattern: 'DROP\s+COLUMN\s+'+ description: "Dropping a column breaks applications expecting it"++ delete_data:+ pattern: 'DELETE\s+FROM\s+'+ description: "Deleting data can break application logic"++ truncate_table:+ pattern: 'TRUNCATE\s+'+ description: "Truncating removes all data from a table"++ rename_table:+ pattern: 'RENAME\s+TO\s+'+ description: "Renaming a table breaks existing queries and code references"++ rename_column:+ pattern: 'RENAME\s+COLUMN\s+'+ description: "Renaming a column breaks applications using the old name"++ set_not_null:+ pattern: 'ALTER\s+COLUMN\s+.*\s+SET\s+NOT\s+NULL'+ description: "Making an existing nullable column NOT NULL can fail with existing NULL data"++ add_column_not_null_no_default:+ pattern: 'ALTER\s+TABLE\s+.*\s+ADD\s+COLUMN\s+(?!.*DEFAULT).*NOT\s+NULL'+ description: "Adding a NOT NULL column without a DEFAULT to an existing table will fail"++ alter_column_type:+ pattern: '(ALTER\s+COLUMN\s+.*\s+TYPE|ALTER\s+COLUMN\s+.*\s+SET\s+DATA\s+TYPE)'+ description: "Changing column type may cause data loss or conversion issues"++ drop_index:+ pattern: 'DROP\s+INDEX\s+'+ description: "Dropping an index can significantly impact query performance"++ drop_constraint:+ pattern: 'DROP\s+CONSTRAINT\s+'+ description: "Dropping a constraint may allow invalid data"++ alter_default:+ pattern: '(SET\s+DEFAULT|DROP\s+DEFAULT)'+ description: "Changing defaults affects new rows only, may cause inconsistency"++# Apply rules per migration folder+# Each folder can have its own set of breaking and warning rules+folder_rules:+ # V1 migrations+ migrations:+ breaking:+ - drop_table+ - drop_column+ - delete_data+ - truncate_table+ - rename_table+ - rename_column+ - set_not_null+ - add_column_not_null_no_default+ - alter_column_type+ warnings:+ - drop_index+ - drop_constraint+ - alter_default++ # V2 migrations+ v2_migrations:+ breaking:+ - drop_table+ - drop_column+ - delete_data+ - truncate_table+ - rename_table+ - rename_column+ - set_not_null+ - add_column_not_null_no_default+ - alter_column_type+ warnings:+ - drop_index+ - drop_constraint+ - alter_default++ # V2 compatible migrations+ v2_compatible_migrations:+ breaking:+ - drop_table+ - drop_column+ - delete_data+ - truncate_table+ - rename_table+ - rename_column+ - set_not_null+ - add_column_not_null_no_default+ - alter_column_type+ warnings:+ - drop_index+ - drop_constraint+ - alter_default+diff --git a/.github/scripts/validate_migrations.sh b/.github/scripts/validate_migrations.shnew file mode 100755index 0000000000..78e76b401e--- /dev/null+++ b/.github/scripts/validate_migrations.sh@@ -0,0 +1,81 @@+#!/bin/bash++# validate_migrations.sh+# Validates database migrations for breaking changes and warnings+# Usage: ./validate_migrations.sh <migration_folder>++set -euo pipefail++MIGRATION_FOLDER="${1:-migrations}"+BASE_REF="${BASE_REF:-origin/main}"+RULES_FILE="${RULES_FILE:-.github/api-migration-compatibility/migration-rules.yaml}"++echo "Validating migrations in: $MIGRATION_FOLDER"++# Check if migration directory exists+if [[ ! -d "$MIGRATION_FOLDER" ]]; then+ echo "breaking_changes=0" >> "$GITHUB_OUTPUT"+ echo "warnings=0" >> "$GITHUB_OUTPUT"+ echo "Directory $MIGRATION_FOLDER does not exist, skipping validation"+ exit 0+fi++# Find new migrations+NEW_MIGRATIONS=$(git diff --name-only --diff-filter=AM "$BASE_REF"...HEAD -- "$MIGRATION_FOLDER/**/up.sql" 2>/dev/null || echo "")++if [[ -z "$NEW_MIGRATIONS" ]]; then+ echo "breaking_changes=0" >> "$GITHUB_OUTPUT"+ echo "warnings=0" >> "$GITHUB_OUTPUT"+ echo "No new migrations found in $MIGRATION_FOLDER"+ exit 0+fi++# Extract breaking rule patterns+BREAKING_PATTERNS=$(+ for rule in $(yq ".folder_rules.${MIGRATION_FOLDER}.breaking[]" "$RULES_FILE" 2>/dev/null || echo ""); do+ if [[ -n "$rule" ]]; then+ yq ".rule_patterns.$rule.pattern" "$RULES_FILE"+ fi+ done | paste -sd'|' -+)++# Extract warning rule patterns+WARNING_PATTERNS=$(+ for rule in $(yq ".folder_rules.${MIGRATION_FOLDER}.warnings[]" "$RULES_FILE" 2>/dev/null || echo ""); do+ if [[ -n "$rule" ]]; then+ yq ".rule_patterns.$rule.pattern" "$RULES_FILE"+ fi+ done | paste -sd'|' -+)++BREAKING=0+WARNINGS=0++while IFS= read -r file; do+ [[ -z "$file" ]] && continue++ # Check for breaking changes+ if grep --ignore-case --extended-regexp --quiet "$BREAKING_PATTERNS" "$file" 2>/dev/null; then+ echo "BREAKING: $file"+ MATCH_COUNT=$(grep --ignore-case --count --extended-regexp "$BREAKING_PATTERNS" "$file" 2>/dev/null || echo "0")+ grep --ignore-case --line-number --extended-regexp "$BREAKING_PATTERNS" "$file" 2>/dev/null | sed 's/^/ /' || true+ BREAKING=$((BREAKING + MATCH_COUNT))+ fi++ # Check for warnings+ if grep --ignore-case --extended-regexp --quiet "$WARNING_PATTERNS" "$file" 2>/dev/null; then+ echo "WARNING: $file"+ MATCH_COUNT=$(grep --ignore-case --count --extended-regexp "$WARNING_PATTERNS" "$file" 2>/dev/null || echo "0")+ grep --ignore-case --line-number --extended-regexp "$WARNING_PATTERNS" "$file" 2>/dev/null | sed 's/^/ /' || true+ WARNINGS=$((WARNINGS + MATCH_COUNT))+ fi+done <<< "$NEW_MIGRATIONS"++echo "breaking_changes=$BREAKING" >> "$GITHUB_OUTPUT"+echo "warnings=$WARNINGS" >> "$GITHUB_OUTPUT"++if [[ $BREAKING -gt 0 ]]; then+ echo "::error::Breaking changes detected in $MIGRATION_FOLDER database migrations."+ echo "::error::Found $BREAKING breaking change(s)."+ exit 1+fi\ No newline at end of filediff --git a/.github/workflows/api-migrations-compatibility.yml b/.github/workflows/api-migrations-compatibility.ymlnew file mode 100644index 0000000000..14d45c4479--- /dev/null+++ b/.github/workflows/api-migrations-compatibility.yml@@ -0,0 +1,206 @@+name: API & Migrations Compatibility Check++permissions:+ contents: read++# This workflow:+# - Runs on ALL PRs that modify API-related files+# - Always fails if breaking changes are detected++on:+ pull_request:+ paths:+ - 'crates/api_models/**'+ - 'crates/openapi/**'+ - 'api-reference/**'+ - 'migrations/**'+ - 'v2_migrations/**'+ - 'v2_compatible_migrations/**'+ - '.github/oasdiff/**'+ types: [opened, synchronize, reopened]++ workflow_dispatch:++concurrency:+ group: ${{ github.workflow }}-${{ github.ref }}+ cancel-in-progress: true++jobs:+ api-compatibility-check:+ name: API Compatibility Check+ runs-on: ubuntu-latest++ steps:+ - name: Checkout repository+ uses: actions/checkout@v5+ with:+ fetch-depth: 0++ - name: Setup Go for oasdiff+ uses: actions/setup-go@v5+ with:+ go-version: '1.21'++ - name: Install oasdiff+ run: |+ go install github.com/oasdiff/[email protected]+ echo "$HOME/go/bin" >> $GITHUB_PATH++ - name: Prepare PR schemas+ run: |+ jq empty api-reference/v1/openapi_spec_v1.json && cp api-reference/v1/openapi_spec_v1.json pr-v1-schema.json || { echo "::error::V1 schema invalid or missing"; exit 1; }+ jq empty api-reference/v2/openapi_spec_v2.json && cp api-reference/v2/openapi_spec_v2.json pr-v2-schema.json || { echo "::error::V2 schema invalid or missing"; exit 1; }++ - name: Extract base branch schemas+ env:+ BASE_SHA: ${{ github.event.pull_request.base.sha }}+ run: |+ git show "$BASE_SHA:api-reference/v1/openapi_spec_v1.json" > base-v1-schema.json 2>/dev/null || echo "{}" > base-v1-schema.json+ git show "$BASE_SHA:api-reference/v2/openapi_spec_v2.json" > base-v2-schema.json 2>/dev/null || echo "{}" > base-v2-schema.json++ - name: Run breaking change detection+ id: breaking_changes+ run: |+ BREAKING_CHANGES=0++ if oasdiff breaking \+ --fail-on ERR \+ --warn-ignore .github/api-migration-compatibility/.oasdiff-warn-ignore.yaml \+ base-v1-schema.json pr-v1-schema.json > v1-breaking-report.txt 2>&1; then+ echo "V1 API is backward compatible" > v1-breaking-status.txt+ else+ echo "Breaking changes detected in V1 API" > v1-breaking-status.txt+ BREAKING_CHANGES=$((BREAKING_CHANGES + 1))+ cat v1-breaking-report.txt+ fi++ if oasdiff breaking \+ --fail-on ERR \+ --warn-ignore .github/api-migration-compatibility/.oasdiff-warn-ignore.yaml \+ base-v2-schema.json pr-v2-schema.json > v2-breaking-report.txt 2>&1; then+ echo "V2 API is backward compatible" > v2-breaking-status.txt+ else+ echo "Breaking changes detected in V2 API" > v2-breaking-status.txt+ BREAKING_CHANGES=$((BREAKING_CHANGES + 1))+ cat v2-breaking-report.txt+ fi++ oasdiff diff base-v1-schema.json pr-v1-schema.json > v1-detailed-diff.txt 2>/dev/null || true+ oasdiff diff base-v2-schema.json pr-v2-schema.json > v2-detailed-diff.txt 2>/dev/null || true++ echo "breaking_changes=$BREAKING_CHANGES" >> $GITHUB_OUTPUT+ echo "total_issues=$BREAKING_CHANGES" >> $GITHUB_OUTPUT+ continue-on-error: true++ - name: Display API Compatibility Report+ if: always()+ run: |+ echo "=========================================="+ echo "API COMPATIBILITY REPORT"+ echo "=========================================="+ echo ""+ echo "V1 API Breaking Changes:"+ cat v1-breaking-report.txt 2>/dev/null || echo "No breaking changes detected"+ echo ""+ echo "V2 API Breaking Changes:"+ cat v2-breaking-report.txt 2>/dev/null || echo "No breaking changes detected"+ echo ""+ echo "V1 API Detailed Diff:"+ cat v1-detailed-diff.txt 2>/dev/null || echo "No changes detected"+ echo ""+ echo "V2 API Detailed Diff:"+ cat v2-detailed-diff.txt 2>/dev/null || echo "No changes detected"+ echo "=========================================="++ - name: Fail if breaking changes detected+ if: steps.breaking_changes.outputs.breaking_changes > 0+ run: |+ echo "::error::Breaking changes detected in API schema."+ echo "::error::Found ${{ steps.breaking_changes.outputs.breaking_changes }} breaking change(s)."+ exit 1++ migration-compatibility-check:+ name: Migration Breaking Change Detection+ runs-on: ubuntu-latest++ steps:+ - name: Checkout repository+ uses: actions/checkout@v5+ with:+ fetch-depth: 0++ - name: Fetch base branch+ env:+ BASE_REF: ${{ github.event.pull_request.base.ref }}+ run: |+ git fetch origin "$BASE_REF:$BASE_REF"++ - name: Validate V1 migrations+ id: migration_check+ run: |+ bash .github/scripts/validate_migrations.sh migrations++ - name: Validate V2 migrations+ if: success() || failure()+ id: v2_migration_check+ run: |+ bash .github/scripts/validate_migrations.sh v2_migrations++ - name: Validate V2 compatible migrations+ if: success() || failure()+ id: v2_compat_migration_check+ run: |+ bash .github/scripts/validate_migrations.sh v2_compatible_migrations++ - name: Calculate migration totals+ if: always()+ id: migration_report+ env:+ MIGRATION_BREAKING: ${{ steps.migration_check.outputs.breaking_changes }}+ MIGRATION_WARNINGS: ${{ steps.migration_check.outputs.warnings }}+ V2_MIGRATION_BREAKING: ${{ steps.v2_migration_check.outputs.breaking_changes }}+ V2_MIGRATION_WARNINGS: ${{ steps.v2_migration_check.outputs.warnings }}+ V2_COMPAT_MIGRATION_BREAKING: ${{ steps.v2_compat_migration_check.outputs.breaking_changes }}+ V2_COMPAT_MIGRATION_WARNINGS: ${{ steps.v2_compat_migration_check.outputs.warnings }}+ run: |+ TOTAL_BREAKING=$((+ ${MIGRATION_BREAKING:-0} ++ ${V2_MIGRATION_BREAKING:-0} ++ ${V2_COMPAT_MIGRATION_BREAKING:-0}+ ))++ TOTAL_WARNINGS=$((+ ${MIGRATION_WARNINGS:-0} ++ ${V2_MIGRATION_WARNINGS:-0} ++ ${V2_COMPAT_MIGRATION_WARNINGS:-0}+ ))++ echo "total_breaking=$TOTAL_BREAKING" >> $GITHUB_OUTPUT+ echo "total_warnings=$TOTAL_WARNINGS" >> $GITHUB_OUTPUT++ if [[ $TOTAL_BREAKING -gt 0 ]]; then+ echo "validation_status=BREAKING CHANGES DETECTED" >> $GITHUB_OUTPUT+ elif [[ $TOTAL_WARNINGS -gt 0 ]]; then+ echo "validation_status=WARNINGS FOUND" >> $GITHUB_OUTPUT+ else+ echo "validation_status=ALL CHECKS PASSED" >> $GITHUB_OUTPUT+ fi++ - name: Display Migration Summary+ if: always()+ run: |+ echo "=========================================="+ echo "MIGRATION VALIDATION SUMMARY"+ echo "=========================================="+ echo "V1: Breaking=${{ steps.migration_check.outputs.breaking_changes }} Warnings=${{ steps.migration_check.outputs.warnings }}"+ echo "V2: Breaking=${{ steps.v2_migration_check.outputs.breaking_changes }} Warnings=${{ steps.v2_migration_check.outputs.warnings }}"+ echo "V2 Compat: Breaking=${{ steps.v2_compat_migration_check.outputs.breaking_changes }} Warnings=${{ steps.v2_compat_migration_check.outputs.warnings }}"+ echo "----------------------------------------"+ echo "Total: Breaking=${{ steps.migration_report.outputs.total_breaking }} Warnings=${{ steps.migration_report.outputs.total_warnings }}"+ echo "Status: ${{ steps.migration_report.outputs.validation_status }}"+ echo "=========================================="++ if [[ "${{ steps.migration_report.outputs.total_breaking }}" != "0" && "${{ steps.migration_report.outputs.total_breaking }}" != "" ]]; then+ echo "::error::Migration validation failed with breaking changes."+ exit 1+ fi