Skip to content

feat(portability): native pgpm deployment, control-file extensions, native roles - #29

Merged
pyramation merged 5 commits into
mainfrom
feat/portability-native-pgpm
Jul 30, 2026
Merged

pyramation merged 5 commits into
mainfrom
feat/portability-native-pgpm

Conversation

@pyramation

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #28 answering three "is this actually native?" questions about the portability suite. The old tests hand-rolled deployment and setup; this makes all of it native to how we deploy pgpm modules and test with pgsql-test.

1. runBundle → native pgpm deploy. runBundle was a hand-rolled stand-in for a real deploy:

// before — replays deploy SQL, never touches the migration ledger
for (const change of bundle.changes) await client.any(change.deploy.sql);

It's gone. The apply proxy deploys as an ordinary workspace module through a seed adapter:

getConnections({}, [
  seed.fn(async ({ config }) => {
    const workspace = new PgpmPackage(workspaceRoot);
    await workspace.deploy(getEnvOptions({ pg: config, deployment: { fast: true, usePlan: true } }),
                           'vendor-app-ported');   // resolves deps from the workspace
  }),
  seed.fn(/* seed rows + narrow grants */)
]);

pgpm resolves the proxy's declared dependencies and deploys them in order — the generic auth-provider module, then its uuid-ossp extension, then the transpiled app — i.e. provider-first, application-second, for real. deploy-vendor does the same for the reverse direction (vendored fixture via seed.pgpm, round-trip module via PgpmPackage).

2. Extensions via control files, not raw SQL. No more pg.any('CREATE EXTENSION ...') in tests. The fixture uses extensions.uuid_generate_v4(), so uuid-ossp is declared as a generic dependency in vendor-app.control (requires = 'plpgsql,uuid-ossp') and in the apply proxy's requires, and pgpm installs it during deploy.

3. Roles via pgsql-test, not an imperative bootstrap. The DO $$ … CREATE ROLE / GRANT … $$ block is gone. Roles come from getConnections (native standard roles: anonymous / authenticated / administrator, image-provided), and only narrow, application-level grants remain in a seed (GRANT USAGE ON SCHEMA app_auth TO authenticated, GRANT EXECUTE ON FUNCTION app_auth.current_user_id() TO authenticated). The deployable on-disk apply spec no longer renames roles; the role-translation capability is still demonstrated in transpile.test.ts via an inline spec, so the SQL-level proof stays without forcing a non-image role into the deploy path.

transpile.test.ts also updated for the new engine behavior: an excluded subsystem's changes are now dropped from the artifact, so the assertions check they're absent rather than emptied tombstones.

Dependency

The native deploy path exercises constructive #1533 (drop excluded subsystem changes instead of emitting empty tombstones) — without it, the excluded auth changes deploy as byte-identical empty scripts and collide on the migration ledger's (package, script_hash) uniqueness. Until #1533 is published, @pgpmjs/bundle + @pgpmjs/core are pinned via pnpm.overrides to tarballs in portability/.tarballs/. After publish: makage update-deps --from ./constructive --in . and drop the tarballs/overrides.

Tests

Plain-PostgreSQL suites pass locally (postgres-plus:18): deploy-ported (3), transpile (2), contract (2) — 9 tests, deploy-vendor skipped (no VENDOR_STACK). tsc + eslint clean. The vendor-image job validates deploy-vendor in CI.

Link to Devin session: https://app.devin.ai/sessions/025fb88043964fdbb335ac5e39df2478
Requested by: @pyramation

… native roles

Replace the hand-rolled runBundle deploy loop with native pgpm deployment,
declare generic extensions through pgpm/control files instead of raw CREATE
EXTENSION, and drive roles through pgsql-test's native role config instead of
an imperative CREATE ROLE / GRANT bootstrap.

- deploy-ported: deploys the apply proxy as an ordinary workspace module via
  PgpmPackage(workspace).deploy(..., 'vendor-app-ported') inside a seed.fn, so
  pgpm resolves and deploys the provider, its uuid-ossp extension, then the
  transpiled app — provider-first, application-second — with no CREATE
  EXTENSION and no runBundle. Roles come from getConnections; only narrow
  object-level grants remain.
- deploy-vendor: same native deployment for the reverse direction; the vendored
  fixture deploys via seed.pgpm and the round-trip module via PgpmPackage.
- vendor-app.control declares uuid-ossp (fixture uses extensions.uuid_generate_v4);
  the apply proxy requires uuid-ossp so it is installed on deploy.
- transpile.test: excluded subsystem changes are now dropped (not empty
  tombstones); role-translation demo moved to an inline spec so the deployable
  on-disk spec can use native standard roles.

Depends on constructive #1533 (drop excluded changes) — pinned via tarball
override until published.
@pyramation pyramation self-assigned this Jul 30, 2026
@devin-ai-integration

Copy link
Copy Markdown

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Plain postgres-plus:18 ships no application roles. Instead of a hand-rolled
CREATE ROLE loop, seed base roles with generateCreateBaseRolesSQL (the same
generator pgpm init uses) and grant them to the app connection role with
generateGrantRoleSQL so transaction-local SET ROLE works in tests.
materializeApplyModule writes a bare module (no pgpm.json); native deploy
resolves its target from a workspace module map, so a standalone outDir yields
MODULE_NOT_FOUND. Materialize the reverse module into a throwaway single-package
workspace and deploy it via the ordinary path.
…rrides

makage update-deps bumps @pgpmjs/* to the now-published versions (core 7.17.2,
bundle 0.12.4, slice 0.11.2, transform 0.12.2, types 2.48.1, env 2.39.2) that
carry the #1533 drop-excluded-changes fix. Removes the temporary file: pnpm
overrides and portability/.tarballs/.
…d-deps

chore(portability): consume published pgpm packages, drop tarball overrides
@pyramation
pyramation merged commit 96f9eac into main Jul 30, 2026
7 checks passed
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.

1 participant