feat: add DML execution support to SchemaManager#25
Merged
Conversation
Add get_connection() and execute_unprepared() to SchemaManager so that migrations can execute DML (INSERT, UPDATE, DELETE) in addition to DDL. SchemaManager now holds a DatabaseConnection internally, making SchemaManager::new() async. MigratorTrait methods reuse this single connection instead of creating separate ones.
Verifies execute_unprepared() and get_connection() work within migration up(), including INSERT and subsequent SELECT verification.
- Include sea-orm-migration-spanner in Makefile targets (fmt, fmt-check, lint, check) and CI workflows (build, test) - Bump MSRV from 1.75 to 1.80 for LazyLock compatibility - Apply nightly fmt import grouping to all migration crate sources
…fig.toml Set SPANNER_EMULATOR_HOST=localhost:9010 in .cargo/config.toml for both workspaces so cargo test works without manual env setup.
gcloud-spanner 1.8.0 added new fields to AdminClientConfig. Use struct update syntax to avoid breaking when new fields are added upstream.
Remove Cargo.lock from .gitignore and commit lock files for both workspaces to pin dependency versions and prevent CI breakage from upstream releases.
There was a problem hiding this comment.
Pull request overview
This PR extends the sea-orm-migration-spanner migration tooling to support DML execution (INSERT/UPDATE/DELETE) from within migrations by having SchemaManager own and expose a DatabaseConnection, and updates the migrator to reuse that connection.
Changes:
- Add
SchemaManager::get_connection()andSchemaManager::execute_unprepared(), withSchemaManager::new()becoming async and returningResult. - Update
MigratorTraitto reuseSchemaManager’s connection rather than creating separateSpannerDatabase::connect()connections. - Add/adjust integration tests and CI/Make targets to build/test the separate migration workspace; export
DatabaseConnectionandExecResultfrom the prelude.
Reviewed changes
Copilot reviewed 12 out of 17 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/database.rs |
Use ..Default::default() in AdminClientConfig initializations (compat with new struct fields). |
sea-orm-migration-spanner/src/schema_manager.rs |
Store DatabaseConnection in SchemaManager; add DML helpers. |
sea-orm-migration-spanner/src/migrator.rs |
Reuse SchemaManager connection for migration bookkeeping queries/inserts. |
sea-orm-migration-spanner/src/prelude.rs |
Re-export DatabaseConnection/ExecResult for migration authors. |
sea-orm-migration-spanner/tests/migration_test.rs |
Add DML migration test; refactor imports in test setup. |
sea-orm-migration-spanner/src/lib.rs |
Reformat exports (no functional change). |
sea-orm-migration-spanner/src/cli.rs |
Reformat imports (no functional change). |
sea-orm-migration-spanner/Cargo.toml |
Bump crate MSRV to Rust 1.80. |
.cargo/config.toml |
Default SPANNER_EMULATOR_HOST for cargo-invoked commands. |
sea-orm-migration-spanner/.cargo/config.toml |
Also defaults SPANNER_EMULATOR_HOST within sub-workspace. |
.github/workflows/ci.yml |
Build/test both workspaces; add cache step for lint job. |
Makefile |
Run fmt/clippy/check/test for both root and migration workspaces. |
.gitignore |
Stop ignoring Cargo.lock. |
examples/basic-crud/Cargo.lock |
Add lockfile for the basic-crud example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Hardcoding the emulator host in .cargo/config.toml routes all cargo commands to the emulator, even when a developer expects real Spanner. Set the env var only in Makefile test target and CI instead.
fresh() already calls up() internally, so the subsequent up() was a no-op. Assert fresh() succeeds and verify inserts directly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
get_connection()andexecute_unprepared()methods toSchemaManager, enabling DML (INSERT, UPDATE, DELETE) execution within migrationsSchemaManagernow holds aDatabaseConnectioninternally;new()is now async and returnsResult<Self, DbErr>MigratorTraitreusesSchemaManager's connection instead of creating separateSpannerDatabase::connect()calls, eliminating duplicate connectionsDatabaseConnectionandExecResultfrom preludeTest plan
test_migration_up_and_down,test_migration_fresh)test_migration_dml_execute_unpreparedtest verifies:execute_unprepared()inserts data within a migrationget_connection()inserts data within a migrationcargo checkpasses for root workspace, migration crate, and example migrationcargo +nightly fmtclean