-
Notifications
You must be signed in to change notification settings - Fork 370
feat: Add Extension to Saved Queries - BED-9321 #3171
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
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5e4a6e0
add extension to saved queries
LawsonWillard 5ff7050
int32 instead of null.int32
LawsonWillard ff3117c
add new db specific model to handle nil to int conversion
LawsonWillard 0f12195
replace int32 with *int32
LawsonWillard 23cb55f
add query_key column and create CreateSavedQuery integration test
LawsonWillard a1b9b97
fix: make saved query uniqueness indexes explicit BED-9321
LawsonWillard 7018f17
delete extension rows on down migration
LawsonWillard 33cf122
chore: refresh saved query migration timestamp BED-9321
LawsonWillard 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
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
57 changes: 57 additions & 0 deletions
57
...abase/migration/migrations/20260901110807_v9_add_schema_extension_id_to_saved_queries.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,57 @@ | ||
| -- Copyright 2026 Specter Ops, Inc. | ||
| -- | ||
| -- Licensed under the Apache License, Version 2.0 | ||
| -- you may not use this file except in compliance with the License. | ||
| -- You may obtain a copy of the License at | ||
| -- | ||
| -- http://www.apache.org/licenses/LICENSE-2.0 | ||
| -- | ||
| -- Unless required by applicable law or agreed to in writing, software | ||
| -- distributed under the License is distributed on an "AS IS" BASIS, | ||
| -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| -- See the License for the specific language governing permissions and | ||
| -- limitations under the License. | ||
| -- | ||
| -- SPDX-License-Identifier: Apache-2.0 | ||
| -- +goose Up | ||
| ALTER TABLE saved_queries | ||
| ADD COLUMN IF NOT EXISTS schema_extension_id INTEGER REFERENCES schema_extensions (id) ON DELETE CASCADE, | ||
| ADD COLUMN IF NOT EXISTS query_key TEXT | ||
| CONSTRAINT chk_saved_queries_extension_shape | ||
| CHECK ( | ||
| (schema_extension_id IS NULL AND query_key IS NULL AND user_id <> '00000000-0000-0000-0000-000000000000') | ||
| OR | ||
| (schema_extension_id IS NOT NULL AND query_key IS NOT NULL AND user_id = '00000000-0000-0000-0000-000000000000') | ||
| ); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_saved_queries_schema_extension_id | ||
| ON saved_queries (schema_extension_id) WHERE schema_extension_id IS NOT NULL; | ||
|
|
||
| DROP INDEX IF EXISTS idx_saved_queries_composite_index; | ||
|
|
||
| CREATE UNIQUE INDEX IF NOT EXISTS idx_saved_queries_user_id_name | ||
| ON saved_queries (user_id, name) WHERE schema_extension_id IS NULL; | ||
| CREATE UNIQUE INDEX IF NOT EXISTS idx_saved_queries_schema_extension_id_name | ||
| ON saved_queries (schema_extension_id, name) WHERE schema_extension_id IS NOT NULL; | ||
|
|
||
| CREATE UNIQUE INDEX IF NOT EXISTS idx_saved_queries_extension_query_key | ||
| ON saved_queries (schema_extension_id, query_key) WHERE schema_extension_id IS NOT NULL; | ||
|
|
||
|
|
||
| -- +goose Down | ||
|
|
||
| DELETE FROM saved_queries WHERE schema_extension_id IS NOT NULL; | ||
|
|
||
| DROP INDEX IF EXISTS idx_saved_queries_user_id_name; | ||
| DROP INDEX IF EXISTS idx_saved_queries_schema_extension_id_name; | ||
|
|
||
| CREATE UNIQUE INDEX IF NOT EXISTS idx_saved_queries_composite_index | ||
| ON saved_queries USING btree (user_id, name); | ||
|
|
||
| DROP INDEX IF EXISTS idx_saved_queries_schema_extension_id; | ||
|
|
||
| DROP INDEX IF EXISTS idx_saved_queries_extension_query_key; | ||
|
|
||
| ALTER TABLE saved_queries | ||
| DROP COLUMN IF EXISTS query_key, | ||
| DROP COLUMN IF EXISTS schema_extension_id; | ||
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
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.