Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 3 additions & 23 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,18 @@ jobs:

runs-on: ubuntu-latest
container:
image: supabase/postgres:15.1.1.79
image: supabase/postgres:17.6.1.054
options: --tmpfs=/pgtmpfs -e PGDATA=/pgtmpfs

steps:
- uses: actions/checkout@v3

- name: Checkout wal2json
uses: actions/checkout@v3
with:
repository: eulerto/wal2json
ref: master
path: ./wal2json

- name: Run Test
run: |
# install wal2json
cd wal2json
apt-get update && apt-get install build-essential llvm-11 -y
apt install -y wget lsb-release
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
apt-get update
apt install libpq5=16.3-1.pgdg20.04+1 libpq-dev postgresql-server-dev-15 -y --allow-downgrades

make
make install
# run tests
cd ..
chown -R postgres /__w/walrus/walrus
su postgres -c 'export PATH=$PATH:/usr/lib/postgresql/15/bin/ ; bin/installcheck'
su postgres -c 'export PATH=$PATH:/usr/lib/postgresql/17/bin/ ; bin/installcheck'

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
if: always()
with:
name: regression.out
Expand Down
61 changes: 61 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
FROM supabase/postgres:17.6.1.054

# Configure PostgreSQL for logical replication
RUN echo "wal_level = logical" >> /usr/share/postgresql/postgresql.conf.sample && \
echo "max_replication_slots = 4" >> /usr/share/postgresql/postgresql.conf.sample && \
echo "max_wal_senders = 4" >> /usr/share/postgresql/postgresql.conf.sample

# Set working directory for walrus
WORKDIR /walrus

# Copy the repository (will be mounted at runtime)
COPY . .

# Give postgres user ownership of /walrus
RUN chown -R postgres:postgres /walrus

# Create a test runner script that switches to postgres user
RUN echo '#!/bin/bash\n\
set -e\n\
echo "Initializing PostgreSQL data directory..."\n\
su - postgres -c "initdb -D /var/lib/postgresql/data"\n\
echo "Starting PostgreSQL..."\n\
su - postgres -c "pg_ctl -D /var/lib/postgresql/data -l /var/lib/postgresql/logfile start"\n\
echo "Waiting for PostgreSQL to be ready..."\n\
until su - postgres -c "pg_isready" > /dev/null 2>&1; do\n\
sleep 1\n\
done\n\
echo "PostgreSQL is ready!"\n\
echo "Running tests..."\n\
cd /walrus\n\
set +e\n\
su - postgres -c "cd /walrus && ./bin/installcheck"\n\
TEST_EXIT=$?\n\
set -e\n\
echo "Tests completed with exit code: $TEST_EXIT"\n\
echo ""\n\
if [ $TEST_EXIT -ne 0 ]; then\n\
echo "========================================"\n\
echo "TEST FAILURES DETECTED"\n\
echo "========================================"\n\
echo ""\n\
if [ -f /walrus/regression.out ]; then\n\
echo "Contents of regression.out:"\n\
echo "========================================"\n\
cat /walrus/regression.out\n\
echo "========================================"\n\
fi\n\
echo ""\n\
if [ -f /walrus/regression.diffs ]; then\n\
echo "Contents of regression.diffs:"\n\
echo "========================================"\n\
cat /walrus/regression.diffs\n\
echo "========================================"\n\
fi\n\
fi\n\
su - postgres -c "pg_ctl -D /var/lib/postgresql/data stop"\n\
exit $TEST_EXIT\n\
' > /usr/local/bin/run-tests.sh && \
chmod +x /usr/local/bin/run-tests.sh

CMD ["/usr/local/bin/run-tests.sh"]
33 changes: 9 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ create table realtime.subscription (
claims jsonb not null,
claims_role regrole not null generated always as (realtime.to_regrole(claims ->> 'role')) stored,
created_at timestamp not null default timezone('utc', now()),

unique (subscription_id, entity, filters)
action_filter text NULL DEFAULT '*'::text CHECK (action_filter IN ('*', 'INSERT', 'UPDATE', 'DELETE'))
unique (subscription_id, entity, filters, action_filter)
);
```
where `realtime.user_defined_filter` is
Expand All @@ -56,6 +56,12 @@ insert into realtime.subscription(subscription_id, entity, filters, claims)
values ('832bd278-dac7-4bef-96be-e21c8a0023c4', 'public.notes', array[('id', 'eq', '6')], '{"role", "authenticated"}');
```

To subscribe to `INSERT`s only on a table named `public.notes` where the `id` is `6` as the `authenticated` role:
```sql
insert into realtime.subscription(subscription_id, entity, filters, claims, action_filter)
values ('832bd278-dac7-4bef-96be-e21c8a0023c4', 'public.notes', array[('id', 'eq', '6')], '{"role", "authenticated"}', 'INSERT');
```


### Reading WAL

Expand Down Expand Up @@ -339,30 +345,9 @@ The project is SQL only and can be installed by executing the contents of `sql/w

## Tests

Requires

- Postgres 13+
- wal2json >= 53b548a29ebd6119323b6eb2f6013d7c5fe807ec

On a Mac:

Install postgres
```sh
brew install postgres
```

Install wal2json
```sh
git clone https://github.com/eulerto/wal2json.git
cd wal2json
git reset --hard 53b548a
make
make install
```

Run the tests, from the repo root.
```sh
./bin/installcheck
./run-test.sh
```

## RFC Process
Expand Down
2 changes: 1 addition & 1 deletion bin/installcheck
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ REGRESS="${PGXS}/../test/regress/pg_regress"
TESTS=$(ls ${TESTDIR}/sql | sed -e 's/\..*$//' | sort )

# Execute the test fixtures
psql -v ON_ERROR_STOP=1 -f sql/setup.sql -f sql/walrus--0.1.sql -f sql/walrus_migration_0001*.sql -f sql/walrus_migration_0002*.sql -f sql/walrus_migration_0003*.sql -f sql/walrus_migration_0004*.sql -f sql/walrus_migration_0005*.sql -f sql/walrus_migration_0006*.sql -f sql/walrus_migration_0007*.sql -f sql/walrus_migration_0008*.sql -f sql/walrus_migration_0009*.sql -f sql/walrus_migration_0010*.sql -f sql/walrus_migration_0011*.sql -f test/fixtures.sql -d contrib_regression
psql -v ON_ERROR_STOP=1 -f sql/setup.sql -f sql/walrus--0.1.sql -f sql/walrus_migration_0001*.sql -f sql/walrus_migration_0002*.sql -f sql/walrus_migration_0003*.sql -f sql/walrus_migration_0004*.sql -f sql/walrus_migration_0005*.sql -f sql/walrus_migration_0006*.sql -f sql/walrus_migration_0007*.sql -f sql/walrus_migration_0008*.sql -f sql/walrus_migration_0009*.sql -f sql/walrus_migration_0010*.sql -f sql/walrus_migration_0011*.sql -f sql/walrus_migration_0012*.sql -f test/fixtures.sql -d contrib_regression

# Run tests
${REGRESS} --use-existing --dbname=contrib_regression --inputdir=${TESTDIR} ${TESTS}
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
services:
walrus-test:
build: .
container_name: walrus-test
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_USER=supabase_admin
- PG_USER=supabase_admin
- POSTGRES_DB=postgres
volumes:
- ./:/walrus
# Keep container running if you want to debug
# command: tail -f /dev/null
10 changes: 10 additions & 0 deletions run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -e

echo "Building Docker image for Walrus tests..."
docker-compose build

echo ""
echo "Running Walrus tests in Docker..."
docker-compose run --rm walrus-test
Loading
Loading