Skip to content

Add target CREATEDB preflight check for snapshot DB creation#996

Open
lghuy05 wants to merge 10 commits into
xataio:mainfrom
lghuy05:feat/target-createdb-privileges
Open

Add target CREATEDB preflight check for snapshot DB creation#996
lghuy05 wants to merge 10 commits into
xataio:mainfrom
lghuy05:feat/target-createdb-privileges

Conversation

@lghuy05

@lghuy05 lghuy05 commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Description

Adds a new access preflight check for pgstream check to verify that the target Postgres role has the CREATEDB privilege when snapshot schema restore is configured with created_target_db: true.

Related Issue(s)

Type of Change

Please select the relevant option(s):

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🔧 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🧪 Test coverage improvement
  • 🔨 Build/CI changes
  • 🧹 Code cleanup

Changes Made

  • Added TargetCreateDBPrivilegeCheck to the access preflight checks
  • Wired the check to run only when snapshot dump/restore is configured with create_target_db: true
  • Added unit tests for the new check and builder coverage for the conditional access check registration

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • All existing tests pass

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Code is well-commented
  • Documentation updated where necessary

Additional Notes

This change only applies to the snapshot schema restore path for Postgres targets. The new check validates the current target session role by querying pg_roles for rolcreatedb, and returns an actionable finding when the privilege is missing.

@lghuy05 lghuy05 changed the title Feat/target createdb privileges Add target CREATEDB preflight check for snapshot DB creation Jul 11, 2026
@lghuy05

lghuy05 commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

I will resolve the conflict in a few days

@kvch

kvch commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

How do you handle if the database pgstream is supposed to create is missing? It seems to me that you are using the connection string that contains the database to be created.

@lghuy05

lghuy05 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Merged lastest main into this branch and resolved the conflicts
@kvch thanks for the catch,I traced the restore path and saw that RunPGRestore removes the database name from the target connection string when Create is true, so pg_restore can connect before creating the target database.
I will update the preflight check to use the same behavior

@lghuy05
lghuy05 force-pushed the feat/target-createdb-privileges branch from 4b2f9a3 to 5745369 Compare July 16, 2026 15:59
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