diff --git a/docs/DEVELOPMENT.md b/docs/DEVELOPMENT.md index 31fb429..f6fef70 100644 --- a/docs/DEVELOPMENT.md +++ b/docs/DEVELOPMENT.md @@ -1,65 +1,104 @@ -# Development Workflow +# Development Guide + +## Project Structure + +``` +pg_morbac/ +├── src/ # Modular SQL source files +├── tests/ # Test files +├── tools/ # Build and test scripts +├── docs/ # Documentation +├── pg_morbac.control # Version source of truth +├── pg_morbac.sql # Generated (git-ignored) +└── Makefile # Build automation +``` ## Version Management -This extension uses a single-source version approach: +Version is defined in `pg_morbac.control` under `default_version`. -- **Version source of truth**: `pg_morbac.control` (the `default_version` field) -- **Development file**: `pg_morbac.sql` (unversioned, for daily work) -- **Release files**: `pg_morbac--X.Y.Z.sql` (generated, git-ignored) +Edit source files in `src/` and commit them. Never edit or commit `pg_morbac.sql` (generated by build script). -## Daily Development +## Development Workflow -1. **Edit**: Work on `pg_morbac.sql` (no version numbers in the file) -2. **Test**: Run `make test` to test changes in a temporary database -3. **Commit**: Commit `pg_morbac.sql` to git regularly +### Edit Source Files + +```bash +vim src/authorization.sql +``` + +### Build and Test + +```bash +make test +``` + +This builds from `src/`, creates a temporary database, runs all tests, and cleans up. + +### Commit Changes + +```bash +git add src/authorization.sql tests/01_authorization.sql +git commit -m "Add feature X" +``` + +The build script concatenates `src/` files in dependency order (header first, footer last). + +## Manual Testing + +```bash +make build +createdb mytest +psql -d mytest -f pg_morbac.sql +psql -d mytest +dropdb mytest +``` ## Release Process -When ready to release a new version: +1. Update version in `pg_morbac.control` +2. Update `CHANGELOG.md` +3. Run `make build` and `make test` +4. Commit and tag: -1. **Update version**: Edit `pg_morbac.control` and change `default_version` - ``` - default_version = '1.1.0' - ``` - -2. **Create release**: Run `make release` - - Reads version from `.control` file - - Copies `pg_morbac.sql` to `pg_morbac--X.Y.Z.sql` - -3. **Test**: Run `make test` with the versioned file - -4. **Tag in git**: - ```bash - git add pg_morbac.control pg_morbac--X.Y.Z.sql - git commit -m "Release vX.Y.Z" - git tag vX.Y.Z - git push origin main --tags - ``` - -## Upgrade Scripts - -For version migrations, create upgrade scripts: ```bash -# Example: upgrade from 1.0.0 to 1.1.0 -touch pg_morbac--1.0.0--1.1.0.sql +git commit -m "Release vX.Y.Z" +git tag vX.Y.Z +git push origin main --tags ``` -These contain only the ALTER/ADD statements needed for the upgrade. +## Makefile Targets -## Make Targets +```bash +make build # Build from src/ files +make test # Build and run tests +make install # Install to PostgreSQL +make help # Show all targets +``` -- `make test`: Test with development file (temporary database) -- `make test`: Full test with persistent database -- `make release`: Generate versioned file from development file -- `make install`: Create release and install in PostgreSQL -- `make cleanup`: Drop test database -- `make help`: Show all targets +## Code Style -## Benefits +SQL keywords in UPPERCASE. Identifiers in lowercase_snake_case. Always qualify with `morbac.` schema. -- No version numbers scattered in code -- Clean git diffs (only one file changes during development) -- Versioned files only created at release time -- Git tags provide version history -- Single source of truth for version number +Functions use `verb_noun` pattern. Tables use plural nouns. + +## Adding Features + +1. Edit files in `src/` +2. Add tests in `tests/` +3. Update `docs/DOCUMENTATION.md` +4. Run `make test` +5. Commit source files + +## Debugging + +```sql +SELECT * FROM morbac.auth_cache ORDER BY last_checked DESC LIMIT 10; +SELECT morbac.invalidate_auth_cache(); +EXPLAIN ANALYZE SELECT morbac.is_allowed(...); +SELECT morbac.refresh_hierarchy_cache(); +``` + +## Resources + +See [DOCUMENTATION.md](DOCUMENTATION.md), [PERFORMANCE.md](PERFORMANCE.md), and [ADMIN_GUIDE.md](ADMIN_GUIDE.md).