Skip to content

PostgreSQL Function and Procedure Implementation#1

Merged
gtripoli merged 72 commits intomainfrom
feature/postgresql-function-procedure
Mar 7, 2026
Merged

PostgreSQL Function and Procedure Implementation#1
gtripoli merged 72 commits intomainfrom
feature/postgresql-function-procedure

Conversation

@gtripoli
Copy link
Owner

@gtripoli gtripoli commented Feb 28, 2026

Summary

Complete implementation of PostgreSQL Function and Procedure support with full CRUD operations, test coverage, and documentation.

Changes Overview

Phase 1: PostgreSQL Function

  • Implemented PostgreSQLFunction class with create/drop/alter methods
  • Added get_functions() to PostgreSQLContext
  • PostgreSQL-specific features: plpgsql, volatility, $$ syntax
  • Override fully_qualified_name to use public schema
  • 3 tests passing (postgres:latest, 16, 15)

Phase 2: PostgreSQL Procedure

  • Implemented PostgreSQLProcedure class with create/drop/alter methods
  • Added get_procedures() to PostgreSQLContext
  • PostgreSQL-specific features: plpgsql, procedure signature handling
  • Override fully_qualified_name to use public schema
  • 3 tests passing (postgres:latest, 16, 15)

Infrastructure

  • Added abstract build_empty_function() and build_empty_procedure() to AbstractContext
  • Implemented concrete methods in PostgreSQL, MariaDB, MySQL contexts
  • Added NotImplementedError stubs for SQLite (no function/procedure support)
  • Created base_function_tests.py and base_procedure_tests.py base test classes

Cleanup

  • Removed backup files: settings.yml.bak, PeterSQL.fbp.bkp, suggestion_builder.py.backup
  • Removed unready assets: petersql_hat.xcf, petersql_hat.png, PeterSQL.png
  • Removed unready scripts: scripts/build/nix/
  • Updated .gitignore to prevent future commits of backup files

Test Results

PostgreSQL: 63/63 tests passing (100%)
Total: 182/182 tests passing (100%)
Increment: +6 tests (3 Function + 3 Procedure)

Files Changed

  • Core implementation: 8 files (database.py, context.py for PostgreSQL/MariaDB/MySQL/SQLite)
  • Tests: 2 new base test files + PostgreSQL test suite updates
  • Documentation: README.md updated with implementation status
  • Cleanup: 8 unwanted files removed, .gitignore updated

Commits (16 total)

  • 6 commits: Function/Procedure implementation
  • 4 commits: Documentation updates
  • 3 commits: CI/workflow improvements
  • 2 commits: UI enhancements
  • 1 commit: Cleanup

- Rename job from 'pre-commit' to 'test' and remove container configuration
- Replace manual uv installation with astral-sh/setup-uv@v4 action
- Add Python 3.14 setup using actions/setup-python@v5
- Change dependency installation from `uv sync --dev` to `uv sync --extra dev`
- Replace pre-commit execution with pytest running full test suite with coverage
- Update pre-commit hook to use runtest-local.sh script
- Add global constants
- Change output file from windows/__init__ to windows/views
- Rename Settings dialog to SettingsDialog
- Expand MainFrameView and adjust default size from 1024x762 to 1280x1024
- Update splitter window sash position from -150 to 432
- Expand Views notebook page and its child components
- Rename view editor panel from m_panel34 to pnl_view_editor_root
- Add view name input field with label and text control
- Add schema selection with
- Change all expanded properties from "true" to "false" in SettingsDialog
- Revert splitter sash position from 432 to -150 in Views panel
- Change Views notebook proportion from 1 to 0
- Add new pnl_view_editor_root panel with view name and schema inputs
- Collapse all tree nodes in view editor components
- Add trigger_options_matrix.md documenting trigger support across MySQL, MariaDB, PostgreSQL, Oracle, and SQLite
- Rename `sql` field to `statement` in SQLView, SQLTrigger, SQLProcedure, and SQLFunction classes
- Add `is_new` property and `sql_safe_name` property to database object classes
- Add abstract `create()`, `drop()`, and `alter()` methods to SQLTrigger, SQLProcedure, SQLFunction
- Implement `save()` method for SQLView
…r sql to statement

PostgreSQL Implementation (100% test coverage - 57/57 tests passing):
- Implement PostgreSQLColumn.modify() with separate ALTER COLUMN statements for type, nullable, default changes
- Implement PostgreSQLTrigger.drop() with regex to extract table name from CREATE TRIGGER statement
- Implement PostgreSQLView with fully_qualified_name override for public schema
- Fix PostgreSQLContext.get_views() to use 'statement' parameter instead of 'sql'
- Fix PostgreSQLContext.get_triggers() to return trigger name without schema prefix

