chore(migrations): register a sqlx migrator image (#40602)

This commit is contained in:
Nick Best
2025-10-30 16:50:26 -07:00
committed by GitHub
parent fae5d8b5f9
commit 98cb47d4de
7 changed files with 33 additions and 16 deletions

View File

@@ -268,18 +268,18 @@ jobs:
python manage.py migrate --noinput
# Build and run Rust migrations using dedicated container
docker build -f rust/Dockerfile.persons-migrate -t posthog-migrations:latest ./rust
docker build -f rust/Dockerfile.sqlx-migrate -t posthog-migrations:latest ./rust
docker run --rm --network host \
-e PERSONS_DATABASE_URL="postgres://posthog:posthog@localhost:5432/posthog_persons" \
-e CYCLOTRON_DATABASE_URL="postgres://posthog:posthog@localhost:5432/cyclotron" \
posthog-migrations:latest
posthog-migrations:latest all
# Build and run Rust migrations using dedicated container
docker build -f rust/Dockerfile.persons-migrate -t posthog-migrations:latest ./rust
docker build -f rust/Dockerfile.sqlx-migrate -t posthog-migrations:latest ./rust
docker run --rm --network host \
-e PERSONS_DATABASE_URL="postgres://posthog:posthog@localhost:5432/posthog_e2e_test" \
-e CYCLOTRON_DATABASE_URL="postgres://posthog:posthog@localhost:5432/cyclotron" \
posthog-migrations:latest
posthog-migrations:latest all
python manage.py setup_dev
wait

View File

@@ -30,6 +30,9 @@ jobs:
- image: hook-migrator
dockerfile: ./rust/Dockerfile.migrate-hooks
project: c1bwj4j4qg
- image: sqlx-migrate
dockerfile: ./rust/Dockerfile.sqlx-migrate
project: jmsz6gms8g
- image: cyclotron-janitor
dockerfile: ./rust/Dockerfile
project: r4zm8vtlbw
@@ -69,6 +72,7 @@ jobs:
hook-janitor_digest: ${{ steps.digest.outputs.hook-janitor_digest }}
hook-worker_digest: ${{ steps.digest.outputs.hook-worker_digest }}
hook-migrator_digest: ${{ steps.digest.outputs.hook-migrator_digest }}
sqlx-migrate_digest: ${{ steps.digest.outputs.sqlx-migrate_digest }}
cymbal_digest: ${{ steps.digest.outputs.cymbal_digest }}
embedding-worker_digest: ${{ steps.digest.outputs.embedding-worker_digest }}
feature-flags_digest: ${{ steps.digest.outputs.feature-flags_digest }}
@@ -209,6 +213,10 @@ jobs:
values:
image:
sha: '${{ needs.build.outputs.kafka-deduplicator_digest }}'
- release: sqlx-migrate
values:
image:
sha: '${{ needs.build.outputs.sqlx-migrate_digest }}'
steps:
- name: get deployer token
id: deployer

View File

@@ -27,11 +27,11 @@
"prepublishOnly": "pnpm build",
"setup:dev:clickhouse": "cd .. && DEBUG=1 python manage.py migrate_clickhouse",
"setup:test": "cd .. && TEST=1 python manage.py setup_test_environment && cd plugin-server && pnpm run setup:test:rust",
"setup:test:rust": "CYCLOTRON_DATABASE_NAME=test_cyclotron PERSONS_DATABASE_NAME=test_persons BEHAVIORAL_COHORTS_DATABASE_NAME=test_behavioral_cohorts ../rust/bin/migrate-all all && PERSONS_DATABASE_NAME=test_persons_migration ../rust/bin/migrate-persons",
"setup:test:rust": "CYCLOTRON_DATABASE_NAME=test_cyclotron PERSONS_DATABASE_NAME=test_persons BEHAVIORAL_COHORTS_DATABASE_NAME=test_behavioral_cohorts ../rust/bin/migrate-entry all && PERSONS_DATABASE_NAME=test_persons_migration ../rust/bin/migrate-persons",
"migrate:persons": "../rust/bin/migrate-persons",
"migrate:cyclotron": "../rust/bin/migrate-cyclotron",
"migrate:behavioral-cohorts": "../rust/bin/migrate-behavioral-cohorts",
"migrate:rust": "../rust/bin/migrate-all all",
"migrate:rust": "../rust/bin/migrate-entry all",
"services:start": "cd .. && docker compose -f docker-compose.dev.yml up",
"services:stop": "cd .. && docker compose -f docker-compose.dev.yml down",
"services:clean": "cd .. && docker compose -f docker-compose.dev.yml rm -v",

View File

@@ -24,13 +24,11 @@ COPY ./behavioral_cohorts_migrations ./behavioral_cohorts_migrations
COPY ./bin/migrate-persons ./bin/migrate-persons
COPY ./bin/migrate-cyclotron ./bin/migrate-cyclotron
COPY ./bin/migrate-behavioral-cohorts ./bin/migrate-behavioral-cohorts
COPY ./bin/migrate-all ./bin/migrate-all
COPY ./bin/migrate-entry ./bin/migrate-entry
RUN chmod +x /migrations/bin/migrate-all && \
RUN chmod +x /migrations/bin/migrate-entry && \
chmod +x /migrations/bin/migrate-persons && \
chmod +x /migrations/bin/migrate-cyclotron && \
chmod +x /migrations/bin/migrate-behavioral-cohorts
ENTRYPOINT ["/migrations/bin/migrate-all"]
CMD ["all"]
ENTRYPOINT ["/migrations/bin/migrate-entry"]

View File

@@ -1,4 +1,4 @@
#!/bin/sh
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
exec "$SCRIPT_DIR/migrate-all" behavioral-cohorts
exec "$SCRIPT_DIR/migrate-entry" behavioral-cohorts

View File

@@ -1,7 +1,18 @@
#!/bin/bash
set -e
MIGRATION_TYPE="${1:-all}"
MIGRATION_TYPE="$1"
if [ -z "$MIGRATION_TYPE" ]; then
echo "Error: No migration type specified"
echo ""
echo "Usage: $0 <all|persons|cyclotron|behavioral-cohorts>"
echo " all - Run all migrations"
echo " persons - Run only persons migrations"
echo " cyclotron - Run only cyclotron migrations"
echo " behavioral-cohorts - Run only behavioral cohorts migrations"
exit 1
fi
# Determine the base directory for migrations
# In Docker, we use /migrations; locally, we use the parent directory
@@ -80,8 +91,8 @@ case "$MIGRATION_TYPE" in
run_behavioral_cohorts_migrations
;;
*)
echo "Usage: $0 [all|persons|cyclotron|behavioral-cohorts]"
echo " all - Run all migrations (default)"
echo "Usage: $0 <all|persons|cyclotron|behavioral-cohorts>"
echo " all - Run all migrations"
echo " persons - Run only persons migrations"
echo " cyclotron - Run only cyclotron migrations"
echo " behavioral-cohorts - Run only behavioral cohorts migrations"

View File

@@ -1,4 +1,4 @@
#!/bin/sh
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
exec "$SCRIPT_DIR/migrate-all" persons
exec "$SCRIPT_DIR/migrate-entry" persons