-
Notifications
You must be signed in to change notification settings - Fork 380
Rename operation database to runtime-persistent and runtime database to runtime-transient #4077
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
Merged
Merged
Changes from all commits
Commits
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
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,13 +7,14 @@ description: Database schema and query conventions for ThunderID. Use when chang | |||||
|
|
||||||
| ## Logical Database Separation | ||||||
|
|
||||||
| ThunderID uses three logically separated databases. Each database owns a specific category of data. | ||||||
| ThunderID uses four logically separated databases. Each database owns a specific category of data. | ||||||
|
|
||||||
| | Database | Responsibility | | ||||||
| |--------------|------------------------------------------------------------------------| | ||||||
| | `configdb` | Identity configuration data Ex: applications, authentication flows, roles, identity providers | | ||||||
| | `runtimedb` | Runtime temporal data which holds the state of the authentication flows: authorization codes, flow contexts, WebAuthn sessions | | ||||||
| | `entitydb` | Identity data: users, groups, indexed user attributes | | ||||||
| | Database (config key) | Responsibility | | ||||||
| |-----------------------|---------------------------------------------------------------| | ||||||
| | `config` | Identity configuration data Ex: applications, authentication flows, roles, identity providers | | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| | `runtime_transient` | Short-lived runtime state: authorization codes, authorization/PAR requests, JTI records, WebAuthn/VCI state, flow contexts | | ||||||
| | `entitydb` | Identity data: users, groups, indexed user attributes | | ||||||
| | `runtime_persistent` | Long-lived operational state that must survive restarts: revoked tokens, SSO sessions, consent records | | ||||||
|
|
||||||
| Although the databases are logically separated, they share consistent schema design principles documented here. | ||||||
|
|
||||||
|
|
@@ -169,15 +170,15 @@ CREATE INDEX idx_user_ou_deployment ON "USER" (DEPLOYMENT_ID, OU_ID); | |||||
|
|
||||||
| ### Expiry Indexes | ||||||
|
|
||||||
| Tables in `runtimedb` that include an `EXPIRY_TIME` column should have a dedicated index on that column to support efficient cleanup queries. | ||||||
| Tables in `runtime_transient` that include an `EXPIRY_TIME` column should have a dedicated index on that column to support efficient cleanup queries. | ||||||
|
|
||||||
| ```sql | ||||||
| CREATE INDEX idx_authz_code_expiry_time ON "AUTHORIZATION_CODE" (EXPIRY_TIME); | ||||||
| ``` | ||||||
|
|
||||||
| ## Runtime Database Expiry Handling | ||||||
| ## Runtime-transient Database Expiry Handling | ||||||
|
|
||||||
| Use these rules for all temporary runtime tables in `runtimedb`. | ||||||
| Use these rules for all temporary runtime tables in `runtime_transient`. | ||||||
|
|
||||||
| ### Agent Rules | ||||||
|
|
||||||
|
|
@@ -187,7 +188,7 @@ Use these rules for all temporary runtime tables in `runtimedb`. | |||||
| 4. Cleanup jobs must delete expired rows regularly. | ||||||
| 5. For association tables, if the foreign key to the owning runtime record uses `ON DELETE CASCADE`, deleting an expired owner row also removes related association rows automatically. | ||||||
| 6. An association table does not require its own `EXPIRY_TIME` column unless the association has an independent expiry lifecycle. | ||||||
| 7. When runtime tables are added, removed, or renamed, update both cleanup artifacts: `backend/dbscripts/runtimedb/postgres-cleanup.sql` and `backend/scripts/cleanup_runtime_db.sh`. | ||||||
| 7. When runtime tables are added, removed, or renamed, update both cleanup artifacts: `backend/dbscripts/runtime-transient/postgres-cleanup.sql` and `backend/scripts/cleanup_runtime_transient_db.sh`. | ||||||
|
|
||||||
| ### Expiry Column | ||||||
|
|
||||||
|
|
@@ -211,13 +212,13 @@ WHERE AUTH_ID = $1 AND EXPIRY_TIME > $2 AND DEPLOYMENT_ID = $3 | |||||
|
|
||||||
| Use the existing cleanup artifacts in this repository: | ||||||
|
|
||||||
| - `backend/dbscripts/runtimedb/postgres-cleanup.sql`: defines the PostgreSQL stored procedure `cleanup_expired_runtimedb_data` (UTC-based cleanup). | ||||||
| - `backend/scripts/cleanup_runtime_db.sh`: provides scheduled/manual cleanup support for PostgreSQL and SQLite. | ||||||
| - `backend/dbscripts/runtime-transient/postgres-cleanup.sql`: defines the PostgreSQL stored procedure `cleanup_expired_runtime_transient_data` (UTC-based cleanup). | ||||||
| - `backend/scripts/cleanup_runtime_transient_db.sh`: provides scheduled/manual cleanup support for PostgreSQL and SQLite. | ||||||
|
|
||||||
| Keep these two files in sync with the current set of runtime tables. | ||||||
|
|
||||||
| ```sql | ||||||
| CREATE OR REPLACE PROCEDURE cleanup_expired_runtimedb_data() | ||||||
| CREATE OR REPLACE PROCEDURE cleanup_expired_runtime_transient_data() | ||||||
| LANGUAGE plpgsql | ||||||
| AS $$ | ||||||
| DECLARE | ||||||
|
|
@@ -293,6 +294,6 @@ Use a consistent prefix per store and increment the sequence number for each new | |||||
| | Query parameter order | Keep `DEPLOYMENT_ID` as the last parameter in parameterized queries. | | ||||||
| | Runtime table expiry column | For runtime owner tables, require `EXPIRY_TIME TIMESTAMP NOT NULL`. | | ||||||
| | Association table expiry column | Omit `EXPIRY_TIME` when lifecycle is inherited via `ON DELETE CASCADE`; add it only if association rows expire independently. | | ||||||
| | Expired data cleanup | Use `backend/dbscripts/runtimedb/postgres-cleanup.sql` and `backend/scripts/cleanup_runtime_db.sh`; keep both updated when runtime tables change. | | ||||||
| | Expired data cleanup | Use `backend/dbscripts/runtime-transient/postgres-cleanup.sql` and `backend/scripts/cleanup_runtime_transient_db.sh`; keep both updated when runtime tables change. | | ||||||
| | Query declaration format | Define queries as `DBQuery` values with unique query IDs. | | ||||||
| | Table identifier format | Use uppercase table names in double quotes in schema scripts and embedded 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
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
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
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
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 |
|---|---|---|
|
|
@@ -16,48 +16,48 @@ | |
| -- ---------------------------------------------------------------------------- | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we rename the folder to runtime-persistentdb to be consistent with config and entitydb? WDYT? |
||
|
|
||
| -- ============================================================ | ||
| -- Stored procedure: purge expired operationdb rows in bounded batches. | ||
| -- Stored procedure: purge expired runtime_persistent rows in bounded batches. | ||
| -- | ||
| -- Unlike runtimedb, operation data is authoritative and must survive a | ||
| -- runtime flush; only rows past their EXPIRY_TIME are safe to delete. A revoked | ||
| -- Unlike runtime_transient, runtime_persistent data is authoritative and must survive a | ||
| -- runtime_transient flush; only rows past their EXPIRY_TIME are safe to delete. A revoked | ||
| -- token's row is removable once the token itself would have naturally expired. | ||
| -- | ||
| -- Deletes expired rows in batches of p_batch_size (default 1000), committing | ||
| -- after each batch to keep locks short on large tables. Must run as a top-level | ||
| -- CALL (the per-batch COMMIT cannot run inside an outer transaction). | ||
| -- | ||
| -- Run once manually (ad-hoc / on-demand): | ||
| -- PGPASSWORD=<pass> psql -h <host> -p <port> -U <user> -d <operationdb> \ | ||
| -- -c "CALL cleanup_expired_operationdb_data();" | ||
| -- PGPASSWORD=<pass> psql -h <host> -p <port> -U <user> -d <runtime_persistent> \ | ||
| -- -c "CALL cleanup_expired_runtime_persistent_data();" | ||
| -- | ||
| -- -- Optional: override the batch size (rows deleted per batch): | ||
| -- -c "CALL cleanup_expired_operationdb_data(500);" | ||
| -- -c "CALL cleanup_expired_runtime_persistent_data(500);" | ||
| -- | ||
| -- Scheduled execution options: | ||
| -- | ||
| -- 1. pg_cron (RECOMMENDED, requires the pg_cron extension): | ||
| -- CREATE EXTENSION IF NOT EXISTS pg_cron; | ||
| -- SELECT cron.schedule( | ||
| -- 'cleanup-operationdb-expired', | ||
| -- 'cleanup-runtime_persistent-expired', | ||
|
indeewari marked this conversation as resolved.
|
||
| -- '*/60 * * * *', | ||
| -- $$CALL cleanup_expired_operationdb_data()$$ | ||
| -- $$CALL cleanup_expired_runtime_persistent_data()$$ | ||
| -- ); | ||
| -- -- To verify: SELECT * FROM cron.job WHERE jobname = 'cleanup-operationdb-expired'; | ||
| -- -- To remove: SELECT cron.unschedule('cleanup-operationdb-expired'); | ||
| -- -- To verify: SELECT * FROM cron.job WHERE jobname = 'cleanup-runtime_persistent-expired'; | ||
| -- -- To remove: SELECT cron.unschedule('cleanup-runtime_persistent-expired'); | ||
| -- | ||
| -- 2. Kubernetes CronJob: call CALL cleanup_expired_operationdb_data() | ||
| -- 2. Kubernetes CronJob: call CALL cleanup_expired_runtime_persistent_data() | ||
| -- via a psql container on the desired schedule. | ||
| -- | ||
| -- 3. OS cron (every 60 minutes): | ||
| -- -- */60 * * * * postgres PGPASSWORD=<pass> psql -h <host> -p <port> \ | ||
| -- -- -U <user> -d <operationdb> -c "CALL cleanup_expired_operationdb_data();" \ | ||
| -- -- -U <user> -d <runtime_persistent> -c "CALL cleanup_expired_runtime_persistent_data();" \ | ||
| -- -- >> /var/log/thunderid-operation-cleanup.log 2>&1 | ||
| -- ============================================================ | ||
|
|
||
| -- Drop the old parameterless signature so re-applying doesn't leave an ambiguous overload. | ||
| DROP PROCEDURE IF EXISTS cleanup_expired_operationdb_data(); | ||
| DROP PROCEDURE IF EXISTS cleanup_expired_runtime_persistent_data(); | ||
|
|
||
| CREATE OR REPLACE PROCEDURE cleanup_expired_operationdb_data(p_batch_size INT DEFAULT 1000) | ||
| CREATE OR REPLACE PROCEDURE cleanup_expired_runtime_persistent_data(p_batch_size INT DEFAULT 1000) | ||
| LANGUAGE plpgsql | ||
| AS $$ | ||
| DECLARE | ||
|
|
||
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
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
File renamed without changes.
File renamed without changes.
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.