Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

automatic db migration for dev (#1357)

Will Hutchinson6f1bd2457ac8
diff --git a/.github/actions/migrate-cloud-storage-db/action.yml b/.github/actions/migrate-cloud-storage-db/action.yml
new file mode 100644
index 0000000000..976f0eb291
--- /dev/null
+++ b/.github/actions/migrate-cloud-storage-db/action.yml
@@ -0,0 +1,67 @@
+name: Migrate Cloud Storage Database
+description: Run database migrations for cloud storage services
+
+inputs:
+ environment:
+ description: 'Environment to run migrations for (dev, prod)'
+ required: true
+ aws-access-key:
+ description: 'AWS access key'
+ required: true
+ aws-secret-key:
+ description: 'AWS secret key'
+ required: true
+ aws-region:
+ description: 'AWS region'
+ required: false
+ default: 'us-east-1'
+
+runs:
+ using: composite
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Configure AWS credentials
+ uses: aws-actions/configure-aws-credentials@v4
+ with:
+ aws-access-key-id: ${{ inputs.aws-access-key }}
+ aws-secret-access-key: ${{ inputs.aws-secret-key }}
+ aws-region: ${{ inputs.aws-region }}
+
+ - name: Setup Rust
+ uses: ./.github/actions/setup-rust
+
+ - name: Install just
+ uses: extractions/setup-just@v2
+
+ - name: Install sqlx-cli
+ shell: bash
+ run: |
+ cargo install sqlx-cli --locked --no-default-features --features postgres
+
+ - name: Get database URL from Secrets Manager
+ id: get-db-url
+ shell: bash
+ run: |
+ if [ "${{ inputs.environment }}" = "prod" ]; then
+ SECRET_NAME="macro-db-prod"
+ else
+ SECRET_NAME="macro-db-dev"
+ fi
+
+ DATABASE_URL=$(aws secretsmanager get-secret-value \
+ --secret-id "$SECRET_NAME" \
+ --query SecretString \
+ --output text)
+
+ echo "::add-mask::$DATABASE_URL"
+ echo "database_url=$DATABASE_URL" >> $GITHUB_OUTPUT
+
+ - name: Run database migrations
+ shell: bash
+ working-directory: rust/cloud-storage
+ env:
+ DATABASE_URL: ${{ steps.get-db-url.outputs.database_url }}
+ run: |
+ echo "Running migrations for ${{ inputs.environment }} environment..."
+ just sqlx::migrate_db "$DATABASE_URL"
diff --git a/.github/workflows/deploy-cloud-storage-on-push.yml b/.github/workflows/deploy-cloud-storage-on-push.yml
index e09ce62181..1dea9605b5 100644
--- a/.github/workflows/deploy-cloud-storage-on-push.yml
+++ b/.github/workflows/deploy-cloud-storage-on-push.yml
@@ -35,25 +35,40 @@ jobs:
run: |
# Make the script executable
chmod +x .github/scripts/detect-affected-services.sh
-
+
# Run the detection script and capture output
OUTPUT=$(.github/scripts/detect-affected-services.sh)
-
+
# Parse the output
SERVICES=$(echo "$OUTPUT" | grep "^services=" | cut -d'=' -f2-)
HAS_CHANGES=$(echo "$OUTPUT" | grep "^has_changes=" | cut -d'=' -f2-)
-
+
# Set outputs
echo "services=$SERVICES" >> $GITHUB_OUTPUT
echo "has_changes=$HAS_CHANGES" >> $GITHUB_OUTPUT
-
+
# Log for debugging
echo "Detected services: $SERVICES"
echo "Has changes: $HAS_CHANGES"
+ migrate-db:
+ name: Run Database Migrations
+ needs: detect-changes
+ if: ${{ needs.detect-changes.outputs.has_changes == 'true' }}
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Run migrations for dev
+ uses: ./.github/actions/migrate-cloud-storage-db
+ with:
+ environment: dev
+ aws-access-key: ${{ secrets.AWS_ACCESS_KEY }}
+ aws-secret-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
+
deploy-services:
name: Deploy ${{ matrix.service }}
- needs: detect-changes
+ needs: [detect-changes, migrate-db]
if: ${{ needs.detect-changes.outputs.has_changes == 'true' }}
runs-on:
[
@@ -92,13 +107,16 @@ jobs:
deployment-summary:
name: Deployment Summary
runs-on: ubuntu-latest
- needs: [ detect-changes, deploy-services ]
+ needs: [detect-changes, migrate-db, deploy-services]
if: always()
steps:
- name: Check deployment results
run: |
if [[ "${{ needs.detect-changes.outputs.has_changes }}" == "false" ]]; then
echo "ℹ️ No cloud-storage services were affected by the changes"
+ elif [[ "${{ needs.migrate-db.result }}" == "failure" ]]; then
+ echo "❌ Database migrations failed"
+ exit 1
elif [[ "${{ needs.deploy-services.result }}" == "failure" ]]; then
echo "❌ One or more service deployments failed"
exit 1