Compare commits
46
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c450c451e5
|
||
|
|
c42209a009
|
||
|
|
40fb92d7d3
|
||
|
|
92066b8e34
|
||
|
|
15fb48a56c
|
||
|
|
0f929ed561 | ||
|
|
00bc6f646c
|
||
|
|
1784a5bf5d
|
||
|
|
602f7f866f
|
||
|
|
c63d6c8ec0
|
||
|
|
308890c974
|
||
|
|
f430b0a28e
|
||
|
|
eb0b9ca4b0
|
||
|
|
a182076722 | ||
|
|
7f0e9b38dc | ||
|
|
d3327cd4f3 | ||
|
|
af7510efc0 | ||
|
|
2e535d5037 | ||
|
|
f47c40ffbf | ||
|
|
15844af91e | ||
|
|
2b7edc25a5 | ||
|
|
f98d8124f4
|
||
|
|
677f800015 | ||
|
|
56b17b5768
|
||
|
|
ad4a492c31 | ||
|
|
912840a22d
|
||
|
|
db4715c906
|
||
|
|
3fcff49d4f | ||
|
|
ae54611acf
|
||
|
|
7304aaf5dd | ||
|
|
e783261d2d
|
||
|
|
ee2fd12aa1 | ||
|
|
60d8776564 | ||
|
|
b281741d2e | ||
|
|
47a3e62a45
|
||
|
|
7e9017c376
|
||
|
|
6da4fb400d
|
||
|
|
7c2d0610a5
|
||
|
|
268499aa74 | ||
|
|
d864eb996d | ||
|
|
c59b2ae72f | ||
|
|
103ef543d1
|
||
|
|
84a7033ae4
|
||
|
|
316a5d6f71 | ||
|
|
236fa901cf
|
||
|
|
5600496cce |
No files matched your search
+11
-68
@@ -1,71 +1,14 @@
|
||||
version: 2.1
|
||||
|
||||
setup: true
|
||||
orbs:
|
||||
qqq-orb: kingsrook/qqq-orb@0.6.8
|
||||
|
||||
commands:
|
||||
configure-package-install:
|
||||
steps:
|
||||
- run:
|
||||
name: Keep package installation unattended
|
||||
command: |
|
||||
# These build machines are discarded after the job.
|
||||
sudo install -d /etc/needrestart/conf.d
|
||||
printf '%s\n' '$nrconf{restart} = "l";' | sudo tee /etc/needrestart/conf.d/99-qqq-ci.conf >/dev/null
|
||||
|
||||
qqq-orb: kingsrook/qqq-orb@0.8
|
||||
workflows:
|
||||
test_only:
|
||||
jobs:
|
||||
- qqq-orb/mvn_test_only:
|
||||
pre-steps:
|
||||
- configure-package-install
|
||||
context: [qqq-maven-registry-credentials]
|
||||
filters:
|
||||
branches:
|
||||
ignore: /(develop|release\/.*|hotfix\/.*)/
|
||||
|
||||
publish_snapshot:
|
||||
jobs:
|
||||
- qqq-orb/mvn_publish:
|
||||
pre-steps:
|
||||
- configure-package-install
|
||||
context: [qqq-maven-registry-credentials]
|
||||
branch_type: snapshot
|
||||
filters:
|
||||
branches:
|
||||
only: [develop]
|
||||
|
||||
publish_release_candidate:
|
||||
jobs:
|
||||
- qqq-orb/mvn_publish:
|
||||
pre-steps:
|
||||
- configure-package-install
|
||||
context: [qqq-maven-registry-credentials]
|
||||
branch_type: release_candidate
|
||||
filters:
|
||||
branches:
|
||||
only: [/release\/.*/]
|
||||
|
||||
publish_release:
|
||||
jobs:
|
||||
- qqq-orb/mvn_publish:
|
||||
pre-steps:
|
||||
- configure-package-install
|
||||
context: [qqq-maven-registry-credentials]
|
||||
branch_type: release
|
||||
filters:
|
||||
branches:
|
||||
ignore: /.*/
|
||||
tags:
|
||||
only: [/^v\d+\.\d+\.\d+$/]
|
||||
|
||||
publish_hotfix_release:
|
||||
jobs:
|
||||
- qqq-orb/mvn_publish:
|
||||
pre-steps:
|
||||
- configure-package-install
|
||||
context: [qqq-maven-registry-credentials]
|
||||
branch_type: hotfix
|
||||
filters:
|
||||
branches:
|
||||
only: [/hotfix\/.*/]
|
||||
setup:
|
||||
jobs:
|
||||
- qqq-orb/generate_pipeline:
|
||||
orb_version: '0.8'
|
||||
filters:
|
||||
branches:
|
||||
ignore: automation/qbit-rc-pending
|
||||
tags:
|
||||
only: /^v\d+\.\d+\.\d+$/
|
||||
@@ -0,0 +1,7 @@
|
||||
name: build
|
||||
on:
|
||||
push:
|
||||
jobs:
|
||||
maven:
|
||||
uses: self:KofTwentyTwo/ci-workflows/.gitea/workflows/maven.yaml@v1
|
||||
secrets: inherit
|
||||
@@ -0,0 +1,23 @@
|
||||
name: CodeQL
|
||||
'on':
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- develop
|
||||
- release/**
|
||||
- hotfix/**
|
||||
pull_request: {}
|
||||
schedule:
|
||||
- cron: 41 16 * * 0
|
||||
workflow_dispatch: {}
|
||||
permissions:
|
||||
contents: read
|
||||
actions: read
|
||||
security-events: write
|
||||
packages: read
|
||||
concurrency:
|
||||
group: codeql-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||
jobs:
|
||||
analyze:
|
||||
uses: QRun-IO/qqq-orb/.github/workflows/qbit-codeql.yml@c288a8864fe9054f68410e1d78f5863aea4c4d22
|
||||
@@ -0,0 +1,74 @@
|
||||
name: Release candidate
|
||||
'on':
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
dry_run:
|
||||
description: Plan a cut without changing release state
|
||||
type: boolean
|
||||
default: false
|
||||
finalize:
|
||||
description: Retry finalization of an existing cut; do not cut another RC
|
||||
type: boolean
|
||||
default: false
|
||||
recover:
|
||||
description: Recover the same published RC after a deployment timeout; never
|
||||
reupload
|
||||
type: boolean
|
||||
default: false
|
||||
circle_build:
|
||||
description: Original Circle publisher build number (recovery only)
|
||||
type: string
|
||||
default: ''
|
||||
merge_sha:
|
||||
description: Existing cut merge_sha (finalize retry only)
|
||||
type: string
|
||||
default: ''
|
||||
bump_sha:
|
||||
description: Existing cut bump_sha (finalize retry only)
|
||||
type: string
|
||||
default: ''
|
||||
branch:
|
||||
description: Existing cut branch (finalize retry only)
|
||||
type: string
|
||||
default: ''
|
||||
version:
|
||||
description: Existing cut version (finalize retry only)
|
||||
type: string
|
||||
default: ''
|
||||
pull_request:
|
||||
types:
|
||||
- closed
|
||||
branches:
|
||||
- develop
|
||||
repository_dispatch:
|
||||
types:
|
||||
- qbit-rc-published
|
||||
permissions:
|
||||
contents: write
|
||||
actions: read
|
||||
checks: read
|
||||
jobs:
|
||||
release-rc:
|
||||
if: github.event_name == 'workflow_dispatch' || github.event_name == 'repository_dispatch'
|
||||
|| (github.event_name == 'pull_request' && github.event.pull_request.merged
|
||||
== true && github.event.pull_request.base.ref == 'develop' && contains(github.event.pull_request.labels.*.name,
|
||||
'release:rc'))
|
||||
uses: QRun-IO/qqq-orb/.github/workflows/qbit-release-rc.yml@cc30f599e63c8e41629c99d23395bac1adb8bc44
|
||||
with:
|
||||
dry_run: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run || false
|
||||
}}
|
||||
finalize: ${{ github.event_name == 'repository_dispatch' || (github.event_name
|
||||
== 'workflow_dispatch' && inputs.finalize) }}
|
||||
recover: ${{ github.event_name == 'workflow_dispatch' && inputs.recover || false
|
||||
}}
|
||||
circle_build: ${{ github.event_name == 'workflow_dispatch' && inputs.circle_build
|
||||
|| '' }}
|
||||
merge_sha: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.merge_sha
|
||||
|| inputs.merge_sha || '' }}
|
||||
bump_sha: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.bump_sha
|
||||
|| inputs.bump_sha || '' }}
|
||||
branch: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.branch
|
||||
|| inputs.branch || '' }}
|
||||
version: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.version
|
||||
|| inputs.version || '' }}
|
||||
secrets: inherit
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
profile: qbit
|
||||
orb_version: '0.8'
|
||||
default_branch: develop
|
||||
java_version: '21'
|
||||
browsers: true
|
||||
api_checks: false
|
||||
docs_only: false
|
||||
release_on_main: false
|
||||
release_tag_policy: stable
|
||||
test_branch_policy: non-release
|
||||
publish:
|
||||
snapshot: true
|
||||
release_candidate: true
|
||||
release: true
|
||||
asciidoc: false
|
||||
release_completion: true
|
||||
@@ -24,7 +24,7 @@ How tests are split:
|
||||
|
||||
**Entry point:** `SqlWorkbenchQBitProducer implements QBitMetaDataProducer<SqlWorkbenchQBitConfig>`.
|
||||
- Component producers are found in the `metadata` package only (`getPackageNameForFindingMetaDataProducers`), because `api` needs the optional Javalin dependency.
|
||||
- `postProduceActions` builds `SqlWorkbenchRuntime` and calls `api.SqlWorkbenchRoutes.register` when Javalin is on the classpath.
|
||||
- `postProduceActions` builds `SqlWorkbenchRuntime` and calls `api.SqlWorkbenchEndpoints.register` when Javalin is on the classpath.
|
||||
|
||||
**Packages:**
|
||||
- `sql/`: `SqlScanner` (dialect-aware lexer), `SqlClassifier` (split, then classify as READ, EXPLAIN_ANALYZE, WRITE, DDL, or FORBIDDEN), `NamedParameterSql` (`:name` → `?`). Pure Java.
|
||||
@@ -38,7 +38,7 @@ How tests are split:
|
||||
- `explain/`: `PlanParser` (Postgres JSON, MySQL JSON/text, SQLite rows, text) and `PlanNode`.
|
||||
- `schema/`: `SchemaIntrospector` (JDBC `DatabaseMetaData` plus the QQQ table and field to SQL name mapping), cached in the runtime.
|
||||
- `notebook/`: `NotebookService` (CRUD, sharing, versions in one transaction, snapshots), run as the caller's session through the standard table actions; `NotebookVersioning` (one version per change, as the system user).
|
||||
- `api/`: `SqlWorkbenchApi` (transport-agnostic, permission checks), `SqlWorkbenchRouteProvider` (Javalin 7 routes under `/qqq/v1/sql-workbench`), `ResultExporter` (CSV/JSON/XLSX via fastexcel), and `SqlWorkbenchRoutes`.
|
||||
- `api/`: `SqlWorkbenchApi` (transport-agnostic, permission checks), `SqlWorkbenchJsonSpec` and concrete endpoint specs (the UI API extension under `/qqq/v1/sql-workbench`), `ResultExporter` (CSV/JSON/XLSX via fastexcel), and `SqlWorkbenchEndpoints`.
|
||||
- `metadata/`: the 6 tables (record locks, joins, child-list widgets), the security key types, the PVSs, the record actions, the `SQL_WORKBENCH` widget and its renderer, the home dashboard widgets, the Runner child app, and the `sqlWorkbench` app (nav: Runner, then the main tables only).
|
||||
- `home/`: the dashboard data (`SqlWorkbenchHome`, read through core actions in the viewer's session so locks apply), its renderer, and inline-styled HTML helpers.
|
||||
- `SqlWorkbenchIntegrations`: opt-in ESB and Quick Search hooks for the main tables.
|
||||
@@ -65,7 +65,7 @@ How tests are split:
|
||||
## Dependencies
|
||||
|
||||
- Java 21.
|
||||
- Parent `com.kingsrook:qbit-build-parent:2.0.0` (qqq 4.0.0). The default-active `qqq-snapshot` profile imports `qqq-bom-pom:4.1.0-RC.4` ahead of it (RC.4 brings the record developer panel contract), as in qbit-quick-search (ADR-0007). Remove that activation when the parent moves to 4.1.
|
||||
- Parent `com.kingsrook:qbit-build-parent:2.0.0` (qqq 4.0.0). The default-active `qqq-snapshot` profile imports `qqq-bom-pom:4.1.0-RC.6` ahead of it (RC.6 brings the UI API extension contract), as in qbit-quick-search (ADR-0007). Remove that activation when the parent moves to 4.1.
|
||||
- `qqq-backend-core`, `qqq-backend-module-rdbms`, and `qqq-middleware-javalin` (optional).
|
||||
- Tests: JUnit 5, AssertJ, Mockito, H2, `qqq-backend-module-sqlite`/`-postgres` (drivers), Testcontainers 1.21.4.
|
||||
|
||||
|
||||
@@ -5,6 +5,10 @@ All notable changes to this project are documented here. The format follows Keep
|
||||
## [1.0.0-RC.4] - Unreleased
|
||||
|
||||
### Added
|
||||
- Host-neutral in-app help bundle `help/qbit-sql-workbench.yaml`, registered with QQQ help bundles, with live references and coverage checks for workbench metadata and generated table actions. Replaces the earlier minimal bundle while retaining inline app/table help for hosts without help storage. Requires QQQ `4.1.0-RC.7`.
|
||||
- Table help: the SQL Workbench app and every `sql_workbench_*` table carry help saying what the table is for and how its rows get created (`help/qbit-sql-workbench.yaml`, QQQ help-bundle format, applied by `SqlWorkbenchHelp`; host help is never overridden). `SqlWorkbenchTablesGuardrailTest` fails when a table is unused by runtime code, unexplained, or has no such help. All six tables are user content or logs and start empty by design; nothing is seeded.
|
||||
- `auditRetentionDays` config (default null: keep forever, no change for existing hosts): when set, execution audit rows older than that many days are deleted, in the background in bounded batches, at most once an hour per process (first pass 5 minutes after start), triggered as a run is audited; rows still RUNNING are kept. DESIGN.md already described this setting; it did not exist before.
|
||||
- OpenAPI coverage for all 21 SQL Workbench UI API operations, including streaming CSV/JSON/XLSX export. The `sql-workbench` extension preserves `/qqq/v1/sql-workbench`, existing request/response shapes, permission and ownership checks, exact decimal parameters, execution limits and audit. The generated fragment is in `src/main/resources/openapi/qqq-v1/sql-workbench.yaml`; strict-server security tests and a fragment contract test guard it.
|
||||
- **App home dashboard.** The `sqlWorkbench` app's home is now an information dashboard of real data, read in the viewer's session (permissions and record locks apply): summary tiles and links, runs per day, recent notebooks, recent runs, slowest and failed queries, most-used notebooks, shared notebooks, committed writes, and (workbench admins only) activity by user. Each widget has an honest empty state.
|
||||
- **Runner.** The notebook editor (`SQL_WORKBENCH` widget) moves to its own nav entry: the `sqlWorkbenchRunner` child app, labeled Runner. Open a notebook with `/app/sqlWorkbenchRunner?notebook=<id>`.
|
||||
- On a notebook's record view: an Open in Runner widget, and a Runs child list (its executions the viewer may see) through the new join `sql_workbench_notebook_join_sql_workbench_execution`.
|
||||
@@ -12,6 +16,8 @@ All notable changes to this project are documented here. The format follows Keep
|
||||
- **Record developer panel** "SQL Workbench" (`SqlWorkbenchDeveloperPanelProvider`, registered by `SqlWorkbenchDeveloperPanelsMetaDataProducer`): read-only `SELECT`s for the record and its table in the backend's own names, backend details, and links that open them in the Runner as a new cell (`/app/sqlWorkbenchRunner?sql=&backend=`, never run). Requires QQQ 4.1.0-RC.4 (the developer panel contract) and a Next UI with the Runner `?sql=` support.
|
||||
|
||||
### Changed
|
||||
- UI API extension sql-workbench 1.1.0 (requires QQQ 4.1.0-RC.15, UI API 1.6.0): operationIds, standard error responses with BasicErrorResponseV1, extension tags, and deprecated SqlWorkbenchErrorV1 retained for compatibility. Existing operationIds, HTTP statuses and success payloads are preserved.
|
||||
- Require QQQ `4.1.0-RC.6` for the UI API extension contract. Replace the raw Javalin route provider with endpoint specs registered by the qbit producer. `registerRoutes=false` still disables HTTP registration. No existing operation wire changes.
|
||||
- **The nav lists only the main tables**: Notebooks and the execution audit, after the Runner. Cells, versions, pinned results and shares are child lists on a notebook (still standard tables, reachable by URL and API). The app's widget list is now the dashboard, not the `SQL_WORKBENCH` widget; links to `/app/sqlWorkbench` that expected the editor should point at `/app/sqlWorkbenchRunner`.
|
||||
- The notebook record's header shows the description.
|
||||
- **Names follow the owner rule: lowercase snake_case, prefixed with the qbit's name (metadata only, no DDL).** Tables `sql_workbench_notebook`, `sql_workbench_cell`, `sql_workbench_notebook_version`, `sql_workbench_result_snapshot`, `sql_workbench_notebook_share`, `sql_workbench_execution` (they now equal their backend table names); possible-value source `sql_workbench_share_audience_type`; permissions `sql_workbench.*`, `sql_workbench_admin.hasAccess` and `<table>.read` etc.; security key types `sql_workbench_user` (all-access `sql_workbench_all_access`) and `sql_workbench_audience`; joins `sql_workbench_notebook_join_sql_workbench_*`.
|
||||
|
||||
@@ -16,7 +16,7 @@ The full design (architecture, data model, security model, limits, API contract,
|
||||
|
||||
## Requirements
|
||||
|
||||
- Java 21 and QQQ 4.1 (built against `4.1.0-RC.4`, which is required: it lets partial edits of child rows pass joined record locks, [qqq#1073](https://github.com/QRun-IO/qqq/issues/1073)).
|
||||
- Java 21 and QQQ `4.1.0-RC.7` or later (UI API extensions and help bundles).
|
||||
- `qqq-backend-module-rdbms` for the targets. `qqq-middleware-javalin` for the REST routes; it is optional, and without it the engine still works but no routes are registered.
|
||||
- A Next UI release that renders the `SQL_WORKBENCH` widget.
|
||||
|
||||
@@ -51,10 +51,18 @@ The producer adds the following to the instance:
|
||||
- **The `sqlWorkbenchWidget` widget** (type `SQL_WORKBENCH`): the notebook editor.
|
||||
- **The home dashboard widgets** ([App home](#app-home)).
|
||||
- **The `sqlWorkbench` app.** Its home page is the dashboard. Its nav lists the **Runner** (`sqlWorkbenchRunner`, a child app whose page is the `SQL_WORKBENCH` widget), then the main tables: Notebooks (`sql_workbench_notebook`) and the execution audit (`sql_workbench_execution`). Cells, versions, pinned results and shares are not in the nav; they are child lists on a notebook.
|
||||
- **The `/qqq/v1/sql-workbench/*` routes**, registered through `QJavalinMetaData`, as `qqq-esb` does.
|
||||
- **All 21 `/qqq/v1/sql-workbench/*` operations**, registered as the `sql-workbench` UI API extension. The producer preserves the established prefix; strict UI API route checking is supported. The generated [OpenAPI fragment](src/main/resources/openapi/qqq-v1/sql-workbench.yaml) covers JSON and streaming exports. See [the contract and operation catalog](docs/UI-API.md).
|
||||
|
||||
To move the app under another app (for example an Admin app), re-parent `SqlWorkbenchQBitProducer.APP_NAME` after producing; the Runner moves with it. Open a notebook in the Runner with `/app/sqlWorkbenchRunner?notebook=<id>`.
|
||||
|
||||
## In-app help
|
||||
|
||||
The producer registers [help/qbit-sql-workbench.yaml](src/main/resources/help/qbit-sql-workbench.yaml), a `QBIT` bundle with summaries, Markdown help and live metadata references. Hosts with `helpContent` load help and call `HelpBundles.syncOnStartup(qInstance)` after defining metadata. Registration itself needs no help table; app/table inline help remains available without one.
|
||||
|
||||
To override wording, register your own resource with `HelpBundles.register(qInstance, "help/my-host.yaml")`, set `layer: HOST`, and use the same entry `key` and `role` (default `ALL_SCREENS`). HOST text takes precedence over QBIT text; user-edited help is preserved by sync. Keep the bundle's literal version aligned with the POM version when releasing.
|
||||
|
||||
`SqlWorkbenchHelpBundleTest` uses `HelpBundleAssertions` to check ownership coverage, keys, summary lengths and live references, including generated table actions. Run it with `./mvnw -q test -Dtest=SqlWorkbenchHelpBundleTest`; it also verifies registration without a help table.
|
||||
|
||||
## App home
|
||||
|
||||
The app's home page is a dashboard of real data, read through QQQ's core actions in the viewer's session. Permissions and record locks therefore decide what each widget counts: a user sees their own runs and the notebooks they can open, and a workbench admin sees everyone's. A widget whose table the user may not read says so rather than showing zeros. Every widget is full width and has an empty state.
|
||||
@@ -101,6 +109,12 @@ public class SnakeCaseCustomizer implements MetaDataCustomizerInterface<QTableMe
|
||||
}
|
||||
```
|
||||
|
||||
## Starter defaults and retention
|
||||
|
||||
All six tables are user content (notebooks, cells, shares, pinned snapshots) or logs (versions, the execution audit), so none is seeded: they start empty, and each table's help (`help/qbit-sql-workbench.yaml`, shown on the table screen) says how its rows get created. No host include or action is needed.
|
||||
|
||||
Retention: `notebookVersionRetention` (default 100) prunes the oldest versions of a notebook on save. `auditRetentionDays` (default null: keep forever) deletes execution audit rows older than that many days, in the background in bounded batches, at most once an hour per process, triggered as a run is audited.
|
||||
|
||||
## Storage upgrade from 1.0.0-RC.1
|
||||
|
||||
RC.2 adds `sql_workbench_notebook_share`. The DDL creates it and backfills an `all` share (the shared library) for every notebook whose `visibility` is `SHARED`; it is additive and idempotent, and owners (`owner_user_id`) are unchanged. Run it before deploying RC.2: without the share rows, published notebooks are visible only to their owners.
|
||||
@@ -231,7 +245,7 @@ A checklist for adding the workbench to a QQQ application. Each row points to th
|
||||
| Item | What to do |
|
||||
|---|---|
|
||||
| Coordinates | `com.kingsrook.qbits:qbit-sql-workbench`. Current release candidate: `1.0.0-RC.2` (Maven Central, published from `release/1.0`). |
|
||||
| QQQ version | QQQ 4.1, `4.1.0-RC.4` or later (qqq#1073: partial edits of child rows under joined locks). Java 21. |
|
||||
| QQQ version | QQQ `4.1.0-RC.6` or later (qqq#1128: UI API extension specs). Java 21. |
|
||||
| Dependencies | `qqq-backend-module-rdbms` comes in transitively. Add `qqq-middleware-javalin` yourself for the REST routes; it is optional in this qbit's POM, and without it no routes are registered. |
|
||||
| Frontend | A Next UI (`qqq-frontend-next`) release that renders the `SQL_WORKBENCH` widget: `v1.0.0-RC.13` or later. Other frontends show the app and tables but not the notebook. |
|
||||
| Registration | `new SqlWorkbenchQBitProducer().withQBitConfig(config).produce(qInstance)` after your backends are in the instance. The producer registers its own QBit metadata; don't add it by hand. To nest the app (for example under Admin), re-parent `SqlWorkbenchQBitProducer.APP_NAME` after producing. |
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# Upgrading
|
||||
|
||||
## Table help and `auditRetentionDays` (unreleased)
|
||||
|
||||
No action needed. The qbit now fills empty `help` slots on its app and tables (help a host already set is kept). The new `auditRetentionDays` config defaults to null, which keeps every audit row as before; set it to bound the size of `sql_workbench_execution`. `notebookVersionRetention` (default 100 per notebook) was already enforced. There is no DDL change and no seed.
|
||||
|
||||
## To 1.0.0-RC.4: snake_case names (metadata only)
|
||||
|
||||
The rename shipped in 1.0.0-RC.4. 1.0.0-RC.3 on Maven Central is an accidental republish of the RC.2 code (see CHANGELOG.md), so upgrading from RC.3 is the same as upgrading from RC.2.
|
||||
|
||||
+4
-4
@@ -42,7 +42,7 @@ SQL Workbench is a super-user SQL notebook for any QQQ application. Users write
|
||||
│ └ WidgetRenderer │◄───────────────►│ /qqq/v1/metaData (app + widget, filtered │
|
||||
│ case 'SQL_WORKBENCH' │ │ by sql_workbench.hasAccess)│
|
||||
│ └ SqlWorkbenchWidget (lazy) │ │ │
|
||||
│ ├ NotebookList │ /qqq/v1/ │ SqlWorkbenchRouteProvider │
|
||||
│ ├ NotebookList │ /qqq/v1/ │ SQL Workbench endpoint specs │
|
||||
│ ├ NotebookEditor │ sql-workbench/*│ └ SqlWorkbenchApi (session, perms, JSON) │
|
||||
│ │ ├ SqlCell (CM6) │◄───────────────►│ ├ SqlExecutionEngine ──► ConnectionMgr │
|
||||
│ │ ├ MarkdownCell │ │ │ ├ SqlClassifier / NamedParameterSql│
|
||||
@@ -73,8 +73,8 @@ SQL Workbench is a super-user SQL notebook for any QQQ application. Users write
|
||||
| `explain/*` | `ExplainService` (per-dialect EXPLAIN syntax) and `PlanParser`, which normalizes Postgres JSON, MySQL JSON, SQLite `EXPLAIN QUERY PLAN` rows, and H2 text into one `PlanNode` tree. |
|
||||
| `notebook/NotebookService` | Notebook CRUD, visibility, versions, and snapshots through QQQ actions on the qbit tables. |
|
||||
| `api/SqlWorkbenchApi` | Transport-agnostic API: map in, map out. Checks permissions and throws QQQ exceptions. Unit-testable without HTTP. |
|
||||
| `api/SqlWorkbenchRouteProvider` | `QJavalinRouteProviderInterface`. Sets up the session (`ExecutorSessionUtils.setupSession`), calls the API, writes JSON, and maps errors through `QJavalinUtils.handleException`. Clears the context in `finally`. |
|
||||
| `api/SqlWorkbenchJavalinMetaDataProducer` | Adds the route provider to `QJavalinMetaData` once (the ESB pattern). Called from `postProduceActions` when the class is loadable. |
|
||||
| `api/SqlWorkbenchEndpoints` and `*Spec` | One `MiddlewareSpecExtension`, `sql-workbench`, at `/sql-workbench`. Twenty JSON specs extend `AbstractJsonEndpointSpec`; export extends `AbstractEndpointSpec` directly. Core sets up and clears the session. The shared JSON transport checks access before parsing and keeps exact decimal parameters and 409 duplicate-execution errors. Existing services retain permission checks, limits and audit. See [UI API contract](UI-API.md). |
|
||||
| `api/SqlWorkbenchSchemas` | Versioned request and response component schemas, declared once by the capabilities spec for the complete extension. The committed fragment is checked by `SqlWorkbenchApiContractTest`. |
|
||||
|
||||
### 2.2 Frontend (Next UI)
|
||||
|
||||
@@ -190,7 +190,7 @@ Publishing in the notebook UI inserts (or deletes) the `ALL` share; the share cu
|
||||
| clientIp | STRING(64) | from the request, when available |
|
||||
| createDate | DATE_TIME | |
|
||||
|
||||
The audit table has its insert, edit, and delete capabilities disabled in the QQQ metadata, so the UI and generic API do not offer those operations, and its customizer rejects them in the core actions for every session but the system user (admins included). Its record lock shows each user their own rows (admins all). The engine writes it through QQQ actions with a system session context. The row is inserted **before** execution (`RUNNING`). If that insert fails, the SQL **does not run** (fail closed). The row is updated at the end. Retention: `auditRetentionDays` (default unlimited; the host prunes).
|
||||
The audit table has its insert, edit, and delete capabilities disabled in the QQQ metadata, so the UI and generic API do not offer those operations, and its customizer rejects them in the core actions for every session but the system user (admins included). Its record lock shows each user their own rows (admins all). The engine writes it through QQQ actions with a system session context. The row is inserted **before** execution (`RUNNING`). If that insert fails, the SQL **does not run** (fail closed). The row is updated at the end. Retention: `auditRetentionDays` (default unlimited; when set, rows whose run started earlier than that many days ago are deleted, in the background in bounded batches, at most once an hour per process (first pass 5 minutes after start), triggered as a run is audited; rows still RUNNING are kept).
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
# SQL Workbench UI API contract
|
||||
|
||||
All 21 operations are registered by `SqlWorkbenchQBitProducer` through
|
||||
`SqlWorkbenchEndpoints` as one `MiddlewareSpecExtension` named `sql-workbench`,
|
||||
version `1.0.0`, with the established `/sql-workbench` prefix. Full URLs remain
|
||||
`/qqq/v1/sql-workbench/...`. QQQ `4.1.0-RC.6` is the minimum core version.
|
||||
`registerRoutes=false` disables extension registration; middleware remains optional.
|
||||
|
||||
The producer registers no raw routes. Twenty JSON operations extend
|
||||
`AbstractJsonEndpointSpec` through `SqlWorkbenchJsonSpec`; `ExportResultSpec`
|
||||
extends `AbstractEndpointSpec` directly and streams CSV, JSON or XLSX with the
|
||||
existing attachment filename and `Cache-Control: no-store` headers.
|
||||
|
||||
The checked-in fragment is
|
||||
[`src/main/resources/openapi/qqq-v1/sql-workbench.yaml`](../src/main/resources/openapi/qqq-v1/sql-workbench.yaml).
|
||||
It is also included in a host's `/qqq/v1/openapi.yaml` and `.json`, and the
|
||||
extension appears in `/qqq/v1/version`. All component names begin with
|
||||
`SqlWorkbench`. Schemas explicitly describe the existing map payloads rather
|
||||
than changing their serialization. SQL results include nullable scalar values,
|
||||
binary previews and nested arrays; execute responses vary by execution status.
|
||||
|
||||
## Compatibility and security
|
||||
|
||||
No existing operation paths, methods, request or response shapes, status codes,
|
||||
or export headers change. Next UI can vendor the fragment without adapting its
|
||||
existing calls. New metadata consists of the extension/version advertisement,
|
||||
OpenAPI schemas and stable operation identifiers.
|
||||
|
||||
Core authenticates the caller before each spec runs and clears `QContext` after
|
||||
the request. Workbench access is checked before parsing bodies, path integers or
|
||||
export formats. JSON object parsing retains `BigDecimal` precision, JSON-only
|
||||
content-type checks, empty/null-body behavior, and existing error messages.
|
||||
Duplicate execution UUIDs still return 409. SQL failures remain HTTP 200 with a
|
||||
`FAILED`, `TIMED_OUT` or `CANCELLED` execution status.
|
||||
|
||||
Specs call the same `SqlWorkbenchApi`, notebook service and execution engine.
|
||||
Write/EXPLAIN ANALYZE gates, sharing permissions, caller record locks, notebook
|
||||
ownership, cached-result ownership, cancellation ownership, per-user concurrency
|
||||
limits, audit-before-SQL and deferred audit updates remain in place. Client IPs
|
||||
continue into execution audits. No request bodies or result data are logged by
|
||||
the transport.
|
||||
|
||||
## Operations
|
||||
|
||||
| Method | Path (after `/qqq/v1/sql-workbench`) | operationId |
|
||||
|---|---|---|
|
||||
| GET | `/capabilities` | `sqlWorkbenchGetCapabilities` |
|
||||
| POST | `/execute` | `sqlWorkbenchExecute` |
|
||||
| POST | `/executions/{uuid}/cancel` | `sqlWorkbenchCancelExecution` |
|
||||
| GET | `/executions/{uuid}/export` | `sqlWorkbenchExportResult` |
|
||||
| GET | `/executions/{uuid}/rows` | `sqlWorkbenchGetRows` |
|
||||
| POST | `/explain` | `sqlWorkbenchExplain` |
|
||||
| GET | `/history` | `sqlWorkbenchGetHistory` |
|
||||
| GET | `/notebooks` | `sqlWorkbenchListNotebooks` |
|
||||
| POST | `/notebooks` | `sqlWorkbenchCreateNotebook` |
|
||||
| DELETE | `/notebooks/{id}` | `sqlWorkbenchDeleteNotebook` |
|
||||
| GET | `/notebooks/{id}` | `sqlWorkbenchGetNotebook` |
|
||||
| PUT | `/notebooks/{id}` | `sqlWorkbenchUpdateNotebook` |
|
||||
| POST | `/notebooks/{id}/duplicate` | `sqlWorkbenchDuplicateNotebook` |
|
||||
| POST | `/notebooks/{id}/publish` | `sqlWorkbenchPublishNotebook` |
|
||||
| GET | `/notebooks/{id}/snapshots` | `sqlWorkbenchListSnapshots` |
|
||||
| POST | `/notebooks/{id}/snapshots` | `sqlWorkbenchCreateSnapshot` |
|
||||
| DELETE | `/notebooks/{id}/snapshots/{snapshotId}` | `sqlWorkbenchDeleteSnapshot` |
|
||||
| GET | `/notebooks/{id}/versions` | `sqlWorkbenchListVersions` |
|
||||
| GET | `/notebooks/{id}/versions/{n}` | `sqlWorkbenchGetVersion` |
|
||||
| POST | `/notebooks/{id}/versions/{n}/restore` | `sqlWorkbenchRestoreVersion` |
|
||||
| GET | `/schema/{backendName}` | `sqlWorkbenchGetSchema` |
|
||||
|
||||
## Verification and regeneration
|
||||
|
||||
`SqlWorkbenchApiContractTest` regenerates the fragment in memory and checks it
|
||||
against the checked-in file using core's deterministic `UiApiContract` tooling.
|
||||
It also checks the namespace, secured specs, prefix, media types and 21 unique
|
||||
operation IDs. Intentional contract changes can regenerate the file with:
|
||||
|
||||
```sh
|
||||
./mvnw -B test -Dtest=SqlWorkbenchApiContractTest -DsqlWorkbench.openapi.update=true
|
||||
```
|
||||
|
||||
Before RC.6 is released, local verification uses the separately installed core:
|
||||
|
||||
```sh
|
||||
./mvnw -B verify -Dqqq.snapshot.version=4.1.0-ARCHRC6-SNAPSHOT
|
||||
```
|
||||
|
||||
The POM must continue to name `4.1.0-RC.6`; the local override is never a release
|
||||
dependency. On PowerShell, quote each `-D...` argument and use `mvnw.cmd`.
|
||||
|
||||
`SqlWorkbenchEndpointSpecTest` runs real HTTP through
|
||||
`QApplicationJavalinServer.withStrictUiApiRoutes(true)`. It preserves the former
|
||||
route-provider tests and adds 401/403 coverage for every operation, mutation
|
||||
denials, execution limits, audited rejection, exact decimals, SQL failures and
|
||||
all three exports. Engine tests continue to verify audit and transaction safety.
|
||||
@@ -74,6 +74,8 @@ CREATE TABLE IF NOT EXISTS sql_workbench_result_snapshot (
|
||||
CONSTRAINT pk_sql_workbench_result_snapshot PRIMARY KEY (id),
|
||||
CONSTRAINT fk_sql_workbench_result_snapshot_notebook FOREIGN KEY (notebook_id) REFERENCES sql_workbench_notebook (id)
|
||||
);
|
||||
-- the notebook page lists its snapshots, and deleting a notebook deletes them, by notebook_id
|
||||
CREATE INDEX IF NOT EXISTS ix_sql_workbench_result_snapshot_notebook ON sql_workbench_result_snapshot (notebook_id);
|
||||
|
||||
-- Shares (1.0.0-RC.2): who, besides the owner, may read a notebook.
|
||||
-- audience_key is "user:<id>", "group:<name>" or "all" (the shared library);
|
||||
@@ -133,3 +135,5 @@ CREATE TABLE IF NOT EXISTS sql_workbench_execution (
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS ix_sql_workbench_execution_user ON sql_workbench_execution (user_id, id);
|
||||
CREATE INDEX IF NOT EXISTS ix_sql_workbench_execution_start ON sql_workbench_execution (start_time);
|
||||
-- the notebook page's "Runs" list joins executions by notebook_id
|
||||
CREATE INDEX IF NOT EXISTS ix_sql_workbench_execution_notebook ON sql_workbench_execution (notebook_id);
|
||||
@@ -18,6 +18,9 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<properties>
|
||||
<qqq.version>4.1.0-RC.26</qqq.version> <!-- feeds qbit-build-parent's qqq-bom-pom import -->
|
||||
<qbit.guardrails.enforce>true</qbit.guardrails.enforce>
|
||||
<qbit.guardrails.strictUiApiRoutes>true</qbit.guardrails.strictUiApiRoutes>
|
||||
<revision>1.0.0-SNAPSHOT</revision>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
@@ -29,7 +32,7 @@
|
||||
<parent>
|
||||
<groupId>com.kingsrook</groupId>
|
||||
<artifactId>qbit-build-parent</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<version>2.2.1</version>
|
||||
</parent>
|
||||
|
||||
<groupId>com.kingsrook.qbits</groupId>
|
||||
@@ -154,6 +157,7 @@
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<include>help/*.yaml</include>
|
||||
<include>sql-workbench.properties</include>
|
||||
</includes>
|
||||
</resource>
|
||||
@@ -161,6 +165,7 @@
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>false</filtering>
|
||||
<excludes>
|
||||
<exclude>help/*.yaml</exclude>
|
||||
<exclude>sql-workbench.properties</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
@@ -250,9 +255,9 @@
|
||||
|
||||
<profiles>
|
||||
<!-- Built against qqq 4.1 (QBitMetaDataProducer, runtime services, Javalin 7 -->
|
||||
<!-- routes; the record developer panel contract needs 4.1.0-RC.4). Until -->
|
||||
<!-- specs and help bundles require 4.1.0-RC.15). Until -->
|
||||
<!-- qbit-build-parent 2.1.0 imports the released 4.1 BOM, this profile is -->
|
||||
<!-- active by default and imports qqq-bom-pom 4.1.0-RC.4 ahead of the -->
|
||||
<!-- active by default and imports qqq-bom-pom 4.1.0-RC.15 ahead of the -->
|
||||
<!-- parent's 4.0.0 BOM (same as qbit-quick-search, ADR-0007). -->
|
||||
<profile>
|
||||
<id>qqq-snapshot</id>
|
||||
@@ -260,7 +265,7 @@
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<properties>
|
||||
<qqq.snapshot.version>4.1.0-RC.4</qqq.snapshot.version>
|
||||
<qqq.snapshot.version>4.1.0-RC.26</qqq.snapshot.version>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
@@ -273,18 +278,6 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sonatype-snapshots</id>
|
||||
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
@@ -122,6 +122,7 @@ public class SqlWorkbenchQBitConfig implements QBitConfig
|
||||
private Integer maxSchemaTables = 2000;
|
||||
private Integer snapshotMaxRows = 1000;
|
||||
private Integer notebookVersionRetention = 100;
|
||||
private Integer auditRetentionDays = null;
|
||||
private Boolean registerRoutes = true;
|
||||
|
||||
private transient MetaDataCustomizerInterface<QTableMetaData> tableMetaDataCustomizer;
|
||||
@@ -215,6 +216,10 @@ public class SqlWorkbenchQBitConfig implements QBitConfig
|
||||
requirePositive(errors, "maxSchemaTables", maxSchemaTables);
|
||||
requirePositive(errors, "snapshotMaxRows", snapshotMaxRows);
|
||||
requirePositive(errors, "notebookVersionRetention", notebookVersionRetention);
|
||||
if(auditRetentionDays != null)
|
||||
{
|
||||
requirePositive(errors, "auditRetentionDays", auditRetentionDays);
|
||||
}
|
||||
|
||||
if(defaultPageSize != null && maxPageSize != null && defaultPageSize > maxPageSize)
|
||||
{
|
||||
@@ -1480,6 +1485,39 @@ public class SqlWorkbenchQBitConfig implements QBitConfig
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for auditRetentionDays: execution audit rows older than this many
|
||||
** days are deleted (at most once an hour, when a run is audited); null (the
|
||||
** default) keeps them forever.
|
||||
*******************************************************************************/
|
||||
public Integer getAuditRetentionDays()
|
||||
{
|
||||
return (this.auditRetentionDays);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for auditRetentionDays
|
||||
*******************************************************************************/
|
||||
public void setAuditRetentionDays(Integer auditRetentionDays)
|
||||
{
|
||||
this.auditRetentionDays = auditRetentionDays;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for auditRetentionDays
|
||||
*******************************************************************************/
|
||||
public SqlWorkbenchQBitConfig withAuditRetentionDays(Integer auditRetentionDays)
|
||||
{
|
||||
this.auditRetentionDays = auditRetentionDays;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for registerRoutes
|
||||
*******************************************************************************/
|
||||
|
||||
@@ -25,9 +25,11 @@ import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.logging.QLogger;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.MetaDataProducerMultiOutput;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.help.bundles.HelpBundles;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.qbits.QBitMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.qbits.QBitMetaDataProducer;
|
||||
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
||||
import com.kingsrook.qbits.sqlworkbench.metadata.SqlWorkbenchHelp;
|
||||
import com.kingsrook.qbits.sqlworkbench.metadata.SqlWorkbenchAppMetaDataProducer;
|
||||
import com.kingsrook.qbits.sqlworkbench.metadata.SqlWorkbenchTableMetaDataHelper;
|
||||
import static com.kingsrook.qqq.backend.core.logging.LogUtils.logPair;
|
||||
@@ -42,7 +44,7 @@ import static com.kingsrook.qqq.backend.core.logging.LogUtils.logPair;
|
||||
** SQL_WORKBENCH widget, sqlWorkbench app), applies the config's table
|
||||
** customizer and default backend, stamps sourceQBitName, then calls
|
||||
** {@link #postProduceActions}, which builds the runtime and registers the
|
||||
** /qqq/v1/sql-workbench Javalin routes.
|
||||
** /qqq/v1/sql-workbench UI API extension.
|
||||
**
|
||||
** Host usage:
|
||||
** new SqlWorkbenchQBitProducer().withQBitConfig(config).produce(qInstance);
|
||||
@@ -182,13 +184,21 @@ public class SqlWorkbenchQBitProducer implements QBitMetaDataProducer<SqlWorkben
|
||||
|
||||
MetaDataProducerMultiOutput output = QBitMetaDataProducer.super.produce(qInstance);
|
||||
output.addSelfToInstance(qInstance);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// after the tables and app are in the instance: fill their empty help //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
SqlWorkbenchHelp.apply(qInstance, qBitConfig);
|
||||
|
||||
// Registration is metadata-only; core guards startup sync when helpContent is absent.
|
||||
HelpBundles.register(qInstance, "help/qbit-sql-workbench.yaml");
|
||||
return (new MetaDataProducerMultiOutput());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Build the runtime and register the REST routes.
|
||||
** Build the runtime and register the UI API extension.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public void postProduceActions(MetaDataProducerMultiOutput output, QInstance qInstance) throws QException
|
||||
@@ -203,7 +213,7 @@ public class SqlWorkbenchQBitProducer implements QBitMetaDataProducer<SqlWorkben
|
||||
boolean routes = false;
|
||||
if(Boolean.TRUE.equals(qBitConfig.getRegisterRoutes()) && isJavalinAvailable())
|
||||
{
|
||||
com.kingsrook.qbits.sqlworkbench.api.SqlWorkbenchRoutes.register(qInstance);
|
||||
com.kingsrook.qbits.sqlworkbench.api.SqlWorkbenchEndpoints.register(qInstance);
|
||||
routes = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.Caller;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicOperation;
|
||||
import com.kingsrook.qqq.openapi.model.HttpMethod;
|
||||
import com.kingsrook.qqq.openapi.model.Parameter;
|
||||
import com.kingsrook.qqq.openapi.model.Schema;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Cancel the caller's running execution.
|
||||
*******************************************************************************/
|
||||
public class CancelExecutionSpec extends SqlWorkbenchJsonSpec
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Describe the operation.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public BasicOperation defineBasicOperation()
|
||||
{
|
||||
return (operation(HttpMethod.POST, "/executions/{uuid}/cancel", "Cancel the caller's running execution"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe path and query parameters.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<Parameter> defineRequestParameters()
|
||||
{
|
||||
return (parameters());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Name the response schema.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected String getResponseSchemaName()
|
||||
{
|
||||
return ("SqlWorkbenchCancelledV1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe the JSON body.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Schema defineRequestBodySchema()
|
||||
{
|
||||
return (SqlWorkbenchSchemas.ref("EmptyRequest"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Invoke the existing service with the authenticated caller.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Object handle(JsonInput input) throws Exception
|
||||
{
|
||||
SqlWorkbenchApi api = new SqlWorkbenchApi();
|
||||
Caller caller = caller(input);
|
||||
return (api.cancel(caller, input.getPathParam("uuid")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.Caller;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicOperation;
|
||||
import com.kingsrook.qqq.openapi.model.HttpMethod;
|
||||
import com.kingsrook.qqq.openapi.model.Parameter;
|
||||
import com.kingsrook.qqq.openapi.model.Schema;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Create a personal notebook.
|
||||
*******************************************************************************/
|
||||
public class CreateNotebookSpec extends SqlWorkbenchJsonSpec
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Describe the operation.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public BasicOperation defineBasicOperation()
|
||||
{
|
||||
return (operation(HttpMethod.POST, "/notebooks", "Create a personal notebook"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe path and query parameters.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<Parameter> defineRequestParameters()
|
||||
{
|
||||
return (parameters());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Name the response schema.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected String getResponseSchemaName()
|
||||
{
|
||||
return ("SqlWorkbenchNotebookV1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe the JSON body.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Schema defineRequestBodySchema()
|
||||
{
|
||||
return (SqlWorkbenchSchemas.ref("NotebookRequest"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Invoke the existing service with the authenticated caller.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Object handle(JsonInput input) throws Exception
|
||||
{
|
||||
SqlWorkbenchApi api = new SqlWorkbenchApi();
|
||||
Caller caller = caller(input);
|
||||
return (api.notebooks().create(input.getBody(), caller));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.Caller;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicOperation;
|
||||
import com.kingsrook.qqq.openapi.model.HttpMethod;
|
||||
import com.kingsrook.qqq.openapi.model.Parameter;
|
||||
import com.kingsrook.qqq.openapi.model.Schema;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Pin the caller's cached result to an owned notebook.
|
||||
*******************************************************************************/
|
||||
public class CreateSnapshotSpec extends SqlWorkbenchJsonSpec
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Describe the operation.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public BasicOperation defineBasicOperation()
|
||||
{
|
||||
return (operation(HttpMethod.POST, "/notebooks/{id}/snapshots", "Pin the caller's cached result to an owned notebook"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe path and query parameters.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<Parameter> defineRequestParameters()
|
||||
{
|
||||
return (parameters());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Name the response schema.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected String getResponseSchemaName()
|
||||
{
|
||||
return ("SqlWorkbenchSnapshotV1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe the JSON body.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Schema defineRequestBodySchema()
|
||||
{
|
||||
return (SqlWorkbenchSchemas.ref("SnapshotRequest"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Invoke the existing service with the authenticated caller.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Object handle(JsonInput input) throws Exception
|
||||
{
|
||||
SqlWorkbenchApi api = new SqlWorkbenchApi();
|
||||
Caller caller = caller(input);
|
||||
return (api.createSnapshot(caller, pathInt(input, "id"), input.getBody()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.Caller;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicOperation;
|
||||
import com.kingsrook.qqq.openapi.model.HttpMethod;
|
||||
import com.kingsrook.qqq.openapi.model.Parameter;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Delete an owned notebook.
|
||||
*******************************************************************************/
|
||||
public class DeleteNotebookSpec extends SqlWorkbenchJsonSpec
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Describe the operation.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public BasicOperation defineBasicOperation()
|
||||
{
|
||||
return (operation(HttpMethod.DELETE, "/notebooks/{id}", "Delete an owned notebook"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe path and query parameters.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<Parameter> defineRequestParameters()
|
||||
{
|
||||
return (parameters());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Name the response schema.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected String getResponseSchemaName()
|
||||
{
|
||||
return ("SqlWorkbenchDeletedV1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Invoke the existing service with the authenticated caller.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Object handle(JsonInput input) throws Exception
|
||||
{
|
||||
SqlWorkbenchApi api = new SqlWorkbenchApi();
|
||||
Caller caller = caller(input);
|
||||
api.notebooks().delete(pathInt(input, "id"), caller);
|
||||
return (Map.of("deleted", true));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.Caller;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicOperation;
|
||||
import com.kingsrook.qqq.openapi.model.HttpMethod;
|
||||
import com.kingsrook.qqq.openapi.model.Parameter;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Delete a snapshot from an owned notebook.
|
||||
*******************************************************************************/
|
||||
public class DeleteSnapshotSpec extends SqlWorkbenchJsonSpec
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Describe the operation.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public BasicOperation defineBasicOperation()
|
||||
{
|
||||
return (operation(HttpMethod.DELETE, "/notebooks/{id}/snapshots/{snapshotId}", "Delete a snapshot from an owned notebook"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe path and query parameters.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<Parameter> defineRequestParameters()
|
||||
{
|
||||
return (parameters());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Name the response schema.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected String getResponseSchemaName()
|
||||
{
|
||||
return ("SqlWorkbenchDeletedV1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Invoke the existing service with the authenticated caller.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Object handle(JsonInput input) throws Exception
|
||||
{
|
||||
SqlWorkbenchApi api = new SqlWorkbenchApi();
|
||||
Caller caller = caller(input);
|
||||
api.notebooks().deleteSnapshot(pathInt(input, "id"), pathInt(input, "snapshotId"), caller);
|
||||
return (Map.of("deleted", true));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.Caller;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicOperation;
|
||||
import com.kingsrook.qqq.openapi.model.HttpMethod;
|
||||
import com.kingsrook.qqq.openapi.model.Parameter;
|
||||
import com.kingsrook.qqq.openapi.model.Schema;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Make a personal copy of a visible notebook.
|
||||
*******************************************************************************/
|
||||
public class DuplicateNotebookSpec extends SqlWorkbenchJsonSpec
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Describe the operation.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public BasicOperation defineBasicOperation()
|
||||
{
|
||||
return (operation(HttpMethod.POST, "/notebooks/{id}/duplicate", "Make a personal copy of a visible notebook"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe path and query parameters.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<Parameter> defineRequestParameters()
|
||||
{
|
||||
return (parameters());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Name the response schema.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected String getResponseSchemaName()
|
||||
{
|
||||
return ("SqlWorkbenchNotebookV1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe the JSON body.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Schema defineRequestBodySchema()
|
||||
{
|
||||
return (SqlWorkbenchSchemas.ref("EmptyRequest"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Invoke the existing service with the authenticated caller.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Object handle(JsonInput input) throws Exception
|
||||
{
|
||||
SqlWorkbenchApi api = new SqlWorkbenchApi();
|
||||
Caller caller = caller(input);
|
||||
return (api.notebooks().duplicate(pathInt(input, "id"), caller));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.Caller;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicOperation;
|
||||
import com.kingsrook.qqq.openapi.model.HttpMethod;
|
||||
import com.kingsrook.qqq.openapi.model.Parameter;
|
||||
import com.kingsrook.qqq.openapi.model.Schema;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Execute read-only SQL or preview and confirm a gated write.
|
||||
*******************************************************************************/
|
||||
public class ExecuteSpec extends SqlWorkbenchJsonSpec
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Describe the operation.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public BasicOperation defineBasicOperation()
|
||||
{
|
||||
return (operation(HttpMethod.POST, "/execute", "Execute read-only SQL or preview and confirm a gated write"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe path and query parameters.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<Parameter> defineRequestParameters()
|
||||
{
|
||||
return (parameters());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Name the response schema.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected String getResponseSchemaName()
|
||||
{
|
||||
return ("SqlWorkbenchExecutionV1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe the JSON body.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Schema defineRequestBodySchema()
|
||||
{
|
||||
return (SqlWorkbenchSchemas.ref("ExecuteRequest"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Invoke the existing service with the authenticated caller.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Object handle(JsonInput input) throws Exception
|
||||
{
|
||||
SqlWorkbenchApi api = new SqlWorkbenchApi();
|
||||
Caller caller = caller(input);
|
||||
return (api.execute(caller, input.getBody()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.Caller;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicOperation;
|
||||
import com.kingsrook.qqq.openapi.model.HttpMethod;
|
||||
import com.kingsrook.qqq.openapi.model.Parameter;
|
||||
import com.kingsrook.qqq.openapi.model.Schema;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Explain SQL; ANALYZE remains subject to write gates.
|
||||
*******************************************************************************/
|
||||
public class ExplainSpec extends SqlWorkbenchJsonSpec
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Describe the operation.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public BasicOperation defineBasicOperation()
|
||||
{
|
||||
return (operation(HttpMethod.POST, "/explain", "Explain SQL; ANALYZE remains subject to write gates"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe path and query parameters.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<Parameter> defineRequestParameters()
|
||||
{
|
||||
return (parameters());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Name the response schema.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected String getResponseSchemaName()
|
||||
{
|
||||
return ("SqlWorkbenchExplainV1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe the JSON body.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Schema defineRequestBodySchema()
|
||||
{
|
||||
return (SqlWorkbenchSchemas.ref("ExplainRequest"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Invoke the existing service with the authenticated caller.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Object handle(JsonInput input) throws Exception
|
||||
{
|
||||
SqlWorkbenchApi api = new SqlWorkbenchApi();
|
||||
Caller caller = caller(input);
|
||||
return (api.explain(caller, input.getBody()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.Caller;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.ResultCache;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
||||
import com.kingsrook.qqq.middleware.javalin.executors.AbstractMiddlewareExecutor;
|
||||
import com.kingsrook.qqq.middleware.javalin.executors.io.AbstractMiddlewareInput;
|
||||
import com.kingsrook.qqq.middleware.javalin.executors.io.AbstractMiddlewareOutputInterface;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.AbstractEndpointSpec;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicOperation;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicResponse;
|
||||
import com.kingsrook.qqq.openapi.model.HttpMethod;
|
||||
import com.kingsrook.qqq.openapi.model.Method;
|
||||
import com.kingsrook.qqq.openapi.model.Parameter;
|
||||
import io.javalin.http.Context;
|
||||
import io.javalin.http.HttpStatus;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Stream a caller-owned cached result without buffering it as a JSON response.
|
||||
*******************************************************************************/
|
||||
public class ExportResultSpec extends AbstractEndpointSpec<ExportResultSpec.ExportInput, ExportResultSpec.ExportOutput, ExportResultSpec.ExportExecutor>
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Describe the existing download endpoint.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public BasicOperation defineBasicOperation()
|
||||
{
|
||||
return (SqlWorkbenchJsonSpec.operation(HttpMethod.GET, "/executions/{uuid}/export", "Export the caller's cached result as CSV, JSON or XLSX"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Stable identifier for generated clients.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected void customizeMethod(Method method)
|
||||
{
|
||||
method.setOperationId("sqlWorkbenchExportResult");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe UUID and format selection.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<Parameter> defineRequestParameters()
|
||||
{
|
||||
return (SqlWorkbenchJsonSpec.parametersFor(defineBasicOperation().getPath(), "format"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** All three media types are served by the same operation.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<BasicResponse> defineAdditionalBasicResponses()
|
||||
{
|
||||
List<BasicResponse> responses = new ArrayList<>(SqlWorkbenchJsonSpec.errors());
|
||||
for(ResultExporter.Format format : ResultExporter.Format.values())
|
||||
{
|
||||
responses.add(new BasicResponse(format.getContentType(), HttpStatus.OK,
|
||||
"Attachment named sql-result-{short UUID}.{format}; Cache-Control: no-store",
|
||||
format == ResultExporter.Format.JSON ? "SqlWorkbenchExportJsonV1" : "SqlWorkbenchExportFileV1", null));
|
||||
}
|
||||
return (responses);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Check access before parsing format, just as the previous route did.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public ExportInput buildInput(Context context) throws Exception
|
||||
{
|
||||
ExportInput input = new ExportInput();
|
||||
input.caller = new SqlWorkbenchApi().caller(context.ip());
|
||||
input.uuid = context.pathParam("uuid");
|
||||
input.format = ResultExporter.Format.of(StringUtils.hasContent(context.queryParam("format")) ? context.queryParam("format") : "csv");
|
||||
return (input);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Stream only after the executor authorizes access to the cached result.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public void handleOutput(Context context, ExportOutput output) throws Exception
|
||||
{
|
||||
String shortId = output.uuid.length() > 8 ? output.uuid.substring(0, 8) : output.uuid;
|
||||
context.contentType(output.format.getContentType());
|
||||
context.header("Content-Disposition", "attachment; filename=\"sql-result-" + shortId.replaceAll("[^A-Za-z0-9-]", "") + "." + output.format.getExtension() + "\"");
|
||||
context.header("Cache-Control", "no-store");
|
||||
ResultExporter.write(output.entry.result(), output.format, context.outputStream());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Request state populated after session authentication.
|
||||
*******************************************************************************/
|
||||
public static class ExportInput extends AbstractMiddlewareInput
|
||||
{
|
||||
private Caller caller;
|
||||
private String uuid;
|
||||
private ResultExporter.Format format;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Authorized cached data and download metadata.
|
||||
*******************************************************************************/
|
||||
public static class ExportOutput implements AbstractMiddlewareOutputInterface
|
||||
{
|
||||
private ResultCache.Entry entry;
|
||||
private String uuid;
|
||||
private ResultExporter.Format format;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Service authorization stays identical to JSON result paging.
|
||||
*******************************************************************************/
|
||||
public static class ExportExecutor extends AbstractMiddlewareExecutor<ExportInput, ExportOutput>
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Resolve only the caller's cached execution.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public void execute(ExportInput input, ExportOutput output) throws QException
|
||||
{
|
||||
output.entry = new SqlWorkbenchApi().exportable(input.caller, input.uuid);
|
||||
output.uuid = input.uuid;
|
||||
output.format = input.format;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.Caller;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicOperation;
|
||||
import com.kingsrook.qqq.openapi.model.HttpMethod;
|
||||
import com.kingsrook.qqq.openapi.model.Parameter;
|
||||
import com.kingsrook.qqq.openapi.model.Schema;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Get caller capabilities and configured limits.
|
||||
*******************************************************************************/
|
||||
public class GetCapabilitiesSpec extends SqlWorkbenchJsonSpec
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Declare shared components once. The extension registers all specs together.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public Map<String, Schema> defineComponentSchemas()
|
||||
{
|
||||
return (SqlWorkbenchSchemas.components());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe the operation.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public BasicOperation defineBasicOperation()
|
||||
{
|
||||
return (operation(HttpMethod.GET, "/capabilities", "Get caller capabilities and configured limits"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe path and query parameters.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<Parameter> defineRequestParameters()
|
||||
{
|
||||
return (parameters());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Name the response schema.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected String getResponseSchemaName()
|
||||
{
|
||||
return ("SqlWorkbenchCapabilitiesV1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Invoke the existing service with the authenticated caller.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Object handle(JsonInput input) throws Exception
|
||||
{
|
||||
SqlWorkbenchApi api = new SqlWorkbenchApi();
|
||||
Caller caller = caller(input);
|
||||
return (api.capabilities(caller));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.Caller;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicOperation;
|
||||
import com.kingsrook.qqq.openapi.model.HttpMethod;
|
||||
import com.kingsrook.qqq.openapi.model.Parameter;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** List the caller's recent audited executions.
|
||||
*******************************************************************************/
|
||||
public class GetHistorySpec extends SqlWorkbenchJsonSpec
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Describe the operation.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public BasicOperation defineBasicOperation()
|
||||
{
|
||||
return (operation(HttpMethod.GET, "/history", "List the caller's recent audited executions"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe path and query parameters.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<Parameter> defineRequestParameters()
|
||||
{
|
||||
return (parameters("limit", "backendName"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Name the response schema.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected String getResponseSchemaName()
|
||||
{
|
||||
return ("SqlWorkbenchHistoryV1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Invoke the existing service with the authenticated caller.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Object handle(JsonInput input) throws Exception
|
||||
{
|
||||
SqlWorkbenchApi api = new SqlWorkbenchApi();
|
||||
Caller caller = caller(input);
|
||||
return (api.history(caller, input.getQueryParamInteger("limit"), input.getQueryParam("backendName")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.Caller;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicOperation;
|
||||
import com.kingsrook.qqq.openapi.model.HttpMethod;
|
||||
import com.kingsrook.qqq.openapi.model.Parameter;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Get a visible notebook and its cells.
|
||||
*******************************************************************************/
|
||||
public class GetNotebookSpec extends SqlWorkbenchJsonSpec
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Describe the operation.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public BasicOperation defineBasicOperation()
|
||||
{
|
||||
return (operation(HttpMethod.GET, "/notebooks/{id}", "Get a visible notebook and its cells"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe path and query parameters.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<Parameter> defineRequestParameters()
|
||||
{
|
||||
return (parameters());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Name the response schema.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected String getResponseSchemaName()
|
||||
{
|
||||
return ("SqlWorkbenchNotebookV1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Invoke the existing service with the authenticated caller.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Object handle(JsonInput input) throws Exception
|
||||
{
|
||||
SqlWorkbenchApi api = new SqlWorkbenchApi();
|
||||
Caller caller = caller(input);
|
||||
return (api.notebooks().get(pathInt(input, "id"), caller));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.Caller;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicOperation;
|
||||
import com.kingsrook.qqq.openapi.model.HttpMethod;
|
||||
import com.kingsrook.qqq.openapi.model.Parameter;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Page or sort the caller's cached result.
|
||||
*******************************************************************************/
|
||||
public class GetRowsSpec extends SqlWorkbenchJsonSpec
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Describe the operation.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public BasicOperation defineBasicOperation()
|
||||
{
|
||||
return (operation(HttpMethod.GET, "/executions/{uuid}/rows", "Page or sort the caller's cached result"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe path and query parameters.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<Parameter> defineRequestParameters()
|
||||
{
|
||||
return (parameters("offset", "limit", "sort", "dir"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Name the response schema.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected String getResponseSchemaName()
|
||||
{
|
||||
return ("SqlWorkbenchRowsV1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Invoke the existing service with the authenticated caller.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Object handle(JsonInput input) throws Exception
|
||||
{
|
||||
SqlWorkbenchApi api = new SqlWorkbenchApi();
|
||||
Caller caller = caller(input);
|
||||
return (api.rows(caller, input.getPathParam("uuid"), input.getQueryParamInteger("offset"), input.getQueryParamInteger("limit"), input.getQueryParamInteger("sort"), input.getQueryParam("dir")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.Caller;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicOperation;
|
||||
import com.kingsrook.qqq.openapi.model.HttpMethod;
|
||||
import com.kingsrook.qqq.openapi.model.Parameter;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Inspect a target backend schema.
|
||||
*******************************************************************************/
|
||||
public class GetSchemaSpec extends SqlWorkbenchJsonSpec
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Describe the operation.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public BasicOperation defineBasicOperation()
|
||||
{
|
||||
return (operation(HttpMethod.GET, "/schema/{backendName}", "Inspect a target backend schema"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe path and query parameters.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<Parameter> defineRequestParameters()
|
||||
{
|
||||
return (parameters("refresh"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Name the response schema.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected String getResponseSchemaName()
|
||||
{
|
||||
return ("SqlWorkbenchSchemaV1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Invoke the existing service with the authenticated caller.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Object handle(JsonInput input) throws Exception
|
||||
{
|
||||
SqlWorkbenchApi api = new SqlWorkbenchApi();
|
||||
Caller caller = caller(input);
|
||||
return (api.schema(caller, input.getPathParam("backendName"), "true".equalsIgnoreCase(input.getQueryParam("refresh"))));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.Caller;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicOperation;
|
||||
import com.kingsrook.qqq.openapi.model.HttpMethod;
|
||||
import com.kingsrook.qqq.openapi.model.Parameter;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Get a visible notebook version and saved content.
|
||||
*******************************************************************************/
|
||||
public class GetVersionSpec extends SqlWorkbenchJsonSpec
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Describe the operation.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public BasicOperation defineBasicOperation()
|
||||
{
|
||||
return (operation(HttpMethod.GET, "/notebooks/{id}/versions/{n}", "Get a visible notebook version and saved content"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe path and query parameters.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<Parameter> defineRequestParameters()
|
||||
{
|
||||
return (parameters());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Name the response schema.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected String getResponseSchemaName()
|
||||
{
|
||||
return ("SqlWorkbenchVersionV1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Invoke the existing service with the authenticated caller.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Object handle(JsonInput input) throws Exception
|
||||
{
|
||||
SqlWorkbenchApi api = new SqlWorkbenchApi();
|
||||
Caller caller = caller(input);
|
||||
return (api.notebooks().version(pathInt(input, "id"), pathInt(input, "n"), caller));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.Caller;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicOperation;
|
||||
import com.kingsrook.qqq.openapi.model.HttpMethod;
|
||||
import com.kingsrook.qqq.openapi.model.Parameter;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** List visible personal or shared notebooks.
|
||||
*******************************************************************************/
|
||||
public class ListNotebooksSpec extends SqlWorkbenchJsonSpec
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Describe the operation.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public BasicOperation defineBasicOperation()
|
||||
{
|
||||
return (operation(HttpMethod.GET, "/notebooks", "List visible personal or shared notebooks"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe path and query parameters.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<Parameter> defineRequestParameters()
|
||||
{
|
||||
return (parameters("scope"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Name the response schema.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected String getResponseSchemaName()
|
||||
{
|
||||
return ("SqlWorkbenchNotebooksV1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Invoke the existing service with the authenticated caller.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Object handle(JsonInput input) throws Exception
|
||||
{
|
||||
SqlWorkbenchApi api = new SqlWorkbenchApi();
|
||||
Caller caller = caller(input);
|
||||
return (Map.of("notebooks", api.notebooks().list(input.getQueryParam("scope"), caller)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.Caller;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicOperation;
|
||||
import com.kingsrook.qqq.openapi.model.HttpMethod;
|
||||
import com.kingsrook.qqq.openapi.model.Parameter;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** List snapshots of a visible notebook.
|
||||
*******************************************************************************/
|
||||
public class ListSnapshotsSpec extends SqlWorkbenchJsonSpec
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Describe the operation.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public BasicOperation defineBasicOperation()
|
||||
{
|
||||
return (operation(HttpMethod.GET, "/notebooks/{id}/snapshots", "List snapshots of a visible notebook"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe path and query parameters.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<Parameter> defineRequestParameters()
|
||||
{
|
||||
return (parameters());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Name the response schema.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected String getResponseSchemaName()
|
||||
{
|
||||
return ("SqlWorkbenchSnapshotsV1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Invoke the existing service with the authenticated caller.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Object handle(JsonInput input) throws Exception
|
||||
{
|
||||
SqlWorkbenchApi api = new SqlWorkbenchApi();
|
||||
Caller caller = caller(input);
|
||||
return (Map.of("snapshots", api.notebooks().snapshots(pathInt(input, "id"), caller)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.Caller;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicOperation;
|
||||
import com.kingsrook.qqq.openapi.model.HttpMethod;
|
||||
import com.kingsrook.qqq.openapi.model.Parameter;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** List versions of a visible notebook.
|
||||
*******************************************************************************/
|
||||
public class ListVersionsSpec extends SqlWorkbenchJsonSpec
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Describe the operation.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public BasicOperation defineBasicOperation()
|
||||
{
|
||||
return (operation(HttpMethod.GET, "/notebooks/{id}/versions", "List versions of a visible notebook"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe path and query parameters.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<Parameter> defineRequestParameters()
|
||||
{
|
||||
return (parameters());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Name the response schema.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected String getResponseSchemaName()
|
||||
{
|
||||
return ("SqlWorkbenchVersionsV1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Invoke the existing service with the authenticated caller.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Object handle(JsonInput input) throws Exception
|
||||
{
|
||||
SqlWorkbenchApi api = new SqlWorkbenchApi();
|
||||
Caller caller = caller(input);
|
||||
return (Map.of("versions", api.notebooks().versions(pathInt(input, "id"), caller)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.Caller;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicOperation;
|
||||
import com.kingsrook.qqq.openapi.model.HttpMethod;
|
||||
import com.kingsrook.qqq.openapi.model.Parameter;
|
||||
import com.kingsrook.qqq.openapi.model.Schema;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Publish or withdraw an owned notebook with share permission.
|
||||
*******************************************************************************/
|
||||
public class PublishNotebookSpec extends SqlWorkbenchJsonSpec
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Describe the operation.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public BasicOperation defineBasicOperation()
|
||||
{
|
||||
return (operation(HttpMethod.POST, "/notebooks/{id}/publish", "Publish or withdraw an owned notebook with share permission"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe path and query parameters.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<Parameter> defineRequestParameters()
|
||||
{
|
||||
return (parameters());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Name the response schema.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected String getResponseSchemaName()
|
||||
{
|
||||
return ("SqlWorkbenchNotebookV1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe the JSON body.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Schema defineRequestBodySchema()
|
||||
{
|
||||
return (SqlWorkbenchSchemas.ref("PublishRequest"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Invoke the existing service with the authenticated caller.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Object handle(JsonInput input) throws Exception
|
||||
{
|
||||
SqlWorkbenchApi api = new SqlWorkbenchApi();
|
||||
Caller caller = caller(input);
|
||||
return (api.notebooks().publish(pathInt(input, "id"), Boolean.TRUE.equals(input.getBody().get("shared")), caller));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.Caller;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicOperation;
|
||||
import com.kingsrook.qqq.openapi.model.HttpMethod;
|
||||
import com.kingsrook.qqq.openapi.model.Parameter;
|
||||
import com.kingsrook.qqq.openapi.model.Schema;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Restore an owned notebook version as a new version.
|
||||
*******************************************************************************/
|
||||
public class RestoreVersionSpec extends SqlWorkbenchJsonSpec
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Describe the operation.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public BasicOperation defineBasicOperation()
|
||||
{
|
||||
return (operation(HttpMethod.POST, "/notebooks/{id}/versions/{n}/restore", "Restore an owned notebook version as a new version"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe path and query parameters.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<Parameter> defineRequestParameters()
|
||||
{
|
||||
return (parameters());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Name the response schema.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected String getResponseSchemaName()
|
||||
{
|
||||
return ("SqlWorkbenchNotebookV1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe the JSON body.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Schema defineRequestBodySchema()
|
||||
{
|
||||
return (SqlWorkbenchSchemas.ref("EmptyRequest"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Invoke the existing service with the authenticated caller.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Object handle(JsonInput input) throws Exception
|
||||
{
|
||||
SqlWorkbenchApi api = new SqlWorkbenchApi();
|
||||
Caller caller = caller(input);
|
||||
return (api.notebooks().restore(pathInt(input, "id"), pathInt(input, "n"), caller));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.extensions.MiddlewareSpecExtension;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.extensions.MiddlewareSpecExtensionsMetaData;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Registers all SQL Workbench operations as UI API specs.
|
||||
*******************************************************************************/
|
||||
public class SqlWorkbenchEndpoints
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Register the extension idempotently.
|
||||
*******************************************************************************/
|
||||
public static void register(QInstance qInstance)
|
||||
{
|
||||
MiddlewareSpecExtensionsMetaData.ofOrWithNew(qInstance).withExtension(extension());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** The complete UI API extension at its established prefix.
|
||||
*******************************************************************************/
|
||||
public static MiddlewareSpecExtension extension()
|
||||
{
|
||||
return (new MiddlewareSpecExtension().withName("sql-workbench").withPathPrefix("/sql-workbench")
|
||||
.withSemanticVersion("1.1.0").withDescription("Audited SQL execution and notebooks")
|
||||
.withSpec(GetCapabilitiesSpec.class)
|
||||
.withSpec(GetSchemaSpec.class)
|
||||
.withSpec(ExecuteSpec.class)
|
||||
.withSpec(ExplainSpec.class)
|
||||
.withSpec(GetRowsSpec.class)
|
||||
.withSpec(CancelExecutionSpec.class)
|
||||
.withSpec(GetHistorySpec.class)
|
||||
.withSpec(ListNotebooksSpec.class)
|
||||
.withSpec(CreateNotebookSpec.class)
|
||||
.withSpec(GetNotebookSpec.class)
|
||||
.withSpec(UpdateNotebookSpec.class)
|
||||
.withSpec(DeleteNotebookSpec.class)
|
||||
.withSpec(PublishNotebookSpec.class)
|
||||
.withSpec(DuplicateNotebookSpec.class)
|
||||
.withSpec(ListVersionsSpec.class)
|
||||
.withSpec(GetVersionSpec.class)
|
||||
.withSpec(RestoreVersionSpec.class)
|
||||
.withSpec(ListSnapshotsSpec.class)
|
||||
.withSpec(CreateSnapshotSpec.class)
|
||||
.withSpec(DeleteSnapshotSpec.class)
|
||||
.withSpec(ExportResultSpec.class));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,336 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.Caller;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.DuplicateExecutionException;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QBadRequestException;
|
||||
import com.kingsrook.qqq.backend.core.utils.JsonUtils;
|
||||
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
||||
import com.kingsrook.qqq.middleware.javalin.QJavalinUtils;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicOperation;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicResponse;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.extensions.AbstractJsonEndpointSpec;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.v1.responses.BasicErrorResponseV1;
|
||||
import com.kingsrook.qqq.openapi.model.HttpMethod;
|
||||
import com.kingsrook.qqq.openapi.model.In;
|
||||
import com.kingsrook.qqq.openapi.model.Method;
|
||||
import com.kingsrook.qqq.openapi.model.Parameter;
|
||||
import com.kingsrook.qqq.openapi.model.RequestBody;
|
||||
import com.kingsrook.qqq.openapi.model.Schema;
|
||||
import com.kingsrook.qqq.openapi.model.Type;
|
||||
import io.javalin.http.Context;
|
||||
import io.javalin.http.HttpStatus;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Shared transport; the existing services retain authorization, limits and audit.
|
||||
*******************************************************************************/
|
||||
public abstract class SqlWorkbenchJsonSpec extends AbstractJsonEndpointSpec
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Check access before parsing; preserve exact decimal parameters.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public JsonInput buildInput(Context context) throws Exception
|
||||
{
|
||||
Caller caller = new SqlWorkbenchApi().caller(context.ip());
|
||||
WorkbenchInput input = new WorkbenchInput(this, caller);
|
||||
input.getPathParams().putAll(context.pathParamMap());
|
||||
context.queryParamMap().forEach((name, values) -> input.getQueryParams().put(name, values == null || values.isEmpty() ? null : values.get(0)));
|
||||
if(defineRequestBodySchema() != null)
|
||||
{
|
||||
input.getBody().putAll(readExactBody(context));
|
||||
}
|
||||
return (input);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Parse the established JSON object shape without losing decimal precision.
|
||||
*******************************************************************************/
|
||||
private static Map<String, Object> readExactBody(Context context) throws QBadRequestException
|
||||
{
|
||||
if(!StringUtils.hasContent(context.body()))
|
||||
{
|
||||
return (Map.of());
|
||||
}
|
||||
if(context.contentType() == null || !context.contentType().toLowerCase().startsWith("application/json"))
|
||||
{
|
||||
throw (new QBadRequestException("Request bodies must be JSON (Content-Type: application/json)."));
|
||||
}
|
||||
try
|
||||
{
|
||||
Map<String, Object> body = JsonUtils.toObject(context.body(), new TypeReference<Map<String, Object>>() {}, mapper -> mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS));
|
||||
return (body == null ? Map.of() : body);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw (new QBadRequestException("The request body is not a JSON object."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Preserve duplicate execution UUID conflicts.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected void handleException(Context context, Exception e)
|
||||
{
|
||||
QJavalinUtils.handleException(e instanceof DuplicateExecutionException ? org.eclipse.jetty.http.HttpStatus.Code.CONFLICT : null, context, e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Bodies remain optional; empty bodies retain their existing service semantics.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public RequestBody defineRequestBody()
|
||||
{
|
||||
RequestBody body = super.defineRequestBody();
|
||||
return (body == null ? null : body.withRequired(false));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Stable operation identifiers for generated clients.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected void customizeMethod(Method method)
|
||||
{
|
||||
method.setOperationId("sqlWorkbench" + getClass().getSimpleName().replace("Spec", ""));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Keep the established extension prefix.
|
||||
*******************************************************************************/
|
||||
static BasicOperation operation(HttpMethod method, String path, String summary)
|
||||
{
|
||||
return (new BasicOperation().withHttpMethod(method).withPath("/sql-workbench" + path)
|
||||
.withShortSummary(summary).withLongDescription(summary + ". Requires SQL Workbench access; services enforce caller permissions, ownership, execution limits and audit."));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Document existing request error statuses.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<BasicResponse> defineAdditionalBasicResponses()
|
||||
{
|
||||
return (errors());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Share error schemas with the export stream.
|
||||
*******************************************************************************/
|
||||
static List<BasicResponse> errors()
|
||||
{
|
||||
return (List.of(new BasicResponse(HttpStatus.BAD_REQUEST, "Invalid input or execution limit exceeded", BasicErrorResponseV1.class.getSimpleName()),
|
||||
new BasicResponse(HttpStatus.UNAUTHORIZED, "Sign in required", BasicErrorResponseV1.class.getSimpleName()),
|
||||
new BasicResponse(HttpStatus.FORBIDDEN, "Permission denied", BasicErrorResponseV1.class.getSimpleName()),
|
||||
new BasicResponse(HttpStatus.NOT_FOUND, "Missing or invisible resource", BasicErrorResponseV1.class.getSimpleName()),
|
||||
new BasicResponse(HttpStatus.CONFLICT, "Execution UUID already used", BasicErrorResponseV1.class.getSimpleName())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Path and query parameter declarations.
|
||||
*******************************************************************************/
|
||||
protected List<Parameter> parameters(String... queries)
|
||||
{
|
||||
return (parametersFor(defineBasicOperation().getPath(), queries));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Share parameter declarations with the export stream.
|
||||
*******************************************************************************/
|
||||
static List<Parameter> parametersFor(String path, String... queries)
|
||||
{
|
||||
List<Parameter> parameters = new ArrayList<>();
|
||||
Matcher matcher = Pattern.compile("\\{([^}]+)}").matcher(path);
|
||||
while(matcher.find())
|
||||
{
|
||||
parameters.add(parameter(matcher.group(1), In.PATH));
|
||||
}
|
||||
for(String query : queries)
|
||||
{
|
||||
parameters.add(parameter(query, In.QUERY));
|
||||
}
|
||||
return (parameters);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Document parameter types and default behavior.
|
||||
*******************************************************************************/
|
||||
private static Parameter parameter(String name, In location)
|
||||
{
|
||||
Type type = Type.STRING;
|
||||
if(List.of("id", "n", "snapshotId", "offset", "limit", "sort").contains(name))
|
||||
{
|
||||
type = Type.INTEGER;
|
||||
}
|
||||
else if("refresh".equals(name))
|
||||
{
|
||||
type = Type.BOOLEAN;
|
||||
}
|
||||
return (new Parameter().withName(name).withIn(location).withRequired(location == In.PATH)
|
||||
.withDescription(parameterDescription(name)).withSchema(new Schema().withType(type)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Parameter help for generated clients.
|
||||
*******************************************************************************/
|
||||
private static String parameterDescription(String name)
|
||||
{
|
||||
switch(name)
|
||||
{
|
||||
case "id":
|
||||
return ("Notebook identifier.");
|
||||
case "n":
|
||||
return ("Notebook version number.");
|
||||
case "snapshotId":
|
||||
return ("Snapshot identifier.");
|
||||
case "uuid":
|
||||
return ("Execution UUID; case insensitive.");
|
||||
case "backendName":
|
||||
return ("Configured target backend name.");
|
||||
case "offset":
|
||||
return ("Rows to skip; default zero; negative values become zero.");
|
||||
case "limit":
|
||||
return ("Page size; nonpositive or absent uses the default. Rows cap at maxPageSize; history caps at 200 (default 50).");
|
||||
case "sort":
|
||||
return ("Optional zero-based result column index.");
|
||||
case "dir":
|
||||
return ("Sort direction: desc (case insensitive) or asc (default).");
|
||||
case "refresh":
|
||||
return ("True to bypass the schema cache; default false.");
|
||||
case "scope":
|
||||
return ("mine (default) or shared notebook library.");
|
||||
case "format":
|
||||
return ("csv (default), json or xlsx; case insensitive.");
|
||||
default:
|
||||
return (name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Preserve integer path validation.
|
||||
*******************************************************************************/
|
||||
protected static Integer pathInt(JsonInput input, String name) throws QBadRequestException
|
||||
{
|
||||
try
|
||||
{
|
||||
return (Integer.parseInt(input.getPathParam(name)));
|
||||
}
|
||||
catch(NumberFormatException e)
|
||||
{
|
||||
throw (new QBadRequestException(name + " must be an integer."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Caller captured before body parsing, including the audit client IP.
|
||||
*******************************************************************************/
|
||||
protected static Caller caller(JsonInput input)
|
||||
{
|
||||
return (((WorkbenchInput) input).caller);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Per-request state; spec instances themselves are shared across requests.
|
||||
*******************************************************************************/
|
||||
private static class WorkbenchInput extends JsonInput
|
||||
{
|
||||
private final SqlWorkbenchJsonSpec spec;
|
||||
private final Caller caller;
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Capture the spec and authorized caller.
|
||||
*******************************************************************************/
|
||||
private WorkbenchInput(SqlWorkbenchJsonSpec spec, Caller caller)
|
||||
{
|
||||
this.spec = spec;
|
||||
this.caller = caller;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Supply the spec to the framework's JSON executor.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public AbstractJsonEndpointSpec getSpec()
|
||||
{
|
||||
return (spec);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Preserve the established integer-query error message.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public Integer getQueryParamInteger(String name) throws QBadRequestException
|
||||
{
|
||||
String value = getQueryParam(name);
|
||||
if(!StringUtils.hasContent(value))
|
||||
{
|
||||
return (null);
|
||||
}
|
||||
try
|
||||
{
|
||||
return (Integer.parseInt(value.trim()));
|
||||
}
|
||||
catch(NumberFormatException e)
|
||||
{
|
||||
throw (new QBadRequestException(name + " must be an integer."));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,268 +0,0 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QBadRequestException;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.utils.JsonUtils;
|
||||
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
||||
import com.kingsrook.qbits.sqlworkbench.SqlWorkbenchRuntime;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.Caller;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.DuplicateExecutionException;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.ResultCache;
|
||||
import com.kingsrook.qqq.middleware.javalin.QJavalinRouteProviderInterface;
|
||||
import com.kingsrook.qqq.middleware.javalin.QJavalinUtils;
|
||||
import com.kingsrook.qqq.middleware.javalin.executors.ExecutorSessionUtils;
|
||||
import io.javalin.config.JavalinConfig;
|
||||
import io.javalin.http.ContentType;
|
||||
import io.javalin.http.Context;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Javalin routes for the SQL Workbench under /qqq/v1/sql-workbench (see
|
||||
** docs/DESIGN.md section 5 for the contract).
|
||||
**
|
||||
** Each request gets a session from the instance's authentication module
|
||||
** (ExecutorSessionUtils), then SqlWorkbenchApi checks permissions and does
|
||||
** the work. Errors map through QJavalinUtils.handleException: 400 bad
|
||||
** request, 401 unauthenticated, 403 not permitted, 404 unknown, 409 a
|
||||
** re-used executionUuid. POST / PUT
|
||||
** bodies must be JSON (Content-Type application/json): a cross-site form
|
||||
** cannot send that without a CORS preflight. Request and response bodies
|
||||
** are never logged.
|
||||
*******************************************************************************/
|
||||
public class SqlWorkbenchRouteProvider implements QJavalinRouteProviderInterface
|
||||
{
|
||||
public static final String BASE_PATH = "/qqq/v1/sql-workbench";
|
||||
|
||||
private QInstance qInstance;
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public void setQInstance(QInstance qInstance)
|
||||
{
|
||||
this.qInstance = qInstance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public void acceptJavalinConfig(JavalinConfig config)
|
||||
{
|
||||
config.routes.get(BASE_PATH + "/capabilities", ctx -> respond(ctx, false, (api, caller, body) -> api.capabilities(caller)));
|
||||
config.routes.get(BASE_PATH + "/schema/{backendName}", ctx -> respond(ctx, false, (api, caller, body) -> api.schema(caller, ctx.pathParam("backendName"), "true".equalsIgnoreCase(ctx.queryParam("refresh")))));
|
||||
config.routes.post(BASE_PATH + "/execute", ctx -> respond(ctx, true, (api, caller, body) -> api.execute(caller, body)));
|
||||
config.routes.post(BASE_PATH + "/explain", ctx -> respond(ctx, true, (api, caller, body) -> api.explain(caller, body)));
|
||||
config.routes.get(BASE_PATH + "/executions/{uuid}/rows", ctx -> respond(ctx, false, (api, caller, body) -> api.rows(caller, ctx.pathParam("uuid"),
|
||||
intParam(ctx, "offset"), intParam(ctx, "limit"), intParam(ctx, "sort"), ctx.queryParam("dir"))));
|
||||
config.routes.get(BASE_PATH + "/executions/{uuid}/export", this::export);
|
||||
config.routes.post(BASE_PATH + "/executions/{uuid}/cancel", ctx -> respond(ctx, true, (api, caller, body) -> api.cancel(caller, ctx.pathParam("uuid"))));
|
||||
config.routes.get(BASE_PATH + "/history", ctx -> respond(ctx, false, (api, caller, body) -> api.history(caller, intParam(ctx, "limit"), ctx.queryParam("backendName"))));
|
||||
|
||||
config.routes.get(BASE_PATH + "/notebooks", ctx -> respond(ctx, false, (api, caller, body) -> Map.of("notebooks", api.notebooks().list(ctx.queryParam("scope"), caller))));
|
||||
config.routes.post(BASE_PATH + "/notebooks", ctx -> respond(ctx, true, (api, caller, body) -> api.notebooks().create(body, caller)));
|
||||
config.routes.get(BASE_PATH + "/notebooks/{id}", ctx -> respond(ctx, false, (api, caller, body) -> api.notebooks().get(id(ctx), caller)));
|
||||
config.routes.put(BASE_PATH + "/notebooks/{id}", ctx -> respond(ctx, true, (api, caller, body) -> api.notebooks().update(id(ctx), body, caller)));
|
||||
config.routes.delete(BASE_PATH + "/notebooks/{id}", ctx -> respond(ctx, false, (api, caller, body) ->
|
||||
{
|
||||
api.notebooks().delete(id(ctx), caller);
|
||||
return (Map.of("deleted", true));
|
||||
}));
|
||||
config.routes.post(BASE_PATH + "/notebooks/{id}/publish", ctx -> respond(ctx, true, (api, caller, body) -> api.notebooks().publish(id(ctx), Boolean.TRUE.equals(body.get("shared")), caller)));
|
||||
config.routes.post(BASE_PATH + "/notebooks/{id}/duplicate", ctx -> respond(ctx, true, (api, caller, body) -> api.notebooks().duplicate(id(ctx), caller)));
|
||||
config.routes.get(BASE_PATH + "/notebooks/{id}/versions", ctx -> respond(ctx, false, (api, caller, body) -> Map.of("versions", api.notebooks().versions(id(ctx), caller))));
|
||||
config.routes.get(BASE_PATH + "/notebooks/{id}/versions/{n}", ctx -> respond(ctx, false, (api, caller, body) -> api.notebooks().version(id(ctx), pathInt(ctx, "n"), caller)));
|
||||
config.routes.post(BASE_PATH + "/notebooks/{id}/versions/{n}/restore", ctx -> respond(ctx, true, (api, caller, body) -> api.notebooks().restore(id(ctx), pathInt(ctx, "n"), caller)));
|
||||
config.routes.get(BASE_PATH + "/notebooks/{id}/snapshots", ctx -> respond(ctx, false, (api, caller, body) -> Map.of("snapshots", api.notebooks().snapshots(id(ctx), caller))));
|
||||
config.routes.post(BASE_PATH + "/notebooks/{id}/snapshots", ctx -> respond(ctx, true, (api, caller, body) -> api.createSnapshot(caller, id(ctx), body)));
|
||||
config.routes.delete(BASE_PATH + "/notebooks/{id}/snapshots/{snapshotId}", ctx -> respond(ctx, false, (api, caller, body) ->
|
||||
{
|
||||
api.notebooks().deleteSnapshot(id(ctx), pathInt(ctx, "snapshotId"), caller);
|
||||
return (Map.of("deleted", true));
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Session, permission check, body, handler, JSON - or the error's status.
|
||||
*******************************************************************************/
|
||||
private void respond(Context context, boolean readsBody, Handler handler)
|
||||
{
|
||||
try
|
||||
{
|
||||
ExecutorSessionUtils.setupSession(context, qInstance);
|
||||
SqlWorkbenchApi api = new SqlWorkbenchApi(qInstance, SqlWorkbenchRuntime.get(qInstance));
|
||||
Caller caller = api.caller(context.ip());
|
||||
Map<String, Object> body = readsBody ? readJsonBody(context) : Map.of();
|
||||
Object result = handler.handle(api, caller, body);
|
||||
|
||||
context.contentType(ContentType.APPLICATION_JSON);
|
||||
context.result(JsonUtils.toJsonCustomized(result, builder -> builder.serializationInclusion(JsonInclude.Include.ALWAYS)));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
QJavalinUtils.handleException(e instanceof DuplicateExecutionException ? HttpStatus.Code.CONFLICT : null, context, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
QContext.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** GET /executions/{uuid}/export?format=csv|json|xlsx
|
||||
*******************************************************************************/
|
||||
private void export(Context context)
|
||||
{
|
||||
try
|
||||
{
|
||||
ExecutorSessionUtils.setupSession(context, qInstance);
|
||||
SqlWorkbenchApi api = new SqlWorkbenchApi(qInstance, SqlWorkbenchRuntime.get(qInstance));
|
||||
Caller caller = api.caller(context.ip());
|
||||
ResultExporter.Format format = ResultExporter.Format.of(StringUtils.hasContent(context.queryParam("format")) ? context.queryParam("format") : "csv");
|
||||
String uuid = context.pathParam("uuid");
|
||||
ResultCache.Entry entry = api.exportable(caller, uuid);
|
||||
|
||||
String shortId = uuid.length() > 8 ? uuid.substring(0, 8) : uuid;
|
||||
context.contentType(format.getContentType());
|
||||
context.header("Content-Disposition", "attachment; filename=\"sql-result-" + shortId.replaceAll("[^A-Za-z0-9-]", "") + "." + format.getExtension() + "\"");
|
||||
context.header("Cache-Control", "no-store");
|
||||
ResultExporter.write(entry.result(), format, context.outputStream());
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
QJavalinUtils.handleException(null, context, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
QContext.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** A JSON object body. Decimals stay exact (BigDecimal).
|
||||
*******************************************************************************/
|
||||
static Map<String, Object> readJsonBody(Context context) throws QBadRequestException
|
||||
{
|
||||
String body = context.body();
|
||||
if(!StringUtils.hasContent(body))
|
||||
{
|
||||
return (new LinkedHashMap<>());
|
||||
}
|
||||
|
||||
String contentType = context.contentType();
|
||||
if(contentType == null || !contentType.toLowerCase().startsWith("application/json"))
|
||||
{
|
||||
throw (new QBadRequestException("Request bodies must be JSON (Content-Type: application/json)."));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Map<String, Object> map = JsonUtils.toObject(body, new TypeReference<Map<String, Object>>() {}, mapper -> mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS));
|
||||
return (map == null ? new LinkedHashMap<>() : map);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw (new QBadRequestException("The request body is not a JSON object."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private static Integer id(Context context) throws QBadRequestException
|
||||
{
|
||||
return (pathInt(context, "id"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private static Integer pathInt(Context context, String name) throws QBadRequestException
|
||||
{
|
||||
try
|
||||
{
|
||||
return (Integer.parseInt(context.pathParam(name)));
|
||||
}
|
||||
catch(NumberFormatException e)
|
||||
{
|
||||
throw (new QBadRequestException(name + " must be an integer."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private static Integer intParam(Context context, String name) throws QBadRequestException
|
||||
{
|
||||
String value = context.queryParam(name);
|
||||
if(!StringUtils.hasContent(value))
|
||||
{
|
||||
return (null);
|
||||
}
|
||||
try
|
||||
{
|
||||
return (Integer.parseInt(value.trim()));
|
||||
}
|
||||
catch(NumberFormatException e)
|
||||
{
|
||||
throw (new QBadRequestException(name + " must be an integer."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** One endpoint's work.
|
||||
*******************************************************************************/
|
||||
@FunctionalInterface
|
||||
private interface Handler
|
||||
{
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
Object handle(SqlWorkbenchApi api, Caller caller, Map<String, Object> body) throws QException;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
|
||||
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
|
||||
import com.kingsrook.qqq.middleware.javalin.QJavalinMetaData;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Registers SqlWorkbenchRouteProvider (the /qqq/v1/sql-workbench routes)
|
||||
** with the Javalin server through the instance's QJavalinMetaData - as
|
||||
** qqq-esb's EsbJavalinMetaDataProducer does. Only touched when
|
||||
** qqq-middleware-javalin is on the classpath (the producer checks first).
|
||||
*******************************************************************************/
|
||||
public class SqlWorkbenchRoutes
|
||||
{
|
||||
|
||||
/*******************************************************************************
|
||||
** Add the route provider reference, once.
|
||||
*******************************************************************************/
|
||||
public static void register(QInstance qInstance)
|
||||
{
|
||||
QJavalinMetaData javalinMetaData = QJavalinMetaData.ofOrWithNew(qInstance);
|
||||
boolean registered = CollectionUtils.nonNullList(javalinMetaData.getAdditionalRouteProviderReferences()).stream()
|
||||
.anyMatch(reference -> reference != null && SqlWorkbenchRouteProvider.class.getName().equals(reference.getName()));
|
||||
if(!registered)
|
||||
{
|
||||
javalinMetaData.withAdditionalRouteProviderReference(new QCodeReference(SqlWorkbenchRouteProvider.class));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,330 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.kingsrook.qqq.openapi.model.Schema;
|
||||
import com.kingsrook.qqq.openapi.model.Type;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Versioned wire schemas shared by SQL Workbench specs.
|
||||
*******************************************************************************/
|
||||
public class SqlWorkbenchSchemas
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Explicit schemas for the existing map payloads; no serialization changes.
|
||||
*******************************************************************************/
|
||||
public static Map<String, Schema> components()
|
||||
{
|
||||
Map<String, Schema> schemas = new LinkedHashMap<>();
|
||||
schemas.put("SqlWorkbenchErrorV1", new Schema().withType(Type.OBJECT)
|
||||
.withDescription("Deprecated since 1.1.0: errors use BasicErrorResponseV1.")
|
||||
.withProperty("error", new Schema().withType(Type.STRING)));
|
||||
schemas.put("SqlWorkbenchEmptyRequestV1", new Schema().withType(Type.OBJECT));
|
||||
schemas.put("SqlWorkbenchDeletedV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("deleted", new Schema().withType(Type.BOOLEAN)));
|
||||
schemas.put("SqlWorkbenchCancelledV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("cancelled", new Schema().withType(Type.BOOLEAN)));
|
||||
schemas.put("SqlWorkbenchLimitsV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("maxRows", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("pageSize", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("maxPageSize", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("maxResultBytes", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("statementTimeoutSeconds", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("writeStatementTimeoutSeconds", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("maxAffectedRowsWithoutAcknowledgement", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("maxAffectedRows", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("maxSqlLength", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("maxStatementsPerRun", new Schema().withType(Type.INTEGER).withFormat("int64")));
|
||||
schemas.put("SqlWorkbenchBackendV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("name", new Schema().withType(Type.STRING))
|
||||
.withProperty("label", new Schema().withType(Type.STRING))
|
||||
.withProperty("vendor", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("dialect", ref("Dialect"))
|
||||
.withProperty("readOnlyCredentials", new Schema().withType(Type.BOOLEAN))
|
||||
.withProperty("readOnlyEnforced", new Schema().withType(Type.BOOLEAN))
|
||||
.withProperty("transactionalDdl", new Schema().withType(Type.BOOLEAN))
|
||||
.withProperty("writeAllowed", new Schema().withType(Type.BOOLEAN)));
|
||||
schemas.put("SqlWorkbenchCapabilitiesV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("version", new Schema().withType(Type.STRING))
|
||||
.withProperty("canWrite", new Schema().withType(Type.BOOLEAN))
|
||||
.withProperty("canShare", new Schema().withType(Type.BOOLEAN))
|
||||
.withProperty("writeModeEnabled", new Schema().withType(Type.BOOLEAN))
|
||||
.withProperty("limits", ref("Limits"))
|
||||
.withProperty("backends", array(ref("Backend"))));
|
||||
schemas.put("SqlWorkbenchColumnV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("name", new Schema().withType(Type.STRING))
|
||||
.withProperty("label", new Schema().withType(Type.STRING))
|
||||
.withProperty("typeName", new Schema().withType(Type.STRING))
|
||||
.withProperty("jdbcType", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("kind", ref("ColumnKind")));
|
||||
schemas.put("SqlWorkbenchBinaryValueV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("$binary", new Schema().withType(Type.BOOLEAN))
|
||||
.withProperty("length", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("hexPreview", new Schema().withType(Type.STRING)));
|
||||
schemas.put("SqlWorkbenchStatementV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("index", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("kind", ref("StatementKind"))
|
||||
.withProperty("leadingKeyword", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("text", new Schema().withType(Type.STRING))
|
||||
.withProperty("affectedRows", new Schema().withType(Type.INTEGER).withFormat("int64").withNullable(true)));
|
||||
schemas.put("SqlWorkbenchExecuteRequestV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("backendName", new Schema().withType(Type.STRING))
|
||||
.withProperty("sql", new Schema().withType(Type.STRING))
|
||||
.withProperty("params", ref("Parameters"))
|
||||
.withProperty("mode", new Schema().withType(Type.STRING))
|
||||
.withProperty("notebookId", new Schema().withType(Type.INTEGER).withFormat("int64").withNullable(true))
|
||||
.withProperty("cellKey", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("pageSize", new Schema().withType(Type.INTEGER).withFormat("int64").withNullable(true))
|
||||
.withProperty("confirmToken", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("acknowledgeRowGuard", new Schema().withType(Type.BOOLEAN))
|
||||
.withProperty("executionUuid", new Schema().withType(Type.STRING).withNullable(true)));
|
||||
schemas.put("SqlWorkbenchExplainRequestV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("backendName", new Schema().withType(Type.STRING))
|
||||
.withProperty("sql", new Schema().withType(Type.STRING))
|
||||
.withProperty("params", ref("Parameters"))
|
||||
.withProperty("analyze", new Schema().withType(Type.BOOLEAN)));
|
||||
schemas.put("SqlWorkbenchExecutionV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("executionUuid", new Schema().withType(Type.STRING))
|
||||
.withProperty("status", ref("Status"))
|
||||
.withProperty("mode", new Schema().withType(Type.STRING))
|
||||
.withProperty("backendName", new Schema().withType(Type.STRING))
|
||||
.withProperty("durationMs", new Schema().withType(Type.INTEGER).withFormat("int64").withNullable(true))
|
||||
.withProperty("statements", array(ref("Statement")))
|
||||
.withProperty("columns", array(ref("Column")))
|
||||
.withProperty("rows", ref("RowsData"))
|
||||
.withProperty("rowCount", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("hasMore", new Schema().withType(Type.BOOLEAN))
|
||||
.withProperty("truncated", new Schema().withType(Type.BOOLEAN))
|
||||
.withProperty("truncatedReason", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("rowsAffected", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("error", new Schema().withType(Type.STRING))
|
||||
.withProperty("sqlState", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("dryRunSupported", new Schema().withType(Type.BOOLEAN))
|
||||
.withProperty("dryRunNote", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("totalAffectedRows", new Schema().withType(Type.INTEGER).withFormat("int64").withNullable(true))
|
||||
.withProperty("rowGuardExceeded", new Schema().withType(Type.BOOLEAN))
|
||||
.withProperty("rowGuardLimit", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("confirmToken", new Schema().withType(Type.STRING))
|
||||
.withProperty("expiresAt", new Schema().withType(Type.STRING))
|
||||
.withProperty("previewAffectedRows", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("actualAffectedRows", new Schema().withType(Type.INTEGER).withFormat("int64")));
|
||||
schemas.put("SqlWorkbenchRowsV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("executionUuid", new Schema().withType(Type.STRING))
|
||||
.withProperty("columns", array(ref("Column")))
|
||||
.withProperty("rows", ref("RowsData"))
|
||||
.withProperty("offset", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("rowCount", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("truncated", new Schema().withType(Type.BOOLEAN))
|
||||
.withProperty("truncatedReason", new Schema().withType(Type.STRING).withNullable(true)));
|
||||
schemas.put("SqlWorkbenchPlanNodeV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("label", new Schema().withType(Type.STRING))
|
||||
.withProperty("detail", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("startupCost", new Schema().withType(Type.NUMBER).withNullable(true))
|
||||
.withProperty("totalCost", new Schema().withType(Type.NUMBER).withNullable(true))
|
||||
.withProperty("planRows", new Schema().withType(Type.INTEGER).withFormat("int64").withNullable(true))
|
||||
.withProperty("actualTimeMs", new Schema().withType(Type.NUMBER).withNullable(true))
|
||||
.withProperty("actualRows", new Schema().withType(Type.INTEGER).withFormat("int64").withNullable(true))
|
||||
.withProperty("loops", new Schema().withType(Type.INTEGER).withFormat("int64").withNullable(true))
|
||||
.withProperty("extra", ref("FreeObject"))
|
||||
.withProperty("children", array(ref("PlanNode"))));
|
||||
schemas.put("SqlWorkbenchExplainV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("executionUuid", new Schema().withType(Type.STRING))
|
||||
.withProperty("status", ref("Status"))
|
||||
.withProperty("mode", new Schema().withType(Type.STRING))
|
||||
.withProperty("backendName", new Schema().withType(Type.STRING))
|
||||
.withProperty("dialect", ref("Dialect"))
|
||||
.withProperty("analyze", new Schema().withType(Type.BOOLEAN))
|
||||
.withProperty("plan", ref("PlanNode"))
|
||||
.withProperty("raw", new Schema().withType(Type.STRING))
|
||||
.withProperty("error", new Schema().withType(Type.STRING))
|
||||
.withProperty("sqlState", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("durationMs", new Schema().withType(Type.INTEGER).withFormat("int64").withNullable(true)));
|
||||
schemas.put("SqlWorkbenchSchemaColumnV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("name", new Schema().withType(Type.STRING))
|
||||
.withProperty("typeName", new Schema().withType(Type.STRING))
|
||||
.withProperty("nullable", new Schema().withType(Type.BOOLEAN)));
|
||||
schemas.put("SqlWorkbenchSchemaTableV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("name", new Schema().withType(Type.STRING))
|
||||
.withProperty("type", new Schema().withType(Type.STRING))
|
||||
.withProperty("columns", array(ref("SchemaColumn"))));
|
||||
schemas.put("SqlWorkbenchDatabaseSchemaV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("name", new Schema().withType(Type.STRING))
|
||||
.withProperty("tables", array(ref("SchemaTable"))));
|
||||
schemas.put("SqlWorkbenchQqqFieldV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("name", new Schema().withType(Type.STRING))
|
||||
.withProperty("label", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("sqlName", new Schema().withType(Type.STRING))
|
||||
.withProperty("type", new Schema().withType(Type.STRING).withNullable(true)));
|
||||
schemas.put("SqlWorkbenchQqqTableV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("name", new Schema().withType(Type.STRING))
|
||||
.withProperty("label", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("sqlName", new Schema().withType(Type.STRING))
|
||||
.withProperty("fields", array(ref("QqqField"))));
|
||||
schemas.put("SqlWorkbenchSchemaV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("backendName", new Schema().withType(Type.STRING))
|
||||
.withProperty("dialect", ref("Dialect"))
|
||||
.withProperty("schemas", array(ref("DatabaseSchema")))
|
||||
.withProperty("truncated", new Schema().withType(Type.BOOLEAN))
|
||||
.withProperty("keywords", array(new Schema().withType(Type.STRING)))
|
||||
.withProperty("functions", array(new Schema().withType(Type.STRING)))
|
||||
.withProperty("qqqTables", array(ref("QqqTable")))
|
||||
.withProperty("cachedAt", new Schema().withType(Type.STRING)));
|
||||
schemas.put("SqlWorkbenchHistoryEntryV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("executionUuid", new Schema().withType(Type.STRING))
|
||||
.withProperty("backendName", new Schema().withType(Type.STRING))
|
||||
.withProperty("mode", new Schema().withType(Type.STRING))
|
||||
.withProperty("status", new Schema().withType(Type.STRING))
|
||||
.withProperty("sqlText", new Schema().withType(Type.STRING))
|
||||
.withProperty("notebookId", new Schema().withType(Type.INTEGER).withFormat("int64").withNullable(true))
|
||||
.withProperty("cellKey", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("startTime", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("durationMs", new Schema().withType(Type.INTEGER).withFormat("int64").withNullable(true))
|
||||
.withProperty("rowsReturned", new Schema().withType(Type.INTEGER).withFormat("int64").withNullable(true))
|
||||
.withProperty("rowsAffected", new Schema().withType(Type.INTEGER).withFormat("int64").withNullable(true))
|
||||
.withProperty("errorMessage", new Schema().withType(Type.STRING).withNullable(true)));
|
||||
schemas.put("SqlWorkbenchHistoryV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("executions", array(ref("HistoryEntry"))));
|
||||
schemas.put("SqlWorkbenchNotebookParameterV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("name", new Schema().withType(Type.STRING))
|
||||
.withProperty("type", new Schema().withType(Type.STRING))
|
||||
.withProperty("defaultValue", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("label", new Schema().withType(Type.STRING).withNullable(true)));
|
||||
schemas.put("SqlWorkbenchCellV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("cellKey", new Schema().withType(Type.STRING))
|
||||
.withProperty("cellType", new Schema().withType(Type.STRING))
|
||||
.withProperty("title", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("content", new Schema().withType(Type.STRING))
|
||||
.withProperty("backendName", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("sortOrder", new Schema().withType(Type.INTEGER).withFormat("int64")));
|
||||
schemas.put("SqlWorkbenchNotebookSummaryV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("id", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("title", new Schema().withType(Type.STRING))
|
||||
.withProperty("description", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("visibility", new Schema().withType(Type.STRING))
|
||||
.withProperty("ownerUserId", new Schema().withType(Type.STRING))
|
||||
.withProperty("ownerName", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("defaultBackendName", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("currentVersion", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("canEdit", new Schema().withType(Type.BOOLEAN))
|
||||
.withProperty("createDate", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("modifyDate", new Schema().withType(Type.STRING).withNullable(true)));
|
||||
schemas.put("SqlWorkbenchNotebookV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("id", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("title", new Schema().withType(Type.STRING))
|
||||
.withProperty("description", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("visibility", new Schema().withType(Type.STRING))
|
||||
.withProperty("ownerUserId", new Schema().withType(Type.STRING))
|
||||
.withProperty("ownerName", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("defaultBackendName", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("currentVersion", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("canEdit", new Schema().withType(Type.BOOLEAN))
|
||||
.withProperty("createDate", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("modifyDate", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("parameters", array(ref("NotebookParameter")))
|
||||
.withProperty("cells", array(ref("Cell"))));
|
||||
schemas.put("SqlWorkbenchNotebookContentV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("title", new Schema().withType(Type.STRING))
|
||||
.withProperty("description", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("defaultBackendName", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("parameters", array(ref("NotebookParameter")))
|
||||
.withProperty("cells", array(ref("Cell"))));
|
||||
schemas.put("SqlWorkbenchNotebookRequestV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("title", new Schema().withType(Type.STRING))
|
||||
.withProperty("description", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("defaultBackendName", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("parameters", array(ref("NotebookParameter")))
|
||||
.withProperty("cells", array(ref("Cell")))
|
||||
.withProperty("comment", new Schema().withType(Type.STRING)));
|
||||
schemas.put("SqlWorkbenchNotebooksV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("notebooks", array(ref("NotebookSummary"))));
|
||||
schemas.put("SqlWorkbenchPublishRequestV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("shared", new Schema().withType(Type.BOOLEAN)));
|
||||
schemas.put("SqlWorkbenchVersionSummaryV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("versionNumber", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("savedByName", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("comment", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("createDate", new Schema().withType(Type.STRING)));
|
||||
schemas.put("SqlWorkbenchVersionV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("versionNumber", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("savedByName", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("comment", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("createDate", new Schema().withType(Type.STRING))
|
||||
.withProperty("notebook", ref("NotebookContent")));
|
||||
schemas.put("SqlWorkbenchVersionsV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("versions", array(ref("VersionSummary"))));
|
||||
schemas.put("SqlWorkbenchSnapshotRequestV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("executionUuid", new Schema().withType(Type.STRING))
|
||||
.withProperty("cellKey", new Schema().withType(Type.STRING))
|
||||
.withProperty("label", new Schema().withType(Type.STRING).withNullable(true)));
|
||||
schemas.put("SqlWorkbenchSnapshotResultV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("columns", array(ref("Column")))
|
||||
.withProperty("rows", ref("RowsData")));
|
||||
schemas.put("SqlWorkbenchSnapshotV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("id", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("cellKey", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("executionUuid", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("label", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("backendName", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("rowCount", new Schema().withType(Type.INTEGER).withFormat("int64"))
|
||||
.withProperty("truncated", new Schema().withType(Type.BOOLEAN))
|
||||
.withProperty("createDate", new Schema().withType(Type.STRING).withNullable(true))
|
||||
.withProperty("result", ref("SnapshotResult")));
|
||||
schemas.put("SqlWorkbenchSnapshotsV1", new Schema().withType(Type.OBJECT)
|
||||
.withProperty("snapshots", array(ref("Snapshot"))));
|
||||
schemas.put("SqlWorkbenchDialectV1", new Schema().withType(Type.STRING).withEnumValues(List.of("postgresql", "mysql", "sqlite", "h2", "sql")));
|
||||
schemas.put("SqlWorkbenchColumnKindV1", new Schema().withType(Type.STRING).withEnumValues(List.of("number", "string", "boolean", "date", "datetime", "time", "json", "binary", "array", "other")));
|
||||
schemas.put("SqlWorkbenchStatementKindV1", new Schema().withType(Type.STRING).withEnumValues(List.of("READ", "EXPLAIN_ANALYZE", "WRITE", "DDL", "FORBIDDEN")));
|
||||
schemas.put("SqlWorkbenchStatusV1", new Schema().withType(Type.STRING).withEnumValues(List.of("SUCCEEDED", "FAILED", "TIMED_OUT", "CANCELLED", "REJECTED", "PREVIEW", "DRIFTED")));
|
||||
schemas.put("SqlWorkbenchParametersV1", new Schema().withType(Type.OBJECT).withAdditionalProperties(new Schema())
|
||||
.withDescription("Named SQL parameter values. JSON decimals are parsed exactly as BigDecimal."));
|
||||
schemas.put("SqlWorkbenchFreeObjectV1", new Schema().withType(Type.OBJECT).withAdditionalProperties(true));
|
||||
schemas.put("SqlWorkbenchValueV1", new Schema().withAnyOf(List.of(
|
||||
new Schema().withType(Type.STRING).withNullable(true), new Schema().withType(Type.NUMBER), new Schema().withType(Type.BOOLEAN),
|
||||
ref("BinaryValue"), array(ref("Value")), ref("FreeObject")))
|
||||
.withDescription("JSON-safe JDBC value; null, scalar, binary preview, nested array or vendor JSON object."));
|
||||
schemas.put("SqlWorkbenchRowsDataV1", array(array(ref("Value"))));
|
||||
schemas.put("SqlWorkbenchExportFileV1", new Schema().withType(Type.STRING).withFormat("binary"));
|
||||
schemas.put("SqlWorkbenchExportJsonV1", array(new Schema().withType(Type.OBJECT).withAdditionalProperties(ref("Value")))
|
||||
.withDescription("Rows keyed by unique column labels, with duplicate labels suffixed."));
|
||||
return (schemas);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Reference a component in this extension's namespace.
|
||||
*******************************************************************************/
|
||||
public static Schema ref(String name)
|
||||
{
|
||||
return (new Schema().withRefToSchema("SqlWorkbench" + name + "V1"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** An array with explicitly described items.
|
||||
*******************************************************************************/
|
||||
private static Schema array(Schema items)
|
||||
{
|
||||
return (new Schema().withType(Type.ARRAY).withItems(items));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import com.kingsrook.qbits.sqlworkbench.engine.Caller;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.BasicOperation;
|
||||
import com.kingsrook.qqq.openapi.model.HttpMethod;
|
||||
import com.kingsrook.qqq.openapi.model.Parameter;
|
||||
import com.kingsrook.qqq.openapi.model.Schema;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Update an owned notebook and record a version.
|
||||
*******************************************************************************/
|
||||
public class UpdateNotebookSpec extends SqlWorkbenchJsonSpec
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Describe the operation.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public BasicOperation defineBasicOperation()
|
||||
{
|
||||
return (operation(HttpMethod.PUT, "/notebooks/{id}", "Update an owned notebook and record a version"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe path and query parameters.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<Parameter> defineRequestParameters()
|
||||
{
|
||||
return (parameters());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Name the response schema.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected String getResponseSchemaName()
|
||||
{
|
||||
return ("SqlWorkbenchNotebookV1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Describe the JSON body.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Schema defineRequestBodySchema()
|
||||
{
|
||||
return (SqlWorkbenchSchemas.ref("NotebookRequest"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Invoke the existing service with the authenticated caller.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
protected Object handle(JsonInput input) throws Exception
|
||||
{
|
||||
SqlWorkbenchApi api = new SqlWorkbenchApi();
|
||||
Caller caller = caller(input);
|
||||
return (api.notebooks().update(pathInt(input, "id"), input.getBody(), caller));
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -28,7 +28,7 @@ import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||
|
||||
/*******************************************************************************
|
||||
** Notebook versions and the execution audit are append-only: only the qbit
|
||||
** itself (the system user) inserts them, and only its retention pruning
|
||||
** itself (the system user) inserts them, and only its retention pruning (auditRetentionDays, notebookVersionRetention)
|
||||
** deletes them. The tables also lack the insert / update / delete
|
||||
** capabilities, which hides those operations in the UI and API; this
|
||||
** customizer enforces it in the core actions, whoever calls them (admins
|
||||
|
||||
@@ -19,14 +19,27 @@ package com.kingsrook.qbits.sqlworkbench.engine;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.DeleteAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.UpdateAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.QueryAction;
|
||||
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.logging.QLogger;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.delete.DeleteInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QCriteriaOperator;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterCriteria;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterOrderBy;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryInput;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.model.session.QSystemUserSession;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertOutput;
|
||||
@@ -50,7 +63,20 @@ public class ExecutionAuditor
|
||||
|
||||
public static final int MAX_ERROR_LENGTH = 4000;
|
||||
|
||||
public static final long PRUNE_INTERVAL_MILLIS = 60L * 60 * 1000;
|
||||
public static final long FIRST_PRUNE_DELAY_MILLIS = 5L * 60 * 1000;
|
||||
public static final int BATCH_SIZE = 1000;
|
||||
public static final int MAX_BATCHES = 20;
|
||||
|
||||
private static final ExecutorService PRUNER = Executors.newSingleThreadExecutor(runnable ->
|
||||
{
|
||||
Thread thread = new Thread(runnable, "sql-workbench-audit-prune");
|
||||
thread.setDaemon(true);
|
||||
return (thread);
|
||||
});
|
||||
|
||||
private final SqlWorkbenchQBitConfig config;
|
||||
private final AtomicLong lastPruneMillis = new AtomicLong(System.currentTimeMillis() - PRUNE_INTERVAL_MILLIS + FIRST_PRUNE_DELAY_MILLIS);
|
||||
|
||||
|
||||
|
||||
@@ -92,11 +118,114 @@ public class ExecutionAuditor
|
||||
|
||||
throwIfNotInserted(inserted[0], "Could not write the SQL Workbench audit record; the SQL was not run.");
|
||||
execution.setId(inserted[0].getValueInteger("id"));
|
||||
pruneIfDue();
|
||||
return (execution.getId());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** For tests: make the next pruneIfDue start a pass now.
|
||||
*******************************************************************************/
|
||||
void allowPruneNow()
|
||||
{
|
||||
lastPruneMillis.set(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Apply auditRetentionDays in the background, at most once an hour per
|
||||
** process, and never the moment a process starts (the first pass is
|
||||
** FIRST_PRUNE_DELAY_MILLIS after construction, so restarts and rolling
|
||||
** deploys do not each trigger a pass). Never delays or fails the run being
|
||||
** audited: a failed pass is logged and tried again an hour later.
|
||||
**
|
||||
** Across replicas: the qbit has no table for shared state, so each replica
|
||||
** keeps its own hourly limit. That is safe because a pass is bounded
|
||||
** (MAX_BATCHES batches of BATCH_SIZE rows) and idempotent: replicas that
|
||||
** overlap delete rows another replica already deleted, which costs one
|
||||
** cheap query. N replicas therefore cost at most N bounded passes an hour.
|
||||
**
|
||||
** @return the pending pass, or null when none was started
|
||||
*******************************************************************************/
|
||||
Future<?> pruneIfDue()
|
||||
{
|
||||
if(config.getAuditRetentionDays() == null)
|
||||
{
|
||||
return (null);
|
||||
}
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
long last = lastPruneMillis.get();
|
||||
if(now - last < PRUNE_INTERVAL_MILLIS || !lastPruneMillis.compareAndSet(last, now))
|
||||
{
|
||||
return (null);
|
||||
}
|
||||
|
||||
QInstance qInstance = QContext.getQInstance();
|
||||
Instant cutoff = Instant.ofEpochMilli(now).minus(Duration.ofDays(config.getAuditRetentionDays()));
|
||||
return (PRUNER.submit(() ->
|
||||
{
|
||||
QContext.init(qInstance, new QSystemUserSession());
|
||||
try
|
||||
{
|
||||
pruneOlderThan(cutoff);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
LOG.warn("Could not prune old SQL Workbench audit rows", e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
QContext.clear();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Delete audit rows that started before a cutoff (system user; the table is
|
||||
** otherwise append-only), in batches of BATCH_SIZE ids (so a large backlog
|
||||
** never loads whole rows, with their SQL text, or builds an unbounded IN
|
||||
** list), at most MAX_BATCHES batches per call; the rest goes on the next
|
||||
** pass. Rows still RUNNING are kept.
|
||||
**
|
||||
** @return the number of rows deleted
|
||||
*******************************************************************************/
|
||||
public int pruneOlderThan(Instant cutoff) throws QException
|
||||
{
|
||||
int[] deleted = new int[1];
|
||||
asSystem(() ->
|
||||
{
|
||||
for(int batch = 0; batch < MAX_BATCHES; batch++)
|
||||
{
|
||||
QQueryFilter filter = new QQueryFilter(new QFilterCriteria("startTime", QCriteriaOperator.LESS_THAN, cutoff))
|
||||
.withCriteria(new QFilterCriteria("status", QCriteriaOperator.NOT_EQUALS, ExecutionStatus.RUNNING.name()))
|
||||
.withOrderBy(new QFilterOrderBy("id"))
|
||||
.withLimit(BATCH_SIZE);
|
||||
List<Serializable> ids = new ArrayList<>();
|
||||
for(QRecord record : new QueryAction().execute(new QueryInput(tableName()).withFilter(filter)).getRecords())
|
||||
{
|
||||
ids.add(record.getValueInteger("id"));
|
||||
}
|
||||
if(ids.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
deleted[0] += new DeleteAction().execute(new DeleteInput(tableName()).withPrimaryKeys(ids)).getDeletedRecordCount();
|
||||
if(ids.size() < BATCH_SIZE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
return (deleted[0]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Record the outcome.
|
||||
*******************************************************************************/
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.metadata;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||
import com.kingsrook.qbits.sqlworkbench.SqlWorkbenchQBitConfig;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.help.QHelpContent;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.layout.QAppMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Applies help/qbit-sql-workbench.yaml (the QQQ help-bundle format) to the SQL
|
||||
** Workbench app and its sql_workbench_* tables: what each table is for and
|
||||
** how its rows get created, shown on the table screen and when it is empty.
|
||||
** Retains inline app/table help for hosts without helpContent, including
|
||||
** prefixed metadata. Core bundle registration supplies the full help catalog.
|
||||
*******************************************************************************/
|
||||
public final class SqlWorkbenchHelp
|
||||
{
|
||||
public static final String RESOURCE = "/help/qbit-sql-workbench.yaml";
|
||||
public static final String SLOT = "help";
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Utility class.
|
||||
*******************************************************************************/
|
||||
private SqlWorkbenchHelp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** The bundle's entries by key, validated (fails startup if malformed).
|
||||
*******************************************************************************/
|
||||
public static Map<String, JsonNode> entries() throws QException
|
||||
{
|
||||
try(InputStream stream = SqlWorkbenchHelp.class.getResourceAsStream(RESOURCE))
|
||||
{
|
||||
if(stream == null)
|
||||
{
|
||||
throw (new IOException("missing resource"));
|
||||
}
|
||||
JsonNode bundle = new ObjectMapper(new YAMLFactory()).readTree(stream);
|
||||
if(!"qbit-sql-workbench".equals(bundle.path("bundle").asText()) || !"QBIT".equals(bundle.path("layer").asText()))
|
||||
{
|
||||
throw (new IOException("invalid bundle header"));
|
||||
}
|
||||
Map<String, JsonNode> entries = new LinkedHashMap<>();
|
||||
for(JsonNode entry : bundle.path("entries"))
|
||||
{
|
||||
String key = entry.path("key").asText();
|
||||
String summary = entry.path("summary").asText();
|
||||
if(key.isBlank() || summary.isBlank() || summary.length() > 120 || entries.put(key, entry) != null)
|
||||
{
|
||||
throw (new IOException("invalid or duplicate entry: " + key));
|
||||
}
|
||||
}
|
||||
return (entries);
|
||||
}
|
||||
catch(IOException | RuntimeException e)
|
||||
{
|
||||
throw (new QException("Could not load " + RESOURCE, e));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Apply the help to the app and every sql_workbench_* table in the instance
|
||||
** (names carry the config's prefix, if any). A host's own help on a table
|
||||
** is kept (the bundle only fills the slot).
|
||||
*******************************************************************************/
|
||||
public static void apply(QInstance qInstance, SqlWorkbenchQBitConfig config) throws QException
|
||||
{
|
||||
for(Map.Entry<String, JsonNode> entry : entries().entrySet())
|
||||
{
|
||||
String key = entry.getKey();
|
||||
if(!key.endsWith(";slot:help"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String name = key.substring(key.indexOf(':') + 1, key.indexOf(';'));
|
||||
if(key.startsWith("table:"))
|
||||
{
|
||||
QTableMetaData table = qInstance.getTable(config.applyPrefix(name));
|
||||
if(table != null && (table.getHelpContent() == null || !table.getHelpContent().containsKey(SLOT)))
|
||||
{
|
||||
table.withHelpContent(SLOT, content(entry.getValue()));
|
||||
}
|
||||
}
|
||||
else if(key.startsWith("app:"))
|
||||
{
|
||||
QAppMetaData app = qInstance.getApp(config.applyPrefix(name));
|
||||
if(app != null && (app.getHelpContent() == null || !app.getHelpContent().containsKey(SLOT)))
|
||||
{
|
||||
app.withHelpContent(SLOT, content(entry.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Summary as the first paragraph, then the content, as markdown.
|
||||
*******************************************************************************/
|
||||
static QHelpContent content(JsonNode entry)
|
||||
{
|
||||
return (new QHelpContent().withContentAsMarkdown(entry.path("summary").asText().strip() + "\n\n" + entry.path("content").asText().strip()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,421 @@
|
||||
bundle: qbit-sql-workbench
|
||||
version: ${project.version}
|
||||
layer: QBIT
|
||||
entries:
|
||||
- key: app:sqlWorkbench;slot:help
|
||||
summary: 'A SQL notebook for your databases: write queries, run them read-only, and review every run afterwards.'
|
||||
content: |
|
||||
The home page is a dashboard of your notebooks and recent runs (admins see everyone's). Use **{{label:sqlWorkbenchRunner}}** to write and run SQL, **{{label:sql_workbench_notebook}}** to manage saved notebooks, and **{{label:sql_workbench_execution}}** to see who ran what.
|
||||
|
||||
**Safe by default.** Runs are read-only and one statement at a time. Writing to the database needs write mode enabled by your administrator, the separate write permission and two steps: a dry run that is rolled back, then a confirmation.
|
||||
|
||||
**Who sees what.** You see your own notebooks, notebooks shared with you, and your own runs. Administrators see everything.
|
||||
|
||||
Raw SQL bypasses normal application record rules, history and search updates. Use application processes for business changes. Every run is recorded in the execution audit.
|
||||
- key: app:sqlWorkbenchRunner;slot:help
|
||||
summary: 'The notebook editor: write SQL and notes in cells, run them, and see results, charts and query plans.'
|
||||
content: |
|
||||
Open a notebook from **{{label:sql_workbench_notebook}}** (the **Open in Runner** link) or start a new one here.
|
||||
|
||||
- A notebook is a list of cells. A SQL cell holds a query, a Markdown cell holds notes.
|
||||
- Each SQL cell runs against one database; read-only is the default.
|
||||
- Named parameters written as :name in the SQL are always bound as values, never pasted into the text.
|
||||
- Saving creates a new version. Results can be pinned as snapshots and exported.
|
||||
|
||||
Only one statement runs per cell in read-only mode, and your administrator sets the limit on simultaneous runs.
|
||||
- key: table:sql_workbench_notebook;slot:help
|
||||
summary: 'A saved SQL notebook: its title, default database, parameters and cells, owned by one person.'
|
||||
content: |
|
||||
**How rows get created:** You create a notebook in the Runner or with New here. It starts with your own content.
|
||||
|
||||
Notebooks are personal until the owner shares them. You can read your own notebooks and ones shared with you; only the owner (or an administrator) can edit or delete one.
|
||||
|
||||
The record view lists the notebook's **Cells**, **Shares**, **Snapshots (pinned results)**, **Versions** and **Runs**, and has an **Open in Runner** link. Actions: **{{label:sqlWorkbenchShareNotebook}}** and **{{label:sqlWorkbenchDuplicateNotebook}}**.
|
||||
|
||||
Creating a notebook here makes you the owner and saves version 1. Deleting a notebook also deletes its cells, versions, pinned results and shares. Past runs stay in **{{label:sql_workbench_execution}}**.
|
||||
- key: table:sql_workbench_notebook;section:identity
|
||||
summary: The notebook's title, description, owner and who can read it.
|
||||
- key: table:sql_workbench_notebook;section:runner
|
||||
summary: A button to open this notebook in the Runner editor.
|
||||
- key: table:sql_workbench_notebook;section:details
|
||||
summary: The default database and the named parameters the notebook's SQL can use.
|
||||
- key: table:sql_workbench_notebook;section:sql_workbench_notebook_join_sql_workbench_cell
|
||||
summary: The SQL and Markdown cells of this notebook, in order.
|
||||
- key: table:sql_workbench_notebook;section:sql_workbench_notebook_join_sql_workbench_notebook_share
|
||||
summary: Who this notebook is shared with, read-only.
|
||||
- key: table:sql_workbench_notebook;section:sql_workbench_notebook_join_sql_workbench_result_snapshot
|
||||
summary: Query results pinned from this notebook so they stay viewable later.
|
||||
- key: table:sql_workbench_notebook;section:sql_workbench_notebook_join_sql_workbench_notebook_version
|
||||
summary: The saved history of this notebook, newest first (the latest 25 are shown).
|
||||
- key: table:sql_workbench_notebook;section:sql_workbench_notebook_join_sql_workbench_execution
|
||||
summary: The most recent runs of this notebook (latest 25), taken from the execution audit.
|
||||
- key: table:sql_workbench_notebook;section:system
|
||||
summary: Owner id, current version number and created and changed dates, all filled in automatically.
|
||||
- key: table:sql_workbench_notebook;field:title
|
||||
summary: The name shown in the notebook list and the Runner.
|
||||
content: |
|
||||
Required. Surrounding spaces are removed and it cannot be blank. Up to {{maxLength:sql_workbench_notebook.title}} characters.
|
||||
- key: table:sql_workbench_notebook;field:description
|
||||
summary: A short note about what the notebook is for.
|
||||
- key: table:sql_workbench_notebook;field:defaultBackendName
|
||||
summary: The database new SQL cells run against unless a cell picks its own.
|
||||
content: |
|
||||
Leave it blank to choose per cell. Your administrator controls which databases are available.
|
||||
- key: table:sql_workbench_notebook;field:parametersJson
|
||||
summary: Named parameters for the SQL, as a JSON list with a name, type, default value and label for each.
|
||||
content: |
|
||||
Reference a parameter in SQL as :name. Values are always bound safely, never pasted into the statement. The Runner has a parameters panel that edits this for you; if you type it by hand it must be a valid JSON list or the save is refused.
|
||||
- key: table:sql_workbench_notebook;field:ownerUserId
|
||||
summary: The sign-in id of the owner, set automatically from whoever created the notebook.
|
||||
content: |
|
||||
Only an administrator can change it, which transfers the notebook to someone else (the owner name then follows the new id).
|
||||
- key: table:sql_workbench_notebook;field:ownerName
|
||||
summary: The owner's display name, copied from their account when the notebook was created.
|
||||
- key: table:sql_workbench_notebook;field:currentVersion
|
||||
summary: The number of the newest saved version, increased by every save.
|
||||
- key: table:sql_workbench_notebook;field:visibility
|
||||
summary: Whether the notebook is in the shared library or limited to its owner, administrators and other share audiences.
|
||||
content: |
|
||||
- **PERSONAL**: not published to everyone.
|
||||
- **SHARED**: shared with Everyone (the shared library).
|
||||
|
||||
You cannot edit this directly. It follows the notebook's shares: add an Everyone share to publish it, remove that share to make it personal again.
|
||||
- key: table:sql_workbench_notebook_share;slot:help
|
||||
summary: One person, group or everyone who may read a notebook, read-only.
|
||||
content: |
|
||||
**How rows get created:** You use Share Notebook or add a share from the notebook's Shares list.
|
||||
|
||||
A share never lets anyone edit the notebook; it only lets them open and run it. Add one from a notebook's **Shares** list or with the **{{label:sqlWorkbenchShareNotebook}}** action. You need the share permission, and only the notebook's owner or an administrator can add or remove shares.
|
||||
|
||||
Share with Everyone to make the notebook available in the shared library.
|
||||
- key: table:sql_workbench_notebook_share;section:identity
|
||||
summary: The notebook and who it is shared with.
|
||||
- key: table:sql_workbench_notebook_share;section:system
|
||||
summary: The matching key, who added the share and when, all filled in automatically.
|
||||
- key: table:sql_workbench_notebook_share;field:audienceType
|
||||
summary: Whether the share goes to one person, a group, or everyone.
|
||||
content: |
|
||||
- **User**: one person, named in User or Group.
|
||||
- **Group**: a sign-in group, named in User or Group.
|
||||
- **Everyone (shared library)**: all workbench users; no name needed. This publishes the notebook to the shared library.
|
||||
- key: table:sql_workbench_notebook_share;field:audienceId
|
||||
summary: The user id or group name to share with; leave blank for Everyone.
|
||||
content: |
|
||||
Required for User and Group shares. Matching ignores upper and lower case and surrounding spaces, so Admins and admins are the same group.
|
||||
- key: table:sql_workbench_notebook_share;field:notebookId
|
||||
summary: The notebook being shared. It cannot be moved to another notebook after the share is created.
|
||||
- key: table:sql_workbench_notebook_share;field:audienceKey
|
||||
summary: The normalized form of the audience, such as user:name, group:name or all, used for access checks.
|
||||
content: |
|
||||
Filled in automatically from the type and name.
|
||||
- key: table:sql_workbench_notebook_share;field:createdByUserId
|
||||
summary: The sign-in id of the person who added the share, set automatically.
|
||||
- key: table:sql_workbench_notebook_share;field:createdByName
|
||||
summary: The display name of the person who added the share, set automatically.
|
||||
- key: table:sql_workbench_cell;slot:help
|
||||
summary: 'One block of a notebook: a SQL query or a Markdown note.'
|
||||
content: |
|
||||
**How rows get created:** You add SQL or Markdown cells to a notebook in the Runner or from its Cells list.
|
||||
|
||||
Cells are normally edited in the Runner, but you can add, edit, reorder and delete them here. A notebook can hold at most 200 cells, and your administrator sets the SQL length limit.
|
||||
|
||||
Every add, edit or delete saves a new notebook version, just like saving in the Runner. A new cell is added at the end with a generated key. Only the notebook's owner or an administrator can change cells.
|
||||
- key: table:sql_workbench_cell;section:identity
|
||||
summary: Which notebook the cell belongs to, its position, type and title.
|
||||
- key: table:sql_workbench_cell;section:content
|
||||
summary: The SQL or Markdown text and the database the cell runs against.
|
||||
- key: table:sql_workbench_cell;section:system
|
||||
summary: The cell's generated key and created and changed dates, filled in automatically.
|
||||
- key: table:sql_workbench_cell;field:notebookId
|
||||
summary: The notebook this cell belongs to. A cell cannot be moved to a different notebook.
|
||||
- key: table:sql_workbench_cell;field:cellKey
|
||||
summary: A generated unique key that stays with the cell. Pinned results and run history refer to it.
|
||||
content: |
|
||||
Set automatically when the cell is created and it cannot be changed.
|
||||
- key: table:sql_workbench_cell;field:sortOrder
|
||||
summary: The cell's position in the notebook, lowest first.
|
||||
content: |
|
||||
Left blank on a new cell it is placed at the end. Change the numbers to reorder cells.
|
||||
- key: table:sql_workbench_cell;field:cellType
|
||||
summary: Whether the cell is runnable SQL or a Markdown note.
|
||||
content: |
|
||||
- **SQL**: a query that you can run. Default: {{default:sql_workbench_cell.cellType}}.
|
||||
- **Markdown**: formatted notes that are displayed, never run.
|
||||
- key: table:sql_workbench_cell;field:title
|
||||
summary: "An optional heading for the cell."
|
||||
content: |
|
||||
Give the cell an optional heading of up to {{maxLength:sql_workbench_cell.title}} characters.
|
||||
- key: table:sql_workbench_cell;field:content
|
||||
summary: The SQL text or Markdown. SQL can use :name parameters defined on the notebook.
|
||||
content: |
|
||||
Your administrator sets the maximum SQL length.
|
||||
- key: table:sql_workbench_cell;field:backendName
|
||||
summary: The database this SQL cell runs against; blank uses the notebook's default.
|
||||
- key: table:sql_workbench_notebook_version;slot:help
|
||||
summary: 'A read-only history entry: the full content of a notebook as it was at one save.'
|
||||
content: |
|
||||
**How rows get created:** The workbench saves a version when you create or change a notebook or its cells.
|
||||
|
||||
A new version is written each time the notebook is saved, a cell is added, edited or removed, or an older version is restored. It holds the title, description, parameters and all cells. You cannot edit or delete versions yourself. Older versions are pruned according to your administrator's retention setting.
|
||||
|
||||
To go back, run **{{label:sqlWorkbenchRestoreNotebookVersion}}** on the version you want. That saves it as a new, latest version, while retained versions remain available.
|
||||
- key: table:sql_workbench_notebook_version;section:identity
|
||||
summary: Which notebook and version number this is, and the note saved with it.
|
||||
- key: table:sql_workbench_notebook_version;section:content
|
||||
summary: The saved notebook content as JSON.
|
||||
- key: table:sql_workbench_notebook_version;section:system
|
||||
summary: Who saved this version and when, filled in automatically.
|
||||
- key: table:sql_workbench_notebook_version;field:notebookId
|
||||
summary: The notebook this version belongs to.
|
||||
- key: table:sql_workbench_notebook_version;field:versionNumber
|
||||
summary: The version's number, counting up from 1 within its notebook.
|
||||
- key: table:sql_workbench_notebook_version;field:comment
|
||||
summary: A short note on why the version was saved, such as Created, Cell added, Cell edited or Restored version 3.
|
||||
- key: table:sql_workbench_notebook_version;field:contentJson
|
||||
summary: The notebook's title, description, default database, parameters and every cell, saved as JSON.
|
||||
- key: table:sql_workbench_notebook_version;field:savedByUserId
|
||||
summary: The sign-in id of the person who saved this version.
|
||||
- key: table:sql_workbench_notebook_version;field:savedByName
|
||||
summary: The display name of the person who saved this version.
|
||||
- key: table:sql_workbench_result_snapshot;slot:help
|
||||
summary: A query result pinned from a notebook so you can look at it later without re-running the SQL.
|
||||
content: |
|
||||
**How rows get created:** You run a query in the Runner and pin its result to your notebook.
|
||||
|
||||
Pin a result from the Runner after running a cell. A snapshot keeps the column list, rows up to the configured snapshot limit, the SQL that produced it and the database it came from. It contains real query data, so it is visible only to the notebook's readers and administrators.
|
||||
|
||||
You cannot add snapshots here, and the only thing you can edit is the **{{label:sql_workbench_result_snapshot.label}}**. Delete a snapshot you no longer need.
|
||||
- key: table:sql_workbench_result_snapshot;section:identity
|
||||
summary: Which notebook and cell the result came from and its label.
|
||||
- key: table:sql_workbench_result_snapshot;section:result
|
||||
summary: The pinned rows, the SQL and database that produced them, and whether the result was cut short.
|
||||
- key: table:sql_workbench_result_snapshot;section:system
|
||||
summary: Who pinned the result and when, filled in automatically.
|
||||
- key: table:sql_workbench_result_snapshot;field:notebookId
|
||||
summary: The notebook the result was pinned from.
|
||||
- key: table:sql_workbench_result_snapshot;field:cellKey
|
||||
summary: The key of the notebook cell that produced the result.
|
||||
- key: table:sql_workbench_result_snapshot;field:label
|
||||
summary: "A name you give the pinned result to find it again."
|
||||
content: |
|
||||
A name you give the pinned result to find it again. This is the only editable field. Up to {{maxLength:sql_workbench_result_snapshot.label}} characters.
|
||||
- key: table:sql_workbench_result_snapshot;field:backendName
|
||||
summary: The database the SQL ran against, recorded when the result was pinned.
|
||||
- key: table:sql_workbench_result_snapshot;field:executionUuid
|
||||
summary: The id of the run that produced this result; it matches a row in SQL Execution Audit.
|
||||
- key: table:sql_workbench_result_snapshot;field:sqlText
|
||||
summary: The SQL that produced the pinned result, as it was when you pinned it.
|
||||
- key: table:sql_workbench_result_snapshot;field:resultJson
|
||||
summary: The pinned columns and rows as JSON, up to the configured snapshot limit.
|
||||
- key: table:sql_workbench_result_snapshot;field:rowCount
|
||||
summary: How many rows the snapshot holds.
|
||||
- key: table:sql_workbench_result_snapshot;field:truncated
|
||||
summary: Yes when the result had more rows than could be kept, so the snapshot holds only the first part.
|
||||
- key: table:sql_workbench_result_snapshot;field:createdByUserId
|
||||
summary: The sign-in id of the person who pinned the result.
|
||||
- key: table:sql_workbench_execution;slot:help
|
||||
summary: 'The audit log of SQL runs: who ran what, where, how long it took and how it ended.'
|
||||
content: |
|
||||
**How rows get created:** The workbench records runs before executing SQL, including rejected SQL attempts.
|
||||
|
||||
Every run is recorded before the SQL starts, and attempts that were refused are logged too, so this is the place to answer "who changed or read this?". Rows are added and updated by the workbench only; you cannot edit or delete them. Your administrator can configure automatic removal of older completed runs.
|
||||
|
||||
You see your own runs; administrators see everyone's. The log keeps the SQL text and parameter values, but never the result rows.
|
||||
|
||||
Use the filters on **{{label:sql_workbench_execution.status}}**, **{{label:sql_workbench_execution.mode}}**, **User** and **{{label:sql_workbench_execution.startTime}}** to narrow it down, or open a run from a notebook's **Runs** list.
|
||||
- key: table:sql_workbench_execution;section:identity
|
||||
summary: The run's id, mode, outcome and database.
|
||||
- key: table:sql_workbench_execution;section:run
|
||||
summary: Who ran it, when, how long it took, and how many rows came back or changed.
|
||||
- key: table:sql_workbench_execution;section:sql
|
||||
summary: The SQL text, its fingerprint, the parameter values used and any error.
|
||||
- key: table:sql_workbench_execution;section:system
|
||||
summary: When the audit row was created, filled in automatically.
|
||||
- key: table:sql_workbench_execution;field:executionUuid
|
||||
summary: A unique id for the run, also used to fetch its results and match pinned snapshots.
|
||||
- key: table:sql_workbench_execution;field:mode
|
||||
summary: How the SQL was run.
|
||||
content: |
|
||||
- **READ_ONLY**: a normal read-only run.
|
||||
- **WRITE_PREVIEW**: a dry run of a write, rolled back so you can see the affected-row counts.
|
||||
- **WRITE_COMMIT**: the confirmed write, committed.
|
||||
- **EXPLAIN**: a query plan without running the query.
|
||||
- **EXPLAIN_ANALYZE**: a query plan that actually runs the query (needs the write permission).
|
||||
- key: table:sql_workbench_execution;field:status
|
||||
summary: How the run ended, or Running while it is still going.
|
||||
content: |
|
||||
- **RUNNING**: in progress. A run that never finishes may stay here.
|
||||
- **SUCCEEDED**: finished normally.
|
||||
- **FAILED**: the database returned an error (see Error).
|
||||
- **CANCELLED**: someone stopped it.
|
||||
- **TIMED_OUT**: it went over the time limit configured by your administrator.
|
||||
- **REJECTED**: refused before running, for example the SQL was not a plain read.
|
||||
- **ROLLED_BACK**: a write preview, undone on purpose.
|
||||
- **DRIFTED**: the data changed between preview and confirm, so the write was rolled back.
|
||||
- key: table:sql_workbench_execution;field:backendName
|
||||
summary: The database the SQL ran against.
|
||||
- key: table:sql_workbench_execution;field:userId
|
||||
summary: The sign-in id of the person who ran it.
|
||||
- key: table:sql_workbench_execution;field:userName
|
||||
summary: The display name of the person who ran it, as it was at the time.
|
||||
- key: table:sql_workbench_execution;field:startTime
|
||||
summary: When the run started.
|
||||
- key: table:sql_workbench_execution;field:endTime
|
||||
summary: When the run finished; blank while it is still running.
|
||||
- key: table:sql_workbench_execution;field:durationMs
|
||||
summary: How long the run took, in milliseconds.
|
||||
- key: table:sql_workbench_execution;field:rowsReturned
|
||||
summary: How many result rows a read returned, up to the configured row limit.
|
||||
- key: table:sql_workbench_execution;field:rowsAffected
|
||||
summary: How many rows a write changed or, for a preview, would change.
|
||||
- key: table:sql_workbench_execution;field:truncated
|
||||
summary: Yes when the result hit the row or size limit and was cut short.
|
||||
- key: table:sql_workbench_execution;field:statementCount
|
||||
summary: How many SQL statements the run contained. Read-only runs allow one.
|
||||
- key: table:sql_workbench_execution;field:statementKinds
|
||||
summary: The kinds of statement the run was classified as, separated by commas.
|
||||
- key: table:sql_workbench_execution;field:notebookId
|
||||
summary: The notebook the run came from; blank for SQL run outside a notebook.
|
||||
- key: table:sql_workbench_execution;field:cellKey
|
||||
summary: The key of the notebook cell that was run, if any.
|
||||
- key: table:sql_workbench_execution;field:sqlText
|
||||
summary: The exact SQL that was run (or refused). It can contain sensitive literals, so treat it as confidential.
|
||||
- key: table:sql_workbench_execution;field:sqlHash
|
||||
summary: A fingerprint of the database, SQL and parameters, useful for spotting repeated queries.
|
||||
- key: table:sql_workbench_execution;field:parametersJson
|
||||
summary: The values bound to the named parameters for this run, stored as written.
|
||||
- key: table:sql_workbench_execution;field:errorMessage
|
||||
summary: The error text when the run failed, timed out or was rejected, cut off at 4,000 characters.
|
||||
- key: table:sql_workbench_execution;field:clientIp
|
||||
summary: The network address the request came from, when it was available.
|
||||
- key: process:sqlWorkbenchShareNotebook;slot:help
|
||||
summary: Share the selected notebook, read-only, with one user, one group or everyone who can use the SQL Workbench.
|
||||
content: |
|
||||
Select one notebook, choose who to share with, and run. Recipients can open the notebook but cannot change it; to edit, they duplicate it into their own copy. Only the owner or an administrator changes the original.
|
||||
|
||||
Sharing with a **User** gives that person read access. Sharing with **Everyone** puts it in the shared library. Sharing needs the notebook share permission. To stop sharing, delete the share under **Shares** on the notebook.
|
||||
- key: process:sqlWorkbenchShareNotebook;field:audienceType
|
||||
summary: 'Who gets access: one user, one group, or everyone.'
|
||||
content: |
|
||||
Choose **User** or **Group** and fill in the next field, or **Everyone (shared library)** to share with every workbench user.
|
||||
- key: process:sqlWorkbenchShareNotebook;field:audienceId
|
||||
summary: The user name or group name to share with; leave blank when sharing with everyone.
|
||||
content: |
|
||||
Names are not case sensitive. Required for User and Group.
|
||||
- key: process:sqlWorkbenchDuplicateNotebook;slot:help
|
||||
summary: Make your own copy of a notebook you can open, with all its cells, parameters and default database.
|
||||
content: |
|
||||
The copy is titled "Copy of" followed by the original title, is owned by you, and starts at version 1 with the note "Duplicated from notebook" and the original's number. Sharing, pinned results and run history are not copied. Duplicate a shared notebook to change it, since shared access is read-only. Works on one notebook at a time.
|
||||
- key: process:sqlWorkbenchRestoreNotebookVersion;slot:help
|
||||
summary: Bring back an earlier saved version of a notebook you own.
|
||||
content: |
|
||||
Select one version under **Versions** and run. The notebook's content goes back to that version and is saved as a new version, with the comment "Restored version" and the number. Other retained versions stay in the history, subject to the retention limit. You must own the notebook to use this action.
|
||||
- key: widget:sql_workbench_notebook_join_sql_workbench_cell;slot:label
|
||||
summary: 'The notebook''s cells, in order: each is a block of SQL or Markdown notes.'
|
||||
- key: widget:sql_workbench_notebook_join_sql_workbench_notebook_share;slot:label
|
||||
summary: 'Who this notebook is shared with: users, groups, or everyone.'
|
||||
- key: widget:sql_workbench_notebook_join_sql_workbench_result_snapshot;slot:label
|
||||
summary: Query results pinned to this notebook, kept as they were when pinned.
|
||||
- key: widget:sql_workbench_notebook_join_sql_workbench_notebook_version;slot:label
|
||||
summary: Every saved version of this notebook, newest first; use Restore Version to bring one back.
|
||||
- key: widget:sql_workbench_notebook_join_sql_workbench_execution;slot:label
|
||||
summary: Recent runs of this notebook's queries, with who ran them and how they ended.
|
||||
- key: widget:sqlWorkbenchWidget;slot:label
|
||||
summary: 'The SQL Workbench runner: write, run and save SQL notebooks against your available databases.'
|
||||
- key: widget:sqlWorkbenchHomeSummary;slot:label
|
||||
summary: Counts of notebooks, runs today, runs and failures in the last 7 days, and writes in the last 30 days.
|
||||
- key: widget:sqlWorkbenchHomeRunsPerDay;slot:label
|
||||
summary: A line chart of runs, failures and committed writes for each of the last 30 days.
|
||||
- key: widget:sqlWorkbenchHomeRecentNotebooks;slot:label
|
||||
summary: The 10 notebooks changed most recently that you can open.
|
||||
- key: widget:sqlWorkbenchHomeRecentRuns;slot:label
|
||||
summary: The 10 most recent query runs you can see.
|
||||
- key: widget:sqlWorkbenchHomeSlowestQueries;slot:label
|
||||
summary: The 10 slowest completed query runs of the last 30 days.
|
||||
- key: widget:sqlWorkbenchHomeFailedQueries;slot:label
|
||||
summary: The latest failed, timed-out, rejected or rolled-back runs of the last 30 days, with the error.
|
||||
- key: widget:sqlWorkbenchHomeMostUsedNotebooks;slot:label
|
||||
summary: The notebooks with the most runs in the last 30 days, with the number of users and the last run.
|
||||
- key: widget:sqlWorkbenchHomeSharedNotebooks;slot:label
|
||||
summary: Notebooks that have been shared, who owns them, who they are shared with and since when.
|
||||
- key: widget:sqlWorkbenchHomeWrites;slot:label
|
||||
summary: 'Changes committed to the database through the workbench: who, what, when, and how many rows.'
|
||||
- key: widget:sqlWorkbenchHomeActivityByUser;slot:label
|
||||
summary: Runs, failures and writes per user over the last 30 days; visible to workbench admins.
|
||||
- key: widget:sqlWorkbenchNotebookOpenInRunner;slot:label
|
||||
summary: A button on a notebook that opens it in the runner to edit and run its cells.
|
||||
- key: possibleValueSource:sql_workbench_share_audience_type;slot:help
|
||||
summary: Who a notebook can be shared with.
|
||||
content: |
|
||||
- **User**: one named person.
|
||||
- **Group**: everyone in a named group.
|
||||
- **Everyone (shared library)**: every workbench user.
|
||||
- key: possibleValueSource:sql_workbench_cell_type;slot:help
|
||||
summary: What a notebook cell holds.
|
||||
content: |
|
||||
- **SQL**: a query you can run.
|
||||
- **Markdown**: formatted notes that are not run.
|
||||
- key: possibleValueSource:sql_workbench_backend;slot:help
|
||||
summary: The databases your administrator makes available for workbench queries.
|
||||
- key: possibleValueSource:sql_workbench_notebook;slot:help
|
||||
summary: Choose a notebook you can access by its title.
|
||||
- key: process:sql_workbench_notebook.bulkInsert;slot:help
|
||||
summary: Create notebooks from a file.
|
||||
content: |
|
||||
Upload your file and map its columns to the fields in **{{label:sql_workbench_notebook}}**. Review the input before creating records. The same permissions and validation apply as when you add a single record.
|
||||
- key: process:sql_workbench_notebook.bulkEdit;slot:help
|
||||
summary: Change selected notebooks together.
|
||||
content: |
|
||||
Select the records to change in **{{label:sql_workbench_notebook}}**, choose the fields and enter their new values. Review your changes before applying them. You can change only records you have permission to edit.
|
||||
- key: process:sql_workbench_notebook.bulkEditWithFile;slot:help
|
||||
summary: Update notebooks using values from a file.
|
||||
content: |
|
||||
Upload your file and map its columns to the fields in **{{label:sql_workbench_notebook}}**. Match the rows to existing records and review the changes. Your normal edit permissions and field validation still apply.
|
||||
- key: process:sql_workbench_notebook.bulkDelete;slot:help
|
||||
summary: Delete selected notebooks.
|
||||
content: |
|
||||
Review your selected records in **{{label:sql_workbench_notebook}}** before confirming deletion. You can delete only records you have permission to remove. Deleting a notebook also removes its cells, shares, snapshots and versions; execution audit rows remain subject to retention.
|
||||
- key: process:sql_workbench_cell.bulkInsert;slot:help
|
||||
summary: Create cells from a file.
|
||||
content: |
|
||||
Upload your file and map its columns to the fields in **{{label:sql_workbench_cell}}**. Review the input before creating records. The same permissions and validation apply as when you add a single record.
|
||||
- key: process:sql_workbench_cell.bulkEdit;slot:help
|
||||
summary: Change selected cells together.
|
||||
content: |
|
||||
Select the records to change in **{{label:sql_workbench_cell}}**, choose the fields and enter their new values. Review your changes before applying them. You can change only records you have permission to edit.
|
||||
- key: process:sql_workbench_cell.bulkEditWithFile;slot:help
|
||||
summary: Update cells using values from a file.
|
||||
content: |
|
||||
Upload your file and map its columns to the fields in **{{label:sql_workbench_cell}}**. Match the rows to existing records and review the changes. Your normal edit permissions and field validation still apply.
|
||||
- key: process:sql_workbench_cell.bulkDelete;slot:help
|
||||
summary: Delete selected cells.
|
||||
content: |
|
||||
Review your selected records in **{{label:sql_workbench_cell}}** before confirming deletion. You can delete only records you have permission to remove.
|
||||
- key: process:sql_workbench_notebook_share.bulkInsert;slot:help
|
||||
summary: Create shares from a file.
|
||||
content: |
|
||||
Upload your file and map its columns to the fields in **{{label:sql_workbench_notebook_share}}**. Review the input before creating records. The same permissions and validation apply as when you add a single record.
|
||||
- key: process:sql_workbench_notebook_share.bulkEdit;slot:help
|
||||
summary: Change selected shares together.
|
||||
content: |
|
||||
Select the records to change in **{{label:sql_workbench_notebook_share}}**, choose the fields and enter their new values. Review your changes before applying them. You can change only records you have permission to edit.
|
||||
- key: process:sql_workbench_notebook_share.bulkEditWithFile;slot:help
|
||||
summary: Update shares using values from a file.
|
||||
content: |
|
||||
Upload your file and map its columns to the fields in **{{label:sql_workbench_notebook_share}}**. Match the rows to existing records and review the changes. Your normal edit permissions and field validation still apply.
|
||||
- key: process:sql_workbench_notebook_share.bulkDelete;slot:help
|
||||
summary: Delete selected shares.
|
||||
content: |
|
||||
Review your selected records in **{{label:sql_workbench_notebook_share}}** before confirming deletion. You can delete only records you have permission to remove. Removing a share ends that access grant; other shares can still allow access.
|
||||
- key: process:sql_workbench_result_snapshot.bulkEdit;slot:help
|
||||
summary: Change selected snapshots together.
|
||||
content: |
|
||||
Select the records to change in **{{label:sql_workbench_result_snapshot}}**, choose the fields and enter their new values. Review your changes before applying them. You can change only records you have permission to edit. Only the snapshot label is editable.
|
||||
- key: process:sql_workbench_result_snapshot.bulkEditWithFile;slot:help
|
||||
summary: Update snapshots using values from a file.
|
||||
content: |
|
||||
Upload your file and map its columns to the fields in **{{label:sql_workbench_result_snapshot}}**. Match the rows to existing records and review the changes. Your normal edit permissions and field validation still apply. Only the snapshot label is editable.
|
||||
- key: process:sql_workbench_result_snapshot.bulkDelete;slot:help
|
||||
summary: Delete selected snapshots.
|
||||
content: |
|
||||
Review your selected records in **{{label:sql_workbench_result_snapshot}}** before confirming deletion. You can delete only records you have permission to remove.
|
||||
File diff suppressed because it is too large.
Load diff
@@ -203,6 +203,106 @@ class PostgresIntegrationTest
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** The shipped DDL gives every foreign-key column and the notebook_id the
|
||||
** "Runs" list joins on a leading index, so notebook pages and notebook
|
||||
** deletes do not scan the child tables.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testShippedDdlIndexesNotebookChildColumns() throws Exception
|
||||
{
|
||||
String sql = """
|
||||
SELECT c.conrelid::regclass::text || '.' || a.attname
|
||||
FROM pg_constraint c
|
||||
JOIN pg_attribute a ON a.attrelid = c.conrelid AND a.attnum = c.conkey[1]
|
||||
WHERE c.contype = 'f' AND c.conrelid::regclass::text LIKE 'sql_workbench_%'
|
||||
AND NOT EXISTS (SELECT 1 FROM pg_index i WHERE i.indrelid = c.conrelid AND i.indkey[0] = c.conkey[1])
|
||||
""";
|
||||
try(Connection connection = java.sql.DriverManager.getConnection(POSTGRES.getJdbcUrl(), POSTGRES.getUsername(), POSTGRES.getPassword());
|
||||
Statement statement = connection.createStatement())
|
||||
{
|
||||
java.util.List<String> unindexed = new java.util.ArrayList<>();
|
||||
try(java.sql.ResultSet result = statement.executeQuery(sql))
|
||||
{
|
||||
while(result.next())
|
||||
{
|
||||
unindexed.add(result.getString(1));
|
||||
}
|
||||
}
|
||||
assertThat(unindexed).isEmpty();
|
||||
try(java.sql.ResultSet result = statement.executeQuery("SELECT 1 FROM pg_indexes WHERE indexname = 'ix_sql_workbench_execution_notebook'"))
|
||||
{
|
||||
assertThat(result.next()).isTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Referential integrity guardrail: every join and every table possible-value
|
||||
** reference between the workbench's tables has a foreign key in the shipped
|
||||
** DDL, or an exemption with its reason. A new reference without a
|
||||
** constraint fails here.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testShippedDdlHasAForeignKeyForEveryReference() throws Exception
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// "child.column" -> why it is deliberately not a foreign key //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
Map<String, String> exempt = Map.of(
|
||||
"sql_workbench_execution.notebook_id", "the execution audit is append-only and outlives its notebook: no CASCADE into it, "
|
||||
+ "RESTRICT would block deleting any notebook that ever ran, SET NULL would rewrite audit rows, and an execution records "
|
||||
+ "the client's notebook id even if the notebook was deleted meanwhile (the audit insert must never fail)");
|
||||
|
||||
java.util.Set<String> references = new java.util.TreeSet<>();
|
||||
for(com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData table : qInstance.getTables().values())
|
||||
{
|
||||
for(com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData field : table.getFields().values())
|
||||
{
|
||||
if(field.getPossibleValueSourceName() != null && qInstance.getTable(field.getPossibleValueSourceName()) != null)
|
||||
{
|
||||
references.add(table.getName() + "." + field.getBackendName());
|
||||
}
|
||||
}
|
||||
}
|
||||
for(com.kingsrook.qqq.backend.core.model.metadata.joins.QJoinMetaData join : qInstance.getJoins().values())
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// the referencing side is the one whose field is not its primary key //
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData left = qInstance.getTable(join.getLeftTable());
|
||||
com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData right = qInstance.getTable(join.getRightTable());
|
||||
join.getJoinOns().forEach(on -> references.add(on.getRightField().equals(right.getPrimaryKeyField())
|
||||
? left.getName() + "." + left.getField(on.getLeftField()).getBackendName()
|
||||
: right.getName() + "." + right.getField(on.getRightField()).getBackendName()));
|
||||
}
|
||||
assertThat(references).as("the workbench's references").contains("sql_workbench_cell.notebook_id", "sql_workbench_execution.notebook_id");
|
||||
|
||||
java.util.Set<String> foreignKeys = new java.util.HashSet<>();
|
||||
try(Connection connection = java.sql.DriverManager.getConnection(POSTGRES.getJdbcUrl(), POSTGRES.getUsername(), POSTGRES.getPassword());
|
||||
Statement statement = connection.createStatement();
|
||||
ResultSet result = statement.executeQuery("""
|
||||
SELECT c.conrelid::regclass::text || '.' || a.attname
|
||||
FROM pg_constraint c
|
||||
JOIN pg_attribute a ON a.attrelid = c.conrelid AND a.attnum = c.conkey[1]
|
||||
WHERE c.contype = 'f'
|
||||
"""))
|
||||
{
|
||||
while(result.next())
|
||||
{
|
||||
foreignKeys.add(result.getString(1));
|
||||
}
|
||||
}
|
||||
|
||||
java.util.List<String> missing = references.stream().filter(r -> !foreignKeys.contains(r) && !exempt.containsKey(r)).toList();
|
||||
assertThat(missing).as("references without a foreign key (add one to docs/ddl/postgres.sql, or an exemption with a reason)").isEmpty();
|
||||
assertThat(foreignKeys).as("exemptions that now have a foreign key").doesNotContainAnyElementsOf(exempt.keySet());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** The database itself refuses writes in a workbench read-only session,
|
||||
** even for SQL the classifier would never let through.
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench;
|
||||
|
||||
|
||||
import com.kingsrook.qqq.backend.core.actions.help.HelpTargetCatalog;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.help.bundles.HelpBundles;
|
||||
import com.kingsrook.qqq.backend.core.testing.HelpBundleAssertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Checks the shipped help against the metadata produced by this QBit.
|
||||
*******************************************************************************/
|
||||
class SqlWorkbenchHelpBundleTest extends BaseSqlWorkbenchTest
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Owned objects and their non-trivial fields must have valid help.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void bundleCoversWorkbench()
|
||||
{
|
||||
HelpBundleAssertions.forInstance(qInstance)
|
||||
.bundles("help/qbit-sql-workbench.yaml")
|
||||
.owning(target -> target.name().startsWith("sqlWorkbench") || target.name().startsWith("sql_workbench_"))
|
||||
.assertComplete();
|
||||
|
||||
// Core requires apps, tables, fields and processes; also cover our widgets and value sources.
|
||||
var keys = HelpBundles.of(qInstance).getBundles().get(0).getEntries().stream().map(entry -> entry.getKey()).toList();
|
||||
HelpTargetCatalog.collect(qInstance).stream()
|
||||
.filter(target -> target.kind().equals("widget") || target.kind().equals("possibleValueSource"))
|
||||
.filter(target -> target.name().startsWith("sqlWorkbench") || target.name().startsWith("sql_workbench_"))
|
||||
.forEach(target -> assertThat(keys).as(target.key()).contains(target.key()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Registration remains useful and startup sync is harmless without storage.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void registersWithoutHelpContentTable()
|
||||
{
|
||||
assertThat(qInstance.getTable("helpContent")).isNull();
|
||||
assertThat(HelpBundles.of(qInstance).getBundles()).singleElement().satisfies(bundle ->
|
||||
{
|
||||
assertThat(bundle.getId()).isEqualTo("qbit-sql-workbench");
|
||||
assertThat(bundle.getVersion()).isEqualTo(SqlWorkbenchQBitProducer.getVersion());
|
||||
assertThat(bundle.getLayer().name()).isEqualTo("QBIT");
|
||||
});
|
||||
assertThatCode(() -> HelpBundles.syncOnStartup(qInstance)).doesNotThrowAnyException();
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ import com.kingsrook.qqq.backend.core.model.metadata.processes.QProcessMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
import com.kingsrook.qqq.backend.core.modules.backend.implementations.memory.MemoryBackendModule;
|
||||
import com.kingsrook.qqq.backend.module.rdbms.model.metadata.RDBMSTableBackendDetails;
|
||||
import com.kingsrook.qqq.middleware.javalin.QJavalinMetaData;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.extensions.MiddlewareSpecExtensionsMetaData;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
@@ -137,7 +137,7 @@ class SqlWorkbenchQBitProducerTest extends BaseSqlWorkbenchTest
|
||||
assertThat(runner.getPermissionRules().getPermissionBaseName()).isEqualTo("sql_workbench");
|
||||
assertThat(app.getChildren()).noneMatch(child -> child instanceof QProcessMetaData);
|
||||
|
||||
assertThat(QJavalinMetaData.of(qInstance).getAdditionalRouteProviderReferences()).isNotEmpty();
|
||||
assertThat(MiddlewareSpecExtensionsMetaData.ofOrWithNew(qInstance).getExtensions()).isNotEmpty();
|
||||
assertThat(SqlWorkbenchRuntime.get(qInstance)).isNotNull();
|
||||
assertThat(new SqlWorkbenchWidgetRenderer().render(null).getWidgetData().getType()).isEqualTo("SQL_WORKBENCH");
|
||||
assertThat(SqlWorkbenchQBitProducer.getVersion()).isNotBlank();
|
||||
@@ -164,7 +164,7 @@ class SqlWorkbenchQBitProducerTest extends BaseSqlWorkbenchTest
|
||||
assertThat(instance.getPossibleValueSource("ns_sql_workbench_backend")).isNotNull();
|
||||
assertThat(instance.getTable("ns_sql_workbench_cell").getField("cellType").getPossibleValueSourceName()).isEqualTo("ns_sql_workbench_cell_type");
|
||||
assertThat(instance.getPossibleValueSource("ns_sql_workbench_cell_type")).isNotNull();
|
||||
assertThat(QJavalinMetaData.of(instance)).isNull();
|
||||
assertThat(MiddlewareSpecExtensionsMetaData.of(instance)).isNull();
|
||||
|
||||
SqlWorkbenchRuntime first = prefixed.getRuntime();
|
||||
new SqlWorkbenchQBitProducer().withQBitConfig(prefixed).getQBitMetaData();
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench;
|
||||
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
import com.kingsrook.qbits.sqlworkbench.metadata.SqlWorkbenchHelp;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.help.QHelpContent;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Guardrail (owner requirement 2026-10-14: "all tables should be populated and
|
||||
** the qbit should be fully using them"). For every sql_workbench_* table:
|
||||
** - runtime code (not just its model, metadata or home dashboard) reads or
|
||||
** writes it, so no table exists only on paper;
|
||||
** - it is listed in STARTS_EMPTY with why (every table here is user content or
|
||||
** a log, so none is seeded);
|
||||
** - it has bundle help that says what it is for and how its rows get created.
|
||||
** A new table fails this test until it is wired and explained.
|
||||
*******************************************************************************/
|
||||
class SqlWorkbenchTablesGuardrailTest extends BaseSqlWorkbenchTest
|
||||
{
|
||||
private static final Path MAIN = Path.of("src", "main", "java", "com", "kingsrook", "qbits", "sqlworkbench");
|
||||
|
||||
/*******************************************************************************
|
||||
** Every table legitimately starts empty, and where its rows come from.
|
||||
*******************************************************************************/
|
||||
static final Map<String, String> STARTS_EMPTY = Map.of(
|
||||
"sql_workbench_notebook", "user content: someone saves a notebook",
|
||||
"sql_workbench_cell", "user content: the cells of a saved notebook",
|
||||
"sql_workbench_notebook_version", "runtime: every notebook save",
|
||||
"sql_workbench_notebook_share", "user content: someone shares a notebook",
|
||||
"sql_workbench_result_snapshot", "user content: someone pins a result",
|
||||
"sql_workbench_execution", "runtime: every statement run (the audit)");
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Every table is used by runtime code.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void everyTableIsUsedAtRuntime() throws Exception
|
||||
{
|
||||
Map<String, String> entityByTable = entityByTable();
|
||||
List<String> runtimeSource;
|
||||
try(Stream<Path> files = Files.walk(MAIN))
|
||||
{
|
||||
runtimeSource = files.filter(p -> p.toString().endsWith(".java"))
|
||||
.filter(p -> !p.startsWith(MAIN.resolve("model")) && !p.startsWith(MAIN.resolve("metadata")) && !p.startsWith(MAIN.resolve("home")))
|
||||
.map(SqlWorkbenchTablesGuardrailTest::read).toList();
|
||||
}
|
||||
for(String table : workbenchTables())
|
||||
{
|
||||
String entity = entityByTable.get(table);
|
||||
assertThat(entity).as("entity class for " + table).isNotNull();
|
||||
Pattern use = Pattern.compile("\\b" + entity + "(\\.TABLE_NAME|\\.class|\\(|::)");
|
||||
assertThat(runtimeSource.stream().anyMatch(source -> use.matcher(source).find()))
|
||||
.as(table + " (" + entity + ") must be read or written by runtime code, not only declared").isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Every table is explained as starting empty.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void everyTableIsExplained()
|
||||
{
|
||||
assertThat(workbenchTables()).isEqualTo(STARTS_EMPTY.keySet().stream().sorted().toList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Every table and the app have bundle help that says how rows get created.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void everyTableHasEmptyStateHelp() throws Exception
|
||||
{
|
||||
assertThat(SqlWorkbenchHelp.entries()).allSatisfy((key, entry) -> assertThat(entry.path("summary").asText().length()).as(key).isLessThanOrEqualTo(120));
|
||||
for(String table : workbenchTables())
|
||||
{
|
||||
QTableMetaData meta = qInstance.getTable(table);
|
||||
List<QHelpContent> help = meta.getHelpContent() == null ? null : meta.getHelpContent().get(SqlWorkbenchHelp.SLOT);
|
||||
assertThat(help).as(table + " table help").isNotEmpty();
|
||||
assertThat(help.get(0).getContent()).as(table + " help says how rows get created").contains("How rows get created");
|
||||
}
|
||||
assertThat(qInstance.getApp("sqlWorkbench").getHelpContent()).containsKey(SqlWorkbenchHelp.SLOT);
|
||||
assertThat(SqlWorkbenchHelp.entries().keySet()).allMatch(key -> !key.startsWith("table:") || qInstance.getTable(key.substring(6, key.indexOf(';'))) != null,
|
||||
"help names only real tables");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Help a host already wrote is kept; the bundle only fills empty slots.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void hostHelpIsNotOverridden() throws Exception
|
||||
{
|
||||
QTableMetaData table = qInstance.getTable("sql_workbench_notebook");
|
||||
table.getHelpContent().remove(SqlWorkbenchHelp.SLOT);
|
||||
table.withHelpContent(SqlWorkbenchHelp.SLOT, new QHelpContent("host words"));
|
||||
|
||||
SqlWorkbenchHelp.apply(qInstance, config);
|
||||
|
||||
assertThat(table.getHelpContent().get(SqlWorkbenchHelp.SLOT).get(0).getContent()).isEqualTo("host words");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private List<String> workbenchTables()
|
||||
{
|
||||
List<String> tables = qInstance.getTables().values().stream().map(QTableMetaData::getName).filter(n -> n.startsWith("sql_workbench_")).sorted().toList();
|
||||
assertThat(tables).hasSize(6);
|
||||
return (tables);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** model/X.java declares TABLE_NAME = "x".
|
||||
*******************************************************************************/
|
||||
private static Map<String, String> entityByTable() throws Exception
|
||||
{
|
||||
Map<String, String> rs = new HashMap<>();
|
||||
Pattern p = Pattern.compile("TABLE_NAME\\s*=\\s*\"([a-z_]+)\"");
|
||||
try(Stream<Path> files = Files.list(MAIN.resolve("model")))
|
||||
{
|
||||
for(Path file : files.toList())
|
||||
{
|
||||
Matcher m = p.matcher(read(file));
|
||||
if(m.find())
|
||||
{
|
||||
rs.put(m.group(1), file.getFileName().toString().replace(".java", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
return (rs);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private static String read(Path path)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (Files.readString(path, StandardCharsets.UTF_8));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw (new IllegalStateException(e));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.v1.MiddlewareVersionV1;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.v1.responses.BasicErrorResponseV1;
|
||||
import com.kingsrook.qqq.middleware.javalin.tools.UiApiContract;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** The committed fragment describes exactly the shipped extension operations.
|
||||
*******************************************************************************/
|
||||
class SqlWorkbenchApiContractTest
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Regenerate with -DsqlWorkbench.openapi.update=true after intentional changes.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void contract() throws Exception
|
||||
{
|
||||
var extension = SqlWorkbenchEndpoints.extension();
|
||||
var version = new MiddlewareVersionV1();
|
||||
String generated = UiApiContract.generateExtensionYaml(version, extension);
|
||||
Path path = Path.of("src/main/resources/openapi/qqq-v1/sql-workbench.yaml");
|
||||
if(Boolean.getBoolean("sqlWorkbench.openapi.update"))
|
||||
{
|
||||
Files.createDirectories(path.getParent());
|
||||
Files.writeString(path, generated);
|
||||
}
|
||||
assertThat(UiApiContract.check(generated, Files.readString(path), null, 1,
|
||||
"./mvnw -Dtest=SqlWorkbenchApiContractTest -DsqlWorkbench.openapi.update=true test")).isEmpty();
|
||||
var model = version.generateExtensionOpenAPIModel("qqq", extension);
|
||||
assertThat(model.getComponents().getSchemas().keySet()).allMatch(name -> name.startsWith("SqlWorkbench") || name.equals(BasicErrorResponseV1.class.getSimpleName()));
|
||||
assertThat(model.getPaths().keySet()).allMatch(name -> name.startsWith("/qqq/v1/sql-workbench/"));
|
||||
assertThat(extension.getSpecs()).hasSize(21);
|
||||
assertThat(extension.getEffectivePathPrefix()).isEqualTo("/sql-workbench");
|
||||
Set<String> operationIds = new HashSet<>();
|
||||
Set<String> componentNames = new HashSet<>();
|
||||
for(var reference : extension.getSpecs())
|
||||
{
|
||||
var spec = (com.kingsrook.qqq.middleware.javalin.specs.AbstractEndpointSpec<?, ?, ?>) Class.forName(reference.getName()).getConstructor().newInstance();
|
||||
assertThat(spec.isSecured()).isTrue();
|
||||
assertThat(spec.defineMethod().getOperationId()).startsWith("sqlWorkbench");
|
||||
assertThat(operationIds.add(spec.defineMethod().getOperationId())).isTrue();
|
||||
for(String name : spec.defineComponentSchemas().keySet())
|
||||
{
|
||||
assertThat(componentNames.add(name)).as("Component declared once: " + name).isTrue();
|
||||
}
|
||||
}
|
||||
assertThat(generated).contains("text/csv; charset=utf-8", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "format: \"binary\"");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,373 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.kingsrook.qbits.sqlworkbench.BaseSqlWorkbenchTest;
|
||||
import com.kingsrook.qbits.sqlworkbench.SqlWorkbenchRuntime;
|
||||
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||
import com.kingsrook.qqq.backend.core.instances.AbstractQQQApplication;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.utils.JsonUtils;
|
||||
import com.kingsrook.qqq.middleware.javalin.QApplicationJavalinServer;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.AbstractEndpointSpec;
|
||||
import com.kingsrook.qqq.middleware.javalin.specs.extensions.MiddlewareSpecExtensionsMetaData;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** The routes over real HTTP (Javalin on a random port, MOCK authentication
|
||||
** with the sessionId cookie choosing the test user).
|
||||
*******************************************************************************/
|
||||
class SqlWorkbenchEndpointSpecTest extends BaseSqlWorkbenchTest
|
||||
{
|
||||
private QApplicationJavalinServer javalin;
|
||||
private String base;
|
||||
private HttpClient client = HttpClient.newHttpClient();
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@BeforeEach
|
||||
void startServer() throws Exception
|
||||
{
|
||||
QContext.clear();
|
||||
javalin = new QApplicationJavalinServer(new AbstractQQQApplication()
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Serve the same instance and runtime prepared by the test fixture.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public QInstance defineQInstance()
|
||||
{
|
||||
return (qInstance);
|
||||
}
|
||||
}).withPort(0).withServeFrontendNext(false).withServeFrontendMaterialDashboard(false)
|
||||
.withServeLegacyUnversionedMiddlewareAPI(false).withStrictUiApiRoutes(true);
|
||||
javalin.start();
|
||||
base = "http://localhost:" + javalin.getBoundPort() + "/qqq/v1/sql-workbench";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@AfterEach
|
||||
void stopServer()
|
||||
{
|
||||
javalin.stop();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private HttpResponse<String> send(String method, String path, String user, String body, String contentType) throws Exception
|
||||
{
|
||||
HttpRequest.Builder builder = HttpRequest.newBuilder(URI.create(base + path)).header("Cookie", "sessionId=" + user);
|
||||
if(contentType != null)
|
||||
{
|
||||
builder.header("Content-Type", contentType);
|
||||
}
|
||||
builder.method(method, body == null ? HttpRequest.BodyPublishers.noBody() : HttpRequest.BodyPublishers.ofString(body));
|
||||
HttpResponse<String> response = client.send(builder.build(), HttpResponse.BodyHandlers.ofString());
|
||||
if(response.statusCode() >= 400)
|
||||
{
|
||||
assertErrorBody(response);
|
||||
}
|
||||
return (response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** HTTP errors retain their message and include the standard diagnostic fields.
|
||||
*******************************************************************************/
|
||||
private static void assertErrorBody(HttpResponse<String> response) throws Exception
|
||||
{
|
||||
Map<String, Object> body = json(response);
|
||||
assertThat(body).containsKeys("error", "code", "message", "traceId");
|
||||
for(String key : List.of("error", "code", "message", "traceId"))
|
||||
{
|
||||
assertThat(body.get(key)).as(key).isInstanceOf(String.class);
|
||||
assertThat((String) body.get(key)).as(key).isNotBlank();
|
||||
}
|
||||
assertThat(body.get("message")).isEqualTo(body.get("error"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private static Map<String, Object> json(HttpResponse<String> response) throws Exception
|
||||
{
|
||||
return (JsonUtils.toObject(response.body(), new TypeReference<Map<String, Object>>() {}));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testRegistration()
|
||||
{
|
||||
SqlWorkbenchEndpoints.register(qInstance);
|
||||
var extensions = MiddlewareSpecExtensionsMetaData.ofOrWithNew(qInstance).getExtensions();
|
||||
assertThat(extensions).containsOnlyKeys("sql-workbench");
|
||||
assertThat(extensions.get("sql-workbench").getSpecs()).hasSize(21);
|
||||
assertThat(javalin.isStrictUiApiRoutes()).isTrue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void testEndToEnd() throws Exception
|
||||
{
|
||||
assertThat(send("GET", "/capabilities", "nobody", null, null).statusCode()).isEqualTo(403);
|
||||
assertThat(send("GET", "/capabilities", READER, null, null).statusCode()).isEqualTo(200);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// JSON only - a form post (CSRF shape) is refused //
|
||||
////////////////////////////////////////////////////////////
|
||||
assertThat(send("POST", "/execute", READER, "backendName=h2&sql=SELECT+1", "application/x-www-form-urlencoded").statusCode()).isEqualTo(400);
|
||||
assertThat(send("POST", "/execute", READER, "not json", "application/json").statusCode()).isEqualTo(400);
|
||||
|
||||
HttpResponse<String> run = send("POST", "/execute", READER, "{\"backendName\":\"h2\",\"sql\":\"SELECT id, salary FROM person WHERE salary > :s ORDER BY id\",\"params\":{\"s\":25000.25}}", "application/json");
|
||||
assertThat(run.statusCode()).isEqualTo(200);
|
||||
Map<String, Object> result = json(run);
|
||||
assertThat(result.get("status")).isEqualTo("SUCCEEDED");
|
||||
assertThat(result.get("rowCount")).isEqualTo(2);
|
||||
String uuid = (String) result.get("executionUuid");
|
||||
|
||||
assertThat(json(send("GET", "/executions/" + uuid + "/rows?offset=1&limit=1&sort=0&dir=desc", READER, null, null)).get("rows")).asList().hasSize(1);
|
||||
assertThat(send("GET", "/executions/" + uuid + "/rows?offset=x", READER, null, null).statusCode()).isEqualTo(400);
|
||||
assertThat(send("GET", "/executions/" + uuid + "/rows", OTHER_READER, null, null).statusCode()).isEqualTo(404);
|
||||
|
||||
HttpResponse<String> csv = send("GET", "/executions/" + uuid + "/export?format=csv", READER, null, null);
|
||||
assertThat(csv.statusCode()).isEqualTo(200);
|
||||
assertThat(csv.headers().firstValue("Content-Disposition").orElse("")).contains("attachment").contains(".csv");
|
||||
assertThat(csv.body()).contains("id,salary");
|
||||
assertThat(send("GET", "/executions/" + uuid + "/export?format=pdf", READER, null, null).statusCode()).isEqualTo(400);
|
||||
assertThat(send("GET", "/executions/" + uuid + "/export", OTHER_READER, null, null).statusCode()).isEqualTo(404);
|
||||
|
||||
assertThat(send("POST", "/execute", READER, "{\"backendName\":\"h2\",\"sql\":\"DELETE FROM person\",\"mode\":\"WRITE\"}", "application/json").statusCode()).isEqualTo(403);
|
||||
assertThat(send("POST", "/execute", READER, "{\"backendName\":\"nope\",\"sql\":\"SELECT 1\"}", "application/json").statusCode()).isEqualTo(404);
|
||||
assertThat(json(send("POST", "/explain", READER, "{\"backendName\":\"h2\",\"sql\":\"SELECT 1\"}", "application/json")).get("status")).isEqualTo("SUCCEEDED");
|
||||
assertThat(json(send("POST", "/executions/" + uuid + "/cancel", READER, "{}", "application/json")).get("cancelled")).isEqualTo(false);
|
||||
assertThat((List<?>) json(send("GET", "/history?limit=5", READER, null, null)).get("executions")).hasSize(3);
|
||||
assertThat(json(send("GET", "/schema/h2", READER, null, null)).get("dialect")).isEqualTo("h2");
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// a client-chosen id: any case on the paths, single-use (409) //
|
||||
///////////////////////////////////////////////////////////////////
|
||||
String clientUuid = "3F2504E0-4F89-11D3-9A0C-0305E82C3301";
|
||||
String body = "{\"backendName\":\"h2\",\"sql\":\"SELECT 1 AS one\",\"executionUuid\":\"" + clientUuid + "\"}";
|
||||
assertThat(json(send("POST", "/execute", READER, body, "application/json")).get("executionUuid")).isEqualTo(clientUuid.toLowerCase());
|
||||
assertThat(send("GET", "/executions/" + clientUuid + "/rows", READER, null, null).statusCode()).isEqualTo(200);
|
||||
assertThat(send("GET", "/executions/" + clientUuid + "/export", READER, null, null).statusCode()).isEqualTo(200);
|
||||
HttpResponse<String> again = send("POST", "/execute", READER, body, "application/json");
|
||||
assertThat(again.statusCode()).isEqualTo(409);
|
||||
assertThat(again.body()).contains("already used");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testNotebookRoutes() throws Exception
|
||||
{
|
||||
Map<String, Object> created = json(send("POST", "/notebooks", WRITER, "{\"title\":\"N1\",\"cells\":[{\"cellKey\":\"a\",\"cellType\":\"SQL\",\"content\":\"SELECT 1\"}]}", "application/json"));
|
||||
Integer id = (Integer) created.get("id");
|
||||
|
||||
assertThat((List<?>) json(send("GET", "/notebooks?scope=mine", WRITER, null, null)).get("notebooks")).hasSize(1);
|
||||
assertThat(json(send("GET", "/notebooks/" + id, WRITER, null, null)).get("title")).isEqualTo("N1");
|
||||
assertThat(send("GET", "/notebooks/" + id, READER, null, null).statusCode()).isEqualTo(404);
|
||||
assertThat(send("GET", "/notebooks/abc", WRITER, null, null).statusCode()).isEqualTo(400);
|
||||
|
||||
assertThat(json(send("PUT", "/notebooks/" + id, WRITER, "{\"title\":\"N2\"}", "application/json")).get("currentVersion")).isEqualTo(2);
|
||||
assertThat(json(send("POST", "/notebooks/" + id + "/publish", WRITER, "{\"shared\":true}", "application/json")).get("visibility")).isEqualTo("SHARED");
|
||||
assertThat((List<?>) json(send("GET", "/notebooks?scope=shared", READER, null, null)).get("notebooks")).hasSize(1);
|
||||
assertThat(json(send("POST", "/notebooks/" + id + "/duplicate", READER, "{}", "application/json")).get("ownerUserId")).isEqualTo(READER);
|
||||
assertThat((List<?>) json(send("GET", "/notebooks/" + id + "/versions", WRITER, null, null)).get("versions")).hasSize(2);
|
||||
assertThat(json(send("GET", "/notebooks/" + id + "/versions/1", WRITER, null, null)).get("versionNumber")).isEqualTo(1);
|
||||
assertThat(json(send("POST", "/notebooks/" + id + "/versions/1/restore", WRITER, "{}", "application/json")).get("title")).isEqualTo("N1");
|
||||
|
||||
String uuid = (String) json(send("POST", "/execute", WRITER, "{\"backendName\":\"h2\",\"sql\":\"SELECT 1 AS one\"}", "application/json")).get("executionUuid");
|
||||
Map<String, Object> snapshot = json(send("POST", "/notebooks/" + id + "/snapshots", WRITER, "{\"executionUuid\":\"" + uuid + "\",\"cellKey\":\"a\"}", "application/json"));
|
||||
assertThat((List<?>) json(send("GET", "/notebooks/" + id + "/snapshots", WRITER, null, null)).get("snapshots")).hasSize(1);
|
||||
assertThat(json(send("DELETE", "/notebooks/" + id + "/snapshots/" + snapshot.get("id"), WRITER, null, null)).get("deleted")).isEqualTo(true);
|
||||
|
||||
assertThat(send("DELETE", "/notebooks/" + id, READER, null, null).statusCode()).isEqualTo(403);
|
||||
assertThat(json(send("DELETE", "/notebooks/" + id, WRITER, null, null)).get("deleted")).isEqualTo(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Every spec checks access before parsing bodies, identifiers or formats.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testEveryOperationDeniesMissingAccess() throws Exception
|
||||
{
|
||||
for(var reference : SqlWorkbenchEndpoints.extension().getSpecs())
|
||||
{
|
||||
var spec = (AbstractEndpointSpec<?, ?, ?>) Class.forName(reference.getName()).getConstructor().newInstance();
|
||||
var operation = spec.defineBasicOperation();
|
||||
String path = operation.getPath().substring("/sql-workbench".length()).replaceAll("\\{[^}]+}", "invalid");
|
||||
String method = operation.getHttpMethod().name();
|
||||
boolean body = method.equals("POST") || method.equals("PUT");
|
||||
HttpResponse<String> response = send(method, path + "?format=invalid", "nobody", body ? "not json" : null, body ? "text/plain" : null);
|
||||
assertThat(response.statusCode()).as(method + " " + path).isEqualTo(403);
|
||||
assertThat(json(response)).containsEntry("error", "Permission denied.");
|
||||
HttpRequest unauthenticated = HttpRequest.newBuilder(URI.create(base + path))
|
||||
.header("Authorization", "Bearer Deny")
|
||||
.method(method, HttpRequest.BodyPublishers.noBody()).build();
|
||||
HttpResponse<String> denied = client.send(unauthenticated, HttpResponse.BodyHandlers.ofString());
|
||||
assertThat(denied.statusCode()).as(method + " authentication").isEqualTo(401);
|
||||
assertErrorBody(denied);
|
||||
}
|
||||
assertThat(json(send("GET", "/history", READER, null, null)).get("executions")).asList().isEmpty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Write gates, read-only classification and concurrency limits remain audited.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testExecutionGatesAndLimits() throws Exception
|
||||
{
|
||||
String write = "{\"backendName\":\"h2\",\"sql\":\"DELETE FROM person\",\"mode\":\"WRITE\"}";
|
||||
assertThat(send("POST", "/execute", READER, write, "application/json").statusCode()).isEqualTo(403);
|
||||
config.setWriteModeEnabled(false);
|
||||
assertThat(send("POST", "/execute", WRITER, write, "application/json").statusCode()).isEqualTo(403);
|
||||
String analyze = "{\"backendName\":\"h2\",\"sql\":\"SELECT 1\",\"analyze\":true}";
|
||||
assertThat(send("POST", "/explain", WRITER, analyze, "application/json").statusCode()).isEqualTo(403);
|
||||
config.setWriteModeEnabled(true);
|
||||
assertThat(send("POST", "/explain", READER, analyze, "application/json").statusCode()).isEqualTo(403);
|
||||
assertThat(send("POST", "/execute", WRITER, write.replace(",\"mode\":\"WRITE\"", ""), "application/json").statusCode()).isEqualTo(400);
|
||||
|
||||
config.setMaxConcurrentExecutionsPerUser(1);
|
||||
var running = SqlWorkbenchRuntime.get(qInstance).getRunningStatements();
|
||||
String uuid = "3f2504e0-4f89-11d3-9a0c-0305e82c3302";
|
||||
var registration = running.register(uuid, READER, 1);
|
||||
try
|
||||
{
|
||||
HttpResponse<String> limited = send("POST", "/execute", READER, "{\"backendName\":\"h2\",\"sql\":\"SELECT 1\"}", "application/json");
|
||||
assertThat(limited.statusCode()).isEqualTo(400);
|
||||
assertThat(limited.body()).contains("executions running");
|
||||
assertThat(json(send("POST", "/executions/" + uuid + "/cancel", OTHER_READER, "{}", "application/json"))).containsEntry("cancelled", false);
|
||||
assertThat(registration.isCancelled()).isFalse();
|
||||
assertThat(json(send("POST", "/executions/" + uuid + "/cancel", READER, "{}", "application/json"))).containsEntry("cancelled", true);
|
||||
}
|
||||
finally
|
||||
{
|
||||
running.unregister(uuid, registration);
|
||||
}
|
||||
List<?> history = (List<?>) json(send("GET", "/history", READER, null, null)).get("executions");
|
||||
assertThat(history).hasSize(3).allSatisfy(entry -> assertThat(((Map<?, ?>) entry).get("status")).isEqualTo("REJECTED"));
|
||||
Map<String, Object> count = json(send("POST", "/execute", READER, "{\"backendName\":\"h2\",\"sql\":\"SELECT COUNT(*) AS n FROM person\"}", "application/json"));
|
||||
assertThat(count.get("rows")).isEqualTo(List.of(List.of(5)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Share permission, ownership and cached-result ownership apply to mutations.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testNotebookMutationDenials() throws Exception
|
||||
{
|
||||
Integer id = (Integer) json(send("POST", "/notebooks", READER, "{\"title\":\"Private\"}", "application/json")).get("id");
|
||||
assertThat(send("POST", "/notebooks/" + id + "/publish", READER, "{\"shared\":true}", "application/json").statusCode()).isEqualTo(403);
|
||||
for(String suffix : List.of("", "/versions", "/versions/1", "/snapshots"))
|
||||
{
|
||||
assertThat(send("GET", "/notebooks/" + id + suffix, OTHER_READER, null, null).statusCode()).isEqualTo(404);
|
||||
}
|
||||
assertThat(send("PUT", "/notebooks/" + id, OTHER_READER, "{\"title\":\"Stolen\"}", "application/json").statusCode()).isEqualTo(404);
|
||||
assertThat(send("POST", "/notebooks/" + id + "/duplicate", OTHER_READER, "{}", "application/json").statusCode()).isEqualTo(404);
|
||||
assertThat(send("POST", "/notebooks/" + id + "/versions/1/restore", OTHER_READER, "{}", "application/json").statusCode()).isEqualTo(404);
|
||||
|
||||
Integer shared = (Integer) json(send("POST", "/notebooks", WRITER, "{\"title\":\"Shared\"}", "application/json")).get("id");
|
||||
send("POST", "/notebooks/" + shared + "/publish", WRITER, "{\"shared\":true}", "application/json");
|
||||
assertThat(send("PUT", "/notebooks/" + shared, READER, "{\"title\":\"Stolen\"}", "application/json").statusCode()).isEqualTo(403);
|
||||
assertThat(send("POST", "/notebooks/" + shared + "/versions/1/restore", READER, "{}", "application/json").statusCode()).isEqualTo(403);
|
||||
String uuid = (String) json(send("POST", "/execute", WRITER, "{\"backendName\":\"h2\",\"sql\":\"SELECT 1\"}", "application/json")).get("executionUuid");
|
||||
String snapshotBody = "{\"executionUuid\":\"" + uuid + "\",\"cellKey\":\"a\"}";
|
||||
assertThat(send("POST", "/notebooks/" + id + "/snapshots", READER, snapshotBody, "application/json").statusCode()).isEqualTo(404);
|
||||
Integer snapshotId = (Integer) json(send("POST", "/notebooks/" + shared + "/snapshots", WRITER, snapshotBody, "application/json")).get("id");
|
||||
assertThat(send("DELETE", "/notebooks/" + shared + "/snapshots/" + snapshotId, READER, null, null).statusCode()).isEqualTo(403);
|
||||
assertThat(json(send("GET", "/notebooks/" + id, READER, null, null))).containsEntry("title", "Private");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Keep decimal parameters, null bodies, SQL failures and all export formats.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testWireCompatibility() throws Exception
|
||||
{
|
||||
HttpResponse<String> run = send("POST", "/execute", READER,
|
||||
"{\"backendName\":\"h2\",\"sql\":\"SELECT CAST(:n AS DECIMAL(30,20)) AS n\",\"params\":{\"n\":0.12345678901234567890}}", "application/json");
|
||||
assertThat(run.statusCode()).isEqualTo(200);
|
||||
assertThat(run.body()).contains("0.12345678901234567890");
|
||||
String uuid = (String) json(run).get("executionUuid");
|
||||
for(String format : List.of("csv", "json", "xlsx"))
|
||||
{
|
||||
HttpResponse<String> export = send("GET", "/executions/" + uuid + "/export?format=" + format, READER, null, null);
|
||||
assertThat(export.statusCode()).isEqualTo(200);
|
||||
assertThat(export.headers().firstValue("Cache-Control")).contains("no-store");
|
||||
assertThat(export.headers().firstValue("Content-Disposition").orElseThrow()).endsWith("." + format + "\"");
|
||||
if(format.equals("json"))
|
||||
{
|
||||
assertThat(export.body()).contains("0.12345678901234567890");
|
||||
}
|
||||
}
|
||||
assertThat(json(send("POST", "/executions/" + uuid + "/cancel", READER, "null", "application/json"))).containsEntry("cancelled", false);
|
||||
assertThat(send("POST", "/execute", READER, "[]", "application/json").statusCode()).isEqualTo(400);
|
||||
assertThat(send("POST", "/execute", READER, "{}", null).statusCode()).isEqualTo(400);
|
||||
HttpResponse<String> failed = send("POST", "/execute", READER, "{\"backendName\":\"h2\",\"sql\":\"SELECT * FROM nonexistent_table\"}", "application/json");
|
||||
assertThat(failed.statusCode()).isEqualTo(200);
|
||||
assertThat(json(failed)).containsEntry("status", "FAILED");
|
||||
String served = client.send(HttpRequest.newBuilder(URI.create(base.replace("/sql-workbench", "/openapi.yaml"))).build(), HttpResponse.BodyHandlers.ofString()).body();
|
||||
assertThat(served).contains("sqlWorkbenchExecute", "sqlWorkbenchExportResult", "SqlWorkbenchNotebookV1");
|
||||
}
|
||||
|
||||
}
|
||||
-203
@@ -1,203 +0,0 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.sqlworkbench.api;
|
||||
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
|
||||
import com.kingsrook.qqq.backend.core.utils.JsonUtils;
|
||||
import com.kingsrook.qbits.sqlworkbench.BaseSqlWorkbenchTest;
|
||||
import com.kingsrook.qqq.middleware.javalin.QJavalinMetaData;
|
||||
import io.javalin.Javalin;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** The routes over real HTTP (Javalin on a random port, MOCK authentication
|
||||
** with the sessionId cookie choosing the test user).
|
||||
*******************************************************************************/
|
||||
class SqlWorkbenchRouteProviderTest extends BaseSqlWorkbenchTest
|
||||
{
|
||||
private Javalin javalin;
|
||||
private String base;
|
||||
private HttpClient client = HttpClient.newHttpClient();
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@BeforeEach
|
||||
void startServer()
|
||||
{
|
||||
QContext.clear();
|
||||
SqlWorkbenchRouteProvider provider = new SqlWorkbenchRouteProvider();
|
||||
provider.setQInstance(qInstance);
|
||||
javalin = Javalin.create(provider::acceptJavalinConfig).start(0);
|
||||
base = "http://localhost:" + javalin.port() + SqlWorkbenchRouteProvider.BASE_PATH;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@AfterEach
|
||||
void stopServer()
|
||||
{
|
||||
javalin.stop();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private HttpResponse<String> send(String method, String path, String user, String body, String contentType) throws Exception
|
||||
{
|
||||
HttpRequest.Builder builder = HttpRequest.newBuilder(URI.create(base + path)).header("Cookie", "sessionId=" + user);
|
||||
if(contentType != null)
|
||||
{
|
||||
builder.header("Content-Type", contentType);
|
||||
}
|
||||
builder.method(method, body == null ? HttpRequest.BodyPublishers.noBody() : HttpRequest.BodyPublishers.ofString(body));
|
||||
return (client.send(builder.build(), HttpResponse.BodyHandlers.ofString()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private static Map<String, Object> json(HttpResponse<String> response) throws Exception
|
||||
{
|
||||
return (JsonUtils.toObject(response.body(), new TypeReference<Map<String, Object>>() {}));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testRegistration()
|
||||
{
|
||||
com.kingsrook.qbits.sqlworkbench.api.SqlWorkbenchRoutes.register(qInstance);
|
||||
List<QCodeReference> references = QJavalinMetaData.of(qInstance).getAdditionalRouteProviderReferences();
|
||||
assertThat(references).filteredOn(r -> r.getName().equals(SqlWorkbenchRouteProvider.class.getName())).hasSize(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void testEndToEnd() throws Exception
|
||||
{
|
||||
assertThat(send("GET", "/capabilities", "nobody", null, null).statusCode()).isEqualTo(403);
|
||||
assertThat(send("GET", "/capabilities", READER, null, null).statusCode()).isEqualTo(200);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// JSON only - a form post (CSRF shape) is refused //
|
||||
////////////////////////////////////////////////////////////
|
||||
assertThat(send("POST", "/execute", READER, "backendName=h2&sql=SELECT+1", "application/x-www-form-urlencoded").statusCode()).isEqualTo(400);
|
||||
assertThat(send("POST", "/execute", READER, "not json", "application/json").statusCode()).isEqualTo(400);
|
||||
|
||||
HttpResponse<String> run = send("POST", "/execute", READER, "{\"backendName\":\"h2\",\"sql\":\"SELECT id, salary FROM person WHERE salary > :s ORDER BY id\",\"params\":{\"s\":25000.25}}", "application/json");
|
||||
assertThat(run.statusCode()).isEqualTo(200);
|
||||
Map<String, Object> result = json(run);
|
||||
assertThat(result.get("status")).isEqualTo("SUCCEEDED");
|
||||
assertThat(result.get("rowCount")).isEqualTo(2);
|
||||
String uuid = (String) result.get("executionUuid");
|
||||
|
||||
assertThat(json(send("GET", "/executions/" + uuid + "/rows?offset=1&limit=1&sort=0&dir=desc", READER, null, null)).get("rows")).asList().hasSize(1);
|
||||
assertThat(send("GET", "/executions/" + uuid + "/rows?offset=x", READER, null, null).statusCode()).isEqualTo(400);
|
||||
assertThat(send("GET", "/executions/" + uuid + "/rows", OTHER_READER, null, null).statusCode()).isEqualTo(404);
|
||||
|
||||
HttpResponse<String> csv = send("GET", "/executions/" + uuid + "/export?format=csv", READER, null, null);
|
||||
assertThat(csv.statusCode()).isEqualTo(200);
|
||||
assertThat(csv.headers().firstValue("Content-Disposition").orElse("")).contains("attachment").contains(".csv");
|
||||
assertThat(csv.body()).contains("id,salary");
|
||||
assertThat(send("GET", "/executions/" + uuid + "/export?format=pdf", READER, null, null).statusCode()).isEqualTo(400);
|
||||
assertThat(send("GET", "/executions/" + uuid + "/export", OTHER_READER, null, null).statusCode()).isEqualTo(404);
|
||||
|
||||
assertThat(send("POST", "/execute", READER, "{\"backendName\":\"h2\",\"sql\":\"DELETE FROM person\",\"mode\":\"WRITE\"}", "application/json").statusCode()).isEqualTo(403);
|
||||
assertThat(send("POST", "/execute", READER, "{\"backendName\":\"nope\",\"sql\":\"SELECT 1\"}", "application/json").statusCode()).isEqualTo(404);
|
||||
assertThat(json(send("POST", "/explain", READER, "{\"backendName\":\"h2\",\"sql\":\"SELECT 1\"}", "application/json")).get("status")).isEqualTo("SUCCEEDED");
|
||||
assertThat(json(send("POST", "/executions/" + uuid + "/cancel", READER, "{}", "application/json")).get("cancelled")).isEqualTo(false);
|
||||
assertThat((List<?>) json(send("GET", "/history?limit=5", READER, null, null)).get("executions")).hasSize(3);
|
||||
assertThat(json(send("GET", "/schema/h2", READER, null, null)).get("dialect")).isEqualTo("h2");
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// a client-chosen id: any case on the paths, single-use (409) //
|
||||
///////////////////////////////////////////////////////////////////
|
||||
String clientUuid = "3F2504E0-4F89-11D3-9A0C-0305E82C3301";
|
||||
String body = "{\"backendName\":\"h2\",\"sql\":\"SELECT 1 AS one\",\"executionUuid\":\"" + clientUuid + "\"}";
|
||||
assertThat(json(send("POST", "/execute", READER, body, "application/json")).get("executionUuid")).isEqualTo(clientUuid.toLowerCase());
|
||||
assertThat(send("GET", "/executions/" + clientUuid + "/rows", READER, null, null).statusCode()).isEqualTo(200);
|
||||
assertThat(send("GET", "/executions/" + clientUuid + "/export", READER, null, null).statusCode()).isEqualTo(200);
|
||||
HttpResponse<String> again = send("POST", "/execute", READER, body, "application/json");
|
||||
assertThat(again.statusCode()).isEqualTo(409);
|
||||
assertThat(again.body()).contains("already used");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testNotebookRoutes() throws Exception
|
||||
{
|
||||
Map<String, Object> created = json(send("POST", "/notebooks", WRITER, "{\"title\":\"N1\",\"cells\":[{\"cellKey\":\"a\",\"cellType\":\"SQL\",\"content\":\"SELECT 1\"}]}", "application/json"));
|
||||
Integer id = (Integer) created.get("id");
|
||||
|
||||
assertThat((List<?>) json(send("GET", "/notebooks?scope=mine", WRITER, null, null)).get("notebooks")).hasSize(1);
|
||||
assertThat(json(send("GET", "/notebooks/" + id, WRITER, null, null)).get("title")).isEqualTo("N1");
|
||||
assertThat(send("GET", "/notebooks/" + id, READER, null, null).statusCode()).isEqualTo(404);
|
||||
assertThat(send("GET", "/notebooks/abc", WRITER, null, null).statusCode()).isEqualTo(400);
|
||||
|
||||
assertThat(json(send("PUT", "/notebooks/" + id, WRITER, "{\"title\":\"N2\"}", "application/json")).get("currentVersion")).isEqualTo(2);
|
||||
assertThat(json(send("POST", "/notebooks/" + id + "/publish", WRITER, "{\"shared\":true}", "application/json")).get("visibility")).isEqualTo("SHARED");
|
||||
assertThat((List<?>) json(send("GET", "/notebooks?scope=shared", READER, null, null)).get("notebooks")).hasSize(1);
|
||||
assertThat(json(send("POST", "/notebooks/" + id + "/duplicate", READER, "{}", "application/json")).get("ownerUserId")).isEqualTo(READER);
|
||||
assertThat((List<?>) json(send("GET", "/notebooks/" + id + "/versions", WRITER, null, null)).get("versions")).hasSize(2);
|
||||
assertThat(json(send("GET", "/notebooks/" + id + "/versions/1", WRITER, null, null)).get("versionNumber")).isEqualTo(1);
|
||||
assertThat(json(send("POST", "/notebooks/" + id + "/versions/1/restore", WRITER, "{}", "application/json")).get("title")).isEqualTo("N1");
|
||||
|
||||
String uuid = (String) json(send("POST", "/execute", WRITER, "{\"backendName\":\"h2\",\"sql\":\"SELECT 1 AS one\"}", "application/json")).get("executionUuid");
|
||||
Map<String, Object> snapshot = json(send("POST", "/notebooks/" + id + "/snapshots", WRITER, "{\"executionUuid\":\"" + uuid + "\",\"cellKey\":\"a\"}", "application/json"));
|
||||
assertThat((List<?>) json(send("GET", "/notebooks/" + id + "/snapshots", WRITER, null, null)).get("snapshots")).hasSize(1);
|
||||
assertThat(json(send("DELETE", "/notebooks/" + id + "/snapshots/" + snapshot.get("id"), WRITER, null, null)).get("deleted")).isEqualTo(true);
|
||||
|
||||
assertThat(send("DELETE", "/notebooks/" + id, READER, null, null).statusCode()).isEqualTo(403);
|
||||
assertThat(json(send("DELETE", "/notebooks/" + id, WRITER, null, null)).get("deleted")).isEqualTo(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -490,6 +490,99 @@ class SqlExecutionEngineTest extends BaseSqlWorkbenchTest
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** auditRetentionDays deletes audit rows older than the window, in the
|
||||
** background, and only those: a 40-day-old RUNNING row survives. The default
|
||||
** keeps everything, and a process does not prune the moment it starts.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testAuditRetentionPrunesOldRows() throws Exception
|
||||
{
|
||||
ExecutionAuditor auditor = new ExecutionAuditor(config);
|
||||
java.time.Instant old = java.time.Instant.now().minus(java.time.Duration.ofDays(40));
|
||||
for(String[] row : new String[][] { { "a1", "REJECTED" }, { "a2", "REJECTED" }, { "r1", "RUNNING" } })
|
||||
{
|
||||
auditor.record(new SqlWorkbenchExecution().withExecutionUuid("00000000-0000-0000-0000-0000000000" + row[0]).withUserId(READER).withBackendName(BACKEND_NAME)
|
||||
.withMode(ExecutionMode.READ_ONLY.name()).withStatus(row[1]).withSqlText("SELECT 1").withStartTime(old));
|
||||
}
|
||||
assertThat(audits()).hasSize(3);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// default (null): nothing is ever pruned //
|
||||
////////////////////////////////////////////////////////////
|
||||
run("SELECT 1", Map.of(), READER);
|
||||
auditor.allowPruneNow();
|
||||
assertThat(auditor.pruneIfDue()).isNull();
|
||||
assertThat(audits()).hasSize(4);
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// 30 days: a fresh auditor waits out its start-up delay //
|
||||
////////////////////////////////////////////////////////////////////
|
||||
config.setAuditRetentionDays(30);
|
||||
ExecutionAuditor pruning = new ExecutionAuditor(config);
|
||||
assertThat(pruning.pruneIfDue()).as("no pass right after start-up").isNull();
|
||||
|
||||
pruning.allowPruneNow();
|
||||
pruning.pruneIfDue().get();
|
||||
assertThat(audits()).extracting(SqlWorkbenchExecution::getExecutionUuid)
|
||||
.doesNotContain("00000000-0000-0000-0000-0000000000a1", "00000000-0000-0000-0000-0000000000a2")
|
||||
.contains("00000000-0000-0000-0000-0000000000r1");
|
||||
assertThat(audits()).as("the old RUNNING row and the fresh run").hasSize(2);
|
||||
assertThat(pruning.pruneIfDue()).as("at most hourly").isNull();
|
||||
assertThat(pruning.pruneOlderThan(java.time.Instant.now().minus(java.time.Duration.ofDays(30)))).as("RUNNING rows are never deleted").isZero();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// the pass that start() triggers runs in the background and spares RUNNING //
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
auditor.record(new SqlWorkbenchExecution().withExecutionUuid("00000000-0000-0000-0000-0000000000a3").withUserId(READER).withBackendName(BACKEND_NAME)
|
||||
.withMode(ExecutionMode.READ_ONLY.name()).withStatus(ExecutionStatus.REJECTED.name()).withSqlText("SELECT 1").withStartTime(old));
|
||||
pruning.allowPruneNow();
|
||||
pruning.start(new SqlWorkbenchExecution().withExecutionUuid("00000000-0000-0000-0000-0000000000b1").withUserId(READER).withBackendName(BACKEND_NAME)
|
||||
.withMode(ExecutionMode.READ_ONLY.name()).withSqlText("SELECT 2").withStartTime(java.time.Instant.now()));
|
||||
for(int i = 0; i < 100 && audits().stream().anyMatch(a -> a.getExecutionUuid().endsWith("a3")); i++)
|
||||
{
|
||||
Thread.sleep(50);
|
||||
}
|
||||
assertThat(audits()).extracting(SqlWorkbenchExecution::getExecutionUuid).doesNotContain("00000000-0000-0000-0000-0000000000a3")
|
||||
.contains("00000000-0000-0000-0000-0000000000r1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** A backlog bigger than one batch is deleted in bounded batches.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testAuditRetentionDeletesInBatches() throws Exception
|
||||
{
|
||||
config.setAuditRetentionDays(30);
|
||||
ExecutionAuditor auditor = new ExecutionAuditor(config);
|
||||
java.time.Instant old = java.time.Instant.now().minus(java.time.Duration.ofDays(40));
|
||||
int total = ExecutionAuditor.BATCH_SIZE + 5;
|
||||
for(int i = 0; i < total; i++)
|
||||
{
|
||||
auditor.record(new SqlWorkbenchExecution().withExecutionUuid(java.util.UUID.randomUUID().toString()).withUserId(READER).withBackendName(BACKEND_NAME)
|
||||
.withMode(ExecutionMode.READ_ONLY.name()).withStatus(ExecutionStatus.REJECTED.name()).withSqlText("SELECT 1").withStartTime(old));
|
||||
}
|
||||
assertThat(auditor.pruneOlderThan(java.time.Instant.now().minus(java.time.Duration.ofDays(30)))).isEqualTo(total);
|
||||
assertThat(audits()).isEmpty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** auditRetentionDays must be positive when set.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testAuditRetentionValidation()
|
||||
{
|
||||
java.util.List<String> errors = new java.util.ArrayList<>();
|
||||
new com.kingsrook.qbits.sqlworkbench.SqlWorkbenchQBitConfig().withBackendName(BACKEND_NAME).withAuditRetentionDays(0).validate(null, errors);
|
||||
assertThat(errors).anyMatch(e -> e.contains("auditRetentionDays"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** A connection that cannot be opened answers with a generic message: the
|
||||
** driver's (URL, host, user) stays in the server log.
|
||||
|
||||
@@ -70,6 +70,8 @@ CREATE TABLE IF NOT EXISTS sql_workbench_result_snapshot (
|
||||
CONSTRAINT pk_sql_workbench_result_snapshot PRIMARY KEY (id),
|
||||
CONSTRAINT fk_sql_workbench_result_snapshot_notebook FOREIGN KEY (notebook_id) REFERENCES sql_workbench_notebook (id)
|
||||
);
|
||||
-- the notebook page lists its snapshots, and deleting a notebook deletes them, by notebook_id
|
||||
CREATE INDEX IF NOT EXISTS ix_sql_workbench_result_snapshot_notebook ON sql_workbench_result_snapshot (notebook_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS sql_workbench_notebook_share (
|
||||
id INTEGER AUTO_INCREMENT NOT NULL,
|
||||
@@ -117,6 +119,8 @@ CREATE TABLE IF NOT EXISTS sql_workbench_execution (
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS ix_sql_workbench_execution_user ON sql_workbench_execution (user_id, id);
|
||||
CREATE INDEX IF NOT EXISTS ix_sql_workbench_execution_start ON sql_workbench_execution (start_time);
|
||||
-- the notebook page's "Runs" list joins executions by notebook_id
|
||||
CREATE INDEX IF NOT EXISTS ix_sql_workbench_execution_notebook ON sql_workbench_execution (notebook_id);
|
||||
|
||||
CREATE TABLE person (
|
||||
id INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY,
|
||||
|
||||
Reference in new issue
Block a user