A reference repo for using sqlalchemy-spanner and alembic with the spanner emulator. This repository is focused on local development.
Before doing anything else, run poetry install.
- Install and start the Spanner emulator.
gcloud emulators spanner start. Note that emulator data DOES NOT persist between sessions. Make sure to follow the directions for creating a gcloud config for the emulator specifically. - Set environment variables for emulator
export SPANNER_EMULATOR_HOST=localhost:9010
export DB_URI=spanner+spanner:///projects/emulator-test-project/instances/test-instance/databases/test-db- Create a Spanner instance and db in the emulator:
poetry run python scripts/create_db.py
- Set environment variable
DB_URIto a deployed empty Spanner DB (no tables). Use the defaultgcloudconfig, NOT the emulator config:gcloud config configurations activate default.
export DB_URI=spanner+spanner:///projects/my-project-id/instances/spanner-demo/databases/alembic_testpoetry run alembic revision --autogenerate -m initto generate a migrationpoetry run alembic upgrade headto upgrade to latest