@libredb/studio 0.9.7 → 0.9.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-34YQUUCM.mjs +319 -0
- package/dist/chunk-34YQUUCM.mjs.map +1 -0
- package/dist/chunk-4LVB3K53.mjs +37 -0
- package/dist/chunk-4LVB3K53.mjs.map +1 -0
- package/dist/chunk-6DRZXXNT.mjs +100 -0
- package/dist/chunk-6DRZXXNT.mjs.map +1 -0
- package/dist/chunk-CPF7XWV5.mjs +1289 -0
- package/dist/chunk-CPF7XWV5.mjs.map +1 -0
- package/dist/chunk-CZVV3JJB.mjs +160 -0
- package/dist/chunk-CZVV3JJB.mjs.map +1 -0
- package/dist/chunk-D4WVWWWF.js +332 -0
- package/dist/chunk-D4WVWWWF.js.map +1 -0
- package/dist/chunk-DY3KXE44.mjs +3 -0
- package/dist/chunk-DY3KXE44.mjs.map +1 -0
- package/dist/chunk-FYSE52VB.js +242 -0
- package/dist/chunk-FYSE52VB.js.map +1 -0
- package/dist/chunk-G3S66G64.mjs +6673 -0
- package/dist/chunk-G3S66G64.mjs.map +1 -0
- package/dist/chunk-G4WYE6TI.js +4 -0
- package/dist/chunk-G4WYE6TI.js.map +1 -0
- package/dist/chunk-HGPD6PWV.js +1310 -0
- package/dist/chunk-HGPD6PWV.js.map +1 -0
- package/dist/chunk-JZO5KRZN.js +165 -0
- package/dist/chunk-JZO5KRZN.js.map +1 -0
- package/dist/chunk-KV356UXJ.js +253 -0
- package/dist/chunk-KV356UXJ.js.map +1 -0
- package/dist/chunk-PPODO6HX.mjs +237 -0
- package/dist/chunk-PPODO6HX.mjs.map +1 -0
- package/dist/chunk-PTIRB2JO.js +258 -0
- package/dist/chunk-PTIRB2JO.js.map +1 -0
- package/dist/chunk-Q6LRDBK7.js +42 -0
- package/dist/chunk-Q6LRDBK7.js.map +1 -0
- package/dist/chunk-QJP5FZRY.mjs +255 -0
- package/dist/chunk-QJP5FZRY.mjs.map +1 -0
- package/dist/chunk-R3POCJK6.mjs +248 -0
- package/dist/chunk-R3POCJK6.mjs.map +1 -0
- package/dist/chunk-RCQB4FCE.js +186 -0
- package/dist/chunk-RCQB4FCE.js.map +1 -0
- package/dist/chunk-SR5DRGBX.mjs +174 -0
- package/dist/chunk-SR5DRGBX.mjs.map +1 -0
- package/dist/chunk-VLCRUZX7.js +102 -0
- package/dist/chunk-VLCRUZX7.js.map +1 -0
- package/dist/chunk-Y52UIFEX.js +6741 -0
- package/dist/chunk-Y52UIFEX.js.map +1 -0
- package/dist/components.d.mts +273 -0
- package/dist/components.d.ts +273 -0
- package/dist/components.js +59 -0
- package/dist/components.js.map +1 -0
- package/dist/components.mjs +6 -0
- package/dist/components.mjs.map +1 -0
- package/dist/custom-BNDOYC5P.js +134 -0
- package/dist/custom-BNDOYC5P.js.map +1 -0
- package/dist/custom-S2EKFMP3.mjs +132 -0
- package/dist/custom-S2EKFMP3.mjs.map +1 -0
- package/dist/gemini-4ASHNK4H.js +81 -0
- package/dist/gemini-4ASHNK4H.js.map +1 -0
- package/dist/gemini-C5RBLQEJ.mjs +79 -0
- package/dist/gemini-C5RBLQEJ.mjs.map +1 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +95 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +10 -0
- package/dist/index.mjs.map +1 -0
- package/dist/mongodb-XMZEZA4A.mjs +748 -0
- package/dist/mongodb-XMZEZA4A.mjs.map +1 -0
- package/dist/mongodb-YQJJTLX3.js +750 -0
- package/dist/mongodb-YQJJTLX3.js.map +1 -0
- package/dist/mssql-PMOU4D36.js +916 -0
- package/dist/mssql-PMOU4D36.js.map +1 -0
- package/{src/lib/db/providers/sql/mssql.ts → dist/mssql-ZH5VP2C5.mjs} +268 -423
- package/dist/mssql-ZH5VP2C5.mjs.map +1 -0
- package/{src/lib/db/providers/sql/mysql.ts → dist/mysql-I3WJQXN2.mjs} +277 -428
- package/dist/mysql-I3WJQXN2.mjs.map +1 -0
- package/dist/mysql-Y3MSA5QY.js +833 -0
- package/dist/mysql-Y3MSA5QY.js.map +1 -0
- package/dist/ollama-26BYLVEV.mjs +115 -0
- package/dist/ollama-26BYLVEV.mjs.map +1 -0
- package/dist/ollama-HVWAGKQC.js +117 -0
- package/dist/ollama-HVWAGKQC.js.map +1 -0
- package/dist/openai-4U56KPG7.mjs +111 -0
- package/dist/openai-4U56KPG7.mjs.map +1 -0
- package/dist/openai-AK3R37BS.js +113 -0
- package/dist/openai-AK3R37BS.js.map +1 -0
- package/dist/oracle-L6VEAVXO.js +917 -0
- package/dist/oracle-L6VEAVXO.js.map +1 -0
- package/{src/lib/db/providers/sql/oracle.ts → dist/oracle-P2G7T4P4.mjs} +321 -454
- package/dist/oracle-P2G7T4P4.mjs.map +1 -0
- package/{src/lib/db/providers/sql/postgres.ts → dist/postgres-O5KOQUVP.mjs} +261 -471
- package/dist/postgres-O5KOQUVP.mjs.map +1 -0
- package/dist/postgres-RLCWNFFX.js +971 -0
- package/dist/postgres-RLCWNFFX.js.map +1 -0
- package/dist/providers.d.mts +149 -0
- package/dist/providers.d.ts +149 -0
- package/dist/providers.js +44 -0
- package/dist/providers.js.map +1 -0
- package/dist/providers.mjs +7 -0
- package/dist/providers.mjs.map +1 -0
- package/dist/redis-4WMQOVLX.mjs +435 -0
- package/dist/redis-4WMQOVLX.mjs.map +1 -0
- package/dist/redis-QVQ6YU62.js +441 -0
- package/dist/redis-QVQ6YU62.js.map +1 -0
- package/dist/sqlite-4I2P2OGQ.js +554 -0
- package/dist/sqlite-4I2P2OGQ.js.map +1 -0
- package/dist/sqlite-OA4YJX5S.mjs +531 -0
- package/dist/sqlite-OA4YJX5S.mjs.map +1 -0
- package/dist/types-BJvJfxSY.d.mts +141 -0
- package/dist/types-BJvJfxSY.d.ts +141 -0
- package/dist/types-ClAg_v5k.d.mts +343 -0
- package/dist/types-Der_X8E8.d.ts +343 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/types.mjs +3 -0
- package/dist/types.mjs.map +1 -0
- package/dist/workspace.d.mts +80 -0
- package/dist/workspace.d.ts +80 -0
- package/dist/workspace.js +4174 -0
- package/dist/workspace.js.map +1 -0
- package/dist/workspace.mjs +4147 -0
- package/dist/workspace.mjs.map +1 -0
- package/package.json +60 -5
- package/.claude/settings.local.json +0 -127
- package/.cursorrules +0 -426
- package/.devin/wiki.json +0 -143
- package/.dockerignore +0 -80
- package/.env.example +0 -159
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -49
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -29
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -57
- package/.github/workflows/ci.yml +0 -185
- package/.github/workflows/codeql.yml +0 -57
- package/.github/workflows/docker-build-push.yml +0 -118
- package/.github/workflows/helm-release.yml +0 -113
- package/CLAUDE.md +0 -265
- package/CODE_OF_CONDUCT.md +0 -124
- package/CONTRIBUTING.md +0 -154
- package/Dockerfile +0 -73
- package/SECURITY.md +0 -107
- package/artifacthub-repo.yml +0 -4
- package/bun.lock +0 -1714
- package/bunfig.toml +0 -3
- package/charts/libredb-studio/.helmignore +0 -11
- package/charts/libredb-studio/Chart.lock +0 -6
- package/charts/libredb-studio/Chart.yaml +0 -50
- package/charts/libredb-studio/README.md +0 -206
- package/charts/libredb-studio/templates/NOTES.txt +0 -59
- package/charts/libredb-studio/templates/_helpers.tpl +0 -135
- package/charts/libredb-studio/templates/configmap.yaml +0 -37
- package/charts/libredb-studio/templates/deployment.yaml +0 -184
- package/charts/libredb-studio/templates/hpa.yaml +0 -32
- package/charts/libredb-studio/templates/ingress.yaml +0 -41
- package/charts/libredb-studio/templates/networkpolicy.yaml +0 -50
- package/charts/libredb-studio/templates/pdb.yaml +0 -18
- package/charts/libredb-studio/templates/pvc.yaml +0 -23
- package/charts/libredb-studio/templates/secret.yaml +0 -30
- package/charts/libredb-studio/templates/seed-configmap.yaml +0 -11
- package/charts/libredb-studio/templates/service.yaml +0 -22
- package/charts/libredb-studio/templates/serviceaccount.yaml +0 -13
- package/charts/libredb-studio/values.schema.json +0 -246
- package/charts/libredb-studio/values.yaml +0 -286
- package/components.json +0 -22
- package/conductor/code_styleguides/typescript.md +0 -43
- package/conductor/product-guidelines.md +0 -43
- package/conductor/product.md +0 -3
- package/conductor/setup_state.json +0 -1
- package/conductor/tech-stack.md +0 -39
- package/conductor/tracks/enhance_postgres_monitoring_20251227/metadata.json +0 -8
- package/conductor/tracks/enhance_postgres_monitoring_20251227/plan.md +0 -44
- package/conductor/tracks/enhance_postgres_monitoring_20251227/spec.md +0 -31
- package/conductor/tracks.md +0 -8
- package/conductor/workflow.md +0 -333
- package/database-compose.yml +0 -55
- package/docker/postgres-init/01-extensions.sql +0 -10
- package/docker/postgres-init/02-sample-data.sql +0 -585
- package/docker/postgres.yml +0 -68
- package/docker-compose.yml +0 -38
- package/docs/AI_PLAN.md +0 -74
- package/docs/API_DOCS.md +0 -875
- package/docs/ARCHITECTURE.md +0 -218
- package/docs/DATABASE_PROVIDERS.md +0 -358
- package/docs/FEATURES.md +0 -116
- package/docs/HELM_CHART.md +0 -252
- package/docs/LOGIN_PAGE.md +0 -178
- package/docs/MONACO_EDITOR_PERFORMANCE.md +0 -315
- package/docs/OIDC_ARCH.md +0 -681
- package/docs/OIDC_SETUP.md +0 -322
- package/docs/POSTGRES_METRICS.md +0 -516
- package/docs/QUERY_OPTIMIZATION.md +0 -370
- package/docs/SEED_CONNECTIONS.md +0 -468
- package/docs/SQL_ALIAS_COMPLETION.md +0 -190
- package/docs/STORAGE_ARCHITECTURE.md +0 -565
- package/docs/STORAGE_QUICK_SETUP.md +0 -419
- package/docs/TECHNICAL_PLAN.md +0 -36
- package/docs/THEMING.md +0 -345
- package/docs/adding-a-new-database-provider.md +0 -642
- package/docs/backlogs/000-PLATFORM_DATA_SYNC_DATABASE.md +0 -360
- package/docs/backlogs/001-INLINE_DATA_EDITING.md +0 -118
- package/docs/backlogs/002-DATA_IMPORT.md +0 -215
- package/docs/backlogs/003-QUERY_TIME_MACHINE.md +0 -183
- package/docs/backlogs/004-AI_DATA_STORYTELLER.md +0 -292
- package/docs/backlogs/005-QUERY_PLAYGROUND.md +0 -352
- package/docs/backlogs/006-DATA_MASKING.md +0 -418
- package/docs/enterprise-features.md +0 -718
- package/docs/kubernetes-helm-chart-artifacthub-plan.md +0 -803
- package/docs/medium-koyeb-article-en.md +0 -215
- package/docs/plans/test-plans.md +0 -445
- package/docs/releases/RELEASE.V0.3.0.md +0 -22
- package/docs/releases/RELEASE.V0.4.0.md +0 -154
- package/docs/releases/RELEASE.V0.5.0.md +0 -252
- package/docs/releases/RELEASE_v0.5.6.md +0 -145
- package/docs/releases/RELEASE_v0.6.1.md +0 -303
- package/docs/releases/RELEASE_v0.6.7.md +0 -292
- package/docs/releases/RELEASE_v0.7.0.md +0 -332
- package/docs/releases/RELEASE_v0.8.0.md +0 -521
- package/docs/sampledb/titanic.sql +0 -1379
- package/docs/superpowers/plans/2026-03-25-seed-connections.md +0 -1362
- package/docs/superpowers/specs/2026-03-25-seed-connections-design.md +0 -590
- package/e2e/admin-dashboard.spec.ts +0 -64
- package/e2e/connection-management.spec.ts +0 -58
- package/e2e/export.spec.ts +0 -34
- package/e2e/login.spec.ts +0 -85
- package/e2e/query-execution.spec.ts +0 -35
- package/e2e/tab-management.spec.ts +0 -64
- package/eslint.config.mjs +0 -28
- package/fly.toml +0 -43
- package/next.config.ts +0 -32
- package/playwright.config.ts +0 -34
- package/postcss.config.mjs +0 -7
- package/public/favicon-32x32.png +0 -0
- package/public/favicon.ico +0 -0
- package/public/file.svg +0 -1
- package/public/globe.svg +0 -1
- package/public/logo.svg +0 -32
- package/public/next.svg +0 -1
- package/public/screenshots/code-generator.png +0 -0
- package/public/screenshots/connection-modal.png +0 -0
- package/public/screenshots/data-profiler.png +0 -0
- package/public/screenshots/erd-diagram.png +0 -0
- package/public/screenshots/hero-editor.png +0 -0
- package/public/screenshots/nl2sql.png +0 -0
- package/public/vercel.svg +0 -1
- package/public/window.svg +0 -1
- package/render.yaml +0 -58
- package/scripts/merge-lcov.mjs +0 -239
- package/sonar-project.properties +0 -16
- package/src/app/admin/error.tsx +0 -46
- package/src/app/admin/page.tsx +0 -10
- package/src/app/api/admin/audit/route.ts +0 -52
- package/src/app/api/admin/fleet-health/route.ts +0 -81
- package/src/app/api/ai/autopilot/route.ts +0 -105
- package/src/app/api/ai/chat/route.ts +0 -132
- package/src/app/api/ai/describe-schema/route.ts +0 -52
- package/src/app/api/ai/explain/route.ts +0 -86
- package/src/app/api/ai/impact/route.ts +0 -97
- package/src/app/api/ai/index-advisor/route.ts +0 -98
- package/src/app/api/ai/nl2sql/route.ts +0 -87
- package/src/app/api/ai/query-safety/route.ts +0 -87
- package/src/app/api/auth/login/route.ts +0 -62
- package/src/app/api/auth/logout/route.ts +0 -25
- package/src/app/api/auth/me/route.ts +0 -10
- package/src/app/api/auth/oidc/callback/route.ts +0 -82
- package/src/app/api/auth/oidc/login/route.ts +0 -43
- package/src/app/api/connections/managed/route.ts +0 -35
- package/src/app/api/db/cancel/route.ts +0 -42
- package/src/app/api/db/disconnect/route.ts +0 -28
- package/src/app/api/db/health/route.ts +0 -49
- package/src/app/api/db/maintenance/route.ts +0 -72
- package/src/app/api/db/monitoring/route.ts +0 -62
- package/src/app/api/db/multi-query/route.ts +0 -116
- package/src/app/api/db/pool-stats/route.ts +0 -37
- package/src/app/api/db/profile/route.ts +0 -144
- package/src/app/api/db/provider-meta/route.ts +0 -49
- package/src/app/api/db/query/route.ts +0 -50
- package/src/app/api/db/schema/route.ts +0 -47
- package/src/app/api/db/schema-snapshot/route.ts +0 -42
- package/src/app/api/db/test-connection/route.ts +0 -55
- package/src/app/api/db/transaction/route.ts +0 -111
- package/src/app/api/storage/[collection]/route.ts +0 -67
- package/src/app/api/storage/config/route.ts +0 -17
- package/src/app/api/storage/migrate/route.ts +0 -45
- package/src/app/api/storage/route.ts +0 -32
- package/src/app/error.tsx +0 -49
- package/src/app/global-error.tsx +0 -55
- package/src/app/globals.css +0 -146
- package/src/app/icon.svg +0 -42
- package/src/app/layout.tsx +0 -34
- package/src/app/login/login-form.tsx +0 -301
- package/src/app/login/page.tsx +0 -11
- package/src/app/monitoring/page.tsx +0 -8
- package/src/app/not-found.tsx +0 -29
- package/src/app/page.tsx +0 -5
- package/src/components/AIAutopilotPanel.tsx +0 -238
- package/src/components/CodeGenerator.tsx +0 -271
- package/src/components/CommandPalette.tsx +0 -227
- package/src/components/ConnectionModal.tsx +0 -759
- package/src/components/CreateTableModal.tsx +0 -281
- package/src/components/DataCharts.tsx +0 -962
- package/src/components/DataImportModal.tsx +0 -582
- package/src/components/DataProfiler.tsx +0 -335
- package/src/components/DatabaseDocs.tsx +0 -251
- package/src/components/MaskingSettings.tsx +0 -414
- package/src/components/MobileNav.tsx +0 -50
- package/src/components/NL2SQLPanel.tsx +0 -281
- package/src/components/PivotTable.tsx +0 -257
- package/src/components/QueryEditor.tsx +0 -760
- package/src/components/QueryHistory.tsx +0 -344
- package/src/components/QuerySafetyDialog.tsx +0 -290
- package/src/components/ResultsGrid.tsx +0 -644
- package/src/components/SaveQueryModal.tsx +0 -104
- package/src/components/SavedQueries.tsx +0 -128
- package/src/components/SchemaDiagram.tsx +0 -473
- package/src/components/SchemaDiff.tsx +0 -473
- package/src/components/SnapshotTimeline.tsx +0 -116
- package/src/components/Studio.tsx +0 -639
- package/src/components/TestDataGenerator.tsx +0 -261
- package/src/components/VisualExplain.tsx +0 -820
- package/src/components/admin/AdminDashboard.tsx +0 -163
- package/src/components/admin/tabs/AuditTab.tsx +0 -531
- package/src/components/admin/tabs/MonitoringEmbed.tsx +0 -11
- package/src/components/admin/tabs/OperationsTab.tsx +0 -646
- package/src/components/admin/tabs/OverviewTab.tsx +0 -1328
- package/src/components/admin/tabs/SecurityTab.tsx +0 -284
- package/src/components/community-section.tsx +0 -92
- package/src/components/icons/db-icons.tsx +0 -84
- package/src/components/libredb-logo.tsx +0 -61
- package/src/components/monitoring/MonitoringDashboard.tsx +0 -345
- package/src/components/monitoring/tabs/MetricChart.tsx +0 -82
- package/src/components/monitoring/tabs/OverviewTab.tsx +0 -263
- package/src/components/monitoring/tabs/PerformanceTab.tsx +0 -254
- package/src/components/monitoring/tabs/PoolTab.tsx +0 -174
- package/src/components/monitoring/tabs/QueriesTab.tsx +0 -287
- package/src/components/monitoring/tabs/SessionsTab.tsx +0 -316
- package/src/components/monitoring/tabs/StorageTab.tsx +0 -335
- package/src/components/monitoring/tabs/TablesTab.tsx +0 -300
- package/src/components/results-grid/ResultCard.tsx +0 -111
- package/src/components/results-grid/RowDetailSheet.tsx +0 -178
- package/src/components/results-grid/StatsBar.tsx +0 -201
- package/src/components/results-grid/index.ts +0 -1
- package/src/components/results-grid/utils.ts +0 -23
- package/src/components/schema-explorer/ColumnList.tsx +0 -53
- package/src/components/schema-explorer/SchemaExplorer.tsx +0 -182
- package/src/components/schema-explorer/TableItem.tsx +0 -210
- package/src/components/schema-explorer/index.ts +0 -1
- package/src/components/sidebar/ConnectionItem.tsx +0 -105
- package/src/components/sidebar/ConnectionsList.tsx +0 -62
- package/src/components/sidebar/Sidebar.tsx +0 -130
- package/src/components/sidebar/index.ts +0 -2
- package/src/components/studio/BottomPanel.tsx +0 -286
- package/src/components/studio/QueryToolbar.tsx +0 -180
- package/src/components/studio/StudioDesktopHeader.tsx +0 -114
- package/src/components/studio/StudioMobileHeader.tsx +0 -340
- package/src/components/studio/StudioTabBar.tsx +0 -82
- package/src/components/studio/index.ts +0 -5
- package/src/components/ui/accordion.tsx +0 -66
- package/src/components/ui/alert-dialog.tsx +0 -157
- package/src/components/ui/alert.tsx +0 -66
- package/src/components/ui/aspect-ratio.tsx +0 -11
- package/src/components/ui/avatar.tsx +0 -53
- package/src/components/ui/badge.tsx +0 -46
- package/src/components/ui/breadcrumb.tsx +0 -109
- package/src/components/ui/button-group.tsx +0 -83
- package/src/components/ui/button.tsx +0 -60
- package/src/components/ui/calendar.tsx +0 -216
- package/src/components/ui/card.tsx +0 -92
- package/src/components/ui/carousel.tsx +0 -241
- package/src/components/ui/chart.tsx +0 -357
- package/src/components/ui/checkbox.tsx +0 -32
- package/src/components/ui/collapsible.tsx +0 -33
- package/src/components/ui/command.tsx +0 -184
- package/src/components/ui/context-menu.tsx +0 -252
- package/src/components/ui/dialog.tsx +0 -143
- package/src/components/ui/drawer.tsx +0 -135
- package/src/components/ui/dropdown-menu.tsx +0 -257
- package/src/components/ui/empty.tsx +0 -104
- package/src/components/ui/field.tsx +0 -248
- package/src/components/ui/form.tsx +0 -167
- package/src/components/ui/hover-card.tsx +0 -44
- package/src/components/ui/input-group.tsx +0 -170
- package/src/components/ui/input-otp.tsx +0 -77
- package/src/components/ui/input.tsx +0 -21
- package/src/components/ui/item.tsx +0 -193
- package/src/components/ui/kbd.tsx +0 -28
- package/src/components/ui/label.tsx +0 -24
- package/src/components/ui/menubar.tsx +0 -276
- package/src/components/ui/navigation-menu.tsx +0 -168
- package/src/components/ui/pagination.tsx +0 -127
- package/src/components/ui/popover.tsx +0 -48
- package/src/components/ui/progress.tsx +0 -31
- package/src/components/ui/radio-group.tsx +0 -45
- package/src/components/ui/resizable.tsx +0 -56
- package/src/components/ui/scroll-area.tsx +0 -58
- package/src/components/ui/select.tsx +0 -187
- package/src/components/ui/separator.tsx +0 -28
- package/src/components/ui/sheet.tsx +0 -139
- package/src/components/ui/sidebar.tsx +0 -726
- package/src/components/ui/skeleton.tsx +0 -13
- package/src/components/ui/slider.tsx +0 -63
- package/src/components/ui/sonner.tsx +0 -40
- package/src/components/ui/spinner.tsx +0 -16
- package/src/components/ui/switch.tsx +0 -31
- package/src/components/ui/table.tsx +0 -116
- package/src/components/ui/tabs.tsx +0 -66
- package/src/components/ui/textarea.tsx +0 -18
- package/src/components/ui/toggle-group.tsx +0 -83
- package/src/components/ui/toggle.tsx +0 -47
- package/src/components/ui/tooltip.tsx +0 -61
- package/src/exports/components.ts +0 -15
- package/src/exports/index.ts +0 -4
- package/src/exports/providers.ts +0 -4
- package/src/exports/types.ts +0 -26
- package/src/hooks/use-ai-chat.ts +0 -182
- package/src/hooks/use-all-connections.ts +0 -66
- package/src/hooks/use-api-call.ts +0 -71
- package/src/hooks/use-auth.ts +0 -51
- package/src/hooks/use-connection-form.ts +0 -349
- package/src/hooks/use-connection-manager.ts +0 -169
- package/src/hooks/use-connection-payload.ts +0 -15
- package/src/hooks/use-inline-editing.ts +0 -109
- package/src/hooks/use-mobile.ts +0 -20
- package/src/hooks/use-monitoring-data.ts +0 -270
- package/src/hooks/use-provider-metadata.ts +0 -62
- package/src/hooks/use-query-execution.ts +0 -478
- package/src/hooks/use-storage-sync.ts +0 -259
- package/src/hooks/use-tab-manager.ts +0 -231
- package/src/hooks/use-toast.ts +0 -20
- package/src/hooks/use-transaction-control.ts +0 -64
- package/src/lib/api/error-codes.ts +0 -30
- package/src/lib/api/errors.ts +0 -236
- package/src/lib/api/with-error-handler.ts +0 -41
- package/src/lib/audit.ts +0 -105
- package/src/lib/auth.ts +0 -87
- package/src/lib/connection-string-parser.ts +0 -172
- package/src/lib/data-masking.ts +0 -385
- package/src/lib/db/base-provider.ts +0 -325
- package/src/lib/db/errors.ts +0 -317
- package/src/lib/db/factory.ts +0 -324
- package/src/lib/db/index.ts +0 -123
- package/src/lib/db/providers/document/index.ts +0 -6
- package/src/lib/db/providers/document/mongodb.ts +0 -992
- package/src/lib/db/providers/keyvalue/redis.ts +0 -554
- package/src/lib/db/providers/sql/index.ts +0 -11
- package/src/lib/db/providers/sql/sql-base.ts +0 -174
- package/src/lib/db/providers/sql/sqlite.ts +0 -721
- package/src/lib/db/types.ts +0 -437
- package/src/lib/db/utils/pool-manager.ts +0 -287
- package/src/lib/db/utils/query-limiter.ts +0 -239
- package/src/lib/db-ui-config.ts +0 -86
- package/src/lib/editor/mongodb-completions.ts +0 -172
- package/src/lib/editor/sql-completions.ts +0 -280
- package/src/lib/llm/base-provider.ts +0 -117
- package/src/lib/llm/factory.ts +0 -102
- package/src/lib/llm/index.ts +0 -90
- package/src/lib/llm/providers/custom.ts +0 -181
- package/src/lib/llm/providers/gemini.ts +0 -126
- package/src/lib/llm/providers/ollama.ts +0 -154
- package/src/lib/llm/providers/openai.ts +0 -146
- package/src/lib/llm/types.ts +0 -173
- package/src/lib/llm/utils/config.ts +0 -187
- package/src/lib/llm/utils/retry.ts +0 -119
- package/src/lib/llm/utils/streaming.ts +0 -202
- package/src/lib/logger.ts +0 -127
- package/src/lib/monitoring-thresholds.ts +0 -44
- package/src/lib/oidc.ts +0 -262
- package/src/lib/query-generators.ts +0 -61
- package/src/lib/schema-diff/diff-engine.ts +0 -273
- package/src/lib/schema-diff/migration-generator.ts +0 -208
- package/src/lib/schema-diff/types.ts +0 -55
- package/src/lib/seed/config-loader.ts +0 -79
- package/src/lib/seed/connection-filter.ts +0 -49
- package/src/lib/seed/credential-resolver.ts +0 -62
- package/src/lib/seed/index.ts +0 -40
- package/src/lib/seed/resolve-connection.ts +0 -57
- package/src/lib/seed/types.ts +0 -69
- package/src/lib/sql/alias-extractor.ts +0 -267
- package/src/lib/sql/index.ts +0 -8
- package/src/lib/sql/statement-splitter.ts +0 -167
- package/src/lib/sql/types.ts +0 -40
- package/src/lib/ssh/tunnel.ts +0 -142
- package/src/lib/storage/factory.ts +0 -84
- package/src/lib/storage/index.ts +0 -14
- package/src/lib/storage/local-storage.ts +0 -99
- package/src/lib/storage/providers/postgres.ts +0 -225
- package/src/lib/storage/providers/sqlite.ts +0 -153
- package/src/lib/storage/storage-facade.ts +0 -272
- package/src/lib/storage/types.ts +0 -75
- package/src/lib/time-series-buffer.ts +0 -58
- package/src/lib/types.ts +0 -173
- package/src/lib/utils.ts +0 -6
- package/src/proxy.ts +0 -104
- package/src/types/db-drivers.d.ts +0 -23
- package/src/types/html2canvas.d.ts +0 -9
- package/tests/api/admin/audit.test.ts +0 -178
- package/tests/api/admin/fleet-health.test.ts +0 -183
- package/tests/api/ai/autopilot.test.ts +0 -174
- package/tests/api/ai/chat.test.ts +0 -250
- package/tests/api/ai/describe-schema.test.ts +0 -266
- package/tests/api/ai/explain.test.ts +0 -199
- package/tests/api/ai/impact.test.ts +0 -168
- package/tests/api/ai/index-advisor.test.ts +0 -171
- package/tests/api/ai/nl2sql.test.ts +0 -202
- package/tests/api/ai/query-safety.test.ts +0 -196
- package/tests/api/auth/login.test.ts +0 -170
- package/tests/api/auth/logout.test.ts +0 -140
- package/tests/api/auth/me.test.ts +0 -73
- package/tests/api/auth/oidc-callback.test.ts +0 -215
- package/tests/api/auth/oidc-login.test.ts +0 -127
- package/tests/api/db/cancel.test.ts +0 -198
- package/tests/api/db/disconnect.test.ts +0 -124
- package/tests/api/db/health.test.ts +0 -222
- package/tests/api/db/maintenance.test.ts +0 -263
- package/tests/api/db/monitoring.test.ts +0 -221
- package/tests/api/db/multi-query.test.ts +0 -316
- package/tests/api/db/pool-stats.test.ts +0 -135
- package/tests/api/db/profile.test.ts +0 -330
- package/tests/api/db/provider-meta.test.ts +0 -193
- package/tests/api/db/query.test.ts +0 -314
- package/tests/api/db/schema-snapshot.test.ts +0 -170
- package/tests/api/db/schema.test.ts +0 -191
- package/tests/api/db/test-connection.test.ts +0 -185
- package/tests/api/db/transaction.test.ts +0 -314
- package/tests/api/proxy.test.ts +0 -191
- package/tests/api/seed/managed-route.test.ts +0 -113
- package/tests/api/storage/config.test.ts +0 -42
- package/tests/api/storage/storage-routes.test.ts +0 -309
- package/tests/components/AIAutopilotPanel.test.tsx +0 -756
- package/tests/components/AdminPage.test.tsx +0 -33
- package/tests/components/CodeGenerator.test.tsx +0 -182
- package/tests/components/CommandPalette.test.tsx +0 -428
- package/tests/components/CommunitySection.test.tsx +0 -91
- package/tests/components/ConnectionModal.mobile.test.tsx +0 -284
- package/tests/components/ConnectionModal.test.tsx +0 -570
- package/tests/components/CreateTableModal.test.tsx +0 -383
- package/tests/components/DataCharts.test.tsx +0 -739
- package/tests/components/DataImportModal.test.tsx +0 -751
- package/tests/components/DataProfiler.test.tsx +0 -589
- package/tests/components/DatabaseDocs.test.tsx +0 -353
- package/tests/components/LoginPage.test.tsx +0 -163
- package/tests/components/LoginPageOIDC.test.tsx +0 -92
- package/tests/components/MaskingSettings.test.tsx +0 -498
- package/tests/components/MobileNav.test.tsx +0 -30
- package/tests/components/MonitoringPage.test.tsx +0 -32
- package/tests/components/NL2SQLPanel.test.tsx +0 -621
- package/tests/components/Page.test.tsx +0 -33
- package/tests/components/PivotTable.test.tsx +0 -350
- package/tests/components/QueryEditor.test.tsx +0 -1730
- package/tests/components/QueryHistory.test.tsx +0 -572
- package/tests/components/QuerySafetyDialog.test.tsx +0 -586
- package/tests/components/ResultsGrid.test.tsx +0 -804
- package/tests/components/RootLayout.test.tsx +0 -83
- package/tests/components/SaveQueryModal.test.tsx +0 -25
- package/tests/components/SavedQueries.test.tsx +0 -43
- package/tests/components/SchemaDiagram.test.tsx +0 -1034
- package/tests/components/SchemaDiff.test.tsx +0 -906
- package/tests/components/SnapshotTimeline.test.tsx +0 -174
- package/tests/components/Studio.test.tsx +0 -1030
- package/tests/components/TestDataGenerator.test.tsx +0 -291
- package/tests/components/VisualExplain.test.tsx +0 -704
- package/tests/components/admin/AdminDashboard.test.tsx +0 -205
- package/tests/components/admin/AuditTab.test.tsx +0 -220
- package/tests/components/admin/MonitoringEmbed.test.tsx +0 -58
- package/tests/components/admin/OperationsTab.test.tsx +0 -975
- package/tests/components/admin/OverviewTab.test.tsx +0 -254
- package/tests/components/admin/SecurityTab.test.tsx +0 -467
- package/tests/components/monitoring/MetricChart.test.tsx +0 -111
- package/tests/components/monitoring/MonitoringDashboard.test.tsx +0 -259
- package/tests/components/monitoring/OverviewTab.test.tsx +0 -78
- package/tests/components/monitoring/PerformanceTab.test.tsx +0 -87
- package/tests/components/monitoring/PoolTab.test.tsx +0 -42
- package/tests/components/monitoring/QueriesTab.test.tsx +0 -80
- package/tests/components/monitoring/SessionsTab.test.tsx +0 -154
- package/tests/components/monitoring/StorageTab.test.tsx +0 -127
- package/tests/components/monitoring/TablesTab.test.tsx +0 -153
- package/tests/components/results-grid/ResultCard.test.tsx +0 -105
- package/tests/components/results-grid/RowDetailSheet.test.tsx +0 -308
- package/tests/components/results-grid/StatsBar.test.tsx +0 -162
- package/tests/components/schema-explorer/ColumnList.test.tsx +0 -151
- package/tests/components/schema-explorer/SchemaExplorer.test.tsx +0 -461
- package/tests/components/schema-explorer/TableItem.test.tsx +0 -415
- package/tests/components/sidebar/ConnectionItem.test.tsx +0 -201
- package/tests/components/sidebar/ConnectionsList.test.tsx +0 -176
- package/tests/components/sidebar/Sidebar.test.tsx +0 -187
- package/tests/components/studio/BottomPanel.test.tsx +0 -383
- package/tests/components/studio/QueryToolbar.test.tsx +0 -321
- package/tests/components/studio/StudioDesktopHeader.test.tsx +0 -377
- package/tests/components/studio/StudioMobileHeader.test.tsx +0 -198
- package/tests/components/studio/StudioTabBar.test.tsx +0 -331
- package/tests/fixtures/connections.ts +0 -96
- package/tests/fixtures/masking-configs.ts +0 -86
- package/tests/fixtures/query-results.ts +0 -71
- package/tests/fixtures/schemas.ts +0 -64
- package/tests/fixtures/seed-connections/invalid-config.yaml +0 -7
- package/tests/fixtures/seed-connections/minimal-config.yaml +0 -8
- package/tests/fixtures/seed-connections/mixed-credentials.yaml +0 -23
- package/tests/fixtures/seed-connections/multi-role-config.yaml +0 -30
- package/tests/fixtures/seed-connections/valid-config.json +0 -15
- package/tests/fixtures/seed-connections/valid-config.yaml +0 -51
- package/tests/helpers/mock-fetch.ts +0 -59
- package/tests/helpers/mock-monaco.ts +0 -112
- package/tests/helpers/mock-navigation.ts +0 -28
- package/tests/helpers/mock-next.ts +0 -80
- package/tests/helpers/mock-provider.ts +0 -133
- package/tests/helpers/mock-sonner.ts +0 -29
- package/tests/helpers/render-with-providers.tsx +0 -19
- package/tests/hooks/use-ai-chat.test.ts +0 -600
- package/tests/hooks/use-auth.test.ts +0 -371
- package/tests/hooks/use-connection-form.test.ts +0 -743
- package/tests/hooks/use-connection-manager.test.ts +0 -466
- package/tests/hooks/use-inline-editing.test.ts +0 -321
- package/tests/hooks/use-mobile.test.ts +0 -177
- package/tests/hooks/use-monitoring-data.test.ts +0 -819
- package/tests/hooks/use-provider-metadata.test.ts +0 -228
- package/tests/hooks/use-query-execution.test.ts +0 -1212
- package/tests/hooks/use-tab-manager.test.ts +0 -756
- package/tests/hooks/use-toast.test.ts +0 -74
- package/tests/hooks/use-transaction-control.test.ts +0 -211
- package/tests/integration/db/mongodb-provider.test.ts +0 -698
- package/tests/integration/db/mssql-provider.test.ts +0 -840
- package/tests/integration/db/mysql-provider.test.ts +0 -872
- package/tests/integration/db/oracle-provider.test.ts +0 -843
- package/tests/integration/db/postgres-provider.test.ts +0 -1382
- package/tests/integration/db/redis-provider.test.ts +0 -526
- package/tests/integration/db/sqlite-provider.test.ts +0 -480
- package/tests/integration/seed/seed-pipeline.test.ts +0 -102
- package/tests/isolated/factory-singleton.test.ts +0 -150
- package/tests/isolated/use-storage-sync.test.ts +0 -389
- package/tests/run-components.sh +0 -196
- package/tests/setup-dom.ts +0 -58
- package/tests/setup.ts +0 -40
- package/tests/unit/api-errors.test.ts +0 -210
- package/tests/unit/code-generator-functions.test.ts +0 -271
- package/tests/unit/components/column-list.test.tsx +0 -190
- package/tests/unit/components/data-import-modal.test.tsx +0 -441
- package/tests/unit/components/studio-mobile-header.test.tsx +0 -327
- package/tests/unit/data-charts-functions.test.ts +0 -496
- package/tests/unit/data-import-functions.test.ts +0 -320
- package/tests/unit/data-import-utils.test.ts +0 -125
- package/tests/unit/db/base-provider.test.ts +0 -517
- package/tests/unit/db/errors.test.ts +0 -403
- package/tests/unit/db/factory.test.ts +0 -436
- package/tests/unit/db/pool-manager.test.ts +0 -440
- package/tests/unit/db/query-limiter.test.ts +0 -387
- package/tests/unit/db/sql-base.test.ts +0 -438
- package/tests/unit/lib/api/error-codes.test.ts +0 -39
- package/tests/unit/lib/audit.test.ts +0 -326
- package/tests/unit/lib/auth.test.ts +0 -146
- package/tests/unit/lib/connection-string-parser.test.ts +0 -424
- package/tests/unit/lib/data-masking.test.ts +0 -583
- package/tests/unit/lib/db-icons.test.tsx +0 -41
- package/tests/unit/lib/monitoring-thresholds.test.ts +0 -133
- package/tests/unit/lib/oidc.test.ts +0 -509
- package/tests/unit/lib/query-generators.test.ts +0 -127
- package/tests/unit/lib/storage/factory.test.ts +0 -71
- package/tests/unit/lib/storage/local-storage.test.ts +0 -114
- package/tests/unit/lib/storage/providers/postgres.test.ts +0 -312
- package/tests/unit/lib/storage/providers/sqlite.test.ts +0 -232
- package/tests/unit/lib/storage/storage-facade-extended.test.ts +0 -331
- package/tests/unit/lib/storage/storage-facade.test.ts +0 -184
- package/tests/unit/lib/storage.test.ts +0 -317
- package/tests/unit/lib/time-series-buffer.test.ts +0 -212
- package/tests/unit/lib/utils.test.ts +0 -24
- package/tests/unit/llm/base-provider.test.ts +0 -238
- package/tests/unit/llm/config.test.ts +0 -262
- package/tests/unit/llm/custom-provider.test.ts +0 -281
- package/tests/unit/llm/gemini-provider.test.ts +0 -248
- package/tests/unit/llm/llm-factory.test.ts +0 -155
- package/tests/unit/llm/ollama-provider.test.ts +0 -288
- package/tests/unit/llm/openai-provider.test.ts +0 -324
- package/tests/unit/llm/retry.test.ts +0 -180
- package/tests/unit/llm/streaming.test.ts +0 -355
- package/tests/unit/logger.test.ts +0 -198
- package/tests/unit/mongodb-completions.test.ts +0 -516
- package/tests/unit/pivot-table-functions.test.ts +0 -76
- package/tests/unit/query-cancelled-error.test.ts +0 -81
- package/tests/unit/schema-diff/diff-engine.test.ts +0 -367
- package/tests/unit/schema-diff/migration-generator.test.ts +0 -513
- package/tests/unit/seed/config-loader.test.ts +0 -73
- package/tests/unit/seed/connection-filter.test.ts +0 -91
- package/tests/unit/seed/credential-resolver.test.ts +0 -85
- package/tests/unit/seed/index.test.ts +0 -72
- package/tests/unit/seed/resolve-connection.test.ts +0 -74
- package/tests/unit/seed/types.test.ts +0 -129
- package/tests/unit/sql/alias-extractor.test.ts +0 -444
- package/tests/unit/sql/statement-splitter.test.ts +0 -348
- package/tests/unit/sql-completions.test.ts +0 -463
- package/tests/unit/ssh-tunnel.test.ts +0 -465
- package/tsconfig.json +0 -42
|
@@ -1,1382 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integration tests for PostgresProvider
|
|
3
|
-
* Uses mock.module() to intercept pg before provider import.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { describe, test, expect, beforeEach, afterEach, mock } from 'bun:test';
|
|
7
|
-
import type { DatabaseConnection } from '@/lib/types';
|
|
8
|
-
import { DatabaseConfigError } from '@/lib/db/errors';
|
|
9
|
-
|
|
10
|
-
// ============================================================================
|
|
11
|
-
// Mock pg BEFORE importing the provider
|
|
12
|
-
// ============================================================================
|
|
13
|
-
|
|
14
|
-
let mockQueryFn: (sql: string, params?: unknown[]) => Promise<{
|
|
15
|
-
rows: unknown[];
|
|
16
|
-
fields?: { name: string }[];
|
|
17
|
-
rowCount?: number;
|
|
18
|
-
}>;
|
|
19
|
-
|
|
20
|
-
const mockClient = {
|
|
21
|
-
query: (sql: string, params?: unknown[]) => mockQueryFn(sql, params),
|
|
22
|
-
release: () => {},
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const mockPool = {
|
|
26
|
-
connect: async () => mockClient,
|
|
27
|
-
end: async () => {},
|
|
28
|
-
totalCount: 10,
|
|
29
|
-
idleCount: 7,
|
|
30
|
-
waitingCount: 0,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
mock.module('pg', () => ({
|
|
34
|
-
Pool: function () {
|
|
35
|
-
return mockPool;
|
|
36
|
-
},
|
|
37
|
-
}));
|
|
38
|
-
|
|
39
|
-
// Dynamic import AFTER mock is installed
|
|
40
|
-
const { PostgresProvider } = await import('@/lib/db/providers/sql/postgres');
|
|
41
|
-
|
|
42
|
-
// ============================================================================
|
|
43
|
-
// Helpers
|
|
44
|
-
// ============================================================================
|
|
45
|
-
|
|
46
|
-
function makePgConfig(overrides: Partial<DatabaseConnection> = {}): DatabaseConnection {
|
|
47
|
-
return {
|
|
48
|
-
id: 'test-pg',
|
|
49
|
-
name: 'Test Postgres',
|
|
50
|
-
type: 'postgres',
|
|
51
|
-
host: 'localhost',
|
|
52
|
-
port: 5432,
|
|
53
|
-
database: 'testdb',
|
|
54
|
-
user: 'postgres',
|
|
55
|
-
password: 'secret',
|
|
56
|
-
createdAt: new Date(),
|
|
57
|
-
...overrides,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Default mock query that matches SQL patterns and returns appropriate mock data.
|
|
63
|
-
*/
|
|
64
|
-
function defaultMockQuery(
|
|
65
|
-
sql: string
|
|
66
|
-
): Promise<{ rows: unknown[]; fields?: { name: string }[]; rowCount?: number }> {
|
|
67
|
-
const normalized = sql.trim().toLowerCase();
|
|
68
|
-
|
|
69
|
-
// pg_backend_pid — PID tracking for query cancellation
|
|
70
|
-
if (normalized.includes('pg_backend_pid()') && normalized.includes('select') && !normalized.includes('pg_stat_activity')) {
|
|
71
|
-
return Promise.resolve({ rows: [{ pid: 12345 }], fields: [{ name: 'pid' }], rowCount: 1 });
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// pg_cancel_backend — cancel a running query
|
|
75
|
-
if (normalized.includes('pg_cancel_backend')) {
|
|
76
|
-
return Promise.resolve({ rows: [{ cancelled: true }], fields: [{ name: 'cancelled' }], rowCount: 1 });
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// pg_terminate_backend — kill session
|
|
80
|
-
if (normalized.includes('pg_terminate_backend')) {
|
|
81
|
-
return Promise.resolve({
|
|
82
|
-
rows: [{ pg_terminate_backend: true }],
|
|
83
|
-
fields: [{ name: 'pg_terminate_backend' }],
|
|
84
|
-
rowCount: 1,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// BEGIN / COMMIT / ROLLBACK — transaction control
|
|
89
|
-
if (normalized === 'begin' || normalized === 'commit' || normalized === 'rollback') {
|
|
90
|
-
return Promise.resolve({ rows: [], fields: [], rowCount: 0 });
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// VACUUM ANALYZE
|
|
94
|
-
if (normalized.includes('vacuum analyze') || normalized === 'vacuum analyze') {
|
|
95
|
-
return Promise.resolve({ rows: [], fields: [], rowCount: 0 });
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// ANALYZE (without vacuum)
|
|
99
|
-
if (normalized.startsWith('analyze')) {
|
|
100
|
-
return Promise.resolve({ rows: [], fields: [], rowCount: 0 });
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// REINDEX
|
|
104
|
-
if (normalized.startsWith('reindex')) {
|
|
105
|
-
return Promise.resolve({ rows: [], fields: [], rowCount: 0 });
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// SELECT * FROM pg_stat_activity (exact, getPgStatActivity)
|
|
109
|
-
if (normalized.includes('select * from pg_stat_activity')) {
|
|
110
|
-
return Promise.resolve({
|
|
111
|
-
rows: [
|
|
112
|
-
{
|
|
113
|
-
datname: 'testdb',
|
|
114
|
-
pid: 123,
|
|
115
|
-
usename: 'testuser',
|
|
116
|
-
application_name: 'testapp',
|
|
117
|
-
client_addr: '127.0.0.1',
|
|
118
|
-
backend_start: new Date().toISOString(),
|
|
119
|
-
state: 'active',
|
|
120
|
-
query: 'SELECT * FROM test_table',
|
|
121
|
-
},
|
|
122
|
-
],
|
|
123
|
-
fields: [
|
|
124
|
-
{ name: 'datname' },
|
|
125
|
-
{ name: 'pid' },
|
|
126
|
-
{ name: 'usename' },
|
|
127
|
-
{ name: 'application_name' },
|
|
128
|
-
{ name: 'client_addr' },
|
|
129
|
-
{ name: 'backend_start' },
|
|
130
|
-
{ name: 'state' },
|
|
131
|
-
{ name: 'query' },
|
|
132
|
-
],
|
|
133
|
-
rowCount: 1,
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// getHealth: count(*) from pg_stat_activity
|
|
138
|
-
if (normalized.includes('count(*)') && normalized.includes('pg_stat_activity') && !normalized.includes('max_connections')) {
|
|
139
|
-
return Promise.resolve({ rows: [{ count: '5' }], fields: [{ name: 'count' }], rowCount: 1 });
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// getHealth: pg_size_pretty(pg_database_size(...))
|
|
143
|
-
if (normalized.includes('pg_size_pretty') && normalized.includes('pg_database_size') && !normalized.includes('pg_tablespace')) {
|
|
144
|
-
return Promise.resolve({
|
|
145
|
-
rows: [{ pg_size_pretty: '256 MB', database_size: '256 MB', database_size_bytes: '268435456' }],
|
|
146
|
-
fields: [{ name: 'pg_size_pretty' }],
|
|
147
|
-
rowCount: 1,
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// pg_stat_statements with total_exec_time (getHealth slow queries)
|
|
152
|
-
if (normalized.includes('pg_stat_statements') && normalized.includes('total_exec_time desc') && normalized.includes('left(query, 100)')) {
|
|
153
|
-
return Promise.resolve({
|
|
154
|
-
rows: [
|
|
155
|
-
{ query: 'SELECT * FROM users', calls: 100, avgtime: '12.5ms' },
|
|
156
|
-
],
|
|
157
|
-
fields: [{ name: 'query' }, { name: 'calls' }, { name: 'avgtime' }],
|
|
158
|
-
rowCount: 1,
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// pg_stat_statements (getSlowQueries — detailed fields)
|
|
163
|
-
if (normalized.includes('pg_stat_statements') && normalized.includes('total_exec_time desc')) {
|
|
164
|
-
return Promise.resolve({
|
|
165
|
-
rows: [
|
|
166
|
-
{
|
|
167
|
-
query_id: '12345',
|
|
168
|
-
query: 'SELECT * FROM users WHERE id = $1',
|
|
169
|
-
calls: '200',
|
|
170
|
-
total_time: '5000.00',
|
|
171
|
-
avg_time: '25.00',
|
|
172
|
-
min_time: '1.00',
|
|
173
|
-
max_time: '150.00',
|
|
174
|
-
rows: '200',
|
|
175
|
-
shared_blks_hit: '8000',
|
|
176
|
-
shared_blks_read: '50',
|
|
177
|
-
},
|
|
178
|
-
],
|
|
179
|
-
fields: [
|
|
180
|
-
{ name: 'query_id' },
|
|
181
|
-
{ name: 'query' },
|
|
182
|
-
{ name: 'calls' },
|
|
183
|
-
{ name: 'total_time' },
|
|
184
|
-
{ name: 'avg_time' },
|
|
185
|
-
{ name: 'min_time' },
|
|
186
|
-
{ name: 'max_time' },
|
|
187
|
-
{ name: 'rows' },
|
|
188
|
-
{ name: 'shared_blks_hit' },
|
|
189
|
-
{ name: 'shared_blks_read' },
|
|
190
|
-
],
|
|
191
|
-
rowCount: 1,
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// pg_stat_activity fallback slow queries (state = 'active')
|
|
196
|
-
if (normalized.includes('pg_stat_activity') && normalized.includes("state = 'active'") && normalized.includes('query_start asc')) {
|
|
197
|
-
return Promise.resolve({
|
|
198
|
-
rows: [
|
|
199
|
-
{
|
|
200
|
-
query_id: '999',
|
|
201
|
-
query: 'SELECT * FROM slow_table',
|
|
202
|
-
calls: '1',
|
|
203
|
-
total_time: '3000',
|
|
204
|
-
avg_time: '3000',
|
|
205
|
-
rows: '0',
|
|
206
|
-
},
|
|
207
|
-
],
|
|
208
|
-
fields: [],
|
|
209
|
-
rowCount: 1,
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// getHealth sessions: pg_stat_activity with pid != pg_backend_pid and datname = $1
|
|
214
|
-
if (
|
|
215
|
-
normalized.includes('pg_stat_activity') &&
|
|
216
|
-
normalized.includes('pid != pg_backend_pid()') &&
|
|
217
|
-
normalized.includes('xact_start desc') &&
|
|
218
|
-
!normalized.includes('application_name')
|
|
219
|
-
) {
|
|
220
|
-
return Promise.resolve({
|
|
221
|
-
rows: [
|
|
222
|
-
{
|
|
223
|
-
pid: 101,
|
|
224
|
-
user: 'app_user',
|
|
225
|
-
database: 'testdb',
|
|
226
|
-
state: 'active',
|
|
227
|
-
query: 'SELECT 1',
|
|
228
|
-
duration: '2.5s',
|
|
229
|
-
},
|
|
230
|
-
],
|
|
231
|
-
fields: [],
|
|
232
|
-
rowCount: 1,
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// getActiveSessions: pg_stat_activity with detailed fields
|
|
237
|
-
if (
|
|
238
|
-
normalized.includes('pg_stat_activity') &&
|
|
239
|
-
normalized.includes('application_name') &&
|
|
240
|
-
normalized.includes('wait_event_type') &&
|
|
241
|
-
normalized.includes('pid != pg_backend_pid()')
|
|
242
|
-
) {
|
|
243
|
-
return Promise.resolve({
|
|
244
|
-
rows: [
|
|
245
|
-
{
|
|
246
|
-
pid: 201,
|
|
247
|
-
user: 'db_user',
|
|
248
|
-
database: 'testdb',
|
|
249
|
-
application_name: 'myapp',
|
|
250
|
-
client_addr: '10.0.0.1',
|
|
251
|
-
state: 'active',
|
|
252
|
-
query: 'SELECT * FROM orders',
|
|
253
|
-
query_start: new Date().toISOString(),
|
|
254
|
-
wait_event_type: null,
|
|
255
|
-
wait_event: null,
|
|
256
|
-
duration: '1.2s',
|
|
257
|
-
duration_ms: '1200',
|
|
258
|
-
},
|
|
259
|
-
],
|
|
260
|
-
fields: [],
|
|
261
|
-
rowCount: 1,
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// getHealth: pg_statio_user_tables (cache ratio with heap_read + heap_hit)
|
|
266
|
-
if (normalized.includes('pg_statio_user_tables') && normalized.includes('heap_blks_read')) {
|
|
267
|
-
return Promise.resolve({
|
|
268
|
-
rows: [{ ratio: 99.5, heap_read: '100', heap_hit: '9900' }],
|
|
269
|
-
fields: [{ name: 'ratio' }, { name: 'heap_read' }, { name: 'heap_hit' }],
|
|
270
|
-
rowCount: 1,
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// getPerformanceMetrics: pg_statio_user_tables (cache_hit_ratio only)
|
|
275
|
-
if (normalized.includes('pg_statio_user_tables') && normalized.includes('cache_hit_ratio')) {
|
|
276
|
-
return Promise.resolve({
|
|
277
|
-
rows: [{ cache_hit_ratio: '98.75' }],
|
|
278
|
-
fields: [{ name: 'cache_hit_ratio' }],
|
|
279
|
-
rowCount: 1,
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// Schema CTE query: information_schema + table_type = 'base table'
|
|
284
|
-
if (normalized.includes('information_schema') && normalized.includes("table_type = 'base table'")) {
|
|
285
|
-
return Promise.resolve({
|
|
286
|
-
rows: [
|
|
287
|
-
{
|
|
288
|
-
table_schema: 'public',
|
|
289
|
-
table_name: 'users',
|
|
290
|
-
row_count: '1000',
|
|
291
|
-
total_size: '81920',
|
|
292
|
-
columns: [
|
|
293
|
-
{ name: 'id', type: 'integer', nullable: false, defaultValue: "nextval('users_id_seq')" },
|
|
294
|
-
{ name: 'name', type: 'character varying', nullable: true, defaultValue: null },
|
|
295
|
-
{ name: 'email', type: 'character varying', nullable: false, defaultValue: null },
|
|
296
|
-
],
|
|
297
|
-
pk_columns: ['id'],
|
|
298
|
-
foreign_keys: [],
|
|
299
|
-
indexes: [
|
|
300
|
-
{ name: 'users_pkey', columns: ['id'], unique: true },
|
|
301
|
-
{ name: 'idx_users_email', columns: ['email'], unique: true },
|
|
302
|
-
],
|
|
303
|
-
},
|
|
304
|
-
{
|
|
305
|
-
table_schema: 'analytics',
|
|
306
|
-
table_name: 'events',
|
|
307
|
-
row_count: '50000',
|
|
308
|
-
total_size: '4194304',
|
|
309
|
-
columns: [
|
|
310
|
-
{ name: 'id', type: 'integer', nullable: false, defaultValue: null },
|
|
311
|
-
{ name: 'user_id', type: 'integer', nullable: false, defaultValue: null },
|
|
312
|
-
{ name: 'event_type', type: 'character varying', nullable: false, defaultValue: null },
|
|
313
|
-
],
|
|
314
|
-
pk_columns: ['id'],
|
|
315
|
-
foreign_keys: [
|
|
316
|
-
{
|
|
317
|
-
columnName: 'user_id',
|
|
318
|
-
referencedSchema: 'public',
|
|
319
|
-
referencedTable: 'users',
|
|
320
|
-
referencedColumn: 'id',
|
|
321
|
-
},
|
|
322
|
-
],
|
|
323
|
-
indexes: [
|
|
324
|
-
{ name: 'events_pkey', columns: ['id'], unique: true },
|
|
325
|
-
],
|
|
326
|
-
},
|
|
327
|
-
],
|
|
328
|
-
fields: [],
|
|
329
|
-
rowCount: 2,
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
// getOverview: version() + pg_postmaster_start_time()
|
|
334
|
-
if (normalized.includes('version()') && normalized.includes('pg_postmaster_start_time()')) {
|
|
335
|
-
return Promise.resolve({
|
|
336
|
-
rows: [
|
|
337
|
-
{
|
|
338
|
-
version: 'PostgreSQL 16.2, compiled by Visual C++ build 1941, 64-bit',
|
|
339
|
-
start_time: new Date(Date.now() - 90061000).toISOString(),
|
|
340
|
-
uptime_seconds: '90061',
|
|
341
|
-
},
|
|
342
|
-
],
|
|
343
|
-
fields: [],
|
|
344
|
-
rowCount: 1,
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// getOverview: connection counts (max_connections + pg_stat_activity)
|
|
349
|
-
if (normalized.includes('max_connections') && normalized.includes('pg_stat_activity')) {
|
|
350
|
-
return Promise.resolve({
|
|
351
|
-
rows: [{ active_connections: '12', max_connections: '200' }],
|
|
352
|
-
fields: [],
|
|
353
|
-
rowCount: 1,
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
// getOverview: database size (pg_database_size with pretty + bytes)
|
|
358
|
-
if (normalized.includes('pg_database_size') && normalized.includes('database_size_bytes')) {
|
|
359
|
-
return Promise.resolve({
|
|
360
|
-
rows: [{ database_size: '512 MB', database_size_bytes: '536870912' }],
|
|
361
|
-
fields: [],
|
|
362
|
-
rowCount: 1,
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
// getOverview: table + index counts
|
|
367
|
-
if (normalized.includes('pg_tables') && normalized.includes('pg_indexes')) {
|
|
368
|
-
return Promise.resolve({
|
|
369
|
-
rows: [{ table_count: '15', index_count: '30' }],
|
|
370
|
-
fields: [],
|
|
371
|
-
rowCount: 1,
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
// getPerformanceMetrics: pg_stat_database (transaction stats)
|
|
376
|
-
if (normalized.includes('pg_stat_database') && normalized.includes('xact_commit')) {
|
|
377
|
-
return Promise.resolve({
|
|
378
|
-
rows: [
|
|
379
|
-
{
|
|
380
|
-
xact_commit: '50000',
|
|
381
|
-
xact_rollback: '150',
|
|
382
|
-
deadlocks: '3',
|
|
383
|
-
blks_read: '2000',
|
|
384
|
-
blks_hit: '98000',
|
|
385
|
-
},
|
|
386
|
-
],
|
|
387
|
-
fields: [],
|
|
388
|
-
rowCount: 1,
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// getPerformanceMetrics: pg_stat_bgwriter (checkpoint stats)
|
|
393
|
-
if (normalized.includes('pg_stat_bgwriter')) {
|
|
394
|
-
return Promise.resolve({
|
|
395
|
-
rows: [
|
|
396
|
-
{
|
|
397
|
-
checkpoint_write_time: '12500',
|
|
398
|
-
checkpoint_sync_time: '3200',
|
|
399
|
-
},
|
|
400
|
-
],
|
|
401
|
-
fields: [],
|
|
402
|
-
rowCount: 1,
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
// getTableStats: pg_stat_user_tables
|
|
407
|
-
if (normalized.includes('pg_stat_user_tables') && normalized.includes('n_live_tup')) {
|
|
408
|
-
return Promise.resolve({
|
|
409
|
-
rows: [
|
|
410
|
-
{
|
|
411
|
-
schema_name: 'public',
|
|
412
|
-
table_name: 'users',
|
|
413
|
-
live_row_count: '1000',
|
|
414
|
-
dead_row_count: '50',
|
|
415
|
-
row_count: '1050',
|
|
416
|
-
table_size: '64 kB',
|
|
417
|
-
table_size_bytes: '65536',
|
|
418
|
-
index_size: '32 kB',
|
|
419
|
-
index_size_bytes: '32768',
|
|
420
|
-
total_size: '96 kB',
|
|
421
|
-
total_size_bytes: '98304',
|
|
422
|
-
last_vacuum: null,
|
|
423
|
-
last_autovacuum: new Date().toISOString(),
|
|
424
|
-
last_analyze: null,
|
|
425
|
-
last_autoanalyze: new Date().toISOString(),
|
|
426
|
-
bloat_ratio: '4.76',
|
|
427
|
-
},
|
|
428
|
-
{
|
|
429
|
-
schema_name: 'public',
|
|
430
|
-
table_name: 'orders',
|
|
431
|
-
live_row_count: '5000',
|
|
432
|
-
dead_row_count: '200',
|
|
433
|
-
row_count: '5200',
|
|
434
|
-
table_size: '256 kB',
|
|
435
|
-
table_size_bytes: '262144',
|
|
436
|
-
index_size: '128 kB',
|
|
437
|
-
index_size_bytes: '131072',
|
|
438
|
-
total_size: '384 kB',
|
|
439
|
-
total_size_bytes: '393216',
|
|
440
|
-
last_vacuum: new Date().toISOString(),
|
|
441
|
-
last_autovacuum: null,
|
|
442
|
-
last_analyze: new Date().toISOString(),
|
|
443
|
-
last_autoanalyze: null,
|
|
444
|
-
bloat_ratio: '3.85',
|
|
445
|
-
},
|
|
446
|
-
],
|
|
447
|
-
fields: [],
|
|
448
|
-
rowCount: 2,
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
// getIndexStats: pg_stat_user_indexes
|
|
453
|
-
if (normalized.includes('pg_stat_user_indexes')) {
|
|
454
|
-
return Promise.resolve({
|
|
455
|
-
rows: [
|
|
456
|
-
{
|
|
457
|
-
schema_name: 'public',
|
|
458
|
-
table_name: 'users',
|
|
459
|
-
index_name: 'users_pkey',
|
|
460
|
-
index_type: 'btree',
|
|
461
|
-
index_size: '16 kB',
|
|
462
|
-
index_size_bytes: '16384',
|
|
463
|
-
scans: '5000',
|
|
464
|
-
tuples_read: '5000',
|
|
465
|
-
tuples_fetched: '5000',
|
|
466
|
-
is_unique: true,
|
|
467
|
-
is_primary: true,
|
|
468
|
-
columns: ['id'],
|
|
469
|
-
usage_ratio: '85.50',
|
|
470
|
-
},
|
|
471
|
-
{
|
|
472
|
-
schema_name: 'public',
|
|
473
|
-
table_name: 'users',
|
|
474
|
-
index_name: 'idx_users_email',
|
|
475
|
-
index_type: 'btree',
|
|
476
|
-
index_size: '32 kB',
|
|
477
|
-
index_size_bytes: '32768',
|
|
478
|
-
scans: '3000',
|
|
479
|
-
tuples_read: '3000',
|
|
480
|
-
tuples_fetched: '3000',
|
|
481
|
-
is_unique: true,
|
|
482
|
-
is_primary: false,
|
|
483
|
-
columns: ['email'],
|
|
484
|
-
usage_ratio: '52.17',
|
|
485
|
-
},
|
|
486
|
-
],
|
|
487
|
-
fields: [],
|
|
488
|
-
rowCount: 2,
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
// getStorageStats: pg_tablespace
|
|
493
|
-
if (normalized.includes('pg_tablespace') && normalized.includes('pg_tablespace_size')) {
|
|
494
|
-
return Promise.resolve({
|
|
495
|
-
rows: [
|
|
496
|
-
{
|
|
497
|
-
name: 'pg_default',
|
|
498
|
-
location: '',
|
|
499
|
-
size: '1.2 GB',
|
|
500
|
-
size_bytes: '1288490188',
|
|
501
|
-
is_default: true,
|
|
502
|
-
},
|
|
503
|
-
],
|
|
504
|
-
fields: [],
|
|
505
|
-
rowCount: 1,
|
|
506
|
-
});
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
// getStorageStats: pg_wal_lsn_diff (WAL info)
|
|
510
|
-
if (normalized.includes('pg_wal_lsn_diff')) {
|
|
511
|
-
return Promise.resolve({
|
|
512
|
-
rows: [{ wal_size: '128 MB', wal_size_bytes: '134217728' }],
|
|
513
|
-
fields: [],
|
|
514
|
-
rowCount: 1,
|
|
515
|
-
});
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
// Default: generic SELECT result
|
|
519
|
-
return Promise.resolve({
|
|
520
|
-
rows: [{ id: 1, name: 'test' }],
|
|
521
|
-
fields: [{ name: 'id' }, { name: 'name' }],
|
|
522
|
-
rowCount: 1,
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
// ============================================================================
|
|
527
|
-
// Tests
|
|
528
|
-
// ============================================================================
|
|
529
|
-
|
|
530
|
-
describe('PostgresProvider', () => {
|
|
531
|
-
let provider: InstanceType<typeof PostgresProvider>;
|
|
532
|
-
|
|
533
|
-
beforeEach(() => {
|
|
534
|
-
mockQueryFn = defaultMockQuery;
|
|
535
|
-
});
|
|
536
|
-
|
|
537
|
-
afterEach(async () => {
|
|
538
|
-
try {
|
|
539
|
-
if (provider?.isConnected()) {
|
|
540
|
-
await provider.disconnect();
|
|
541
|
-
}
|
|
542
|
-
} catch {
|
|
543
|
-
// Ignore cleanup errors
|
|
544
|
-
}
|
|
545
|
-
});
|
|
546
|
-
|
|
547
|
-
// --------------------------------------------------------------------------
|
|
548
|
-
// Validation
|
|
549
|
-
// --------------------------------------------------------------------------
|
|
550
|
-
|
|
551
|
-
describe('validate()', () => {
|
|
552
|
-
test('missing host throws DatabaseConfigError', () => {
|
|
553
|
-
expect(() => {
|
|
554
|
-
new PostgresProvider(makePgConfig({ host: undefined }));
|
|
555
|
-
}).toThrow(DatabaseConfigError);
|
|
556
|
-
});
|
|
557
|
-
|
|
558
|
-
test('missing database throws DatabaseConfigError', () => {
|
|
559
|
-
expect(() => {
|
|
560
|
-
new PostgresProvider(makePgConfig({ database: undefined }));
|
|
561
|
-
}).toThrow(DatabaseConfigError);
|
|
562
|
-
});
|
|
563
|
-
|
|
564
|
-
test('valid config passes validation', () => {
|
|
565
|
-
expect(() => {
|
|
566
|
-
new PostgresProvider(makePgConfig());
|
|
567
|
-
}).not.toThrow();
|
|
568
|
-
});
|
|
569
|
-
|
|
570
|
-
test('connectionString bypasses host/database requirement', () => {
|
|
571
|
-
expect(() => {
|
|
572
|
-
new PostgresProvider(
|
|
573
|
-
makePgConfig({
|
|
574
|
-
host: undefined,
|
|
575
|
-
database: undefined,
|
|
576
|
-
connectionString: 'postgresql://user:pass@localhost:5432/mydb',
|
|
577
|
-
})
|
|
578
|
-
);
|
|
579
|
-
}).not.toThrow();
|
|
580
|
-
});
|
|
581
|
-
});
|
|
582
|
-
|
|
583
|
-
// --------------------------------------------------------------------------
|
|
584
|
-
// Connection lifecycle
|
|
585
|
-
// --------------------------------------------------------------------------
|
|
586
|
-
|
|
587
|
-
describe('connect / disconnect', () => {
|
|
588
|
-
test('isConnected() is false before connect', () => {
|
|
589
|
-
provider = new PostgresProvider(makePgConfig());
|
|
590
|
-
expect(provider.isConnected()).toBe(false);
|
|
591
|
-
});
|
|
592
|
-
|
|
593
|
-
test('connect() sets connected to true', async () => {
|
|
594
|
-
provider = new PostgresProvider(makePgConfig());
|
|
595
|
-
await provider.connect();
|
|
596
|
-
expect(provider.isConnected()).toBe(true);
|
|
597
|
-
});
|
|
598
|
-
|
|
599
|
-
test('disconnect() sets connected to false', async () => {
|
|
600
|
-
provider = new PostgresProvider(makePgConfig());
|
|
601
|
-
await provider.connect();
|
|
602
|
-
await provider.disconnect();
|
|
603
|
-
expect(provider.isConnected()).toBe(false);
|
|
604
|
-
});
|
|
605
|
-
|
|
606
|
-
test('double connect is idempotent', async () => {
|
|
607
|
-
provider = new PostgresProvider(makePgConfig());
|
|
608
|
-
await provider.connect();
|
|
609
|
-
await provider.connect();
|
|
610
|
-
expect(provider.isConnected()).toBe(true);
|
|
611
|
-
});
|
|
612
|
-
});
|
|
613
|
-
|
|
614
|
-
// --------------------------------------------------------------------------
|
|
615
|
-
// buildSSLConfig()
|
|
616
|
-
// --------------------------------------------------------------------------
|
|
617
|
-
|
|
618
|
-
describe('buildSSLConfig()', () => {
|
|
619
|
-
test('ssl mode disable returns false (no SSL)', async () => {
|
|
620
|
-
provider = new PostgresProvider(
|
|
621
|
-
makePgConfig({
|
|
622
|
-
ssl: { mode: 'disable' },
|
|
623
|
-
})
|
|
624
|
-
);
|
|
625
|
-
await provider.connect();
|
|
626
|
-
// If we get here without error, connect succeeded with ssl=false
|
|
627
|
-
expect(provider.isConnected()).toBe(true);
|
|
628
|
-
});
|
|
629
|
-
|
|
630
|
-
test('ssl mode verify-ca sets rejectUnauthorized to true', async () => {
|
|
631
|
-
provider = new PostgresProvider(
|
|
632
|
-
makePgConfig({
|
|
633
|
-
ssl: { mode: 'verify-ca' },
|
|
634
|
-
})
|
|
635
|
-
);
|
|
636
|
-
await provider.connect();
|
|
637
|
-
expect(provider.isConnected()).toBe(true);
|
|
638
|
-
});
|
|
639
|
-
|
|
640
|
-
test('ssl mode verify-full with certs includes ca, cert, key', async () => {
|
|
641
|
-
provider = new PostgresProvider(
|
|
642
|
-
makePgConfig({
|
|
643
|
-
ssl: {
|
|
644
|
-
mode: 'verify-full',
|
|
645
|
-
caCert: '-----BEGIN CERTIFICATE-----\nCA\n-----END CERTIFICATE-----',
|
|
646
|
-
clientCert: '-----BEGIN CERTIFICATE-----\nCLIENT\n-----END CERTIFICATE-----',
|
|
647
|
-
clientKey: '-----BEGIN RSA PRIVATE KEY-----\nKEY\n-----END RSA PRIVATE KEY-----',
|
|
648
|
-
},
|
|
649
|
-
})
|
|
650
|
-
);
|
|
651
|
-
await provider.connect();
|
|
652
|
-
expect(provider.isConnected()).toBe(true);
|
|
653
|
-
});
|
|
654
|
-
|
|
655
|
-
test('auto-detect cloud provider enables SSL', async () => {
|
|
656
|
-
provider = new PostgresProvider(
|
|
657
|
-
makePgConfig({
|
|
658
|
-
host: 'my-db.supabase.co',
|
|
659
|
-
})
|
|
660
|
-
);
|
|
661
|
-
await provider.connect();
|
|
662
|
-
expect(provider.isConnected()).toBe(true);
|
|
663
|
-
});
|
|
664
|
-
|
|
665
|
-
test('options.ssl=false returns false', async () => {
|
|
666
|
-
provider = new PostgresProvider(makePgConfig(), { ssl: false });
|
|
667
|
-
await provider.connect();
|
|
668
|
-
expect(provider.isConnected()).toBe(true);
|
|
669
|
-
});
|
|
670
|
-
|
|
671
|
-
test('no SSL config returns undefined (default)', async () => {
|
|
672
|
-
provider = new PostgresProvider(makePgConfig());
|
|
673
|
-
await provider.connect();
|
|
674
|
-
expect(provider.isConnected()).toBe(true);
|
|
675
|
-
});
|
|
676
|
-
});
|
|
677
|
-
|
|
678
|
-
// --------------------------------------------------------------------------
|
|
679
|
-
// Query execution
|
|
680
|
-
// --------------------------------------------------------------------------
|
|
681
|
-
|
|
682
|
-
describe('query()', () => {
|
|
683
|
-
test('SELECT returns rows, fields, and executionTime', async () => {
|
|
684
|
-
provider = new PostgresProvider(makePgConfig());
|
|
685
|
-
await provider.connect();
|
|
686
|
-
const result = await provider.query('SELECT * FROM users');
|
|
687
|
-
expect(result.rows.length).toBeGreaterThan(0);
|
|
688
|
-
expect(Array.isArray(result.fields)).toBe(true);
|
|
689
|
-
expect(typeof result.executionTime).toBe('number');
|
|
690
|
-
expect(typeof result.rowCount).toBe('number');
|
|
691
|
-
});
|
|
692
|
-
|
|
693
|
-
test('PID is tracked when queryId is provided', async () => {
|
|
694
|
-
provider = new PostgresProvider(makePgConfig());
|
|
695
|
-
await provider.connect();
|
|
696
|
-
const result = await provider.query('SELECT 1', undefined, 'test-query-id');
|
|
697
|
-
expect(result.rows.length).toBeGreaterThan(0);
|
|
698
|
-
});
|
|
699
|
-
|
|
700
|
-
test('query error is mapped to database error', async () => {
|
|
701
|
-
provider = new PostgresProvider(makePgConfig());
|
|
702
|
-
await provider.connect();
|
|
703
|
-
|
|
704
|
-
// Override mock to throw a syntax error
|
|
705
|
-
mockQueryFn = async () => {
|
|
706
|
-
throw new Error('syntax error at or near "SELEC"');
|
|
707
|
-
};
|
|
708
|
-
|
|
709
|
-
await expect(provider.query('SELEC * FROM users')).rejects.toThrow();
|
|
710
|
-
});
|
|
711
|
-
});
|
|
712
|
-
|
|
713
|
-
// --------------------------------------------------------------------------
|
|
714
|
-
// Cancel query
|
|
715
|
-
// --------------------------------------------------------------------------
|
|
716
|
-
|
|
717
|
-
describe('cancelQuery()', () => {
|
|
718
|
-
test('cancels known PID and returns true', async () => {
|
|
719
|
-
provider = new PostgresProvider(makePgConfig());
|
|
720
|
-
await provider.connect();
|
|
721
|
-
|
|
722
|
-
// We need a query running to have a tracked PID.
|
|
723
|
-
// Simulate: trigger a query with queryId, then cancel mid-flight.
|
|
724
|
-
// Since our mock is synchronous, we'll manually set the PID map.
|
|
725
|
-
// Access the private runningQueryPids map via casting.
|
|
726
|
-
const providerAny = provider as unknown as { runningQueryPids: Map<string, number> };
|
|
727
|
-
providerAny.runningQueryPids.set('cancel-test', 12345);
|
|
728
|
-
|
|
729
|
-
const cancelled = await provider.cancelQuery('cancel-test');
|
|
730
|
-
expect(cancelled).toBe(true);
|
|
731
|
-
});
|
|
732
|
-
|
|
733
|
-
test('returns false for unknown queryId', async () => {
|
|
734
|
-
provider = new PostgresProvider(makePgConfig());
|
|
735
|
-
await provider.connect();
|
|
736
|
-
const result = await provider.cancelQuery('nonexistent-query-id');
|
|
737
|
-
expect(result).toBe(false);
|
|
738
|
-
});
|
|
739
|
-
|
|
740
|
-
test('handles cancel error gracefully and returns false', async () => {
|
|
741
|
-
provider = new PostgresProvider(makePgConfig());
|
|
742
|
-
await provider.connect();
|
|
743
|
-
|
|
744
|
-
const providerAny = provider as unknown as { runningQueryPids: Map<string, number> };
|
|
745
|
-
providerAny.runningQueryPids.set('error-cancel', 99999);
|
|
746
|
-
|
|
747
|
-
// Override mock to throw on pg_cancel_backend
|
|
748
|
-
const originalMock = mockQueryFn;
|
|
749
|
-
mockQueryFn = async (sql: string, params?: unknown[]) => {
|
|
750
|
-
if (sql.includes('pg_cancel_backend')) {
|
|
751
|
-
throw new Error('Connection lost');
|
|
752
|
-
}
|
|
753
|
-
return originalMock(sql, params);
|
|
754
|
-
};
|
|
755
|
-
|
|
756
|
-
const result = await provider.cancelQuery('error-cancel');
|
|
757
|
-
expect(result).toBe(false);
|
|
758
|
-
});
|
|
759
|
-
});
|
|
760
|
-
|
|
761
|
-
// --------------------------------------------------------------------------
|
|
762
|
-
// Transaction lifecycle
|
|
763
|
-
// --------------------------------------------------------------------------
|
|
764
|
-
|
|
765
|
-
describe('Transaction lifecycle', () => {
|
|
766
|
-
test('beginTransaction / commitTransaction works', async () => {
|
|
767
|
-
provider = new PostgresProvider(makePgConfig());
|
|
768
|
-
await provider.connect();
|
|
769
|
-
|
|
770
|
-
expect(provider.isInTransaction()).toBe(false);
|
|
771
|
-
await provider.beginTransaction();
|
|
772
|
-
expect(provider.isInTransaction()).toBe(true);
|
|
773
|
-
await provider.commitTransaction();
|
|
774
|
-
expect(provider.isInTransaction()).toBe(false);
|
|
775
|
-
});
|
|
776
|
-
|
|
777
|
-
test('beginTransaction / rollbackTransaction works', async () => {
|
|
778
|
-
provider = new PostgresProvider(makePgConfig());
|
|
779
|
-
await provider.connect();
|
|
780
|
-
|
|
781
|
-
await provider.beginTransaction();
|
|
782
|
-
expect(provider.isInTransaction()).toBe(true);
|
|
783
|
-
await provider.rollbackTransaction();
|
|
784
|
-
expect(provider.isInTransaction()).toBe(false);
|
|
785
|
-
});
|
|
786
|
-
|
|
787
|
-
test('double beginTransaction throws', async () => {
|
|
788
|
-
provider = new PostgresProvider(makePgConfig());
|
|
789
|
-
await provider.connect();
|
|
790
|
-
|
|
791
|
-
await provider.beginTransaction();
|
|
792
|
-
await expect(provider.beginTransaction()).rejects.toThrow('Transaction already active');
|
|
793
|
-
// Clean up
|
|
794
|
-
await provider.rollbackTransaction();
|
|
795
|
-
});
|
|
796
|
-
|
|
797
|
-
test('commitTransaction without begin throws', async () => {
|
|
798
|
-
provider = new PostgresProvider(makePgConfig());
|
|
799
|
-
await provider.connect();
|
|
800
|
-
|
|
801
|
-
await expect(provider.commitTransaction()).rejects.toThrow('No active transaction');
|
|
802
|
-
});
|
|
803
|
-
|
|
804
|
-
test('rollbackTransaction without begin throws', async () => {
|
|
805
|
-
provider = new PostgresProvider(makePgConfig());
|
|
806
|
-
await provider.connect();
|
|
807
|
-
|
|
808
|
-
await expect(provider.rollbackTransaction()).rejects.toThrow('No active transaction');
|
|
809
|
-
});
|
|
810
|
-
|
|
811
|
-
test('queryInTransaction executes within active transaction', async () => {
|
|
812
|
-
provider = new PostgresProvider(makePgConfig());
|
|
813
|
-
await provider.connect();
|
|
814
|
-
|
|
815
|
-
await provider.beginTransaction();
|
|
816
|
-
const result = await provider.queryInTransaction('SELECT 1');
|
|
817
|
-
expect(result.rows).toBeDefined();
|
|
818
|
-
expect(typeof result.executionTime).toBe('number');
|
|
819
|
-
await provider.commitTransaction();
|
|
820
|
-
});
|
|
821
|
-
|
|
822
|
-
test('queryInTransaction without begin throws', async () => {
|
|
823
|
-
provider = new PostgresProvider(makePgConfig());
|
|
824
|
-
await provider.connect();
|
|
825
|
-
|
|
826
|
-
await expect(provider.queryInTransaction('SELECT 1')).rejects.toThrow('No active transaction');
|
|
827
|
-
});
|
|
828
|
-
|
|
829
|
-
test('expireTransaction auto-rollbacks an active transaction', async () => {
|
|
830
|
-
provider = new PostgresProvider(makePgConfig());
|
|
831
|
-
await provider.connect();
|
|
832
|
-
|
|
833
|
-
await provider.beginTransaction();
|
|
834
|
-
expect(provider.isInTransaction()).toBe(true);
|
|
835
|
-
|
|
836
|
-
await provider.expireTransaction();
|
|
837
|
-
expect(provider.isInTransaction()).toBe(false);
|
|
838
|
-
});
|
|
839
|
-
|
|
840
|
-
test('expireTransaction is no-op when no active transaction', async () => {
|
|
841
|
-
provider = new PostgresProvider(makePgConfig());
|
|
842
|
-
await provider.connect();
|
|
843
|
-
|
|
844
|
-
// Should not throw
|
|
845
|
-
await provider.expireTransaction();
|
|
846
|
-
expect(provider.isInTransaction()).toBe(false);
|
|
847
|
-
});
|
|
848
|
-
});
|
|
849
|
-
|
|
850
|
-
// --------------------------------------------------------------------------
|
|
851
|
-
// Schema
|
|
852
|
-
// --------------------------------------------------------------------------
|
|
853
|
-
|
|
854
|
-
describe('getSchema()', () => {
|
|
855
|
-
test('returns TableSchema array with columns, indexes, foreignKeys', async () => {
|
|
856
|
-
provider = new PostgresProvider(makePgConfig());
|
|
857
|
-
await provider.connect();
|
|
858
|
-
const schema = await provider.getSchema();
|
|
859
|
-
|
|
860
|
-
expect(schema.length).toBe(2);
|
|
861
|
-
|
|
862
|
-
for (const table of schema) {
|
|
863
|
-
expect(typeof table.name).toBe('string');
|
|
864
|
-
expect(Array.isArray(table.columns)).toBe(true);
|
|
865
|
-
expect(table.columns.length).toBeGreaterThan(0);
|
|
866
|
-
expect(Array.isArray(table.indexes)).toBe(true);
|
|
867
|
-
expect(Array.isArray(table.foreignKeys)).toBe(true);
|
|
868
|
-
}
|
|
869
|
-
});
|
|
870
|
-
|
|
871
|
-
test('primary key columns are detected via isPrimary flag', async () => {
|
|
872
|
-
provider = new PostgresProvider(makePgConfig());
|
|
873
|
-
await provider.connect();
|
|
874
|
-
const schema = await provider.getSchema();
|
|
875
|
-
|
|
876
|
-
const usersTable = schema.find((t) => t.name === 'users');
|
|
877
|
-
expect(usersTable).toBeDefined();
|
|
878
|
-
|
|
879
|
-
const idCol = usersTable!.columns.find((c) => c.name === 'id');
|
|
880
|
-
expect(idCol).toBeDefined();
|
|
881
|
-
expect(idCol!.isPrimary).toBe(true);
|
|
882
|
-
|
|
883
|
-
const nameCol = usersTable!.columns.find((c) => c.name === 'name');
|
|
884
|
-
expect(nameCol).toBeDefined();
|
|
885
|
-
expect(nameCol!.isPrimary).toBe(false);
|
|
886
|
-
});
|
|
887
|
-
|
|
888
|
-
test('non-public schema tables get schema prefix in name', async () => {
|
|
889
|
-
provider = new PostgresProvider(makePgConfig());
|
|
890
|
-
await provider.connect();
|
|
891
|
-
const schema = await provider.getSchema();
|
|
892
|
-
|
|
893
|
-
const eventsTable = schema.find((t) => t.name === 'analytics.events');
|
|
894
|
-
expect(eventsTable).toBeDefined();
|
|
895
|
-
expect(eventsTable!.name).toBe('analytics.events');
|
|
896
|
-
|
|
897
|
-
// Foreign key from analytics.events.user_id -> public.users.id should have no prefix
|
|
898
|
-
expect(eventsTable!.foreignKeys!.length).toBe(1);
|
|
899
|
-
expect(eventsTable!.foreignKeys![0].referencedTable).toBe('users');
|
|
900
|
-
});
|
|
901
|
-
});
|
|
902
|
-
|
|
903
|
-
// --------------------------------------------------------------------------
|
|
904
|
-
// Health
|
|
905
|
-
// --------------------------------------------------------------------------
|
|
906
|
-
|
|
907
|
-
describe('getHealth()', () => {
|
|
908
|
-
test('returns all health fields', async () => {
|
|
909
|
-
provider = new PostgresProvider(makePgConfig());
|
|
910
|
-
await provider.connect();
|
|
911
|
-
const health = await provider.getHealth();
|
|
912
|
-
|
|
913
|
-
expect(typeof health.activeConnections).toBe('number');
|
|
914
|
-
expect(health.activeConnections).toBe(5);
|
|
915
|
-
expect(typeof health.databaseSize).toBe('string');
|
|
916
|
-
expect(health.databaseSize).toBe('256 MB');
|
|
917
|
-
expect(typeof health.cacheHitRatio).toBe('string');
|
|
918
|
-
expect(health.cacheHitRatio).toContain('99.5');
|
|
919
|
-
expect(Array.isArray(health.slowQueries)).toBe(true);
|
|
920
|
-
expect(Array.isArray(health.activeSessions)).toBe(true);
|
|
921
|
-
});
|
|
922
|
-
|
|
923
|
-
test('pg_stat_statements fallback when extension is not enabled', async () => {
|
|
924
|
-
provider = new PostgresProvider(makePgConfig());
|
|
925
|
-
await provider.connect();
|
|
926
|
-
|
|
927
|
-
// Override: make pg_stat_statements fail
|
|
928
|
-
const originalMock = mockQueryFn;
|
|
929
|
-
mockQueryFn = async (sql: string, params?: unknown[]) => {
|
|
930
|
-
const normalized = sql.trim().toLowerCase();
|
|
931
|
-
if (normalized.includes('pg_stat_statements') && normalized.includes('total_exec_time desc')) {
|
|
932
|
-
throw new Error('relation "pg_stat_statements" does not exist');
|
|
933
|
-
}
|
|
934
|
-
return originalMock(sql, params);
|
|
935
|
-
};
|
|
936
|
-
|
|
937
|
-
const health = await provider.getHealth();
|
|
938
|
-
expect(Array.isArray(health.slowQueries)).toBe(true);
|
|
939
|
-
expect(health.slowQueries.length).toBe(1);
|
|
940
|
-
expect(health.slowQueries[0].query).toContain('pg_stat_statements extension not enabled');
|
|
941
|
-
});
|
|
942
|
-
|
|
943
|
-
test('sessions data is populated', async () => {
|
|
944
|
-
provider = new PostgresProvider(makePgConfig());
|
|
945
|
-
await provider.connect();
|
|
946
|
-
const health = await provider.getHealth();
|
|
947
|
-
|
|
948
|
-
expect(health.activeSessions.length).toBeGreaterThan(0);
|
|
949
|
-
const session = health.activeSessions[0];
|
|
950
|
-
expect(typeof session.pid).toBe('number');
|
|
951
|
-
expect(typeof session.user).toBe('string');
|
|
952
|
-
expect(typeof session.state).toBe('string');
|
|
953
|
-
});
|
|
954
|
-
});
|
|
955
|
-
|
|
956
|
-
// --------------------------------------------------------------------------
|
|
957
|
-
// Maintenance
|
|
958
|
-
// --------------------------------------------------------------------------
|
|
959
|
-
|
|
960
|
-
describe('runMaintenance()', () => {
|
|
961
|
-
test('vacuum with target returns success', async () => {
|
|
962
|
-
provider = new PostgresProvider(makePgConfig());
|
|
963
|
-
await provider.connect();
|
|
964
|
-
const result = await provider.runMaintenance('vacuum', 'users');
|
|
965
|
-
expect(result.success).toBe(true);
|
|
966
|
-
expect(typeof result.executionTime).toBe('number');
|
|
967
|
-
expect(result.message).toContain('VACUUM');
|
|
968
|
-
});
|
|
969
|
-
|
|
970
|
-
test('vacuum without target returns success', async () => {
|
|
971
|
-
provider = new PostgresProvider(makePgConfig());
|
|
972
|
-
await provider.connect();
|
|
973
|
-
const result = await provider.runMaintenance('vacuum');
|
|
974
|
-
expect(result.success).toBe(true);
|
|
975
|
-
expect(result.message).toContain('VACUUM');
|
|
976
|
-
});
|
|
977
|
-
|
|
978
|
-
test('analyze with target returns success', async () => {
|
|
979
|
-
provider = new PostgresProvider(makePgConfig());
|
|
980
|
-
await provider.connect();
|
|
981
|
-
const result = await provider.runMaintenance('analyze', 'users');
|
|
982
|
-
expect(result.success).toBe(true);
|
|
983
|
-
expect(result.message).toContain('ANALYZE');
|
|
984
|
-
});
|
|
985
|
-
|
|
986
|
-
test('analyze without target returns success', async () => {
|
|
987
|
-
provider = new PostgresProvider(makePgConfig());
|
|
988
|
-
await provider.connect();
|
|
989
|
-
const result = await provider.runMaintenance('analyze');
|
|
990
|
-
expect(result.success).toBe(true);
|
|
991
|
-
expect(result.message).toContain('ANALYZE');
|
|
992
|
-
});
|
|
993
|
-
|
|
994
|
-
test('reindex with target returns success', async () => {
|
|
995
|
-
provider = new PostgresProvider(makePgConfig());
|
|
996
|
-
await provider.connect();
|
|
997
|
-
const result = await provider.runMaintenance('reindex', 'users');
|
|
998
|
-
expect(result.success).toBe(true);
|
|
999
|
-
expect(result.message).toContain('REINDEX');
|
|
1000
|
-
});
|
|
1001
|
-
|
|
1002
|
-
test('reindex without target returns success (database-level)', async () => {
|
|
1003
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1004
|
-
await provider.connect();
|
|
1005
|
-
const result = await provider.runMaintenance('reindex');
|
|
1006
|
-
expect(result.success).toBe(true);
|
|
1007
|
-
expect(result.message).toContain('REINDEX');
|
|
1008
|
-
});
|
|
1009
|
-
|
|
1010
|
-
test('kill with valid PID returns success', async () => {
|
|
1011
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1012
|
-
await provider.connect();
|
|
1013
|
-
const result = await provider.runMaintenance('kill', '12345');
|
|
1014
|
-
expect(result.success).toBe(true);
|
|
1015
|
-
expect(result.message).toContain('KILL');
|
|
1016
|
-
});
|
|
1017
|
-
|
|
1018
|
-
test('kill without target throws QueryError', async () => {
|
|
1019
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1020
|
-
await provider.connect();
|
|
1021
|
-
await expect(provider.runMaintenance('kill')).rejects.toThrow(
|
|
1022
|
-
'Target PID is required for kill operation'
|
|
1023
|
-
);
|
|
1024
|
-
});
|
|
1025
|
-
|
|
1026
|
-
test('kill with invalid (non-numeric) PID throws QueryError', async () => {
|
|
1027
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1028
|
-
await provider.connect();
|
|
1029
|
-
await expect(provider.runMaintenance('kill', 'abc')).rejects.toThrow(
|
|
1030
|
-
'Invalid PID for kill operation'
|
|
1031
|
-
);
|
|
1032
|
-
});
|
|
1033
|
-
|
|
1034
|
-
test('unsupported maintenance type throws QueryError', async () => {
|
|
1035
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1036
|
-
await provider.connect();
|
|
1037
|
-
await expect(
|
|
1038
|
-
provider.runMaintenance('optimize' as unknown as 'vacuum', 'users')
|
|
1039
|
-
).rejects.toThrow('Unsupported maintenance type');
|
|
1040
|
-
});
|
|
1041
|
-
});
|
|
1042
|
-
|
|
1043
|
-
// --------------------------------------------------------------------------
|
|
1044
|
-
// Overview
|
|
1045
|
-
// --------------------------------------------------------------------------
|
|
1046
|
-
|
|
1047
|
-
describe('getOverview()', () => {
|
|
1048
|
-
test('returns all overview fields', async () => {
|
|
1049
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1050
|
-
await provider.connect();
|
|
1051
|
-
const overview = await provider.getOverview();
|
|
1052
|
-
|
|
1053
|
-
expect(typeof overview.version).toBe('string');
|
|
1054
|
-
expect(overview.version).toContain('PostgreSQL');
|
|
1055
|
-
expect(typeof overview.uptime).toBe('string');
|
|
1056
|
-
expect(typeof overview.activeConnections).toBe('number');
|
|
1057
|
-
expect(overview.activeConnections).toBe(12);
|
|
1058
|
-
expect(typeof overview.maxConnections).toBe('number');
|
|
1059
|
-
expect(overview.maxConnections).toBe(200);
|
|
1060
|
-
expect(typeof overview.databaseSize).toBe('string');
|
|
1061
|
-
expect(typeof overview.databaseSizeBytes).toBe('number');
|
|
1062
|
-
expect(typeof overview.tableCount).toBe('number');
|
|
1063
|
-
expect(overview.tableCount).toBe(15);
|
|
1064
|
-
expect(typeof overview.indexCount).toBe('number');
|
|
1065
|
-
expect(overview.indexCount).toBe(30);
|
|
1066
|
-
});
|
|
1067
|
-
|
|
1068
|
-
test('uptime is formatted with days, hours, minutes', async () => {
|
|
1069
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1070
|
-
await provider.connect();
|
|
1071
|
-
const overview = await provider.getOverview();
|
|
1072
|
-
|
|
1073
|
-
// 90061 seconds = 1d 1h 1m
|
|
1074
|
-
expect(overview.uptime).toBe('1d 1h 1m');
|
|
1075
|
-
});
|
|
1076
|
-
});
|
|
1077
|
-
|
|
1078
|
-
// --------------------------------------------------------------------------
|
|
1079
|
-
// Performance Metrics
|
|
1080
|
-
// --------------------------------------------------------------------------
|
|
1081
|
-
|
|
1082
|
-
describe('getPerformanceMetrics()', () => {
|
|
1083
|
-
test('returns all performance metrics', async () => {
|
|
1084
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1085
|
-
await provider.connect();
|
|
1086
|
-
const metrics = await provider.getPerformanceMetrics();
|
|
1087
|
-
|
|
1088
|
-
expect(typeof metrics.cacheHitRatio).toBe('number');
|
|
1089
|
-
expect(typeof metrics.bufferPoolUsage).toBe('number');
|
|
1090
|
-
expect(typeof metrics.deadlocks).toBe('number');
|
|
1091
|
-
expect(metrics.deadlocks).toBe(3);
|
|
1092
|
-
expect(typeof metrics.checkpointWriteTime).toBe('string');
|
|
1093
|
-
expect(metrics.checkpointWriteTime).not.toBe('N/A');
|
|
1094
|
-
});
|
|
1095
|
-
|
|
1096
|
-
test('handles checkpoint fallback gracefully', async () => {
|
|
1097
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1098
|
-
await provider.connect();
|
|
1099
|
-
|
|
1100
|
-
const originalMock = mockQueryFn;
|
|
1101
|
-
mockQueryFn = async (sql: string, params?: unknown[]) => {
|
|
1102
|
-
const normalized = sql.trim().toLowerCase();
|
|
1103
|
-
if (normalized.includes('pg_stat_bgwriter')) {
|
|
1104
|
-
throw new Error('permission denied for pg_stat_bgwriter');
|
|
1105
|
-
}
|
|
1106
|
-
return originalMock(sql, params);
|
|
1107
|
-
};
|
|
1108
|
-
|
|
1109
|
-
const metrics = await provider.getPerformanceMetrics();
|
|
1110
|
-
expect(metrics.checkpointWriteTime).toBe('N/A');
|
|
1111
|
-
});
|
|
1112
|
-
});
|
|
1113
|
-
|
|
1114
|
-
// --------------------------------------------------------------------------
|
|
1115
|
-
// Slow Queries
|
|
1116
|
-
// --------------------------------------------------------------------------
|
|
1117
|
-
|
|
1118
|
-
describe('getSlowQueries()', () => {
|
|
1119
|
-
test('pg_stat_statements returns detailed slow query stats', async () => {
|
|
1120
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1121
|
-
await provider.connect();
|
|
1122
|
-
const slowQueries = await provider.getSlowQueries();
|
|
1123
|
-
|
|
1124
|
-
expect(slowQueries.length).toBe(1);
|
|
1125
|
-
const sq = slowQueries[0];
|
|
1126
|
-
expect(typeof sq.queryId).toBe('string');
|
|
1127
|
-
expect(typeof sq.query).toBe('string');
|
|
1128
|
-
expect(typeof sq.calls).toBe('number');
|
|
1129
|
-
expect(typeof sq.totalTime).toBe('number');
|
|
1130
|
-
expect(typeof sq.avgTime).toBe('number');
|
|
1131
|
-
expect(typeof sq.minTime).toBe('number');
|
|
1132
|
-
expect(typeof sq.maxTime).toBe('number');
|
|
1133
|
-
expect(typeof sq.rows).toBe('number');
|
|
1134
|
-
expect(typeof sq.sharedBlksHit).toBe('number');
|
|
1135
|
-
expect(typeof sq.sharedBlksRead).toBe('number');
|
|
1136
|
-
});
|
|
1137
|
-
|
|
1138
|
-
test('fallback to pg_stat_activity when pg_stat_statements is unavailable', async () => {
|
|
1139
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1140
|
-
await provider.connect();
|
|
1141
|
-
|
|
1142
|
-
const originalMock = mockQueryFn;
|
|
1143
|
-
mockQueryFn = async (sql: string, params?: unknown[]) => {
|
|
1144
|
-
const normalized = sql.trim().toLowerCase();
|
|
1145
|
-
// Make pg_stat_statements queries fail
|
|
1146
|
-
if (normalized.includes('pg_stat_statements')) {
|
|
1147
|
-
throw new Error('relation "pg_stat_statements" does not exist');
|
|
1148
|
-
}
|
|
1149
|
-
return originalMock(sql, params);
|
|
1150
|
-
};
|
|
1151
|
-
|
|
1152
|
-
const slowQueries = await provider.getSlowQueries();
|
|
1153
|
-
expect(Array.isArray(slowQueries)).toBe(true);
|
|
1154
|
-
expect(slowQueries.length).toBeGreaterThan(0);
|
|
1155
|
-
// Fallback rows have no minTime/maxTime
|
|
1156
|
-
expect(slowQueries[0].minTime).toBeUndefined();
|
|
1157
|
-
expect(slowQueries[0].maxTime).toBeUndefined();
|
|
1158
|
-
});
|
|
1159
|
-
|
|
1160
|
-
test('respects limit option', async () => {
|
|
1161
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1162
|
-
await provider.connect();
|
|
1163
|
-
|
|
1164
|
-
// With limit=5, the query passes $2=5 to the mock; our mock always returns 1 row
|
|
1165
|
-
const slowQueries = await provider.getSlowQueries({ limit: 5 });
|
|
1166
|
-
expect(Array.isArray(slowQueries)).toBe(true);
|
|
1167
|
-
});
|
|
1168
|
-
});
|
|
1169
|
-
|
|
1170
|
-
// --------------------------------------------------------------------------
|
|
1171
|
-
// Active Sessions
|
|
1172
|
-
// --------------------------------------------------------------------------
|
|
1173
|
-
|
|
1174
|
-
describe('getActiveSessions()', () => {
|
|
1175
|
-
test('returns session details', async () => {
|
|
1176
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1177
|
-
await provider.connect();
|
|
1178
|
-
const sessions = await provider.getActiveSessions();
|
|
1179
|
-
|
|
1180
|
-
expect(sessions.length).toBe(1);
|
|
1181
|
-
const session = sessions[0];
|
|
1182
|
-
expect(session.pid).toBe(201);
|
|
1183
|
-
expect(session.user).toBe('db_user');
|
|
1184
|
-
expect(session.database).toBe('testdb');
|
|
1185
|
-
expect(session.applicationName).toBe('myapp');
|
|
1186
|
-
expect(session.state).toBe('active');
|
|
1187
|
-
expect(typeof session.query).toBe('string');
|
|
1188
|
-
expect(typeof session.duration).toBe('string');
|
|
1189
|
-
expect(typeof session.durationMs).toBe('number');
|
|
1190
|
-
expect(session.blocked).toBe(false);
|
|
1191
|
-
});
|
|
1192
|
-
|
|
1193
|
-
test('respects limit option', async () => {
|
|
1194
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1195
|
-
await provider.connect();
|
|
1196
|
-
const sessions = await provider.getActiveSessions({ limit: 10 });
|
|
1197
|
-
expect(Array.isArray(sessions)).toBe(true);
|
|
1198
|
-
});
|
|
1199
|
-
});
|
|
1200
|
-
|
|
1201
|
-
// --------------------------------------------------------------------------
|
|
1202
|
-
// Table Stats
|
|
1203
|
-
// --------------------------------------------------------------------------
|
|
1204
|
-
|
|
1205
|
-
describe('getTableStats()', () => {
|
|
1206
|
-
test('returns table stats for all schemas', async () => {
|
|
1207
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1208
|
-
await provider.connect();
|
|
1209
|
-
const stats = await provider.getTableStats();
|
|
1210
|
-
|
|
1211
|
-
expect(stats.length).toBe(2);
|
|
1212
|
-
|
|
1213
|
-
const usersStats = stats.find((s) => s.tableName === 'users');
|
|
1214
|
-
expect(usersStats).toBeDefined();
|
|
1215
|
-
expect(usersStats!.schemaName).toBe('public');
|
|
1216
|
-
expect(typeof usersStats!.rowCount).toBe('number');
|
|
1217
|
-
expect(typeof usersStats!.liveRowCount).toBe('number');
|
|
1218
|
-
expect(typeof usersStats!.deadRowCount).toBe('number');
|
|
1219
|
-
expect(typeof usersStats!.tableSize).toBe('string');
|
|
1220
|
-
expect(typeof usersStats!.tableSizeBytes).toBe('number');
|
|
1221
|
-
expect(typeof usersStats!.indexSize).toBe('string');
|
|
1222
|
-
expect(typeof usersStats!.totalSize).toBe('string');
|
|
1223
|
-
expect(typeof usersStats!.bloatRatio).toBe('number');
|
|
1224
|
-
});
|
|
1225
|
-
|
|
1226
|
-
test('filters by schema when option is provided', async () => {
|
|
1227
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1228
|
-
await provider.connect();
|
|
1229
|
-
const stats = await provider.getTableStats({ schema: 'public' });
|
|
1230
|
-
expect(Array.isArray(stats)).toBe(true);
|
|
1231
|
-
});
|
|
1232
|
-
});
|
|
1233
|
-
|
|
1234
|
-
// --------------------------------------------------------------------------
|
|
1235
|
-
// Index Stats
|
|
1236
|
-
// --------------------------------------------------------------------------
|
|
1237
|
-
|
|
1238
|
-
describe('getIndexStats()', () => {
|
|
1239
|
-
test('returns index stats for all schemas', async () => {
|
|
1240
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1241
|
-
await provider.connect();
|
|
1242
|
-
const stats = await provider.getIndexStats();
|
|
1243
|
-
|
|
1244
|
-
expect(stats.length).toBe(2);
|
|
1245
|
-
|
|
1246
|
-
const pkeyStats = stats.find((s) => s.indexName === 'users_pkey');
|
|
1247
|
-
expect(pkeyStats).toBeDefined();
|
|
1248
|
-
expect(pkeyStats!.schemaName).toBe('public');
|
|
1249
|
-
expect(pkeyStats!.tableName).toBe('users');
|
|
1250
|
-
expect(pkeyStats!.indexType).toBe('btree');
|
|
1251
|
-
expect(pkeyStats!.isUnique).toBe(true);
|
|
1252
|
-
expect(pkeyStats!.isPrimary).toBe(true);
|
|
1253
|
-
expect(Array.isArray(pkeyStats!.columns)).toBe(true);
|
|
1254
|
-
expect(typeof pkeyStats!.indexSize).toBe('string');
|
|
1255
|
-
expect(typeof pkeyStats!.indexSizeBytes).toBe('number');
|
|
1256
|
-
expect(typeof pkeyStats!.scans).toBe('number');
|
|
1257
|
-
expect(typeof pkeyStats!.usageRatio).toBe('number');
|
|
1258
|
-
});
|
|
1259
|
-
|
|
1260
|
-
test('filters by schema when option is provided', async () => {
|
|
1261
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1262
|
-
await provider.connect();
|
|
1263
|
-
const stats = await provider.getIndexStats({ schema: 'public' });
|
|
1264
|
-
expect(Array.isArray(stats)).toBe(true);
|
|
1265
|
-
});
|
|
1266
|
-
});
|
|
1267
|
-
|
|
1268
|
-
// --------------------------------------------------------------------------
|
|
1269
|
-
// Storage Stats
|
|
1270
|
-
// --------------------------------------------------------------------------
|
|
1271
|
-
|
|
1272
|
-
describe('getStorageStats()', () => {
|
|
1273
|
-
test('returns tablespaces and WAL info', async () => {
|
|
1274
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1275
|
-
await provider.connect();
|
|
1276
|
-
const stats = await provider.getStorageStats();
|
|
1277
|
-
|
|
1278
|
-
// Should have tablespace(s) + WAL entry
|
|
1279
|
-
expect(stats.length).toBeGreaterThanOrEqual(2);
|
|
1280
|
-
|
|
1281
|
-
const defaultTs = stats.find((s) => s.name === 'pg_default');
|
|
1282
|
-
expect(defaultTs).toBeDefined();
|
|
1283
|
-
expect(typeof defaultTs!.size).toBe('string');
|
|
1284
|
-
expect(typeof defaultTs!.sizeBytes).toBe('number');
|
|
1285
|
-
|
|
1286
|
-
const walEntry = stats.find((s) => s.name === 'WAL');
|
|
1287
|
-
expect(walEntry).toBeDefined();
|
|
1288
|
-
expect(walEntry!.location).toBe('pg_wal');
|
|
1289
|
-
expect(typeof walEntry!.walSize).toBe('string');
|
|
1290
|
-
expect(typeof walEntry!.walSizeBytes).toBe('number');
|
|
1291
|
-
});
|
|
1292
|
-
|
|
1293
|
-
test('WAL permission denied handled gracefully', async () => {
|
|
1294
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1295
|
-
await provider.connect();
|
|
1296
|
-
|
|
1297
|
-
const originalMock = mockQueryFn;
|
|
1298
|
-
mockQueryFn = async (sql: string, params?: unknown[]) => {
|
|
1299
|
-
const normalized = sql.trim().toLowerCase();
|
|
1300
|
-
if (normalized.includes('pg_wal_lsn_diff')) {
|
|
1301
|
-
throw new Error('permission denied for function pg_current_wal_lsn');
|
|
1302
|
-
}
|
|
1303
|
-
return originalMock(sql, params);
|
|
1304
|
-
};
|
|
1305
|
-
|
|
1306
|
-
const stats = await provider.getStorageStats();
|
|
1307
|
-
// Should still have tablespace info, but no WAL entry
|
|
1308
|
-
expect(stats.length).toBeGreaterThanOrEqual(1);
|
|
1309
|
-
const walEntry = stats.find((s) => s.name === 'WAL');
|
|
1310
|
-
expect(walEntry).toBeUndefined();
|
|
1311
|
-
});
|
|
1312
|
-
});
|
|
1313
|
-
|
|
1314
|
-
// --------------------------------------------------------------------------
|
|
1315
|
-
// Pool Stats
|
|
1316
|
-
// --------------------------------------------------------------------------
|
|
1317
|
-
|
|
1318
|
-
describe('getPoolStats()', () => {
|
|
1319
|
-
test('connected provider returns pool stats', async () => {
|
|
1320
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1321
|
-
await provider.connect();
|
|
1322
|
-
const stats = provider.getPoolStats();
|
|
1323
|
-
|
|
1324
|
-
expect(stats.total).toBe(10);
|
|
1325
|
-
expect(stats.idle).toBe(7);
|
|
1326
|
-
expect(stats.active).toBe(3); // total - idle
|
|
1327
|
-
expect(stats.waiting).toBe(0);
|
|
1328
|
-
});
|
|
1329
|
-
|
|
1330
|
-
test('not connected returns zeros', () => {
|
|
1331
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1332
|
-
const stats = provider.getPoolStats();
|
|
1333
|
-
|
|
1334
|
-
expect(stats.total).toBe(0);
|
|
1335
|
-
expect(stats.idle).toBe(0);
|
|
1336
|
-
expect(stats.active).toBe(0);
|
|
1337
|
-
expect(stats.waiting).toBe(0);
|
|
1338
|
-
});
|
|
1339
|
-
});
|
|
1340
|
-
|
|
1341
|
-
// --------------------------------------------------------------------------
|
|
1342
|
-
// Capabilities
|
|
1343
|
-
// --------------------------------------------------------------------------
|
|
1344
|
-
|
|
1345
|
-
describe('getCapabilities()', () => {
|
|
1346
|
-
test('returns correct PostgreSQL capabilities', () => {
|
|
1347
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1348
|
-
const caps = provider.getCapabilities();
|
|
1349
|
-
|
|
1350
|
-
expect(caps.defaultPort).toBe(5432);
|
|
1351
|
-
expect(caps.queryLanguage).toBe('sql');
|
|
1352
|
-
expect(caps.supportsExplain).toBe(true);
|
|
1353
|
-
expect(caps.supportsConnectionString).toBe(true);
|
|
1354
|
-
expect(caps.maintenanceOperations).toContain('vacuum');
|
|
1355
|
-
expect(caps.maintenanceOperations).toContain('analyze');
|
|
1356
|
-
expect(caps.maintenanceOperations).toContain('reindex');
|
|
1357
|
-
expect(caps.maintenanceOperations).toContain('kill');
|
|
1358
|
-
});
|
|
1359
|
-
});
|
|
1360
|
-
|
|
1361
|
-
// --------------------------------------------------------------------------
|
|
1362
|
-
// getPgStatActivity
|
|
1363
|
-
// --------------------------------------------------------------------------
|
|
1364
|
-
|
|
1365
|
-
describe('getPgStatActivity()', () => {
|
|
1366
|
-
test('returns activity rows from pg_stat_activity', async () => {
|
|
1367
|
-
provider = new PostgresProvider(makePgConfig());
|
|
1368
|
-
await provider.connect();
|
|
1369
|
-
const activity = await provider.getPgStatActivity();
|
|
1370
|
-
|
|
1371
|
-
expect(activity).toBeArray();
|
|
1372
|
-
expect(activity.length).toBe(1);
|
|
1373
|
-
expect(activity[0].datname).toBe('testdb');
|
|
1374
|
-
expect(activity[0].pid).toBe(123);
|
|
1375
|
-
expect(activity[0].usename).toBe('testuser');
|
|
1376
|
-
expect(activity[0].application_name).toBe('testapp');
|
|
1377
|
-
expect(activity[0].client_addr).toBe('127.0.0.1');
|
|
1378
|
-
expect(activity[0].state).toBe('active');
|
|
1379
|
-
expect(activity[0].query).toBe('SELECT * FROM test_table');
|
|
1380
|
-
});
|
|
1381
|
-
});
|
|
1382
|
-
});
|