Skip to content

Releases: tkcrm/pgxgen

v0.5.6

23 Apr 15:38
4738e40

Choose a tag to compare

What's Changed

Full Changelog: v0.5.5...v0.5.6

v0.5.5

23 Apr 15:16
09ac8c6

Choose a tag to compare

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

16 Apr 18:23
96fb147

Choose a tag to compare

What's Changed

  • feat: ensure CRUD results are written before running sqlc and add reg… by @sxwebdev in #83
  • feat: add support for keeping generated sqlc.yaml configuration by @sxwebdev in #84

Full Changelog: v0.5.3...v0.5.4

v0.5.3

14 Apr 06:41

Choose a tag to compare

Fix

  • Updated golang.org/x/tools from v0.43.0 to v0.44.0
  • Updated github.com/go-playground/validator/v10 from v10.30.1 to v10.30.2
  • Updated github.com/pingcap/tidb/pkg/parser to a newer version
  • Updated github.com/urfave/cli/v3 from v3.7.0 to v3.8.0
  • Updated various indirect dependencies including golang.org/x/crypto, golang.org/x/net, and google.golang.org/grpc
  • Modified generator.go to ensure generated files end with a single newline and are not empty
  • Added unit test TestGenerateTable_SingleTrailingNewline to verify the newline behavior in generated files
  • Changed file permission setting in SaveFile function to use octal notation (0o644) for clarity
  • Added a new test TestSaveFile_NotExecutable to ensure generated files are not executable on Unix systems

Full Changelog: v0.5.2...v0.5.3

v0.5.2

24 Mar 17:10
f17f4a1

Choose a tag to compare

What's Changed

Full Changelog: v0.5.1...v0.5.2

v0.5.1

22 Mar 13:09

Choose a tag to compare

What's Changed

  • feat: Implement CREATE and DROP VIEW functionality by @sxwebdev in #80
  • feat: Add skip_tables and skip_enums to Models Config by @sxwebdev in #81

Full Changelog: v0.5.0...v0.5.1

v0.5.0

20 Mar 01:54

Choose a tag to compare

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 file

Captures: 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 dialect

Dialects: 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 schema and pgxgen fmt accept positional path argument (file or directory) instead of --dir flag
  • pgxgen fmt searches directories recursively

Enriched SQL parser

  • PostgreSQL — column defaults, all constraint types, CREATE INDEX (partial with WHERE), 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

19 Mar 23:12

Choose a tag to compare

Breaking Changes (v2)

  • New config format v2 — unified pgxgen.yaml replaces the dual pgxgen.yaml + sqlc.yaml setup
  • sqlc.yaml is now auto-generated — pgxgen generates .pgxgen/sqlc.yaml from schemas[].sqlc section
  • Unified tables section — 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 — replaces ozzo-validation
  • Removed all v1 legacy packagesinternal/crud, internal/sqlc, internal/genmodels, internal/goconstatnts, internal/generator, internal/schema, internal/structs, internal/assets/assets.go deleted
  • Removed v1 config typesconfig.go, pgxgen.go, crud.go, sqlc.go, go_constants.go replaced by v2.go + loader.go
  • Run pgxgen migrate --in-place to convert v1 config to v2 (creates .v1.bak backup)

New Features (v2)

  • Template-based CRUD generation — SQL templates per engine (postgresql/mysql/sqlite) instead of imperative string building
  • Soft delete supportsoft_delete.column: deleted_at generates UPDATE SET deleted_at = now() instead of DELETE, auto-adds WHERE deleted_at IS NULL to get/find/total/exists
  • Batch createbatch_create method generates :copyfrom (PostgreSQL) or multi-VALUES insert
  • Custom SQL queries — define arbitrary SQL with sqlc annotations in custom_queries section
  • 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_prefix auto-derive paths per table
  • Single repo (Pattern B)queries_dir + output_dir put all tables in one place
  • pgxgen generate --dry-run — preview changes without writing files
  • pgxgen generate --debug — show detailed timing for each generation step
  • pgxgen migrate — convert v1 config to v2, with --in-place option. Migrates sqlc overrides (types, columns, struct tags, renames) and per-table query_parameter_limit
  • pgxgen example — generate annotated v2 config with all features
  • pgxgen validate — validate config and schema (useful for CI): checks tables exist, primary columns exist, SQL parses
  • pgxgen init — interactive wizard with default directories (sql/migrations/{engine}/, internal/store/repos/repo_*)
  • pgxgen watch — file system watcher with 500ms debounce, regenerates on .sql changes
  • 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 replacementreplace_nullable_types: true converts pgtype.Text → *string, pgtype.Timestamp → *time.Time, pgtype.Int2 → *int16, pgtype.UUID → *uuid.UUID etc.
  • Defaults inheritance — global defaults for crud methods, constants, emit_db_tags/emit_json_tags inherited 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_overrides in models config for custom SQL→Go type mapping
    • custom_tags for additional struct tags on NOT NULL fields
    • sqlc go_type with import resolved to pkg.Type (e.g., storecmn.JSONField)
    • Nullable sqlc type overrides matched correctly (uuid.UUID for NOT NULL, uuid.NullUUID for nullable)
  • Engine abstraction (internal/engine/) — eliminates repeated engine switch statements
  • User-provided templates — custom SQL templates in .pgxgen/templates/crud/{engine}/
  • JSON Schema v2schemas/pgxgen-schema-v2.json for 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 15 goimports calls with fast format.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/cli instead of copying its internal/ package into pkg/sqlc/
  • Removed gomodels command — replaced by pgxgen generate models which generates Go structs directly from SQL schema (not from existing Go files)
  • Removed gen_models config section — replaced by generate.models in pgxgen.yaml
  • Removed cmd/copysqlc/ utility (no longer needed)
  • Removed MobX Keystone and TypeScript code generation support (#73)
  • Replaced github.com/a-h/templ with Go's standard text/template for constants generation

Features

  • New pgxgen generate models command — 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 json and db struct 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
  • New SQL type-to-Go type mapper (internal/sqlparser/typemap/) with comprehensive mappings for all three engines
  • Added pgxgen generate crud subcommand — new recommended way to run CRUD generation
  • Deprecated pgxgen crud command with a warning message directing to pgxgen generate crud

Bug Fixes

  • Fixed config path resolution — all relative paths in sqlc.yaml and pgxgen.yaml are now correctly resolved relative to their config file location, not the working directory. This fixes --sqlc-config sql/sqlc.yaml and 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 processFind LIMIT/OFFSET generating PostgreSQL-only $N placeholders for MySQL and SQLite engines
  • Fixed processExists using PostgreSQL-only ::boolean cast for MySQL and SQLite engines
  • Fixed getTableMetaData iterating over map instead of direct O(1) lookup
  • Fixed double sorting of WHERE parameters in getWhereParams and processWhereParam
  • Fixed unnecessary memory allocation in getWhereAddtitionalParams when no params exist
  • Fixed wasted allocation in getTableMeta where tableMetaData was created then immediately overwritten

Improvements

  • Extracted magic number 6 into named constant columnsPerLineThreshold in processUpdate
  • Added comprehensive unit tests for SQL parsers (PostgreSQL, MySQL, SQLite) and type mappers
  • Updated JSON schema (schemas/pgxgen-schema.json) with new generate.models config
  • 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

27 Nov 09:29
54c4141

Choose a tag to compare

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: false

Allows 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 AttributeGroup

What's Changed

Full Changelog: v0.3.13...v0.3.14

v0.3.13

13 Nov 16:48

Choose a tag to compare

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