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
19 changes: 0 additions & 19 deletions .claude/settings.json

This file was deleted.

1 change: 0 additions & 1 deletion .envrc

This file was deleted.

17 changes: 0 additions & 17 deletions .githooks/pre-commit

This file was deleted.

26 changes: 19 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,29 @@ jobs:
runs-on: ubuntu-latest

env:
MUTANT_SINCE: ${{ github.event.pull_request.base.sha || 'HEAD^' }}
MUTANT_SINCE: ${{ github.event.pull_request.base.sha || github.event.before }}

steps:
- uses: actions/checkout@v6
with:
persist-credentials: false
fetch-depth: 0
- name: Set up Ruby
uses: ruby/setup-ruby@v1
- name: Install Nix
uses: cachix/install-nix-action@v31
with:
ruby-version: '4.0.2'
bundler-cache: true
- name: Run the default task
run: bin/rake
extra_nix_config: |
accept-flake-config = true
- name: Set up cachix
uses: cachix/cachix-action@v16
with:
name: devenv
- name: Install devenv
run: nix profile install nixpkgs#devenv
- name: Cache gems
uses: actions/cache@v4
with:
path: .devenv/state/.bundle
key: ${{ runner.os }}-gems-${{ hashFiles('Gemfile.lock') }}
restore-keys: ${{ runner.os }}-gems-
- name: Run the tests
run: devenv tasks run test
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
/.claude/settings.json
/.mcp.json
/.bundle/
/.mutant/
/pkg/
/tmp/
/test/pg_regress/results/
.devenv*
devenv.local.nix
devenv.local.yaml
.pre-commit-config.yaml
/.githooks/
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Agent rules

- Prefer inlining variables when they are not reused.
- After editing files, run `bin/rake format`.
- After editing files, run `treefmt`.
- When adding and building a feature, follow the TDD process.
3 changes: 1 addition & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ CHECKSUMS
benchmark (0.5.0) sha256=465df122341aedcb81a2a24b4d3bd19b6c67c1530713fd533f3ff034e419236c
bigdecimal (4.1.2) sha256=53d217666027eab4280346fba98e7d5b66baaae1b9c3c1c0ffe89d48188a3fbd
builder (3.3.0) sha256=497918d2f9dca528fdca4b88d84e4ef4387256d984b8154e9d5d3fe5a9c8835f
bundler (4.0.11) sha256=5bcec0fb78302e48d02ee46f10ee6e6942be647ba5b44a6d1ddfda9a240ce785
concurrent-ruby (1.3.6) sha256=6b56837e1e7e5292f9864f34b69c5a2cbc75c0cf5338f1ce9903d10fa762d5ab
connection_pool (3.0.2) sha256=33fff5ba71a12d2aa26cb72b1db8bba2a1a01823559fb01d29eb74c286e62e0a
crass (1.0.6) sha256=dc516022a56e7b3b156099abc81b6d2b08ea1ed12676ac7a5657617f012bd45d
Expand Down Expand Up @@ -396,4 +395,4 @@ CHECKSUMS
zeitwerk (2.8.2) sha256=7212a61311083c604184b1ea2574b9aa05cd14f855a0841c06985cabe9181d12

BUNDLED WITH
4.0.11
2.7.2
75 changes: 0 additions & 75 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,79 +1,4 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "fileutils"
require "minitest/test_task"
require "uri"
require_relative "lib/en57/tasks"

Minitest::TestTask.create

def pg_regress_bin
candidates = [
ENV["PG_REGRESS"],
`command -v pg_regress`.strip,
"/opt/homebrew/lib/postgresql@18/pgxs/src/test/regress/pg_regress",
]

candidates.find do |candidate|
candidate && !candidate.empty? && File.executable?(candidate)
end
end

task :format do
system("stree write **/*.rb")
system("pg_format -i db/**/*.sql")
end

task :mutate do
system("bin/mutant run")
end

task :mutate_since do
system("bin/mutant run --since #{ENV.fetch("MUTANT_SINCE")}")
end

desc "Run pg_regress tests against a pg-ephemeral instance"
task :pg_regress do
require "pg_ephemeral"

pg_regress = pg_regress_bin
unless pg_regress
abort("pg_regress not found. Set PG_REGRESS=/path/to/pg_regress")
end

server = PgEphemeral.start
uri = URI(server.url)

host = uri.host
port = uri.port
user = uri.user
dbname = uri.path.delete_prefix("/")
bindir = ENV["PG_BINDIR"] || `pg_config --bindir`.strip
schedule = ENV["PG_REGRESS_SCHEDULE"] || "test/pg_regress/schedule_existing"

FileUtils.rm_rf("test/pg_regress/results")
FileUtils.mkdir_p("test/pg_regress/results")

success =
system(
{ "PGPASSWORD" => uri.password },
pg_regress,
"--use-existing",
"--host=#{host}",
"--port=#{port}",
"--user=#{user}",
"--dbname=#{dbname}",
"--inputdir=test/pg_regress",
"--outputdir=test/pg_regress/results",
"--expecteddir=test/pg_regress",
"--bindir=#{bindir}",
"--schedule=#{schedule}",
)

abort("pg_regress failed") unless success
ensure
server&.shutdown
end

task default: %i[test mutate_since]
8 changes: 0 additions & 8 deletions bin/setup

This file was deleted.

40 changes: 23 additions & 17 deletions db/schema/0.1.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@ CREATE TYPE en57.event AS (
type text,
data jsonb,
meta jsonb,
tags text[]
tags text []
);

CREATE TYPE en57.append_result AS (
"position" bigint,
conflicting_events jsonb
);

CREATE FUNCTION en57.append_events (new_events en57.event[], append_condition jsonb DEFAULT '{}'::jsonb)
RETURNS en57.append_result
LANGUAGE plpgsql
SET enable_seqscan = OFF
AS $$
CREATE FUNCTION en57.append_events(
new_events en57.event [], append_condition jsonb DEFAULT '{}'::jsonb
)
RETURNS en57.append_result
LANGUAGE plpgsql
SET enable_seqscan = OFF
AS $$
DECLARE
criteria jsonb[] := ARRAY (
SELECT
Expand Down Expand Up @@ -150,16 +152,21 @@ INSERT INTO en57.events (id, type, data, meta)
END;
$$;

CREATE FUNCTION en57.read_events (criteria jsonb[], batch_size int DEFAULT NULL, after_position bigint DEFAULT NULL)
RETURNS TABLE (
"position" bigint,
id uuid,
type text,
data jsonb,
meta jsonb,
tags text[])
LANGUAGE SQL
AS $$
CREATE FUNCTION en57.read_events(
criteria jsonb [],
batch_size int DEFAULT NULL,
after_position bigint DEFAULT NULL
)
RETURNS TABLE (
"position" bigint,
id uuid,
type text,
data jsonb,
meta jsonb,
tags text []
)
LANGUAGE sql
AS $$
WITH parsed_criteria AS (
SELECT
c,
Expand Down Expand Up @@ -226,4 +233,3 @@ ORDER BY
e.position
LIMIT batch_size;
$$;

3 changes: 1 addition & 2 deletions db/seeds/concurrent_append_non_conflicting_tags_seeded.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-- of the same shape the benchmark queries.
INSERT INTO en57.events (id, type)
SELECT
gen_random_uuid (),
gen_random_uuid(),
'event_benchmarked'
FROM
generate_series(1, 1000000);
Expand All @@ -15,4 +15,3 @@ SELECT
'writer:' || substr(md5(random()::text), 1, 8)
FROM
en57.events;

Loading
Loading