diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5848402 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +# Generated versioned files (created by 'make release') +morbac_pg--*.sql + +# Test database dumps +*.dump +*.backup + +# OS files +.DS_Store +Thumbs.db + +# Editor files +*.swp +*.swo +*~ +.vscode/ +.idea/ \ No newline at end of file diff --git a/Makefile b/Makefile index 690a43c..5ee9668 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,12 @@ # Multi-OrBAC: Organization-Based Access Control EXTENSION = morbac_pg -EXTVERSION = 1.0.0 +# Read version from control file +EXTVERSION = $(shell grep default_version $(EXTENSION).control | sed "s/default_version = '\(.*\)'/\1/") + +# For development, work on unversioned file +DEV_SQL = $(EXTENSION).sql DATA = $(EXTENSION)--$(EXTVERSION).sql DOCS = README.md @@ -14,46 +18,34 @@ include $(PGXS) # Custom targets -# Install extension in PostgreSQL +# Create versioned release file from development file +.PHONY: release +release: + @echo "Preparing release $(EXTVERSION)..." + @if [ ! -f $(DEV_SQL) ]; then \ + echo "Error: $(DEV_SQL) not found"; \ + exit 1; \ + fi + cp $(DEV_SQL) $(DATA) + @echo "Created $(DATA)" + @echo "Ready to commit and tag with: git tag v$(EXTVERSION)" + +# Install extension in PostgreSQL (creates versioned file if needed) .PHONY: install -install: +install: release @echo "Installing morbac_pg extension..." $(MAKE) -f Makefile install -# Run tests +# Run tests with development file in temporary database .PHONY: test test: - @echo "Running morbac_pg tests..." - psql -f test_morbac.sql - -# Run tests on specific database -.PHONY: test-db -test-db: - @if [ -z "$(DB)" ]; then \ - echo "Usage: make test-db DB=your_database"; \ - exit 1; \ - fi - @echo "Running tests on database $(DB)..." - psql -d $(DB) -f test_morbac.sql - -# Run tests in dedicated test database -.PHONY: test -test: - @echo "Creating test database morbac_test..." + @echo "Testing with development file..." -dropdb morbac_test 2>/dev/null || true createdb morbac_test - @echo "Running tests..." + psql -d morbac_test -f $(DEV_SQL) psql -d morbac_test -f test_morbac.sql - @echo "" - @echo "Tests completed. Database 'morbac_test' is available." - @echo "To explore: psql -d morbac_test" - @echo "To cleanup: dropdb morbac_test" - -# Cleanup test database -.PHONY: cleanup -cleanup: - @echo "Dropping test database..." - -dropdb morbac_test 2>/dev/null && echo "Test database dropped." || echo "No test database found." + dropdb morbac_test + @echo "Test completed." # Uninstall extension .PHONY: uninstall @@ -66,14 +58,19 @@ uninstall: help: @echo "morbac_pg Makefile targets:" @echo "" - @echo " make install - Install extension in PostgreSQL" + @echo "Development:" + @echo " Edit morbac_pg.sql (unversioned) for daily development" + @echo "" + @echo " make test - Test with development file" + @echo " make release - Create versioned file from morbac_pg.sql" + @echo " make install - Create release and install extension" @echo " make uninstall - Uninstall extension from PostgreSQL" - @echo " make test - Run tests on default database" - @echo " make test-db DB=name - Run tests on specified database" - @echo " make test - Create test DB, run tests, keep DB" - @echo " make cleanup - Drop test database" @echo " make help - Show this help" @echo "" - @echo "Quick start:" - @echo " make test # Run complete test in isolated database" + @echo "Workflow:" + @echo " 1. Edit morbac_pg.sql (version-free development)" + @echo " 2. make test (test your changes)" + @echo " 3. Update version in morbac_pg.control" + @echo " 4. make release (creates morbac_pg--X.Y.Z.sql)" + @echo " 5. git tag vX.Y.Z && git push --tags" @echo "" diff --git a/docs/DEVELOPMENT.md b/docs/DEVELOPMENT.md new file mode 100644 index 0000000..5eb4b29 --- /dev/null +++ b/docs/DEVELOPMENT.md @@ -0,0 +1,65 @@ +# Development Workflow + +## Version Management + +This extension uses a single-source version approach: + +- **Version source of truth**: `morbac_pg.control` (the `default_version` field) +- **Development file**: `morbac_pg.sql` (unversioned, for daily work) +- **Release files**: `morbac_pg--X.Y.Z.sql` (generated, git-ignored) + +## Daily Development + +1. **Edit**: Work on `morbac_pg.sql` (no version numbers in the file) +2. **Test**: Run `make test` to test changes in a temporary database +3. **Commit**: Commit `morbac_pg.sql` to git regularly + +## Release Process + +When ready to release a new version: + +1. **Update version**: Edit `morbac_pg.control` and change `default_version` + ``` + default_version = '1.1.0' + ``` + +2. **Create release**: Run `make release` + - Reads version from `.control` file + - Copies `morbac_pg.sql` → `morbac_pg--X.Y.Z.sql` + +3. **Test**: Run `make test` with the versioned file + +4. **Tag in git**: + ```bash + git add morbac_pg.control morbac_pg--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 morbac_pg--1.0.0--1.1.0.sql +``` + +These contain only the ALTER/ADD statements needed for the upgrade. + +## Make 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 + +## Benefits + +- 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 diff --git a/morbac_pg--1.0.0.sql b/morbac_pg.sql similarity index 99% rename from morbac_pg--1.0.0.sql rename to morbac_pg.sql index 2ee7876..7a7ee54 100644 --- a/morbac_pg--1.0.0.sql +++ b/morbac_pg.sql @@ -1,5 +1,5 @@ -- ============================================================================= --- morbac_pg Extension - Version 1.0.0 +-- morbac_pg Extension -- ============================================================================= -- Multi-OrBAC: Organization-Based Access Control with Multi-Organization Support -- Based on the CNRS research paper on Multi-OrBAC model