From fba9850366fc59e2989757766be208ae213da198 Mon Sep 17 00:00:00 2001 From: Jon Langevin Date: Sat, 28 Feb 2026 18:21:19 -0500 Subject: [PATCH] feat: add pgx driver import and Start/Stop lifecycle to WorkflowDatabase Register the pgx/v5 stdlib driver alongside SQLite so database.workflow module can connect to PostgreSQL out of the box. Add Start(ctx)/Stop(ctx) methods to WorkflowDatabase so the modular framework auto-opens the DB connection at startup and closes it at shutdown. This removes the need for a separate persistence.store module when using database.workflow for direct SQL pipeline steps (db_query, db_exec). Co-Authored-By: Claude Opus 4.6 --- module/database.go | 16 ++++++++++++++++ module/database_drivers.go | 5 ++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/module/database.go b/module/database.go index e07b1119..310e3098 100644 --- a/module/database.go +++ b/module/database.go @@ -143,6 +143,22 @@ func (w *WorkflowDatabase) Open() (*sql.DB, error) { return db, nil } +// Start opens the database connection during application startup so that +// pipeline steps (db_query, db_exec) can use DB() without requiring a +// separate persistence.store module. +func (w *WorkflowDatabase) Start(ctx context.Context) error { + if w.config.DSN == "" { + return nil // no DSN configured, skip auto-open + } + _, err := w.Open() + return err +} + +// Stop closes the database connection during application shutdown. +func (w *WorkflowDatabase) Stop(ctx context.Context) error { + return w.Close() +} + // Close closes the database connection func (w *WorkflowDatabase) Close() error { w.mu.Lock() diff --git a/module/database_drivers.go b/module/database_drivers.go index 5f007f65..f1f86749 100644 --- a/module/database_drivers.go +++ b/module/database_drivers.go @@ -1,3 +1,6 @@ package module -import _ "modernc.org/sqlite" +import ( + _ "github.com/jackc/pgx/v5/stdlib" + _ "modernc.org/sqlite" +)