Releases: tkcrm/pgxgen
v0.5.6
v0.5.5
What's Changed
- build(deps): bump github.com/jackc/pgx/v5 from 5.9.1 to 5.9.2 by @dependabot[bot] in #85
- bump sqlc version to v1.31.1 by @sxwebdev in #86
Full Changelog: v0.5.4...v0.5.5
v0.5.4
v0.5.3
Fix
- Updated
golang.org/x/toolsfrom v0.43.0 to v0.44.0 - Updated
github.com/go-playground/validator/v10from v10.30.1 to v10.30.2 - Updated
github.com/pingcap/tidb/pkg/parserto a newer version - Updated
github.com/urfave/cli/v3from v3.7.0 to v3.8.0 - Updated various indirect dependencies including
golang.org/x/crypto,golang.org/x/net, andgoogle.golang.org/grpc - Modified
generator.goto ensure generated files end with a single newline and are not empty - Added unit test
TestGenerateTable_SingleTrailingNewlineto verify the newline behavior in generated files - Changed file permission setting in
SaveFilefunction to use octal notation (0o644) for clarity - Added a new test
TestSaveFile_NotExecutableto ensure generated files are not executable on Unix systems
Full Changelog: v0.5.2...v0.5.3
v0.5.2
v0.5.1
v0.5.0
What's New
pgxgen schema — Consolidated DDL Output
Standalone command that reads .up.sql migration files and outputs the final schema state as a single DDL script. No pgxgen.yaml required.
pgxgen schema sql/migrations/postgres # PostgreSQL (default)
pgxgen schema sql/migrations/sqlite -e sqlite # SQLite
pgxgen schema sql/migrations/001_init.up.sql # Single file
pgxgen schema sql/migrations/postgres > schema.sql # Save to fileCaptures: tables, columns (types, NOT NULL, defaults), PRIMARY KEY, FOREIGN KEY (with actions), UNIQUE/CHECK constraints, indexes (including partial), extensions, enums, comments. Tables topologically sorted by FK dependencies.
Engines: PostgreSQL (full), SQLite (full).
pgxgen fmt — SQL Formatter
Standalone command that formats SQL files with dialect-aware rules. Shows files to format and asks for confirmation before writing.
pgxgen fmt . # Format all .sql files recursively
pgxgen fmt sql/migrations/001_init.up.sql # Single file
pgxgen fmt . --check # CI mode — exit 1 if unformatted
pgxgen fmt . --dry-run # Test without saving
pgxgen fmt . --yes # Skip confirmation
pgxgen fmt . -e mysql # MySQL dialectDialects: PostgreSQL (default), MySQL, SQLite.
Handles: keyword/type uppercasing (50+ keywords, 20+ types), TIMESTAMP WITH TIME ZONE preservation, JSON operators (->, ->>), dollar-quoting, sqlc annotations (-- name: XXX :exec), $1/$2 params, PL/pgSQL DO blocks (skipped gracefully), block/line comments, multi-statement files. Fully idempotent.
| Flag | Description |
|---|---|
--check, -c |
Check only, exit 1 if unformatted (CI) |
--dry-run |
Process without saving |
--yes, -y |
Skip confirmation |
--engine, -e |
Dialect: postgresql, mysql, sqlite |
CLI improvements
pgxgen schemaandpgxgen fmtaccept positional path argument (file or directory) instead of--dirflagpgxgen fmtsearches directories recursively
Enriched SQL parser
- PostgreSQL — column defaults, all constraint types,
CREATE INDEX(partial withWHERE),CREATE EXTENSION,ALTER TABLE ADD/DROP CONSTRAINT,DROP INDEX - SQLite — column defaults, all constraint types,
CREATE INDEX,DROP INDEX, FK actions - New catalog types:
PrimaryKey,Index,ForeignKey,UniqueConstraint,CheckConstraint
Tests
All existing tests pass. 290+ new tests across parser, DDL generator, and formatter packages.
What's Changed
Full Changelog: v0.4.0...v0.5.0
v0.4.0
Breaking Changes (v2)
- New config format v2 — unified
pgxgen.yamlreplaces the dualpgxgen.yaml+sqlc.yamlsetup sqlc.yamlis now auto-generated — pgxgen generates.pgxgen/sqlc.yamlfromschemas[].sqlcsection- Unified
tablessection — CRUD, constants, and sqlc repo settings are now per-table instead of 3 separate sections - CLI upgraded to
urfave/cli/v3— flag syntax unchanged, but internal API is v3 - Validation switched to
go-playground/validator/v10— replacesozzo-validation - Removed all v1 legacy packages —
internal/crud,internal/sqlc,internal/genmodels,internal/goconstatnts,internal/generator,internal/schema,internal/structs,internal/assets/assets.godeleted - Removed v1 config types —
config.go,pgxgen.go,crud.go,sqlc.go,go_constants.goreplaced byv2.go+loader.go - Run
pgxgen migrate --in-placeto convert v1 config to v2 (creates.v1.bakbackup)
New Features (v2)
- Template-based CRUD generation — SQL templates per engine (postgresql/mysql/sqlite) instead of imperative string building
- Soft delete support —
soft_delete.column: deleted_atgeneratesUPDATE SET deleted_at = now()instead ofDELETE, auto-addsWHERE deleted_at IS NULLto get/find/total/exists - Batch create —
batch_createmethod generates:copyfrom(PostgreSQL) or multi-VALUES insert - Custom SQL queries — define arbitrary SQL with sqlc annotations in
custom_queriessection - Multi-engine support — multiple
schemas[]with different engines (e.g., PostgreSQL + SQLite) in one project - Per-table repos (Pattern A) —
queries_dir_prefix+output_dir_prefixauto-derive paths per table - Single repo (Pattern B) —
queries_dir+output_dirput all tables in one place pgxgen generate --dry-run— preview changes without writing filespgxgen generate --debug— show detailed timing for each generation steppgxgen migrate— convert v1 config to v2, with--in-placeoption. Migrates sqlc overrides (types, columns, struct tags, renames) and per-tablequery_parameter_limitpgxgen example— generate annotated v2 config with all featurespgxgen validate— validate config and schema (useful for CI): checks tables exist, primary columns exist, SQL parsespgxgen init— interactive wizard with default directories (sql/migrations/{engine}/,internal/store/repos/repo_*)pgxgen watch— file system watcher with 500ms debounce, regenerates on.sqlchanges- sqlc overrides in models — type overrides (
uuid → uuid.UUID,geography → orb.Point) and column overrides (go_struct_tag,go_type) applied to generated Go models - Nullable type replacement —
replace_nullable_types: trueconvertspgtype.Text → *string,pgtype.Timestamp → *time.Time,pgtype.Int2 → *int16,pgtype.UUID → *uuid.UUIDetc. - Defaults inheritance — global defaults for crud methods, constants,
emit_db_tags/emit_json_tagsinherited by all tables - Model generation improvements:
- Struct names singularized (
todos → Todo,counterparties → Counterparty) - Go acronym handling (
user_id → UserID,website_url → WebsiteURL,http_status → HTTPStatus) - Structs sorted alphabetically, enums always before structs
type_overridesin models config for custom SQL→Go type mappingcustom_tagsfor additional struct tags on NOT NULL fields- sqlc
go_typewithimportresolved topkg.Type(e.g.,storecmn.JSONField) - Nullable sqlc type overrides matched correctly (
uuid.UUIDfor NOT NULL,uuid.NullUUIDfor nullable)
- Struct names singularized (
- Engine abstraction (
internal/engine/) — eliminates repeated engine switch statements - User-provided templates — custom SQL templates in
.pgxgen/templates/crud/{engine}/ - JSON Schema v2 —
schemas/pgxgen-schema-v2.jsonfor IDE autocompletion
Performance
- Schema parsed once — single parse reused across CRUD, models, and constants generators
- No goimports dependency — models generator resolves imports statically instead of calling
goimports(~2.4s → ~0.8ms) - Constants use
go/format— replaced 15goimportscalls with fastformat.Source - Total generation time — ~200ms for a typical project (was ~60s before optimization)
Previous Breaking Changes
- Removed vendored sqlc (~150K lines, 523 files) — sqlc is now used as a Go module via
github.com/sqlc-dev/sqlc/pkg/cliinstead of copying itsinternal/package intopkg/sqlc/ - Removed
gomodelscommand — replaced bypgxgen generate modelswhich generates Go structs directly from SQL schema (not from existing Go files) - Removed
gen_modelsconfig section — replaced bygenerate.modelsin pgxgen.yaml - Removed
cmd/copysqlc/utility (no longer needed) - Removed MobX Keystone and TypeScript code generation support (#73)
- Replaced
github.com/a-h/templwith Go's standardtext/templatefor constants generation
Features
- New
pgxgen generate modelscommand — generates Go model structs for ALL tables in SQL schema files, with support for:- All three database engines: PostgreSQL, MySQL, SQLite
- SQL driver selection:
pgx/v5,pgx/v4,database/sql - Optional
jsonanddbstruct tags - Pointer-based nullable types (
emit_pointers_for_null) - Enum type generation with
Valid()method
- New built-in SQL schema parser (
internal/sqlparser/) replacing vendored sqlc compiler:- PostgreSQL parser using
pg_query_go/v6— handles CREATE TABLE, CREATE TYPE AS ENUM, ALTER TABLE (ADD/DROP COLUMN, SET NOT NULL, ALTER TYPE), DROP TABLE/TYPE, COMMENT ON, CREATE SCHEMA - MySQL parser using TiDB parser — handles CREATE TABLE, ALTER TABLE (ADD/DROP/MODIFY COLUMN, RENAME), DROP TABLE, table/column comments
- SQLite parser using ANTLR4 — handles CREATE TABLE, ALTER TABLE (ADD/DROP COLUMN, RENAME TO), DROP TABLE
- PostgreSQL parser using
- New SQL type-to-Go type mapper (
internal/sqlparser/typemap/) with comprehensive mappings for all three engines - Added
pgxgen generate crudsubcommand — new recommended way to run CRUD generation - Deprecated
pgxgen crudcommand with a warning message directing topgxgen generate crud
Bug Fixes
- Fixed config path resolution — all relative paths in
sqlc.yamlandpgxgen.yamlare now correctly resolved relative to their config file location, not the working directory. This fixes--sqlc-config sql/sqlc.yamland similar setups where configs are in subdirectories - Fixed SQLite ALTER TABLE ADD COLUMN not parsed — columns added via ALTER TABLE in migrations were silently ignored, causing CRUD to generate SQL with missing columns (e.g.
workspace_id,priority) - Fixed
processFindLIMIT/OFFSET generating PostgreSQL-only$Nplaceholders for MySQL and SQLite engines - Fixed
processExistsusing PostgreSQL-only::booleancast for MySQL and SQLite engines - Fixed
getTableMetaDataiterating over map instead of direct O(1) lookup - Fixed double sorting of WHERE parameters in
getWhereParamsandprocessWhereParam - Fixed unnecessary memory allocation in
getWhereAddtitionalParamswhen no params exist - Fixed wasted allocation in
getTableMetawheretableMetaDatawas created then immediately overwritten
Improvements
- Extracted magic number
6into named constantcolumnsPerLineThresholdinprocessUpdate - Added comprehensive unit tests for SQL parsers (PostgreSQL, MySQL, SQLite) and type mappers
- Updated JSON schema (
schemas/pgxgen-schema.json) with newgenerate.modelsconfig - Updated README with new commands and configuration examples
What's Changed
- Add MIT License to the project by @sxwebdev in #69
- Add badges to README for project visibility by @sxwebdev in #70
- add schema for github.com/SchemaStore/schemastore by @stickpro in #71
- refator: remove mobx keystone and typescript support by @sxwebdev in #73
- feat(parser): implement internal sql parser by @sxwebdev in #74
- refactor: fully refactored tool by @sxwebdev in #75
- feat(skills): added agent skills by @sxwebdev in #76
- refactor: removed replace nullable types by @sxwebdev in #77
Full Changelog: v0.3.14...v0.4.0
v0.3.14
New feature
Introduce new models option include_struct_comments: true
version: "1"
sqlc:
- # directory with migrations. required
schema_dir: sql/migrations
models:
# include comments for structs. useful for swagger generation
include_struct_comments: falseAllows you to add comments to SQLC-generated models with the structure name. Useful for Swagger generation.
Example:
type AttributeGroup struct {
ID uuid.UUID `db:"id" json:"id"`
Name string `db:"name" json:"name"`
Description pgtype.Text `db:"description" json:"description"`
CreatedAt pgtype.Timestamp `db:"created_at" json:"created_at"`
UpdatedAt pgtype.Timestamp `db:"updated_at" json:"updated_at"`
} // @name AttributeGroupWhat's Changed
- added include_struct_comments config (#68) by @sxwebdev in 54c4141
- feat: enhance struct formatting by adding comments to closing braces for swagger generate (#67) by @stickpro in 3cc7f07
- Bump golang.org/x/crypto from 0.44.0 to 0.45.0 (#66) by @dependabot[bot] in c4c0807
Full Changelog: v0.3.13...v0.3.14
v0.3.13
Breaking Changes
Now all paths in pgxgen.yaml must be relative to the config file where it resides, not relative to the directory where the CRUD generation command is run. The same applies to sqlc.yaml.
What's Changed
- fix: update Go version to 1.25.4 in workflow configuration by @sxwebdev in e3f9d0b
- fix: update Go version to 1.25.4 and bump dependencies by @sxwebdev in 7f09a48
- fix: update version to v0.3.13 and improve error handling in GenerateConstants by @sxwebdev in 83a577a
- fix: improve file path handling in CRUD and SQLC modules by @sxwebdev in 62d56fc
Full Changelog: v0.3.12...v0.3.13