engineeringNovember 26, 2026·7 min read

From PG Connector to SW Connector: Growing a Multi-Engine Security Boundary

How we evolved @schema-weaver/pg-connector from a single-database PostgreSQL daemon into SW Connector 2.0.5—supporting multiple databases, capability-aware MySQL exploration, hardened transport, and a staged MongoDB driver without relaxing our local credential boundary.

S

Schema Weaver Team

VivekMind

From PG Connector to SW Connector: Growing a Multi-Engine Security Boundary

We didn't simply rename a connector—we expanded a security boundary. Over the 2.0.x release line, what started as PG Connector (a PostgreSQL-focused on-premises tunnel) evolved into SW Connector (2.0.5): a multi-database, capability-aware execution engine supporting PostgreSQL and MySQL in production, with a staged MongoDB driver—all while keeping credentials, SQL classification, and cryptographic audit trails strictly on your side of the wire.

1. Where It Started: A Narrow Tunnel With Non-Negotiable Guarantees

Schema Weaver began with a deliberately focused daemon distributed as @schema-weaver/pg-connector:

npm i -g @schema-weaver/pg-connector

Its job was intentionally tight: run inside the customer's machine or VPC, hold PostgreSQL credentials locally, connect outward to the Schema Weaver cloud relay, and let the browser IDE's Data Explorer and SQL Editor query data without ever transmitting database passwords, hosts, or private keys to the cloud.

Even in that first narrow shape, three architectural primitives defined the product:

  • Local Credential Boundary (LCB): Database secrets remain strictly on-premises in encrypted configuration (AES-256-GCM under a scrypt-derived key), never uploaded to cloud storage.
  • Connector-Enforced Read-Only Execution (CERO): The connector parses and enforces read-only rules locally—regardless of what the browser or cloud claims.
  • Outbound-Only Networking: Outbound TLS (SSE control wake channel plus short-lived WSS data channels) eliminates inbound firewall ports, public database IPs, and VPN plumbing.

Turning PG Connector into SW Connector wasn't a rewrite from scratch. It was a disciplined expansion of that boundary from one PostgreSQL database per project to a platform-grade multi-database, multi-engine connector layer.

2. Why We Changed the Name—Without Breaking npm

Once the connector added multi-database routing and MySQL Data Explorer support, calling it "PG Connector" actively misled new teams. At the same time, breaking existing CI scripts and server installs just to switch an npm scope would have punished early adopters.

In 2.0.5, we separated the ergonomic product identity from package resolution:

  • What evolved: Product name is now SW Connector, the canonical CLI binary is sw-connector, the GitHub repository moved to Schema-Weaver/sw-connector, and all docs, help output, and Data Explorer UI copy reflect the multi-engine identity.
  • What deliberately stayed compatible: The npm package name remains @schema-weaver/pg-connector, and legacy CLI aliases (sw-connector, db-connector, pg-connector, sw-agent, schemaweaver) continue resolving identically.

Existing installs upgrade cleanly to 2.0.5 with zero broken scripts, while new teams start directly with sw-connector.

3. The 2.0.0 → 2.0.5 Engineering Arc

Version Release Date What Shipped Why It Mattered
2.0.0 2026-10-08 Formalized LCB & CERO, outbound SSE + WSS relay, RBAC, HMAC audit chain, transient streaming, CLI suite, typed SDK Established the core zero-trust security architecture
2.0.1 2026-10-09 Higher rate/concurrency burst limits, read-only catalog function support, wake recovery, auth header alignment Made interactive browser IDE exploration fast and resilient
2.0.2 2026-11-05 Headless Linux/EC2 clipboard resilience when xclip/pbcopy/wl-copy are missing Unblocked first-time setup on SSH servers and containers
2.0.3 2026-11-10 Database-centric routing by db_alias, removed 1-DB-per-project limit, resilient default fallback Unlocked multiple databases on a single connector daemon
2.0.4 2026-11-10 All registered databases reachable by default; allowed_databases made an optional narrowing scope Eliminated false fail-closed blocks while preserving explicit scoping
2.0.5 2026-11-21 MySQL Data Explorer support, sw-connector canonical binary, full-screen TUI wizard, engine-aware wake metadata, loopback-only plaintext rule Completed the transition from PG Connector to multi-engine SW Connector

