Skip to content

feat: schema index declarations backed by entity indexes (rapiq 2.0.0-beta.20) - #3425

Merged
tada5hi merged 4 commits into
masterfrom
feat/rapiq-schema-indexes
Aug 11, 2026
Merged

feat: schema index declarations backed by entity indexes (rapiq 2.0.0-beta.20)#3425
tada5hi merged 4 commits into
masterfrom
feat/rapiq-schema-indexes

Conversation

@tada5hi

@tada5hi tada5hi commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adopts rapiq 2.0.0-beta.20's schema index declarations (tada5hi/rapiq#895) end to end and hardens the decode path.

rapiq bump + decode failures answer 400

  • @rapiq/* ^2.0.0-beta.19 -> ^2.0.0-beta.20 across all 8 workspaces. The removed sort tuple groups were unused (no-op here).
  • sanitizeError maps rapiq ParseError/CodecError onto BAD_REQUEST: the expression dialect has always thrown on disallowed keys (previously a 500), and beta.20's pagination prototype-key guard widened the throwing surface (routup's qs passes prototype segments through). Pinned over HTTP.

Index declarations + enforcement

Every registered schema declares indexes and opts into filters: { indexed: true } (anchor mode) + sort: { indexed: true }, under one invariant: every allowed filter/sort key leads a declared index backed by a real database structure — enforcement can never reject a query the allow-lists permit. The only observable narrowing is a multi-key sort without a matching composite prefix, which drops whole-parameter (fail-soft; no UI surface sends one). Corollary, now documented: adding a filterable/sortable key requires a backing entity index + migration.

Boot-time assertSchemaIndexesMatchEntity fails the start when a declared sequence is not a leftmost prefix of a real PK/unique/index (assertSchemaMatchesEntity does not cover indexes yet — tada5hi/rapiq#898).

Migration 1786436332251-QueryIndexes

  • 126 new indexes: the query vocabulary, every remaining FK scalar column (junction *_realm_id/policy_id, client.access_policy_id, EA + IdP mapping tables — a Postgres-only gap, MySQL keeps implicit FK indexes; realm deletion no longer full-scans every junction), the login-throttle composite (actor_name, request_ip_address, created_at) (replaces the redundant actor_name single), session_tokens.parent_id (grace-window hasConsumedChild), the federated-login pair (provider_user_id, provider_id), and reset_hash/activate_hash (sole selective predicate on unauthenticated endpoints, were full scans).
  • Drops the three orphaned legacy tables (auth_authorization_codes, auth_refresh_tokens, auth_identity_provider_roles); down() recreates them exactly as the pre-existing chain leaves them so every older down() path keeps working.
  • The mysql down() wraps the generated statements with hand-authored FK drop/re-add phases: MySQL silently drops a constraint's implicit index once a created index can serve it, so a plain DROP INDEX fails with ER 1553 on 50 constraints (pattern + affected-set query documented in conventions and the typeorm reference). Naming: all constraint names come from typeorm 1.1.0's built-in default strategy via migration generate — no naming-strategy override, no legacy-naming-strategies dependency.

Verification

  • Both dialects: migration run -> revert x16 -> run, schema-drift gate green, populated round-trip 12/12 (test:migration-latest).
  • Full monorepo suite green (18 projects; server-core 187 spec files / 2082 tests), check:types clean.
  • New pins: decode-error 400s (HTTP), indexed enforcement semantics + describe() surface (decode), index-drift assert (unit).

Summary by CodeRabbit

  • New Features

    • Improved filtering and sorting across authentication, authorization, identity, session, and policy data.
    • Added indexed query support for commonly searched and sorted fields.
    • Added validation to ensure supported query filters and sort combinations use available indexes.
  • Bug Fixes

    • Invalid query expressions and unsafe pagination parameters now return clear 400 Bad Request responses.
    • Unsupported multi-field sorts are safely ignored instead of causing failures.
  • Documentation

    • Added guidance for query indexing and safe database migration rollbacks.

The release ships schema index declarations (tada5hi/rapiq#895) and
closes the pre-GA decode-hardening gaps (tada5hi/rapiq#893): a
pagination key carrying a prototype segment now raises a typed
ParseError instead of being ignored, and routup's qs passes
'prototype' segments through, so the throw is reachable over HTTP.

sanitizeError maps rapiq ParseError/CodecError onto BAD_REQUEST: a
decode failure is client wire input, not a server fault. The
expression dialect has always thrown on disallowed keys, so those
requests answered 500 before this. Pinned over HTTP for both paths.
…ndexes

Every registered schema declares its `indexes` and opts into the
rapiq 2.0.0-beta.20 indexed filters (anchor mode) and sort policies,
under one invariant: every allowed filter/sort key LEADS a declared
index backed by a real database structure, so enforcement never
rejects a query the allow-lists permit. The only narrowing is a
multi-key sort without a matching composite prefix, which drops
whole-parameter (no UI surface sends one).

Migration 1786436332251-QueryIndexes backs the declarations: 126 new
indexes covering the query vocabulary, every remaining FK scalar
column (junction *_realm_id and policy_id columns,
client.access_policy_id, the EA and identity-provider mapping tables;
a Postgres-only gap since MySQL keeps implicit FK indexes), the
login-throttle composite (actor_name, request_ip_address, created_at)
replacing the redundant actor_name single, session_tokens.parent_id
(grace-window lookup), and the reset_hash/activate_hash token lookups
(sole selective predicate on unauthenticated endpoints). It also
drops the three orphaned legacy tables (auth_authorization_codes,
auth_refresh_tokens, auth_identity_provider_roles); down() recreates
them exactly as the pre-existing chain leaves them.

The mysql down() wraps the generated statements with hand-authored
FK drop/re-add phases: MySQL silently drops a constraint's implicit
index once a created index can serve it, so the plain DROP INDEX
would fail with ER 1553 on 50 constraints.

assertSchemaIndexesMatchEntity joins the boot-time validation pass
(a declared sequence must be a leftmost prefix of a real
PK/unique/index; tada5hi/rapiq#898 tracks upstreaming it).

Verified on both dialects: run, revert x16, re-run, schema-drift
gate, populated round-trip.
Query IR flow gains the index-declaration rules (adding a filterable
or sortable key now requires a backing entity index plus migration);
conventions and the typeorm reference record that MySQL auto-drops a
foreign key's implicit index when a created index can serve the
constraint, breaking generated down() paths, and the wrap pattern
that restores the exact pre-migration state.
Copilot AI lite review requested due to automatic review settings August 11, 2026 11:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@tada5hi, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 16 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6e03aa37-1d7d-4e7f-afb5-59a4a99d9d9c

📥 Commits

Reviewing files that changed from the base of the PR and between dcddd49 and 55e3c79.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (8)
  • apps/client-account-console/package.json
  • apps/client-admin-console/package.json
  • apps/server-core/package.json
  • packages/access/package.json
  • packages/client-web-kit/package.json
  • packages/core-http-kit/package.json
  • packages/server-kit/package.json
  • packages/server-test-kit/package.json
📝 Walkthrough

Walkthrough

The query architecture now requires entity-backed schema indexes and indexed filter and sort declarations. TypeORM entities and database migrations add the required indexes. Boot validation, query decoding, error mapping, tests, documentation, and Rapiq dependencies were updated.

Changes

Indexed query contracts

Layer / File(s) Summary
Schema declarations and validation
apps/server-core/src/core/entities/*/schema.ts, apps/server-core/src/app/modules/database/repositories/schema-validation.ts
Schemas declare database-backed indexes and mark supported filters and sorts as indexed. Boot validation checks primary keys, unique constraints, and TypeORM indexes by leftmost-prefix matching.
TypeORM entity indexes
apps/server-core/src/adapters/database/domains/*/entity.ts
Authentication entities add indexes for query fields, foreign-key columns, timestamps, and selected composite lookups.
Database migrations
apps/server-core/src/adapters/database/migrations/mysql/*, apps/server-core/src/adapters/database/migrations/postgres/*
New migrations create query indexes and remove legacy tables. Rollbacks restore indexes, tables, and foreign keys, including MySQL foreign-key handling.
Error handling and validation coverage
apps/server-core/src/utils/error.ts, apps/server-core/test/unit/*
CodecError and ParseError become BAD_REQUEST errors. Tests cover schema index validation, indexed query enforcement, and query-decoding failures.
Rapiq package alignment
apps/*/package.json, packages/*/package.json
Rapiq dependencies advance from beta.19 to beta.20.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant QueryClient
  participant QueryDecoder
  participant EntitySchema
  participant Database
  QueryClient->>QueryDecoder: submit filters and sorts
  QueryDecoder->>EntitySchema: validate indexed fields and prefixes
  EntitySchema->>Database: execute query using declared indexes
  Database-->>QueryClient: return matching entities
Loading

Possibly related PRs

  • authup/authup#3285: Both changes extend schema-validation.ts and its tests with boot-time TypeORM schema validation.
  • authup/authup#3229: Both changes modify EventEntity and auth_events indexes.
  • authup/authup#3352: Both changes align TypeORM entity constraints and database migrations.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the primary change: adding schema index declarations backed by entity indexes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/rapiq-schema-indexes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Aug 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

authup

npm i https://pkg.pr.new/authup@3425

@authup/client-account-console

npm i https://pkg.pr.new/@authup/client-account-console@3425

@authup/client-admin-console

npm i https://pkg.pr.new/@authup/client-admin-console@3425

@authup/client-auth-console

npm i https://pkg.pr.new/@authup/client-auth-console@3425

@authup/server-core

npm i https://pkg.pr.new/@authup/server-core@3425

@authup/access

npm i https://pkg.pr.new/@authup/access@3425

@authup/client-web-kit

npm i https://pkg.pr.new/@authup/client-web-kit@3425

@authup/client-web-kit-theme

npm i https://pkg.pr.new/@authup/client-web-kit-theme@3425

@authup/client-web-nuxt

npm i https://pkg.pr.new/@authup/client-web-nuxt@3425

@authup/client-web-theme

npm i https://pkg.pr.new/@authup/client-web-theme@3425

@authup/core-http-kit

npm i https://pkg.pr.new/@authup/core-http-kit@3425

@authup/core-kit

npm i https://pkg.pr.new/@authup/core-kit@3425

@authup/core-realtime-kit

npm i https://pkg.pr.new/@authup/core-realtime-kit@3425

@authup/errors

npm i https://pkg.pr.new/@authup/errors@3425

@authup/i18n

npm i https://pkg.pr.new/@authup/i18n@3425

@authup/kit

npm i https://pkg.pr.new/@authup/kit@3425

@authup/server-adapter-kit

npm i https://pkg.pr.new/@authup/server-adapter-kit@3425

@authup/server-adapter-node

npm i https://pkg.pr.new/@authup/server-adapter-node@3425

@authup/server-adapter-socket-io

npm i https://pkg.pr.new/@authup/server-adapter-socket-io@3425

@authup/server-adapter-web

npm i https://pkg.pr.new/@authup/server-adapter-web@3425

@authup/server-kit

npm i https://pkg.pr.new/@authup/server-kit@3425

@authup/server-test-kit

npm i https://pkg.pr.new/@authup/server-test-kit@3425

@authup/specs

npm i https://pkg.pr.new/@authup/specs@3425

commit: 55e3c79

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/server-core/test/unit/core/query/module.spec.ts (1)

404-412: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert the retained sort field and direction.

The length-only assertion passes if decoding retains a sort other than -createdAt. Assert that the retained entry represents createdAt in descending order.

Verify the Query sort entry shape for @rapiq/core 2.0.0-beta.20 before adding the assertion. Run npm run build before the repository test command. As per coding guidelines, “Run npm run build before testing; use the repository-provided npm scripts for building, testing, and linting.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/server-core/test/unit/core/query/module.spec.ts` around lines 404 - 412,
Update the test “should keep an allowed single-key filter and sort” to assert
the retained sort entry’s field is createdAt and its direction is descending,
using the Query sort-entry shape from `@rapiq/core` 2.0.0-beta.20. Replace or
supplement the length-only assertion while preserving the existing filter
assertion, then run npm run build before the repository test command.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@apps/server-core/test/unit/core/query/module.spec.ts`:
- Around line 404-412: Update the test “should keep an allowed single-key filter
and sort” to assert the retained sort entry’s field is createdAt and its
direction is descending, using the Query sort-entry shape from `@rapiq/core`
2.0.0-beta.20. Replace or supplement the length-only assertion while preserving
the existing filter assertion, then run npm run build before the repository test
command.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4045ccc3-a369-437c-8d35-80b99b5103f1

📥 Commits

Reviewing files that changed from the base of the PR and between 485e046 and dcddd49.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (74)
  • .agents/architecture.md
  • .agents/conventions.md
  • .agents/references/typeorm.md
  • apps/client-account-console/package.json
  • apps/client-admin-console/package.json
  • apps/server-core/package.json
  • apps/server-core/src/adapters/database/domains/client-permission/entity.ts
  • apps/server-core/src/adapters/database/domains/client-role/entity.ts
  • apps/server-core/src/adapters/database/domains/client-scope/entity.ts
  • apps/server-core/src/adapters/database/domains/client/entity.ts
  • apps/server-core/src/adapters/database/domains/consent/entity.ts
  • apps/server-core/src/adapters/database/domains/event/entity.ts
  • apps/server-core/src/adapters/database/domains/identity-provider-account/entity.ts
  • apps/server-core/src/adapters/database/domains/identity-provider-attribute-mapping/entity.ts
  • apps/server-core/src/adapters/database/domains/identity-provider-attribute/entity.ts
  • apps/server-core/src/adapters/database/domains/identity-provider-permission-mapping/entity.ts
  • apps/server-core/src/adapters/database/domains/identity-provider-role-mapping/entity.ts
  • apps/server-core/src/adapters/database/domains/identity-provider/entity.ts
  • apps/server-core/src/adapters/database/domains/key/entity.ts
  • apps/server-core/src/adapters/database/domains/permission-policy/entity.ts
  • apps/server-core/src/adapters/database/domains/permission/entity.ts
  • apps/server-core/src/adapters/database/domains/policy-attribute/entity.ts
  • apps/server-core/src/adapters/database/domains/policy/entity.ts
  • apps/server-core/src/adapters/database/domains/realm/entity.ts
  • apps/server-core/src/adapters/database/domains/role-attribute/entity.ts
  • apps/server-core/src/adapters/database/domains/role-permission/entity.ts
  • apps/server-core/src/adapters/database/domains/role/entity.ts
  • apps/server-core/src/adapters/database/domains/scope/entity.ts
  • apps/server-core/src/adapters/database/domains/session-token/entity.ts
  • apps/server-core/src/adapters/database/domains/session/entity.ts
  • apps/server-core/src/adapters/database/domains/trust-anchor/entity.ts
  • apps/server-core/src/adapters/database/domains/user-attribute/entity.ts
  • apps/server-core/src/adapters/database/domains/user-authenticator/entity.ts
  • apps/server-core/src/adapters/database/domains/user-permission/entity.ts
  • apps/server-core/src/adapters/database/domains/user-role/entity.ts
  • apps/server-core/src/adapters/database/domains/user/entity.ts
  • apps/server-core/src/adapters/database/migrations/mysql/1786436332251-QueryIndexes.ts
  • apps/server-core/src/adapters/database/migrations/postgres/1786436332251-QueryIndexes.ts
  • apps/server-core/src/app/modules/database/repositories/schema-validation.ts
  • apps/server-core/src/core/entities/client-permission/schema.ts
  • apps/server-core/src/core/entities/client-role/schema.ts
  • apps/server-core/src/core/entities/client-scope/schema.ts
  • apps/server-core/src/core/entities/client/schema.ts
  • apps/server-core/src/core/entities/consent/schema.ts
  • apps/server-core/src/core/entities/event/schema.ts
  • apps/server-core/src/core/entities/identity-provider-account/schema.ts
  • apps/server-core/src/core/entities/identity-provider-role-mapping/schema.ts
  • apps/server-core/src/core/entities/identity-provider/schema.ts
  • apps/server-core/src/core/entities/key/schema.ts
  • apps/server-core/src/core/entities/permission-policy/schema.ts
  • apps/server-core/src/core/entities/permission/schema.ts
  • apps/server-core/src/core/entities/policy/schema.ts
  • apps/server-core/src/core/entities/realm/schema.ts
  • apps/server-core/src/core/entities/role-attribute/schema.ts
  • apps/server-core/src/core/entities/role-permission/schema.ts
  • apps/server-core/src/core/entities/role/schema.ts
  • apps/server-core/src/core/entities/scope/schema.ts
  • apps/server-core/src/core/entities/session-token/schema.ts
  • apps/server-core/src/core/entities/session/schema.ts
  • apps/server-core/src/core/entities/trust-anchor/schema.ts
  • apps/server-core/src/core/entities/user-attribute/schema.ts
  • apps/server-core/src/core/entities/user-authenticator/schema.ts
  • apps/server-core/src/core/entities/user-permission/schema.ts
  • apps/server-core/src/core/entities/user-role/schema.ts
  • apps/server-core/src/core/entities/user/schema.ts
  • apps/server-core/src/utils/error.ts
  • apps/server-core/test/unit/app/modules/database/schema-validation.spec.ts
  • apps/server-core/test/unit/core/query/module.spec.ts
  • apps/server-core/test/unit/http/controllers/entities/query-decode-errors.spec.ts
  • packages/access/package.json
  • packages/client-web-kit/package.json
  • packages/core-http-kit/package.json
  • packages/server-kit/package.json
  • packages/server-test-kit/package.json

A clean re-tag of 2.0.0-beta.20 - no content changes; the full suite
re-verified against the resolved release artifacts.
@tada5hi
tada5hi merged commit d34afb7 into master Aug 11, 2026
13 checks passed
@tada5hi
tada5hi deleted the feat/rapiq-schema-indexes branch August 11, 2026 12:31
@github-actions github-actions Bot mentioned this pull request Aug 11, 2026
@github-actions github-actions Bot mentioned this pull request Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants