Skip to content

feat: add DML execution support to SchemaManager#25

Merged
devgony merged 10 commits into
mainfrom
feat/mig-dml
Mar 20, 2026
Merged

feat: add DML execution support to SchemaManager#25
devgony merged 10 commits into
mainfrom
feat/mig-dml

Conversation

@devgony

@devgony devgony commented Mar 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add get_connection() and execute_unprepared() methods to SchemaManager, enabling DML (INSERT, UPDATE, DELETE) execution within migrations
  • SchemaManager now holds a DatabaseConnection internally; new() is now async and returns Result<Self, DbErr>
  • MigratorTrait reuses SchemaManager's connection instead of creating separate SpannerDatabase::connect() calls, eliminating duplicate connections
  • Export DatabaseConnection and ExecResult from prelude

Test plan

  • All existing integration tests pass (test_migration_up_and_down, test_migration_fresh)
  • New test_migration_dml_execute_unprepared test verifies:
    • execute_unprepared() inserts data within a migration
    • get_connection() inserts data within a migration
    • SELECT query confirms both rows were persisted
  • cargo check passes for root workspace, migration crate, and example migration
  • cargo +nightly fmt clean

devgony added 8 commits March 20, 2026 21:51
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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() and SchemaManager::execute_unprepared(), with SchemaManager::new() becoming async and returning Result.
  • Update MigratorTrait to reuse SchemaManager’s connection rather than creating separate SpannerDatabase::connect() connections.
  • Add/adjust integration tests and CI/Make targets to build/test the separate migration workspace; export DatabaseConnection and ExecResult from 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.

Comment thread sea-orm-migration-spanner/tests/migration_test.rs Outdated
Comment thread .cargo/config.toml Outdated
Comment thread sea-orm-migration-spanner/.cargo/config.toml Outdated
Comment thread sea-orm-migration-spanner/Cargo.toml
devgony added 2 commits March 21, 2026 00:37
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.
@devgony devgony merged commit 4b569ae into main Mar 20, 2026
2 checks passed
@devgony devgony deleted the feat/mig-dml branch March 20, 2026 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants