Contributing to pgtofu
Thank you for your interest in contributing to pgtofu! This guide will help you get started.Getting Started
Prerequisites
- Go 1.25 or later
- Docker (for running PostgreSQL locally)
- Git
Setting Up Development Environment
Running PostgreSQL Locally
Development Workflow
Making Changes
-
Create a branch:
- Make your changes
-
Run tests:
-
Run linters:
-
Build:
Running Specific Tests
Code Style
Go Style Guidelines
We follow standard Go conventions with some additions:- Use
gofmtfor formatting - Line length: max 100 characters (enforced by
golines) - Add comments for exported functions and types
- Use meaningful variable names
Linter Configuration
The project uses golangci-lint with 95+ linters. Key settings:Project Structure
Key Packages
| Package | Purpose |
|---|---|
internal/cli | Cobra-based CLI commands |
internal/schema | JSON-serializable data models |
internal/extractor | PostgreSQL system catalog queries |
internal/parser | SQL statement parsing |
internal/differ | Schema comparison logic |
internal/generator | DDL generation |
internal/graph | Topological sorting |
Adding Features
Adding a New Change Type
-
Define the change type in
internal/differ/types.go: -
Implement detection in the relevant comparator (e.g.,
table_comparator.go): -
Register the DDL builder in
internal/generator/ddl_registry.go: -
Implement the builder in appropriate
ddl_*.go: -
Add tests in the
tests/subdirectory.
Adding a New CLI Command
-
Create command file in
internal/cli/: -
Register in cli.go:
Adding SQL Parser Support
- Add statement detection in
internal/parser/statement.go - Create parser in
internal/parser/your_object.go - Register in parser.go statement handling
- Add tests in
internal/parser/tests/
Testing
Test Organization
Tests are intests/ subdirectories:
Writing Tests
Use table-driven tests:Test Utilities
Use testify for assertions:Pull Request Process
Before Submitting
-
Tests pass:
-
Linters pass:
- Documentation updated (if applicable)
-
Commit messages are clear:
PR Description
Include in your PR description:- What: Summary of changes
- Why: Motivation/issue being fixed
- How: Implementation approach
- Testing: How you tested the changes
Review Process
- CI checks must pass
- At least one maintainer review
- Address review feedback
- Squash and merge
Release Process
Releases are automated via GitHub Actions:-
Tag with semantic version:
-
GitHub Actions builds and publishes:
- Docker image to Docker Hub
- GitHub release
Getting Help
- Issues: GitHub Issues
- Discussions: GitHub Discussions