-
Notifications
You must be signed in to change notification settings - Fork 83
feat(api-keys): add multi-tenant Cassandra schema #2157
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
nvaghela-oss
merged 3 commits into
feat/multi-tenant-api-keys
from
feat/api-keys-multi-tenant-schema
Sep 30, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
90 changes: 90 additions & 0 deletions
90
migrations/cassandra/keyspaces/api_keys_api/04_add_multi_tenant_schema.up.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,90 @@ | ||
| -- Multi-tenant API Keys tables. 03_init_tables.up.sql stays the original schema. | ||
| -- New and existing clusters apply this file. Statements are idempotent. | ||
| -- Keep keys_by_owner_and_service until the dual-write migration stops using it. | ||
| -- Hash lookup stays keyed by api_key_hash. nca_id is a regular column. | ||
|
|
||
| ALTER TABLE api_keys_api.keys ADD IF NOT EXISTS nca_id TEXT; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS api_keys_api.keys_by_account_owner_and_service | ||
| ( | ||
| nca_id TEXT, | ||
| owner_type TEXT, | ||
| owner_id TEXT, | ||
| issuer_service_id TEXT, | ||
| key_id TEXT, | ||
| key_status TEXT, | ||
| created_at TIMESTAMP, | ||
| expires_at TIMESTAMP, | ||
| deletes_at TIMESTAMP, | ||
| key_details TEXT, | ||
| PRIMARY KEY ((nca_id, owner_type, owner_id), issuer_service_id, key_id) | ||
| ); | ||
|
|
||
| CREATE CUSTOM INDEX IF NOT EXISTS keys_by_scope_nca_idx | ||
| ON api_keys_api.keys_by_account_owner_and_service (nca_id) | ||
| USING 'StorageAttachedIndex'; | ||
|
|
||
| CREATE CUSTOM INDEX IF NOT EXISTS keys_by_scope_owner_idx | ||
| ON api_keys_api.keys_by_account_owner_and_service (owner_id) | ||
| USING 'StorageAttachedIndex'; | ||
|
|
||
| CREATE CUSTOM INDEX IF NOT EXISTS keys_by_scope_owner_type_idx | ||
| ON api_keys_api.keys_by_account_owner_and_service (owner_type) | ||
| USING 'StorageAttachedIndex'; | ||
|
|
||
| CREATE CUSTOM INDEX IF NOT EXISTS keys_by_scope_service_idx | ||
| ON api_keys_api.keys_by_account_owner_and_service (issuer_service_id) | ||
| USING 'StorageAttachedIndex'; | ||
|
|
||
| CREATE CUSTOM INDEX IF NOT EXISTS keys_by_scope_status_idx | ||
| ON api_keys_api.keys_by_account_owner_and_service (key_status) | ||
| USING 'StorageAttachedIndex'; | ||
|
|
||
| CREATE CUSTOM INDEX IF NOT EXISTS keys_by_scope_created_at_idx | ||
| ON api_keys_api.keys_by_account_owner_and_service (created_at) | ||
| USING 'StorageAttachedIndex'; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS api_keys_api.owner_status_by_account | ||
| ( | ||
| nca_id TEXT, | ||
| owner_type TEXT, | ||
| owner_id TEXT, | ||
| owner_status TEXT, | ||
| created_at TIMESTAMP, | ||
| updated_at TIMESTAMP, | ||
| PRIMARY KEY ((nca_id, owner_type, owner_id)) | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS api_keys_api.owner_status_by_account_and_service | ||
| ( | ||
| nca_id TEXT, | ||
| owner_type TEXT, | ||
| owner_id TEXT, | ||
| issuer_service_id TEXT, | ||
| owner_status TEXT, | ||
| created_at TIMESTAMP, | ||
| updated_at TIMESTAMP, | ||
| PRIMARY KEY ((nca_id, owner_type, owner_id, issuer_service_id)) | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS api_keys_api.key_operations_by_id | ||
| ( | ||
| operation_id UUID, | ||
| actor_type TEXT, | ||
| actor_id TEXT, | ||
| operation TEXT, | ||
| nca_ids FROZEN<SET<TEXT>>, | ||
| issuer_service_ids FROZEN<SET<TEXT>>, | ||
| user_ids FROZEN<SET<TEXT>>, | ||
| operation_status TEXT, | ||
| matched_count BIGINT, | ||
| completed_count BIGINT, | ||
| failed_count BIGINT, | ||
| selection_state TEXT, | ||
| paging_state TEXT, | ||
| reason TEXT, | ||
| cutoff_at TIMESTAMP, | ||
| created_at TIMESTAMP, | ||
| updated_at TIMESTAMP, | ||
| PRIMARY KEY ((operation_id)) | ||
| ); |
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
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.