Skip to content

Feat/createrole preflight check - #1055

Open
lghuy05 wants to merge 17 commits into
xataio:mainfrom
lghuy05:feat/createrole-preflight-check
Open

Feat/createrole preflight check#1055
lghuy05 wants to merge 17 commits into
xataio:mainfrom
lghuy05:feat/createrole-preflight-check

Conversation

@lghuy05

@lghuy05 lghuy05 commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Description

Adds an access preflight check that verifies the target PostgreSQL connection role can create roles when schema snapshots are configured to restore roles.

The check runs when roles_snapshot_mode is enabled or no_passwords and accepts either the CREATEROLE attribute or superuser capability.

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 TargetCreateRolePrivilegeCheck to query the target connection role's CREATEROLE or superuser capability.
  • Registered the check only when roles_snapshot_mode is enabled or no_passwords.
  • Added an actionable remediation message and unit tests for check behavior, errors, configuration applicability, and builder 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

The target connection URL is adjusted using the existing postgres.RemoveDatabaseFromConnectionString helper. PostgreSQL roles are cluster-wide, so the check can run even when the configured target database does not exist yet.

The CREATEDB and CREATEROLE builder paths remain separate to avoid expanding this PR into a refactor while #996 is still open. They can share a target connection in a later cleanup.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown

Coverage

Total: 58.7% (+0.2% vs main)

Coverage in packages changed by this PR:

Package Coverage Δ
internal/postgres 47.0% +1.5%
pkg/stream 43.4% ±0.0%
pkg/stream/preflight 80.8% +1.6%

@kvch

kvch commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

@lghuy05 I have merged your previous PR. Could you please rebase your changes?

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.

Add pgstream check command for pre-migration sanity checks

2 participants