Code Style Refactoring (all engines):
- Rename all 'sql' variables to 'statement' for better code clarity
- Applied across PostgreSQL, MariaDB, MySQL, and SQLite engines
- Affects all CRUD methods (create, drop, alter, modify, etc.)

Test Coverage:
- PostgreSQL: 57/57 tests passing (was 0/57)
- Overall: 176/176 tests passing (100% pass rate)
- All PostgreSQL test skips removed

Files modified:
- structures/engines/postgresql/database.py: Column.modify, Trigger.drop, View.fully_qualified_name
- structures/engines/postgresql/context.py: get_views, get_triggers fixes
- structures/engines/mariadb/database.py: sql → statement refactoring
- structures/engines/mysql/database.py: sql → statement refactoring
- structures/engines/sqlite/database.py: sql → statement refactoring
- tests/engines/postgresql/test_integration_suite.py: remove skip decorators
- tests/README.md: update test coverage matrix and statistics
- Add new section 3: Commit Messages
- Commit messages must be concise and non-verbose
- Detailed explanations belong in merge request descriptions
- Renumber subsequent sections (3-10 → 4-11)
…atrix

- Add Create/Drop/Alter operations for Function, Procedure, Event
- Function: MariaDB/MySQL implemented, PostgreSQL/SQLite missing
- Procedure: Not implemented on any engine (native support exists)
- Event: Not implemented on any engine (MariaDB/MySQL only)
- Update legend to clarify implementation status
- Add priority matrix for Function/Procedure/Event implementation
- PostgreSQLFunction marked as HIGH priority (complete PostgreSQL)
- Recommended implementation order: Function → Procedure → Event
- Rationale: PostgreSQL almost complete, only Function/Procedure missing
- MariaDB/MySQL already have Function, PostgreSQL is the gap
- Add PostgreSQLFunction class with PostgreSQL-specific syntax
- Support parameters, returns, language (plpgsql), volatility
- Implement create() using CREATE OR REPLACE FUNCTION with $$ syntax
- Implement drop() with function signature for proper overload handling
- Implement alter() as drop + create pattern
- Add get_functions() to PostgreSQLContext querying information_schema.routines
- Register get_functions_handler in PostgreSQLDatabase initialization
- Import SQLFunction in postgresql/database.py
- Mark PostgreSQLFunction as implemented in test coverage matrix
- Update priority status from HIGH to DONE
- Update Key Findings with PostgreSQLFunction details
- Update Missing Implementations - PostgreSQLFunction complete
- PostgreSQL Function supports plpgsql, volatility, create/drop/alter
… tests

- Add abstract build_empty_function method to AbstractContext
- Implement build_empty_function in PostgreSQL, MariaDB, MySQL contexts
- Add NotImplementedError stub in SQLite (no function support)
- Override fully_qualified_name in PostgreSQLFunction to use public schema
- Create base_function_tests.py with BaseFunctionTests class
- Add TestPostgreSQLFunction to test_integration_suite.py
- All 3 PostgreSQL Function tests passing (postgres:latest, 16, 15)
- Update test statistics: 179 total tests (+3), 60 PostgreSQL tests (+3)
- Mark PostgreSQLFunction as COMPLETED in priorities section
- Update next priority to PostgreSQLProcedure
- All PostgreSQL tests passing with Function implementation
- Phase 1 complete: PostgreSQL Function fully implemented and tested
- Add PostgreSQLProcedure class with PostgreSQL-specific syntax
- Support parameters, language (plpgsql), statement
- Implement create() using CREATE OR REPLACE PROCEDURE with $$ syntax
- Implement drop() with procedure signature for proper overload handling
- Implement alter() as drop + create pattern
- Override fully_qualified_name to use public schema
- Add get_procedures() to PostgreSQLContext querying information_schema.routines
- Register get_procedures_handler in PostgreSQLDatabase initialization
- Add abstract build_empty_procedure to AbstractContext
- Implement build_empty_procedure in PostgreSQL context
- Add NotImplementedError stubs in MariaDB, MySQL, SQLite contexts
- Create base_procedure_tests.py with BaseProcedureTests class
- Add TestPostgreSQLProcedure to test_integration_suite.py
- All 3 PostgreSQL Procedure tests passing (postgres:latest, 16, 15)
- Import SQLProcedure in postgresql/database.py
- Update test statistics: 182 total tests (+3), 63 PostgreSQL tests (+3)
- Mark PostgreSQLProcedure as COMPLETED in priorities section
- Update next priority to MariaDB/MySQL Procedure
- All PostgreSQL tests passing with Procedure implementation
- Phase 2 complete: PostgreSQL Procedure fully implemented and tested
- PostgreSQL now has complete Function and Procedure support
Remove backup files (deleted from filesystem):
- settings.yml.bak
- PeterSQL.fbp.bkp
- suggestion_builder.py.backup