4. The Architectural Shift: Resolve the Engine From Config, Never From SQL

Early versions assumed every inbound query targeted PostgreSQL. As soon as a customer registered a MySQL or MongoDB instance alongside PostgreSQL, that assumption failed in three places: wrong SQL grammar classification, rigid SQL templates in cloud routes, and no way for the frontend to know which capabilities a connection supported.

We eliminated SQL-guessing entirely. Now, the engine type (db_type) is declared in the customer's local database configuration and propagated as connection metadata—never inferred from query strings or browser requests.

Customer-Side Driver Registry

Inside sw-agent/src/drivers/, every engine implements the unified DatabaseDriver interface (classify, testConnection, runOneShot, runStreaming, capabilities) and is selected deterministically via DriverRegistry.forEntry(entry):

// sw-agent/src/drivers/registry.ts
// The type comes from the entry, never from the SQL or from a request.
// A caller that reaches a MySQL database cannot have its statement
// classified by the PostgreSQL grammar, or vice versa.
export class DriverRegistry {
  get(type: DbType): DatabaseDriver {
    const driver = this.drivers.get(type);
    if (!driver) {
      throw new Error(`No database driver is registered for '${type}'.`);
    }
    return driver;
  }

  forEntry(entry: DbEntry): DatabaseDriver {
    return this.get(dbTypeOf(entry));
  }
}

Every driver enforces two non-optional security gates: classification fails closed (any unparseable statement or disallowed method is rejected locally), and the database session enforces read-only posture independently (AST-verified libpg_query plus read-only transactions on PostgreSQL; stored function denial plus SET SESSION TRANSACTION READ ONLY posture on MySQL).

Cloud-Side Capability Gating & Discovery

On the cloud side (backend/routes/data-explorer/data.routes.js), routes no longer embed raw SQL dialects. Every handler selects an engine adapter and asserts required capabilities before touching the WebSocket relay:

// backend/routes/data-explorer/data.routes.js
function engineFor(conn, ...capabilities) {
  const adapter = getEngineAdapter(conn.dbType);
  for (const capability of capabilities) assertCapability(adapter, capability);
  return adapter;
}

A dedicated discovery endpoint—GET /api/data/:connectionId/info—tells the frontend each connection's dbType, database, datasetShape (relational vs. document), and exact supported capabilities up front. Unsupported actions are disabled in the UI cleanly instead of failing mid-query. (Legacy connectors that don't report db_type automatically normalize to PostgreSQL for full backward compatibility.)

End-to-End Request Flow

flowchart LR
  UI["sw-data-explorer UI"] -->|"1. GET /api/data/:id/info"| Cloud["Cloud Relay & Engine Adapters"]
  Cloud -->|"2. Select Adapter + assertCapability"| Route["Build SQL or Mongo Command"]
  Route -->|"3. Signed WSS Frame (db_alias)"| Agent["SW Connector Daemon (Customer VPC)"]
  Agent -->|"4. DriverRegistry.forEntry(db_type)"| Guard["CERO Classifier + Read-Only Session"]
  Guard -->|"5. Stream Results In-Memory"| DB[("PostgreSQL / MySQL / MongoDB")]
  Agent -->|"6. HMAC Chained Log"| Audit["audit.jsonl + head/floor anchors"]

5. Multi-Database & Multi-Engine Scale

Scaling required two separate layers of architecture:

  1. Multi-Database Routing (2.0.3–2.0.4): We decoupled routing from the legacy one-database-per-project limit so a single sw-connector process serves multiple registered aliases (db_alias) across a realistic fleet of microservices, with allowed_databases acting as an explicit optional narrowing filter.
  2. Multi-Engine Capabilities (2.0.5): Rather than forcing every database into identical lowest-common-denominator features, backend/services/sw-data-explorer/engines/contract.js defines an explicit 12-capability vocabulary (schemaListing, tableListing, schemaColumns, tableMeta, indexListing, rowQuery, rowCount, distinct, stats, export, sqlExport, etc.).
  • PostgreSQL: Full grid capabilities, stats histograms, SQL export, server-side query cancellation, and schema migrations.
  • MySQL: Full relational grid exploration—schemas, tables, columns, metadata, indexes, filters, cursor paging, counts, distinct values, and CSV/XLSX export—while cleanly gating off PostgreSQL-specific stats and sqlExport affordances.
  • MongoDB (Staged Driver): Implemented inside sw-agent/src/drivers/mongodb.ts with strict JSON command parsing (find, aggregate, count, distinct, listCollections—blocking $out, $merge, $where, and arbitrary shell passthrough). Its document UI stays intentionally staged for a future Document Explorer milestone so 2.0.5 ships as a rock-solid relational release.

