Contents
Contributing to ulak
Thank you for your interest in contributing to ulak! This document provides guidelines and instructions for contributing.
Development Environment
Prerequisites
- Docker and Docker Compose
- PostgreSQL 14-18 development headers (if building locally)
- libcurl development headers (required)
- Optional protocol libraries: librdkafka, libmosquitto, hiredis, librabbitmq
lefthook(installed automatically bymake hooks-installwhen Homebrew or Go is available)clang-format,cppcheck(install withmake tools-installfor local/CI parity)
Quick Start
# Clone the repository
git clone https://github.com/zeybek/ulak.git
cd ulak
# Start development environment (PostgreSQL + all protocol services)
docker compose up -d
# Build and install the extension
docker exec ulak-postgres-1 bash -c \
"cd /src/ulak && make clean && make ENABLE_KAFKA=1 ENABLE_MQTT=1 ENABLE_REDIS=1 ENABLE_AMQP=1 ENABLE_NATS=1 && make install"
# Restart PostgreSQL to load the extension
docker restart ulak-postgres-1
# Run regression tests
docker exec ulak-postgres-1 bash -c \
"cd /src/ulak && make installcheck"
Testing Against Different PostgreSQL Versions
The Dockerfile accepts a PG_MAJOR build argument:
docker compose build --build-arg PG_MAJOR=15 postgres
docker compose up -d postgres
Code Style
C Code
- Follow the PostgreSQL coding conventions.
- Use
clang-formatfor formatting:make format - Use
cppcheckfor static analysis:make lint - Always use
palloc/pfree— nevermalloc/free. - Always use
strlcpy/snprintf— neverstrcpy/strcat. - Zero sensitive data before
pfree.
Git Hooks
This repository uses lefthook to keep local commits aligned with CI.
Install and wire the local hooks with:
make tools-install
make hooks-install
Check your local toolchain with:
make tools-versions
Configured hooks:
pre-commitcppcheckclang-format -ion stagedsrc/andinclude/C headers/sources, then auto re-stage
commit-msg- conventional-commit style validation
Accepted commit header format:
type(scope): subject
type: subject
type(scope)!: subject
Allowed commit types:
feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
SQL
- Use lowercase for SQL keywords.
- Prefix all objects with the
ulakschema. - Add
GRANT EXECUTEfor all three RBAC roles on every new function. - Include
SECURITY DEFINERonly when elevated privileges are required.
Pull Requests
Before Submitting
- Run
make formatto ensure code is formatted correctly. - Run
make lintto check for static analysis warnings. - Run
make hooks-runto exercise the same local pre-commit checks manually when needed. - Run
make installcheckto verify the regression and isolation suites pass. - Add or update tests in
tests/regress/sql/,tests/regress/expected/, ortests/isolation/for new functionality. - Update
CHANGELOG.mdto reflect the changes included in the next release.
PR Guidelines
- Keep PRs focused on a single change.
- Write clear commit messages explaining the “why”, not just the “what”.
- Reference related issues in the PR description.
- Ensure backward compatibility with PostgreSQL 14-18.
- Use
#if PG_VERSION_NUMguards for version-specific code.
Architecture Guidelines
Adding a New Protocol Dispatcher
See src/dispatchers/dispatcher.h for the dispatcher interface. In summary:
- Create
src/dispatchers/{protocol}/directory. - Implement the
DispatcherOperationsinterface. - Register in the factory (
src/dispatchers/dispatcher.c). - Add conditional compilation with
ENABLE_{PROTOCOL}flag. - Update the Makefile, Dockerfile, and docker-compose.yml.
- Add regression tests and documentation.
Adding a New GUC Parameter
- Add the
DefineCustom*Variable()call insrc/config/guc.c. - Add a corresponding
config_is_valid_*()validation function. - Keep the validation range in sync with the
DefineCustomVariablebounds. - Declare the extern in
src/config/guc.h. - Update
CHANGELOG.md.
Memory Safety
- Always wrap SPI calls in
PG_TRY/PG_CATCHblocks. - Never call
SPI_finish()inPG_CATCH— onlyAbortCurrentTransaction(). - Never use
REPEATABLE READin workers — it causes serialization failures. - Use
MemoryContextswitches for long-lived allocations.
Reporting Issues
When reporting bugs, please include:
- PostgreSQL version (
SELECT version()) - ulak version
- Enabled protocols and build flags
- Steps to reproduce
- Relevant log output (
SET ulak.log_level = 'DEBUG')
License
By contributing, you agree that your contributions will be licensed under the Apache License 2.0, consistent with the rest of the repository.