Remove unready images (kept in filesystem):
- petersql_hat.xcf
- petersql_hat.png
- PeterSQL.png

Remove unready build scripts (kept in filesystem):
- scripts/build/nix/

Update .gitignore:
- Add patterns for backup files (*.bak, *.bkp, *.backup)
- Add specific unready assets
- Add scripts/build/nix/ directory
gtripoli added 29 commits March 4, 2026 15:26
AI-Assisted-By: Cline
AI-Contribution: 80%
Tracked-By: CodeShield AI
AI-Assisted-By: Cline
AI-Contribution: 100%
Tracked-By: CodeShield AI
AI-Assisted-By: Cline
AI-Contribution: 100%
Tracked-By: CodeShield AI
AI-Assisted-By: Cline
AI-Contribution: 100%
Tracked-By: CodeShield AI
AI-Assisted-By: Cline
AI-Contribution: 100%
Tracked-By: CodeShield AI
AI-Assisted-By: Cline
AI-Contribution: 100%
Tracked-By: CodeShield AI
- Fix GROUP BY s| example to show status column (not 'none')
- Clarify VIRTUAL_SCOPED requires CURRENT_TABLE set in UI
- Add rule for CURRENT_TABLE with no scope and no prefix
- Update SELECT_LIST 3a to include CURRENT_TABLE columns
- Fix Out-of-Scope Table Hints ordering (functions first)
- Add clear distinction between EMPTY and SINGLE_TOKEN contexts

AI-Assisted-By: Cline
AI-Contribution: 100%
Tracked-By: CodeShield AI
- RULES.md: keywords only shown when CURRENT_TABLE is set (not syntactically valid otherwise)
- from.json: remove FROM_005 (CTE test - moved to derived_tables_cte.json)
- derived_tables_cte.json: add FROM_005_MOVED with xfail

AI-Assisted-By: Cline
AI-Contribution: 100%
Tracked-By: CodeShield AI
Keywords like FROM/WHERE only make sense when there's already
something in the SELECT list to continue from. Empty SELECT (e.g.
'SELECT |') has no context for keywords.

AI-Assisted-By: Cline
AI-Contribution: 100%
Tracked-By: CodeShield AI
- FROM: 9 → 8 tests (moved CTE test to derived_tables_cte.json)
- DERIVED_TABLES_CTE: 8 → 9 tests (added FROM_005_MOVED with xfail)
- Updated summary statistics

AI-Assisted-By: Cline
AI-Contribution: 100%
Tracked-By: CodeShield AI
- suggestion_builder.py: removed alphabetical sorting for columns
- Updated test expectations to reflect schema order (not alphabetical):
  - join_on.json: JOIN_ON_001
  - sel.json: SEL_LIST_006
  - select_prefix.json: SELECT_PREFIX_006

Per RULES.md, columns should preserve their table definition order
(ordinal_position), NOT alphabetical order.

AI-Assisted-By: Cline
AI-Contribution: 100%
Tracked-By: CodeShield AI
- autocomplete_adapter.py: use WORKDIR, load functions from YAML
- test_golden_cases.py: parametrize tests for all 4 engines
- README: update test counters (712 total = 178 × 4 engines)
- Add functions.yaml for mysql, postgresql, mariadb, sqlite

AI-Assisted-By: Cline
AI-Contribution: 100%
Tracked-By: CodeShield AI
Introduce normalized global and engine specification files with major-version targets, and update autocomplete golden tests to use engine/version parametrization.

AI-Assisted-By: Cline
AI-Contribution: 100%
Tracked-By: CodeShield AI
AI-Assisted-By: Cline
AI-Contribution: 100%
Tracked-By: CodeShield AI
Keep specification model as common baseline plus version removals only, add schema examples/docs, and update loaders to ignore *_add fields.

AI-Assisted-By: Cline
AI-Contribution: 100%
Tracked-By: CodeShield AI
…pe handling

