From aa5cf7941696fe4068a365d677d95cf825e4bc6a Mon Sep 17 00:00:00 2001 From: Richie Varghese Date: Sat, 21 Mar 2026 23:07:44 +0530 Subject: [PATCH 01/10] feat: New features for version 0.8.8, including command palette integration, improved sidebar layout, and enhanced notebook editing with transaction safety. --- CHANGELOG.md | 15 + README.md | 29 +- SECURITY.md | 6 +- docs/ARCHITECTURE.md | 15 +- docs/CONTRIBUTING.md | 478 --- docs/GAP_ANALYSIS.md | 61 - docs/OPTIMIZATION_SUMMARY.md | 222 -- docs/QUICK_REFERENCE.md | 298 -- docs/REFACTORING_EXAMPLE.md | 332 -- docs/ROADMAP.md | 346 +- docs/ROADMAP_PROPOSAL.md | 85 - docs/STYLING_GUIDE.md | 30 + docs/VISUAL_TOOLS.md | 60 - package.json | 53 +- src/activation/WhatsNewManager.ts | 83 +- src/activation/commands.ts | 5 + src/activation/providers.ts | 4 +- src/commands/pickQueryHistory.ts | 41 + src/common/htmlStyles.ts | 4 +- src/extension.ts | 8 +- src/notebookProvider.ts | 5 +- src/providers/chat/AiService.ts | 7 + src/renderer_v2.ts | 20 +- src/renderer_v2_legacy.ts | 2773 ----------------- src/schemaDesigner/TableDesignerPanel.ts | 61 +- src/schemaDesigner/webviewSqlHighlight.ts | 117 + src/services/handlers/QueryHandlers.ts | 181 +- .../integration/NotebookRendererFlow.test.ts | 59 + src/test/unit/QueryHandlers.test.ts | 151 + 29 files changed, 878 insertions(+), 4671 deletions(-) delete mode 100644 docs/CONTRIBUTING.md delete mode 100644 docs/GAP_ANALYSIS.md delete mode 100644 docs/OPTIMIZATION_SUMMARY.md delete mode 100644 docs/QUICK_REFERENCE.md delete mode 100644 docs/REFACTORING_EXAMPLE.md delete mode 100644 docs/ROADMAP_PROPOSAL.md delete mode 100644 docs/VISUAL_TOOLS.md create mode 100644 src/commands/pickQueryHistory.ts delete mode 100644 src/renderer_v2_legacy.ts create mode 100644 src/schemaDesigner/webviewSqlHighlight.ts create mode 100644 src/test/integration/NotebookRendererFlow.test.ts create mode 100644 src/test/unit/QueryHandlers.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index eacf7bb..f21347d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 --- +## [0.8.8] - 2026-03-21 + +### Added +- **Command palette — release notes**: **PgStudio: Show Release Notes / What's New** is registered in the manifest for discovery (changelog opens in an editor-area webview panel). +- **Tests**: Integration coverage for notebook renderer message flow (`NotebookRendererFlow.test.ts`) and unit tests for query save/delete handlers (`QueryHandlers.test.ts`). +- **Table Designer (create mode)**: Drag-and-drop column reorder with clear create-vs-edit UI behavior. +- **AI chat**: Explicit **production safety** rules in the system prompt (read-first bias, transaction/rollback guidance, guarded writes). + +### Changed +- **Sidebar layout**: **Connections** and **SQL Assistant** are listed first; **Saved Queries** and **Query History** use new view identifiers and start **collapsed by default** (VS Code only applies manifest defaults when it has no prior UI state for that view). +- **Release notes**: **What's New** is no longer a sidebar section; use the command palette command. Automatic release-note panels on upgrade are not shown on activation. +- **Notebook inline edits**: `SaveChangesHandler` and bulk/table deletes use **parameterized** `UPDATE`/`DELETE`, run inside a **transaction** (`BEGIN` / `COMMIT` / `ROLLBACK` on failure), and build predicates with proper identifier quoting (fixes composite-key and NULL edge cases). + +--- + ## [0.8.6...0.8.7] - 2026-03-15 ### Added diff --git a/README.md b/README.md index f26b581..9228735 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![Version](https://img.shields.io/visual-studio-marketplace/v/ric-v.postgres-explorer?style=for-the-badge&logo=visual-studio-code&logoColor=white&color=0066CC)](https://marketplace.visualstudio.com/items?itemName=ric-v.postgres-explorer) [![Downloads](https://img.shields.io/visual-studio-marketplace/d/ric-v.postgres-explorer?style=for-the-badge&logo=visual-studio-code&logoColor=white&color=2ECC71)](https://marketplace.visualstudio.com/items?itemName=ric-v.postgres-explorer) [![Rating](https://img.shields.io/visual-studio-marketplace/r/ric-v.postgres-explorer?style=for-the-badge&logo=visual-studio-code&logoColor=white&color=F39C12)](https://marketplace.visualstudio.com/items?itemName=ric-v.postgres-explorer) -[![Status](https://img.shields.io/badge/status-beta-blue?style=for-the-badge&logo=git&logoColor=white)](https://github.com/dev-asterix/yape) +[![Status](https://img.shields.io/badge/status-beta-blue?style=for-the-badge&logo=git&logoColor=white)](https://github.com/dev-asterix/PgStudio) **PgStudio** (formerly YAPE) is a comprehensive PostgreSQL database management extension featuring interactive SQL notebooks, real-time monitoring dashboard, AI-powered assistance, and advanced database operations—all within VS Code. @@ -119,12 +119,25 @@ code --install-extension ric-v.postgres-explorer Then: **PostgreSQL icon** → **Add Connection** → Enter details → **Connect!** +--- + +## 📚 Documentation Map + +- `README.md` - Product overview, installation, development, and troubleshooting +- `docs/ARCHITECTURE.md` - System architecture and component/data-flow details +- `docs/STYLING_GUIDE.md` - Centralized styling/templates and UI refactoring patterns +- `docs/ROADMAP.md` - Active pipeline and upcoming phases +- `SECURITY.md` - Security policy and vulnerability reporting guidance +- `CHANGELOG.md` - Release notes and what changed across versions + +**v0.8.8 (latest) —** Sidebar puts **Connections** and **SQL Assistant** first; **Saved Queries** and **Query History** start collapsed for fresh view state; **What’s New** is command-palette only. Notebook inline edits use **parameterized SQL inside transactions**. **Table Designer** adds **create-mode column reorder** and improved **SQL preview** styling. Details: `CHANGELOG.md`. + --- ## 🏗️ Project Structure ``` -yape/ +PgStudio/ ├── src/ │ ├── extension.ts # Extension entry point │ ├── commands/ # Command implementations @@ -243,8 +256,8 @@ Turn any query result into beautiful, interactive charts in seconds. ```bash # Clone the repository -git clone https://github.com/dev-asterix/yape.git -cd yape +git clone https://github.com/dev-asterix/PgStudio.git +cd PgStudio # Install dependencies npm install @@ -349,14 +362,14 @@ PgStudio includes comprehensive testing infrastructure: - **Docker Containers**: PostgreSQL 12, 14, 15, 16, 17 for compatibility testing - **CI/CD Pipeline**: GitHub Actions with Matrix testing (Node 18-22, PostgreSQL 12-17) -📖 **Full documentation**: See [TESTING.md](TESTING.md) and [TESTING_QUICKSTART.md](TESTING_QUICKSTART.md) +📖 **Testing docs**: Use the scripts listed above and CI workflow in `.github/workflows/test.yml`. --- ## 🤝 Contributing -- 🐛 [Report Bugs](https://github.com/dev-asterix/yape/issues/new?template=bug_report.md) -- 💡 [Request Features](https://github.com/dev-asterix/yape/issues/new?template=feature_request.md) +- 🐛 [Report Bugs](https://github.com/dev-asterix/PgStudio/issues/new?template=bug_report.md) +- 💡 [Request Features](https://github.com/dev-asterix/PgStudio/issues/new?template=feature_request.md) - 🔧 Fork → Branch → PR - 🧪 Ensure all tests pass: `npm run test:all && npm run coverage` @@ -410,7 +423,7 @@ Also on [Open VSX](https://open-vsx.org/extension/ric-v/postgres-explorer) --- -## ???? Troubleshooting +## 🔧 Troubleshooting ### Connection Issues diff --git a/SECURITY.md b/SECURITY.md index f0b8fe3..deb1d26 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -6,12 +6,12 @@ We actively support security updates for the latest major release. | Version | Supported | | ------- | ------------------ | -| 0.5.x | :white_check_mark: | -| < 0.5.0 | :x: | +| 0.8.x | :white_check_mark: | +| < 0.8.0 | :x: | ## Reporting a Vulnerability -If you discover a security vulnerability in this extension (e.g., improper credential storage, SQL injection risks within the helper, or data leakage), please report it through github issues. +If you discover a security vulnerability in this extension (for example, credential storage issues, SQL injection risks, or data leakage), please report it via GitHub issues and clearly mark it as a security report. ### What to Include * Description of the vulnerability. diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 1106eb5..b67d28f 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -1,6 +1,6 @@ # PgStudio Architecture -> **Last Updated**: December 2025 +> **Last Updated**: March 2026 This document provides a comprehensive overview of PgStudio's architecture, design decisions, and component interactions. @@ -414,6 +414,19 @@ Default pool configuration: - Session clients closed on notebook disposal - Result truncation prevents OOM errors +### Large Operation Optimizations + +- **Adaptive schema cache TTL** in `src/lib/schema-cache.ts` + - Hot entries expire faster, cold entries live longer. + - Balances freshness and query volume under large schemas. +- **Connection pool metrics and idle cleanup** in `src/services/ConnectionManager.ts` + - Tracks pool health and closes idle pools after inactivity. + - Helps prevent pool exhaustion and stale resource usage. +- **Debounced tree refresh** in `src/providers/DatabaseTreeProvider.ts` + - Batches rapid refresh triggers to reduce UI flicker and redundant renders. +- **Large-tree prioritization** + - Prioritizes favorites/recent objects for faster perceived responsiveness on databases with many objects. + --- ## Security diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md deleted file mode 100644 index 4800a13..0000000 --- a/docs/CONTRIBUTING.md +++ /dev/null @@ -1,478 +0,0 @@ -# Contributing to PgStudio - -Thank you for your interest in contributing to PgStudio! This guide will help you get started with development. - ---- - -## Table of Contents - -- [Development Setup](#development-setup) -- [Project Structure](#project-structure) -- [Code Style Guide](#code-style-guide) -- [Testing Guidelines](#testing-guidelines) -- [Pull Request Process](#pull-request-process) -- [Commit Message Format](#commit-message-format) - ---- - -## Development Setup - -### Prerequisites - -- **Node.js** >= 18.x -- **npm** >= 9.x -- **VS Code** >= 1.80.0 -- **PostgreSQL** >= 12.x (for testing) - -### Initial Setup - -```bash -# Clone the repository -git clone https://github.com/dev-asterix/yape.git -cd yape - -# Install dependencies -npm install - -# Compile TypeScript -npm run compile - -# Watch mode for development -npm run watch -``` - -### Running the Extension - -1. Open the project in VS Code -2. Press `F5` to launch Extension Development Host -3. The extension will be loaded in a new VS Code window - -### Project Scripts - -```bash -npm run compile # Compile TypeScript -npm run watch # Watch mode (auto-compile on save) -npm run test # Run unit tests -npm run lint # Run ESLint -npm run esbuild-renderer # Bundle renderer for production -``` - ---- - -## Project Structure - -``` -yape/ -├── src/ -│ ├── extension.ts # Extension entry point -│ ├── commands/ # Command implementations -│ │ ├── connections.ts # Connection management -│ │ ├── tables.ts # Table operations -│ │ ├── views.ts # View operations -│ │ ├── functions.ts # Function operations -│ │ ├── fdw.ts # Foreign Data Wrapper ops -│ │ ├── ai.ts # AI commands -│ │ └── helper.ts # Shared utilities -│ ├── providers/ # VS Code providers -│ │ ├── DatabaseTreeProvider.ts -│ │ ├── SqlCompletionProvider.ts -│ │ ├── NotebookKernel.ts -│ │ └── DashboardPanel.ts -│ ├── services/ # Core services -│ │ ├── ConnectionManager.ts # Connection pooling -│ │ ├── SecretStorageService.ts -│ │ ├── SSHService.ts -│ │ ├── AIService.ts -│ │ ├── HistoryService.ts -│ │ ├── ErrorService.ts -│ │ └── DbObjectService.ts -│ ├── renderer_v2.ts # Notebook renderer -│ ├── renderer/ # Renderer modules -│ │ ├── components/ui.ts -│ │ └── features/ -│ │ ├── export.ts -│ │ └── ai.ts -│ ├── common/ # Shared types -│ │ └── types.ts -│ └── test/ # Tests -│ └── unit/ -├── docs/ # Documentation -├── package.json # Extension manifest -└── tsconfig.json # TypeScript config -``` - ---- - -## Code Style Guide - -### TypeScript Conventions - -#### 1. **Strict Typing** -Always use explicit types. Avoid `any` unless absolutely necessary. - -```typescript -// ✅ Good -async function getTableData( - client: PoolClient, - schema: string, - table: string -): Promise { - return await client.query('SELECT * FROM $1.$2', [schema, table]); -} - -// ❌ Bad -async function getTableData(client: any, schema: any, table: any): Promise { - return await client.query('SELECT * FROM $1.$2', [schema, table]); -} -``` - -#### 2. **Naming Conventions** - -| Type | Convention | Example | -|------|------------|---------| -| Classes | PascalCase | `ConnectionManager` | -| Interfaces | PascalCase with `I` prefix (optional) | `ConnectionConfig` | -| Functions | camelCase | `getPooledClient` | -| Constants | UPPER_SNAKE_CASE | `MAX_ROWS` | -| Private members | camelCase with `_` prefix | `_pools` | - -#### 3. **Async/Await** -Prefer `async/await` over `.then()` chains. - -```typescript -// ✅ Good -async function fetchData() { - try { - const result = await client.query('SELECT ...'); - return result.rows; - } catch (error) { - ErrorService.getInstance().handleError(error); - } -} - -// ❌ Bad -function fetchData() { - return client.query('SELECT ...') - .then(result => result.rows) - .catch(error => ErrorService.getInstance().handleError(error)); -} -``` - ---- - -### Connection Management Best Practices - -#### 1. **Always Use Pooling** - -```typescript -// ✅ Good - Pooled client (auto-released) -const client = await ConnectionManager.getInstance().getPooledClient(config); -try { - await client.query('SELECT ...'); -} finally { - client.release(); // CRITICAL: Always release in finally -} - -// ❌ Bad - Direct client creation -const client = new Client(config); -await client.connect(); -await client.query('SELECT ...'); -await client.end(); // May not execute if error occurs -``` - -#### 2. **Session Clients for Notebooks** - -```typescript -// ✅ Good - Session client for stateful operations -const client = await ConnectionManager.getInstance() - .getSessionClient(config, notebook.uri.toString()); - -// Client persists across cells -// Automatically closed when notebook closes -``` - -#### 3. **Error Handling** - -```typescript -// ✅ Good - Centralized error handling -try { - await client.query('...'); -} catch (error) { - ErrorService.getInstance().handleError(error, { - context: 'Table Operations', - operation: 'INSERT', - table: tableName - }); - throw error; // Re-throw if caller needs to handle -} -``` - ---- - -### SQL Query Patterns - -#### 1. **Parameterized Queries** -Always use parameterized queries to prevent SQL injection. - -```typescript -// ✅ Good -await client.query( - 'SELECT * FROM $1.$2 WHERE id = $3', - [schema, table, id] -); - -// ❌ Bad - SQL injection risk -await client.query( - `SELECT * FROM ${schema}.${table} WHERE id = ${id}` -); -``` - -#### 2. **Identifier Quoting** -Use double quotes for identifiers to handle special characters. - -```typescript -// ✅ Good -const query = `SELECT * FROM "${schema}"."${table}"`; - -// Handles schemas/tables with spaces, uppercase, etc. -``` - ---- - -### Error Handling Patterns - -#### 1. **Service Layer Errors** - -```typescript -export class MyService { - private static instance: MyService; - - public static getInstance(): MyService { - if (!MyService.instance) { - MyService.instance = new MyService(); - } - return MyService.instance; - } - - async performOperation(): Promise { - try { - // Operation logic - } catch (error) { - ErrorService.getInstance().handleError(error, { - context: 'MyService', - operation: 'performOperation' - }); - throw error; - } - } -} -``` - -#### 2. **Command Handler Errors** - -```typescript -export async function myCommandHandler(node: TreeNode) { - try { - const client = await ConnectionManager.getInstance() - .getPooledClient(node.connection); - try { - await client.query('...'); - vscode.window.showInformationMessage('Success!'); - } finally { - client.release(); - } - } catch (error) { - vscode.window.showErrorMessage(`Failed: ${error.message}`); - } -} -``` - ---- - -## Testing Guidelines - -### Unit Tests - -Located in `src/test/unit/`. Use Mocha + Chai. - -```typescript -import { expect } from 'chai'; -import * as sinon from 'sinon'; - -describe('ConnectionManager', () => { - let sandbox: sinon.SinonSandbox; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('should create a new pool if one does not exist', async () => { - const manager = ConnectionManager.getInstance(); - const config = { /* ... */ }; - - const poolStub = { - connect: sandbox.stub().resolves({ release: sandbox.stub() }), - on: sandbox.stub(), - end: sandbox.stub().resolves() - }; - - sandbox.stub(require('pg'), 'Pool').returns(poolStub); - - const client = await manager.getPooledClient(config); - - expect(poolStub.connect.calledOnce).to.be.true; - expect(client).to.exist; - }); -}); -``` - -### Integration Tests - -Require a local PostgreSQL instance. Use environment variables for configuration: - -```bash -export PGHOST=localhost -export PGPORT=5432 -export PGUSER=postgres -export PGPASSWORD=postgres -export PGDATABASE=test_db -``` - ---- - -## Pull Request Process - -### 1. **Fork and Branch** - -```bash -# Fork the repository on GitHub -# Clone your fork -git clone https://github.com/YOUR_USERNAME/yape.git - -# Create a feature branch -git checkout -b feature/my-new-feature -``` - -### 2. **Make Changes** - -- Follow the code style guide -- Add tests for new functionality -- Update documentation if needed - -### 3. **Test Your Changes** - -```bash -npm run compile -npm run test -npm run lint -``` - -### 4. **Commit** - -Follow the [commit message format](#commit-message-format). - -### 5. **Push and Create PR** - -```bash -git push origin feature/my-new-feature -``` - -Then create a Pull Request on GitHub with: -- Clear description of changes -- Reference to related issues -- Screenshots/GIFs for UI changes - -### 6. **Code Review** - -- Address reviewer feedback -- Keep commits clean (squash if needed) -- Ensure CI passes - ---- - -## Commit Message Format - -We follow the [Conventional Commits](https://www.conventionalcommits.org/) specification. - -### Format - -``` -(): - - - -