Repository navigation
feat: database workbench — objects, jobs and governed changes (#38) - #39
Merged
Merged
Conversation
List programmable objects per schema on Postgres and SQL Server, read a definition live (overloads keyed by argument types, hidden bodies explained), compare one object across two connections, and expose the same over MCP as list_objects and get_object_definition. Definition reads are audited as OBJECT_VIEW. Refs #38
Show what an object uses and what uses it before it is changed (SQL Server keeps unresolved and cross-database references; Postgres function bodies are matched by name and flagged best-effort), and list every object whose normalized definition differs between two connections. Both are available over MCP as get_object_dependencies and compare_objects. Refs #38
List the jobs that run against a connection's database with enabled state, plain-language schedule, last outcome and next run, and open one to see its step commands, schedules (with how many other jobs share each) and recent runs. msdb's integer dates, durations and schedule codes are decoded in one pure, tested module. A login without the grant gets a message naming it; a database without pg_cron shows no jobs node. Also over MCP as list_jobs and get_job. Object and job tabs now stay on the connection they were opened from when another connection is picked in the explorer. Refs #38
A job is listed for a database when any step targets it, so its detail showed the commands and run messages of steps aimed at other databases on the same server. Those are now blanked in SQL and replaced with a note; steps with no database (CmdExec, PowerShell) are the job's own and stay visible. Refs #38
Edit a procedure, function, view or trigger and submit it as an object_change write request. The new definition must be one idempotent CREATE OR ALTER / CREATE OR REPLACE of the same object; it runs as a transactional migration through the existing executor. The definition deployed at submit is stored as a snapshot: reviewers see a diff against it, the AI review gets it plus the object's dependents, and submit, approve and override answer 409 OBJECT_CHANGED if it has changed since. Revising re-bases. An executed change offers Restore previous version (a new governed request) and Copy as migration, and definitions that look like they contain credentials are flagged. MCP drafts can target an object too. Refs #38
List and read MongoDB views, indexes and validation rules, and Elasticsearch index templates, ingest pipelines, aliases and ILM policies (Elastic-managed ones skipped, ILM optional), as JSON in the same object browser. Compare with another connection and the drift report work for them too; editing and dependencies stay SQL-only. Each engine's routes accept only its own kinds. Monaco now loads its JSON worker for these definitions. Refs #38
Propose one change to a SQL Server Agent or pg_cron job (enable or disable, rename, description, edit/add/delete a step, change a schedule) as a job_change write request. The server generates the SQL from the structured action, with ids validated and values quoted, and runs it as a transactional migration. A new or edited step command must pass as a direct write would: EXEC/CALL or scoped DML only, no DDL or dynamic SQL; non-SQL steps and steps on other databases are refused, and every refusal is audited as JOB_CHANGE_REFUSED. The job is snapshotted at submit and approval returns 409 if it changed since. Raising or submitting one needs the new per-environment jobEnvironments capability, editable in Settings. The README documents the minimum database grants for objects and jobs. Refs #38
A job change could reach work this connection's reviewers can't see. Changing a schedule shared with other jobs moved their run times too, and those jobs may belong to other databases. Disabling, renaming, rescheduling or adding/deleting a step on a job that also runs steps against another database changed that database's work too. Both are now refused (and audited like any refused job change). On such a job only this database's own step commands can change, and the UI no longer offers the refused actions. Refs #38
npm run dev:db starts three Postgres servers in Docker (5433-5435, with pg_cron), reseeds each from scripts/seed-local.sql and registers them as connections. The environments differ on purpose: row counts, an unreleased function version and an audit trigger PROD lacks (drift), and pg_cron jobs, one paused in PROD. Replaces the single dev database and dev-seed.sql.
Server: - A target that can't be read on approve, submit or create is answered (503/409/500), never thrown out of an async handler, which on Node 22 took the whole server down. - A job step calls exactly one routine with literal arguments, and the catalog must show it is the database's own: not built in, not an extension's (dblink, pg_cron, query_to_xml-style string runners), not a system schema or another database. Trailing T-SQL statements, E-strings and nested calls no longer get through. - An object change keeps its Postgres overload (the database resolves both argument lists' types), its trigger table and quoted-name case; a Postgres trigger's schema is its table's. - Object and job changes need read as well as write (job changes also the job capability), on create and submit; the deployed snapshot is hidden from anyone who can't read the environment. - Drift guard treats a now-unreadable object as changed; job changes get the migration AI review; a non-boolean enabled is refused. - Catalog: partition-cloned triggers left out; overloads matched across environments by argument types; view deps filtered to relations; a missing msdb/cron grant on job detail is named. Features: - "Run by": jobs whose steps name an object, and "Changing this … affects N objects and M jobs" before an edit; "Compare with… Pasted text". - Object and job edits and "Restore previous version" always save a draft; the request page runs it or submits it for approval. Client: views keyed per tab, late responses dropped, keyboard access to tree rows, dependency links and drift rows, audit labels, job retry.
- A quoted name holding a quote, semicolon or comment marker is refused: "EXEC dbo.[p'];SHUTDOWN--']" read as one call to the checker and as two statements to SQL Server. The tokenizer now reads quoted identifiers before strings, and routine names must be plain. - Casts in call arguments are plain type names only, so "f(1::bool or pg_terminate_backend(1))" no longer passes. - Functions inside a step's INSERT/UPDATE/DELETE, beyond a short safe list, go through the same catalog check as called routines (query_to_xml, OPENROWSET, dblink…). - The AI review of an object or job change reads the deployed code: it is refused to, and hidden from, anyone who can't read the environment.
- The job-step lexer is per dialect: E'…' and $tag$ quotes only on
Postgres, [names] only on SQL Server. Read with the other dialect's
rules, "E'\''" hid a string boundary from the checker.
- A Postgres job step can't use E'…' strings: the statement splitter reads
their backslashes differently than Postgres does.
- A name followed by "(" in FROM, JOIN or UPDATE position is a call and
goes through the catalog check (FROM query_to_xml(…), JOIN dblink(…),
UPDATE OPENQUERY(…)); only INTO t (cols) and AS x (cols) are skipped.
- The string placeholder can no longer pass for a column name.
The job-step checker read SQL with hand-written patterns, and reviews kept finding forms it read differently than the database: quotes inside names, E'…' strings, functions hidden in an UPDATE's FROM. It is replaced by the engines' own reading. - Postgres: the step is parsed by Postgres's parser (libpg-query, the real parser compiled to WebAssembly). Allowed statements are CALL, SELECT, INSERT, UPDATE/DELETE with a WHERE at any depth, VACUUM/ANALYZE and REFRESH MATERIALIZED VIEW; every function called anywhere in the tree is a value built-in on a short list or must be the database's own routine. - SQL Server: the step is compiled under SET SHOWPLAN_XML ON, which runs nothing (and which the step can't switch off). The plan lists every statement SQL Server would run, so SHUTDOWN, KILL, EXECUTE STRING, IF… are refused by type; EXEC must resolve to a procedure of this database; any Remote operator (OPENROWSET, OPENQUERY, linked server, BULK) is refused. Needs SHOWPLAN permission, named when missing. - Every routine is then checked in the catalog (isUserRoutine) with the exact name the engine resolved. The analysis is pure and tested on real parser output and SHOWPLAN XML captured from SQL Server 2022; checked end to end against SQL Server 2022 and Postgres 16 with pg_cron.
…ir database - The SHOWPLAN check holds one connection through a transaction: if it drops, the next request fails rather than running the step on a fresh session where SHOWPLAN is off. A result that isn't a plan is an error. - A step whose plan touches another database's objects (three-part names, or a function SQL Server inlined) is refused; functions a write calls are sent to the catalog check; function and procedure bodies in the plan are the routine's code, not the step's. - The catalog check compares name, schema and database (PARSENAME vs DB_NAME()) instead of OBJECT_ID, which resolves a three-part name in another database.
- Editing a step now sets its @database_name to the connection's database, as adding one already did: a step with none would run in the login's default database, not the one its command was compiled in. - Plan database names are compared exactly (brackets off, ]] unescaped): on a case-sensitive server App_Core and app_core are two databases, so a name differing only in case is refused. - The catalog check resolves a three-part name's database by identity, DB_ID(PARSENAME(@name, 3)) = DB_ID(), not by collation-folded name.
|
🎉 This PR is included in version 2.7.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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.
Closes #38.
What it adds
list_objects,get_object_definition,get_object_dependencies,compare_objects,list_jobs,get_job. Agents can still only create drafts.npm run dev:dbstarts DEV/QA/PROD Postgres in Docker, seeded so they differ (data, drift, jobs) and registered as connections.Review
Three independent reviews were run on this branch. Their findings are fixed, each with a test that fails on the old code. Among them:
Testing
npm run verify(1092 tests) andnpm run buildpass.Not included
🤖 Generated with Claude Code