Contributing to pg-safe-migrate
March 3, 2026 · View on GitHub
Thank you for your interest in contributing! This guide will help you get started.
Development Setup
Prerequisites
- Node.js >= 18
- pnpm >= 8
- PostgreSQL >= 14 (for integration tests)
Getting Started
# Clone the repository
git clone https://github.com/defnotwig/pg-safe-migrate.git
cd pg-safe-migrate
# Install dependencies
pnpm install
# Build all packages
pnpm build
# Run unit tests
pnpm test
# Run integration tests (requires running PostgreSQL)
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres \
pnpm --filter pg-safe-migrate-core test:integration
Project Structure
pg-safe-migrate/
├── packages/
│ ├── core/ # Migration engine, linter, planner
│ │ └── src/
│ │ ├── lint/ # SQL safety rules + splitter
│ │ └── __tests__/
│ └── cli/ # CLI commands + config resolution
│ └── src/
│ ├── commands/
│ └── __tests__/
├── action/ # GitHub Action (composite)
├── docs/ # Documentation
├── examples/ # Example projects
└── .github/ # CI/CD workflows
Development Workflow
Making Changes
- Fork the repository and create a feature branch
- Make your changes
- Add or update tests as needed
- Run the full test suite:
pnpm test - Run the build:
pnpm build - Submit a pull request
Changesets
We use Changesets for version management.
After making changes, create a changeset:
pnpm changeset
- Select the packages affected
- Choose the semver bump type (patch/minor/major)
- Write a concise summary of the change
Code Style
- TypeScript strict mode — no
any, no implicit returns - Use
node:prefix for Node.js built-in imports - Prefer
constoverlet - Functions should be pure where possible
- Test files mirror source structure
Testing Guidelines
- Unit tests: Mock external dependencies (DB, file system)
- Integration tests: Test against real PostgreSQL
- Aim for tests that document behavior, not just cover lines
- Name tests descriptively:
it('detects drift when file changes after applied')
Commit Messages
Follow Conventional Commits:
feat(core): add PGSM011 rule for large table locks
fix(cli): resolve config file path on Windows
docs: add zero-downtime deployment guide
test(core): add drift detection edge cases
Adding a New Lint Rule
-
Add the rule to
packages/core/src/lint/rules.ts:- Choose the next available PGSM ID
- Define the regex pattern
- Set severity (
errororwarning) - Write a clear message and safe alternative
-
Add the rule ID to
LintRuleIdtype inpackages/core/src/types.ts -
Add tests in
packages/core/src/__tests__/unit/lint-rules.test.ts -
Document the rule in
docs/safety-rules.md -
Create a changeset
Reporting Issues
- Use the Bug Report template for bugs
- Use the Feature Request template for new features
- Include reproduction steps and your environment details
Code of Conduct
This project follows the Contributor Covenant Code of Conduct.
Contributors
Thanks to all the people who contribute to pg-safe-migrate! Whether it's code, documentation, bug reports, or feedback — every contribution matters.
We welcome contributors of all experience levels. If you're new to open source, check out First Timers Only for helpful resources.
License
By contributing, you agree that your contributions will be licensed under the MIT License.