-
Notifications
You must be signed in to change notification settings - Fork 513
Queries view #1145
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
Queries view #1145
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
4807eb3
Queries view
N2D4 a748cf0
Fix issue
N2D4 034a6fa
Run Query link
N2D4 0bbf269
Fix PR review comments
N2D4 eedc0e9
Fix analytics config tests to check override for deletions
N2D4 f4e2d0b
Query deletion schema changes
N2D4 8eda5ed
better
N2D4 c4fb883
Increase email send timeout
N2D4 b405cd5
Merge remote-tracking branch 'origin/dev' into saved-queries
N2D4 32f4bf4
Extract shared analytics utilities to reduce code duplication
N2D4 f10e0c9
More fixes
N2D4 ba88e99
Merge remote-tracking branch 'origin/dev' into saved-queries
N2D4 6c7e41c
Final fixes
N2D4 302f272
Better null checks in token fetching logic
N2D4 da60514
Update AGENTS.md
N2D4 dea866d
Improve sign-up rule error descriptions
N2D4 61a248f
Fix sign-up rules test
N2D4 cbe7611
Better error messages for tests
N2D4 06668fd
Fix external DB sync tests
N2D4 836eb65
Better error logging when db sync fails
N2D4 6f402d9
Merge branch 'dev' into saved-queries
N2D4 66a7910
Add warnings
N2D4 078d7f0
Fix build
N2D4 0523bad
Fix lint
N2D4 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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Please review the PR comments with `gh pr status` and fix & resolve those issues that are valid and relevant. Leave those comments that are mostly bullshit unresolved. Report the result to me in detail. Do NOT automatically commit or stage the changes back to the PR! |
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
123 changes: 123 additions & 0 deletions
123
apps/backend/prisma/migrations/20260202000000_fix_trusted_domains_config/migration.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,123 @@ | ||
| -- Migration to fix incorrectly formatted trusted domain entries in EnvironmentConfigOverride. | ||
| -- | ||
| -- A previous migration sometimes generated entries like: | ||
| -- "domains.trustedDomains.<id>.<property1>": value1, | ||
| -- "domains.trustedDomains.<id>.<property2>": value2 | ||
| -- | ||
| -- Without the parent key: | ||
| -- "domains.trustedDomains.<id>": { ... } | ||
| -- | ||
| -- This migration adds an empty object at the <id> level for any missing parent keys: | ||
| -- "domains.trustedDomains.<id>": {}, | ||
| -- "domains.trustedDomains.<id>.<property1>": value1, | ||
| -- "domains.trustedDomains.<id>.<property2>": value2 | ||
|
|
||
| -- Add temporary column to track processed rows (outside transaction so it's visible immediately) | ||
| -- SPLIT_STATEMENT_SENTINEL | ||
| -- SINGLE_STATEMENT_SENTINEL | ||
| -- RUN_OUTSIDE_TRANSACTION_SENTINEL | ||
| ALTER TABLE /* SCHEMA_NAME_SENTINEL */."EnvironmentConfigOverride" ADD COLUMN IF NOT EXISTS "temp_trusted_domains_checked" BOOLEAN DEFAULT FALSE; | ||
| -- SPLIT_STATEMENT_SENTINEL | ||
|
|
||
| -- Create index on the temporary column for efficient querying | ||
| -- SPLIT_STATEMENT_SENTINEL | ||
| -- SINGLE_STATEMENT_SENTINEL | ||
| -- RUN_OUTSIDE_TRANSACTION_SENTINEL | ||
| CREATE INDEX CONCURRENTLY IF NOT EXISTS "temp_eco_trusted_domains_checked_idx" | ||
| ON /* SCHEMA_NAME_SENTINEL */."EnvironmentConfigOverride" ("temp_trusted_domains_checked") | ||
| WHERE "temp_trusted_domains_checked" IS NOT TRUE; | ||
| -- SPLIT_STATEMENT_SENTINEL | ||
|
|
||
| -- Process rows in batches (outside transaction so each batch commits independently) | ||
| -- SPLIT_STATEMENT_SENTINEL | ||
| -- SINGLE_STATEMENT_SENTINEL | ||
| -- RUN_OUTSIDE_TRANSACTION_SENTINEL | ||
| -- CONDITIONALLY_REPEAT_MIGRATION_SENTINEL | ||
| WITH rows_to_check AS ( | ||
| -- Get unchecked rows | ||
| SELECT "projectId", "branchId", "config" | ||
| FROM /* SCHEMA_NAME_SENTINEL */."EnvironmentConfigOverride" | ||
| WHERE "temp_trusted_domains_checked" IS NOT TRUE | ||
| -- Keep batch size small for consistent performance | ||
| LIMIT 1000 | ||
| ), | ||
| matching_keys AS ( | ||
| -- Find all keys that look like "domains.trustedDomains.<id>.<property...>" | ||
| -- (4 or more dot-separated parts starting with domains.trustedDomains) | ||
| SELECT | ||
| rtc."projectId", | ||
| rtc."branchId", | ||
| key, | ||
| -- Extract the parent key: domains.trustedDomains.<id> | ||
| (string_to_array(key, '.'))[1] || '.' || | ||
| (string_to_array(key, '.'))[2] || '.' || | ||
| (string_to_array(key, '.'))[3] AS parent_key | ||
| FROM rows_to_check rtc, | ||
| jsonb_object_keys(rtc."config") AS key | ||
| WHERE key ~ '^domains\.trustedDomains\.[^.]+\..+' | ||
| -- Pattern matches: domains.trustedDomains.<id>.<anything> | ||
| -- e.g. "domains.trustedDomains.abc123.baseUrl" | ||
| ), | ||
| missing_parents AS ( | ||
| -- Find parent keys that don't exist in the config | ||
| SELECT DISTINCT | ||
| mk."projectId", | ||
| mk."branchId", | ||
| mk.parent_key | ||
| FROM matching_keys mk | ||
| JOIN rows_to_check rtc | ||
| ON rtc."projectId" = mk."projectId" | ||
| AND rtc."branchId" = mk."branchId" | ||
| WHERE NOT (rtc."config" ? mk.parent_key) | ||
| ), | ||
| parents_to_add AS ( | ||
| -- Aggregate all missing parent keys per row into a single jsonb object | ||
| SELECT | ||
| mp."projectId", | ||
| mp."branchId", | ||
| jsonb_object_agg(mp.parent_key, '{}'::jsonb) AS new_keys | ||
| FROM missing_parents mp | ||
| GROUP BY mp."projectId", mp."branchId" | ||
| ), | ||
| updated_with_keys AS ( | ||
| -- Update rows that need new parent keys | ||
| UPDATE /* SCHEMA_NAME_SENTINEL */."EnvironmentConfigOverride" eco | ||
| SET | ||
| "config" = eco."config" || pta.new_keys, | ||
| "updatedAt" = NOW(), | ||
| "temp_trusted_domains_checked" = TRUE | ||
| FROM parents_to_add pta | ||
| WHERE eco."projectId" = pta."projectId" | ||
| AND eco."branchId" = pta."branchId" | ||
| RETURNING eco."projectId", eco."branchId" | ||
| ), | ||
| marked_as_checked AS ( | ||
| -- Mark all checked rows (including ones that didn't need fixing) | ||
| UPDATE /* SCHEMA_NAME_SENTINEL */."EnvironmentConfigOverride" eco | ||
| SET "temp_trusted_domains_checked" = TRUE | ||
| FROM rows_to_check rtc | ||
| WHERE eco."projectId" = rtc."projectId" | ||
| AND eco."branchId" = rtc."branchId" | ||
| AND NOT EXISTS ( | ||
| SELECT 1 FROM updated_with_keys uwk | ||
| WHERE uwk."projectId" = eco."projectId" | ||
| AND uwk."branchId" = eco."branchId" | ||
| ) | ||
| RETURNING eco."projectId" | ||
| ) | ||
| SELECT COUNT(*) > 0 AS should_repeat_migration | ||
| FROM rows_to_check; | ||
| -- SPLIT_STATEMENT_SENTINEL | ||
|
|
||
| -- Clean up: drop temporary index (outside transaction since CREATE was also outside) | ||
| -- SPLIT_STATEMENT_SENTINEL | ||
| -- SINGLE_STATEMENT_SENTINEL | ||
| -- RUN_OUTSIDE_TRANSACTION_SENTINEL | ||
| DROP INDEX IF EXISTS /* SCHEMA_NAME_SENTINEL */."temp_eco_trusted_domains_checked_idx"; | ||
| -- SPLIT_STATEMENT_SENTINEL | ||
|
|
||
| -- Clean up: drop temporary column (outside transaction) | ||
| -- SPLIT_STATEMENT_SENTINEL | ||
| -- SINGLE_STATEMENT_SENTINEL | ||
| -- RUN_OUTSIDE_TRANSACTION_SENTINEL | ||
| ALTER TABLE /* SCHEMA_NAME_SENTINEL */."EnvironmentConfigOverride" DROP COLUMN IF EXISTS "temp_trusted_domains_checked"; | ||
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
55 changes: 55 additions & 0 deletions
55
apps/backend/src/app/api/latest/internal/config/override/[level]/reset-keys/route.tsx
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,55 @@ | ||
| import { resetBranchConfigOverrideKeys, resetEnvironmentConfigOverrideKeys } from "@/lib/config"; | ||
| import { createSmartRouteHandler } from "@/route-handlers/smart-route-handler"; | ||
| import { adaptSchema, adminAuthTypeSchema, yupArray, yupNumber, yupObject, yupString } from "@stackframe/stack-shared/dist/schema-fields"; | ||
|
|
||
| const levelSchema = yupString().oneOf(["branch", "environment"]).defined(); | ||
|
|
||
| const levelConfigs = { | ||
| branch: { | ||
| reset: (options: { projectId: string, branchId: string, keysToReset: string[] }) => | ||
| resetBranchConfigOverrideKeys(options), | ||
| }, | ||
| environment: { | ||
| reset: (options: { projectId: string, branchId: string, keysToReset: string[] }) => | ||
| resetEnvironmentConfigOverrideKeys(options), | ||
| }, | ||
| }; | ||
|
|
||
| export const POST = createSmartRouteHandler({ | ||
| metadata: { | ||
| hidden: true, | ||
| summary: 'Reset config override keys', | ||
| description: 'Remove specific keys (and their nested descendants) from the config override at a given level. Uses the same nested key logic as the override algorithm.', | ||
| tags: ['Config'], | ||
| }, | ||
| request: yupObject({ | ||
| auth: yupObject({ | ||
| type: adminAuthTypeSchema, | ||
| tenancy: adaptSchema, | ||
| }).defined(), | ||
| params: yupObject({ | ||
| level: levelSchema, | ||
| }).defined(), | ||
| body: yupObject({ | ||
| keys: yupArray(yupString().defined()).defined(), | ||
| }).defined(), | ||
| }), | ||
| response: yupObject({ | ||
| statusCode: yupNumber().oneOf([200]).defined(), | ||
| bodyType: yupString().oneOf(["success"]).defined(), | ||
| }), | ||
| handler: async (req) => { | ||
| const levelConfig = levelConfigs[req.params.level]; | ||
|
|
||
| await levelConfig.reset({ | ||
| projectId: req.auth.tenancy.project.id, | ||
| branchId: req.auth.tenancy.branchId, | ||
| keysToReset: req.body.keys, | ||
| }); | ||
|
|
||
| return { | ||
| statusCode: 200 as const, | ||
| bodyType: "success" as const, | ||
| }; | ||
| }, | ||
| }); |
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.
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.