Contributing
git clone https://github.com/gdpotter/pgmt.gitcd pgmt./scripts/test-setup.sh # Start PostgreSQL containerscargo test # Run testsPrerequisites: Rust 1.74+, Docker
Code Style
Section titled “Code Style”cargo fmtbefore committingcargo clippy -- -D warnings- no warnings- Use
anyhow::Resultfor errors - All SQL queries use sqlx compile-time verification
- Tests required for new features
Adding Database Object Support
Section titled “Adding Database Object Support”Each object type needs:
-
Catalog module (
src/catalog/object.rs)fetch()function using PostgreSQL system catalogs- Include
comment: Option<String>field - Implement
DependsOnandCommentabletraits
-
Diff logic (
src/diff/object.rs)- Compare old vs new states
- Generate CREATE, DROP, ALTER operations
- Handle comment changes with
diff_comments()
-
Migration operations (
src/diff/operations/)- Define operation enums
- Implement
SqlRenderertrait
-
Tests (
tests/catalog/andtests/migrations/)
Look at src/catalog/triggers.rs for a pattern to follow.
Testing
Section titled “Testing”// Isolated test database#[tokio::test]async fn test_fetch() { with_test_db(async |db| { db.execute("CREATE TABLE users (id INT)").await; let tables = fetch(db.pool()).await.unwrap(); assert_eq!(tables.len(), 1); }).await;}
// Migration testing#[tokio::test]async fn test_migration() { let helper = MigrationTestHelper::new().await; helper.run_migration_test( &[], // Both databases &[], // Initial only &["CREATE TABLE users (id INT)"], // Target only |steps, _| { assert!(!steps.is_empty()); Ok(()) } ).await;}Pull Requests
Section titled “Pull Requests”Before submitting:
cargo testcargo fmtcargo clippy -- -D warningsSQLX_OFFLINE=true cargo buildPR requirements:
- Clear description of changes
- Tests pass
- No clippy warnings
- sqlx metadata committed (
.sqlx/files)
Reporting Issues
Section titled “Reporting Issues”Include: pgmt version, PostgreSQL version, OS, full error messages, steps to reproduce.
Code Organization
Section titled “Code Organization”| Directory | Purpose |
|---|---|
catalog/ | PostgreSQL introspection |
diff/ | Schema comparison |
commands/ | CLI implementations |
config/ | Configuration |
schema_loader/ | Multi-file schema loading |
render/ | SQL generation |