This aligns context detection and suggestion ordering with RULES.md, including HAVING after-operator/after-expression and multi-table GROUP BY behavior.

AI-Assisted-By: Cline
AI-Contribution: 80%
Tracked-By: CodeShield AI
- Add ORDER_BY_AFTER_COLUMN context for ORDER BY column suggestions
- Add AFTER_LIMIT_NUMBER context for LIMIT clause (suggests OFFSET)
- Update golden tests for WHERE, ORDER, and LIMIT to match implementation
- Add new functions to WHERE suggestions (CURRENT_DATE, PI, POW, etc.)
- Update test statistics in README

AI-Assisted-By: Cline
AI-Contribution: 100%
Tracked-By: CodeShield AI
Add WINDOW_OVER context suggestions (ORDER BY, PARTITION BY) and improve scope extraction by ignoring comments during FROM/JOIN parsing. Align dot, alias, multi-query, and edge-case golden fixtures with current RULES behavior, and move legacy scope coverage into derived/CTE coverage.

AI-Assisted-By: Cline
AI-Contribution: 80%
Tracked-By: CodeShield AI
AI-Assisted-By: Cline
AI-Contribution: 80%
Tracked-By: CodeShield AI
…drails

Update OUT_OF_SCOPE_HINTS, LEX, ALX, and LARGE_SCHEMA_GUARDRAILS expectations to match current scope-first behavior and function set, then refresh README status/summary with all non-xfail golden tests passing.

AI-Assisted-By: Cline
AI-Contribution: 80%
Tracked-By: CodeShield AI
… cleanup

Implement minimal virtual-scope support for CTEs and derived subqueries, including projected-column extraction for WHERE, FROM/JOIN suggestions, and dot completion on derived aliases. Clean up redundant golden cases, align remaining expectations with current scope-first behavior, and refresh README statistics with all golden cases passing.

AI-Assisted-By: Cline
AI-Contribution: 80%
Tracked-By: CodeShield AI
…tions

Remove the Example Query column from README coverage tables and rewrite group descriptions to better describe test intent and behavior coverage.

AI-Assisted-By: Cline
AI-Contribution: 80%
Tracked-By: CodeShield AI
…w-up behavior

Propagate qualified column style from SELECT across SELECT/WHERE/JOIN/GROUP/HAVING/ORDER contexts with alias-first qualification, preserve schema-order column rendering in UI completion lists, and fix FROM post-table continuation suggestions (including no-space and aliased-prefix paths like W->WHERE). Add and align golden cases/rules/docs for wildcard transitions and qualified-style scenarios; full golden suite passes.

AI-Assisted-By: Cline
AI-Contribution: 100%
Tracked-By: CodeShield AI
…estions

Add SELECT wildcard completions (*, table.*) across SELECT contexts, prevent invalid FROM alias suggestions by mapping qualifiers to real tables/aliases, and enforce alias-qualified column suggestions in aliased WHERE paths. Update golden cases and README counts for the new behaviors.

AI-Assisted-By: Cline
AI-Contribution: 80%
Tracked-By: CodeShield AI
Add remote SSH tunnel target fields and TLS settings in the connection UI, auto-enable/persist TLS when auth requires it, and keep runtime tunnel/connect behavior aligned across MySQL and MariaDB.

AI-Assisted-By: Cline
AI-Contribution: 80%
Tracked-By: CodeShield AI
Rework connection manager actions (create/clone/rename/delete) to use the new tree context menu, preserve expansion state after deletes, and keep selection/pending-state handling consistent. Also register engine-specific pytest skip selectors and add MySQL/MariaDB warning+info logs when TLS is auto-enabled after auth failures.

AI-Assisted-By: Cline
AI-Contribution: 80%
Tracked-By: CodeShield AI
Use directory ids for tree operations, keep connection parent context during save/create/clone, preserve expanded state, and remove id migration writeback in favor of lenient fallback warnings.

AI-Assisted-By: Cline
AI-Contribution: 80%
Tracked-By: CodeShield AI
Persist and display connection statistics in the connection manager, update tree metadata after edits, and accept empty database passwords for local setups while keeping connection validation for required fields.

AI-Assisted-By: Cline
AI-Contribution: 80%
Tracked-By: CodeShield AI
AI-Assisted-By: Cline
AI-Contribution: 80%
Tracked-By: CodeShield AI
@gtripoli gtripoli merged commit e6b193d into main Mar 7, 2026
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant