Skip to content

Contributing

Terminal window
git clone https://github.com/gdpotter/pgmt.git
cd pgmt
./scripts/test-setup.sh # Start PostgreSQL containers
cargo test # Run tests

Prerequisites: Rust 1.74+, Docker

  • cargo fmt before committing
  • cargo clippy -- -D warnings - no warnings
  • Use anyhow::Result for errors
  • All SQL queries use sqlx compile-time verification
  • Tests required for new features

Each object type needs:

  1. Catalog module (src/catalog/object.rs)

    • fetch() function using PostgreSQL system catalogs
    • Include comment: Option<String> field
    • Implement DependsOn and Commentable traits
  2. Diff logic (src/diff/object.rs)

    • Compare old vs new states
    • Generate CREATE, DROP, ALTER operations
    • Handle comment changes with diff_comments()
  3. Migration operations (src/diff/operations/)

    • Define operation enums
    • Implement SqlRenderer trait
  4. Tests (tests/catalog/ and tests/migrations/)

Look at src/catalog/triggers.rs for a pattern to follow.

// 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;
}

Before submitting:

Terminal window
cargo test
cargo fmt
cargo clippy -- -D warnings
SQLX_OFFLINE=true cargo build

PR requirements:

  • Clear description of changes
  • Tests pass
  • No clippy warnings
  • sqlx metadata committed (.sqlx/ files)

Include: pgmt version, PostgreSQL version, OS, full error messages, steps to reproduce.

DirectoryPurpose
catalog/PostgreSQL introspection
diff/Schema comparison
commands/CLI implementations
config/Configuration
schema_loader/Multi-file schema loading
render/SQL generation