Repository navigation
feat(push-gateway): declarative desired-state schema, one file per table #8328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TheSentinel454
wants to merge
5
commits into
main
Choose a base branch
from
elrond/push-gateway-desired-schema
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+511
−18
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5446d49
feat(push-gateway): declarative desired-state schema, one file per table
b788b3d
test(push-gateway): compare full column types, table options, and non…
a3d4196
test(push-gateway): drop parity probe databases on failure and decode…
5107eba
test(push-gateway): attempt every probe drop before reporting a drop …
df3ff10
test(push-gateway): take pgschema password from resolved connect options
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| -- Push gateway desired-state database manifest. | ||
| -- | ||
| -- The gateway's authority store is deployment-global and lives in its own | ||
| -- dedicated database, outside relay community tenancy. This directory declares | ||
| -- its end state; `../migrations/` remains the incremental path the gateway | ||
| -- binary applies at startup. | ||
| -- `src/postgres/desired_schema_postgres_tests.rs` proves that, applied through | ||
| -- `pgschema`, the two produce the same `public` tables, columns, table options, | ||
| -- constraints, and indexes. That is not full SchemaBot support: the inline FK | ||
| -- in `push_gateway_delegations.sql` must be revisited before SchemaBot adopts | ||
| -- this schema. | ||
| -- | ||
| -- `tables/public/<table>.sql` declares one table per file: its CREATE TABLE | ||
| -- and the CREATE INDEX statements on it, the one-table-per-file shape SchemaBot | ||
| -- reads. `tables/` is the SchemaBot schema directory and `public` is its | ||
| -- namespace, so nothing else may live under it. The gateway has no types, | ||
| -- functions, triggers, or seed rows. Its pre-migration bootstrap guard and | ||
| -- runtime-role grants are operational steps in `src/postgres.rs`, not schema. | ||
| -- It also has nothing pgschema cannot express (no seed DML, no storage | ||
| -- parameters), so the relay's `scripts/reconcile-schema-after-pgschema.sql` | ||
| -- step (root `AGENTS.md` gotcha #7) does not apply to it. | ||
| -- | ||
| -- `./bin/pgschema apply --file crates/buzz-push-gateway/schema/schema.sql` | ||
| -- resolves the `\i` includes relative to this file. Raw `psql` resolves `\i` | ||
| -- against the working directory instead, so run it from here: | ||
| -- `cd crates/buzz-push-gateway/schema && psql -f schema.sql`. | ||
| -- | ||
| -- Adding a table: add `tables/public/<table>.sql` and include it below after | ||
| -- the tables it references. This file holds only `\i` lines. The layout | ||
| -- test in `src/postgres/desired_schema_postgres_tests.rs` enforces both. | ||
|
|
||
| \i tables/public/push_gateway_challenges.sql | ||
| \i tables/public/push_gateway_installations.sql | ||
| \i tables/public/push_gateway_delegations.sql | ||
| \i tables/public/push_gateway_endpoint_quotas.sql | ||
| \i tables/public/push_gateway_delivery_auth_replays.sql | ||
| \i tables/public/push_gateway_delivery_request_replays.sql |
13 changes: 13 additions & 0 deletions
13
crates/buzz-push-gateway/schema/tables/public/push_gateway_challenges.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| -- Single-use App Attest enrollment challenges. Only the hash is stored. | ||
| CREATE TABLE push_gateway_challenges ( | ||
| id UUID PRIMARY KEY, | ||
| challenge_hash BYTEA NOT NULL CHECK (length(challenge_hash) = 32), | ||
| expires_at TIMESTAMPTZ NOT NULL, | ||
| created_at TIMESTAMPTZ NOT NULL DEFAULT now() | ||
| ); | ||
|
|
||
| CREATE INDEX push_gateway_challenges_expiry ON push_gateway_challenges (expires_at); | ||
|
|
||
| -- The unauthenticated challenge route applies a deployment-global rolling | ||
| -- issuance quota. Keep its count query bounded as challenge volume grows. | ||
| CREATE INDEX push_gateway_challenges_created_at ON push_gateway_challenges (created_at); | ||
17 changes: 17 additions & 0 deletions
17
crates/buzz-push-gateway/schema/tables/public/push_gateway_delegations.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| -- An installation's delegation to one relay signing key. Installations may | ||
| -- authorize multiple relay deployments, one row per relay key. | ||
| CREATE TABLE push_gateway_delegations ( | ||
| id UUID PRIMARY KEY, | ||
| installation_id UUID NOT NULL REFERENCES push_gateway_installations(id), | ||
| relay_pubkey BYTEA NOT NULL CHECK (length(relay_pubkey) = 32), | ||
| endpoint_epoch BIGINT NOT NULL CHECK (endpoint_epoch > 0), | ||
| generation BIGINT NOT NULL CHECK (generation > 0), | ||
| not_before TIMESTAMPTZ NOT NULL, | ||
| expires_at TIMESTAMPTZ NOT NULL, | ||
| revoked_at TIMESTAMPTZ, | ||
| updated_at TIMESTAMPTZ NOT NULL DEFAULT now(), | ||
| UNIQUE (installation_id, relay_pubkey), | ||
| CHECK (not_before < expires_at) | ||
| ); | ||
|
|
||
| CREATE INDEX push_gateway_delegations_expiry ON push_gateway_delegations (expires_at) WHERE revoked_at IS NULL; |
9 changes: 9 additions & 0 deletions
9
crates/buzz-push-gateway/schema/tables/public/push_gateway_delivery_auth_replays.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| -- Replay ledger for relay delivery auth events, retained until expiry. | ||
| CREATE TABLE push_gateway_delivery_auth_replays ( | ||
| relay_pubkey BYTEA NOT NULL CHECK (length(relay_pubkey) = 32), | ||
| auth_event_id BYTEA NOT NULL CHECK (length(auth_event_id) = 32), | ||
| expires_at TIMESTAMPTZ NOT NULL, | ||
| PRIMARY KEY (relay_pubkey, auth_event_id) | ||
| ); | ||
|
|
||
| CREATE INDEX push_gateway_delivery_auth_replays_expiry ON push_gateway_delivery_auth_replays (expires_at); |
9 changes: 9 additions & 0 deletions
9
crates/buzz-push-gateway/schema/tables/public/push_gateway_delivery_request_replays.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| -- Replay ledger for relay delivery request ids, retained until expiry. | ||
| CREATE TABLE push_gateway_delivery_request_replays ( | ||
| relay_pubkey BYTEA NOT NULL CHECK (length(relay_pubkey) = 32), | ||
| request_id UUID NOT NULL, | ||
| expires_at TIMESTAMPTZ NOT NULL, | ||
| PRIMARY KEY (relay_pubkey, request_id) | ||
| ); | ||
|
|
||
| CREATE INDEX push_gateway_delivery_request_replays_expiry ON push_gateway_delivery_request_replays (expires_at); |
9 changes: 9 additions & 0 deletions
9
crates/buzz-push-gateway/schema/tables/public/push_gateway_endpoint_quotas.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| -- Per-APNs-token delivery admission window. | ||
| CREATE TABLE push_gateway_endpoint_quotas ( | ||
| token_fingerprint BYTEA PRIMARY KEY CHECK (length(token_fingerprint) = 32), | ||
| window_started_at TIMESTAMPTZ NOT NULL, | ||
| admitted BIGINT NOT NULL CHECK (admitted >= 0), | ||
| updated_at TIMESTAMPTZ NOT NULL DEFAULT now() | ||
| ); | ||
|
|
||
| CREATE INDEX push_gateway_endpoint_quotas_updated ON push_gateway_endpoint_quotas (updated_at); |
23 changes: 23 additions & 0 deletions
23
crates/buzz-push-gateway/schema/tables/public/push_gateway_installations.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| -- App Attest-bound device installations and their encrypted APNs tokens. | ||
| -- Revoked installations remain as retry tombstones until authority expiry, so | ||
| -- ownership uniqueness covers live rows only: a replacement can enroll without | ||
| -- deleting the old installation's idempotency state. | ||
| CREATE TABLE push_gateway_installations ( | ||
| id UUID PRIMARY KEY, | ||
| app_attest_key_id BYTEA NOT NULL CHECK (octet_length(app_attest_key_id) BETWEEN 1 AND 128), | ||
| app_attest_public_key BYTEA NOT NULL CHECK (octet_length(app_attest_public_key) BETWEEN 33 AND 256), | ||
| assertion_counter BIGINT NOT NULL CHECK (assertion_counter BETWEEN 0 AND 4294967295), | ||
| token_ciphertext BYTEA NOT NULL CHECK (octet_length(token_ciphertext) BETWEEN 1 AND 2048), | ||
| token_fingerprint BYTEA NOT NULL CHECK (length(token_fingerprint) = 32), | ||
| endpoint_epoch BIGINT NOT NULL CHECK (endpoint_epoch > 0), | ||
| expires_at TIMESTAMPTZ NOT NULL, | ||
| revoked_at TIMESTAMPTZ, | ||
| created_at TIMESTAMPTZ NOT NULL DEFAULT now(), | ||
| updated_at TIMESTAMPTZ NOT NULL DEFAULT now() | ||
| ); | ||
|
|
||
| CREATE INDEX push_gateway_installations_expiry ON push_gateway_installations (expires_at) WHERE revoked_at IS NULL; | ||
|
|
||
| CREATE UNIQUE INDEX push_gateway_installations_active_app_attest_key ON push_gateway_installations (app_attest_key_id) WHERE revoked_at IS NULL; | ||
|
|
||
| CREATE UNIQUE INDEX push_gateway_installations_active_token ON push_gateway_installations (token_fingerprint) WHERE revoked_at IS NULL; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.