6. Hardening Transport, Identity, and Tamper-Evident Audits

Expanding surface area only works if security tightens alongside it. Across 2.0.5, we kept LCB and CERO intact and added stricter defaults:

  • Loopback-Only Plaintext Rule: Remote relays strictly require wss:// or https:// (wss://api.schemaweaver.dev in production). Plaintext ws:// and http:// are rejected unless pointing explicitly to loopback hosts (localhost, 127.0.0.1, ::1).
  • Zero Raw Token Transmission: The connector never sends raw long-lived agent tokens over the wire—it sends an HMAC proof for relay authentication, and every data-channel envelope carries HMAC, nonce, and timestamp checks, with negotiated default ceiling capped at developer rather than admin.
  • Tamper-Evident Audit Chain: Every query, stream, introspection, migration, and cancellation is logged locally to ~/.sw-agent/audit/audit.jsonl using monotonic sequence numbers, HMAC-SHA256 hash chaining, an anchored head.json, and an out-of-band monotonic floor anchor (.floor.json) to expose log rollback tampering—verifiable anytime with sw-connector audit verify.
  • Honest Failure Modes: If the audit chain cannot initialize or fails verification, manual and full permission modes refuse to start outright. Even read_only refuses to pretend everything is fine, printing an explicit degraded-audit warning if started without logging.

7. Built for SSH Sessions and Servers, Not Just Laptops

Connectors don't live exclusively on developer MacBooks—they live inside EC2 instances, Docker containers, and bastions with no display server.

In 2.0.5, interactive terminals get a dependency-free, 12-step full-screen ANSI setup wizard (sw-agent/src/cli/tui/add-wizard.ts) covering engine selection, optional passwordless URL parsing, host/port resets when switching engines, TLS modes, permission scope, alias selection, and live connection testing. Meanwhile, piped workflows, CI runners, and SW_AGENT_NO_TUI=1 keep the compact prompt path, and clipboard copy gracefully handles headless Linux without crashing on missing xclip binaries.

8. Before vs. After

Area Before (PG Connector) After (SW Connector 2.0.5)
Identity & CLI PG Connector / pg-connector SW Connector / canonical sw-connector (@schema-weaver/pg-connector compatible)
Repository Schema-Weaver/pg-connector Schema-Weaver/sw-connector
Engine Resolution PostgreSQL assumed by default db_type resolved from local config via DriverRegistry
Database Scaling 1 database per project constraint Unlimited registered db_alias targets on one connector
Cloud Routes Engine SQL assumptions in route handlers Capability-gated engine adapters (/api/data/:id/info)
Engine Matrix PostgreSQL only PostgreSQL + MySQL in Data Explorer; MongoDB staged
Transport Safety Broad relay URL acceptance Loopback-only plaintext; mandatory wss:///https:// remotely
Setup UX Basic line prompts 12-step ANSI TUI wizard + headless fallback

What's Next

With SW Connector 2.0.5 cleanly separating connection transport, capability discovery, and local security boundaries, adding new engines no longer touches core relay security. Next on the roadmap: unlocking the staged MongoDB Document Explorer UI, expanding Resona AI analytics over multi-engine connections, and bringing the same zero-storage, audit-logged connector philosophy to live payment gateways.

Already running @schema-weaver/pg-connector? Upgrade to 2.0.5, run sw-connector status or sw-connector audit verify, and explore your PostgreSQL and MySQL databases side by side in Schema Weaver.

sw-connectorarchitecturesecuritypostgresqlmysqlmulti-engine

Comments (0)

Share this article

All articles

Subscribe to updates

Get notified when we publish new articles.