Add print only flags to dbos migrate#459
Merged
Merged
Conversation
Prints the full system database migration SQL (schema creation, all migrations, version bookkeeping, and optional role grants) to stdout without connecting to the database, so users can run 'dbos migrate --print-only > migration.sql' and apply it with psql.
…, funny-schema tests
Match the final design of dbos-transact-py#780: - dbos migrate --print-migrations [all|N] prints migrations N..latest to stdout without ever connecting to a database; no DO $$ guard blocks, migration 10 always skipped with a comment, per-migration version bookkeeping mirroring the runner. - dbos migrate --print-user-role --app-role R prints the GRANT statements; mutually exclusive with --print-migrations. - GRANT_QUERIES now double-quote schema and role identifiers on both the print and execute paths.
devhawk
approved these changes
Jul 24, 2026
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.
Java port of dbos-inc/dbos-transact-py#780:
dbos migrategets two mutually exclusive flags that print SQL to stdout instead of executing it. Stdout stays pure SQL and--comments (pipeable to a.sqlfile); neither flag ever connects to a database.--print-migrations [all|N]Prints the SQL of all DBOS system database migrations, or of migrations N (1-based) through latest, with per-migration
dbos_migrationsversion bookkeeping mirroring the runner (so an interrupted apply can be resumed from the next migration number):all(or1) emits the fresh-database prelude (CREATE SCHEMA/CREATE TABLE ... dbos_migrations) and is for fresh databases only.DO $$guard blocks appear anywhere in the output.CREATE/DROP INDEX CONCURRENTLY, so it must run outside a transaction block (plainpsql, notpsql --single-transaction).--print-migrations nope, out-of-range numbers) print an error to stderr and exit 1.--print-user-rolePrints the SQL granting the application role access to the DBOS system tables. Requires
--app-role:The two flags cannot be combined. Schema or role names containing quotes are rejected.
Deviations from the Python PR
GRANT_QUERIEStemplates are used by the execute path — sodbos migrate -r rolewith unusual schema/role names is also fixed.MigrationManager.generateMigrationScript(schema, useListenNotify, startMigration)validatesstartMigration(1..latest) withIllegalArgumentException; the CLI maps invalid--print-migrationsvalues to the Python stderr messages.-- DBOS system database migrations for {url}header masks anypassword=query parameter in the JDBC URL; when no URL is configured (Java's-D/DBOS_SYSTEM_JDBC_URLis optional, unlike Python's required URL), the header reads... for the system database.