-
Notifications
You must be signed in to change notification settings - Fork 6
feat: 1325 add global and per feed configurationintegrate feeds download #1363
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
davidgamez
merged 17 commits into
main
from
1325-add-global-and-per-feed-configurationintegrate-feeds-download
Sep 25, 2025
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
bfa28e6
Added global and per feed configuration
qcdyx c2363dd
imported config reader only in download_and_get_hash
qcdyx 9c2a265
fixed multiple values for db_session errors
qcdyx 6416ee0
fixed bad path
qcdyx 77dd598
fixed search path problem
qcdyx b0d12ea
fixed errors
qcdyx 7060350
used feed_id as primary key
qcdyx 710995c
removed delete cascade
qcdyx 21310c3
Merge branch 'main' into 1325-add-global-and-per-feed-configurationin…
qcdyx ca8ef5f
fixed lint errors
qcdyx 3d2031c
fixed broken test
qcdyx 4e67cfb
added a @patch decorator to each of the failing test methods to mock …
qcdyx 6889933
used the right patch
qcdyx 55f2c89
more fixes
qcdyx 83f3f04
more fixes
qcdyx d6919de
Merge branch 'main' into 1325-add-global-and-per-feed-configurationin…
qcdyx a5de48c
Merge branch 'main' into 1325-add-global-and-per-feed-configurationin…
davidgamez 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,48 @@ | ||
| from typing import Optional, Any | ||
| from sqlalchemy.orm import Session | ||
| from shared.database.database import with_db_session | ||
| from shared.database_gen.sqlacodegen_models import ConfigKey, ConfigValueFeed | ||
|
|
||
|
|
||
| @with_db_session | ||
| def get_config_value( | ||
| namespace: str, | ||
| key: str, | ||
| feed_id: Optional[str] = None, | ||
| db_session: Session = None, | ||
| ) -> Optional[Any]: | ||
| """ | ||
| Retrieves a configuration value from the database using the provided session. | ||
|
|
||
| It first looks for a feed-specific override. If a feed_stable_id is provided and a | ||
| value is found, it returns that value. | ||
|
|
||
| If no feed-specific value is found or no feed_stable_id is provided, it looks for | ||
| the global default value in the `config_key` table. | ||
|
|
||
| :param namespace: The namespace of the configuration key. | ||
| :param key: The configuration key. | ||
| :param feed_stable_id: The optional feed_stable_id for a specific override. | ||
| :param db_session: The SQLAlchemy session, injected by the `with_db_session` decorator. | ||
| :return: The configuration value, or None if not found. | ||
| """ | ||
| # 1. Try to get feed-specific value if feed_id is provided | ||
| if feed_id: | ||
| feed_config = ( | ||
| db_session.query(ConfigValueFeed.value) | ||
| .filter( | ||
| ConfigValueFeed.feed_id == feed_id, | ||
| ConfigValueFeed.namespace == namespace, | ||
| ConfigValueFeed.key == key, | ||
| ) | ||
| .first() | ||
| ) | ||
| if feed_config: | ||
| return feed_config.value | ||
|
|
||
| # 2. If not found or no feed_id, get the default value | ||
| default_config = ( | ||
| db_session.query(ConfigKey.default_value).filter(ConfigKey.namespace == namespace, ConfigKey.key == key).first() | ||
| ) | ||
|
|
||
| return default_config.default_value if default_config else None |
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 |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| ALTER TABLE feed ADD CONSTRAINT feed_stable_id_unique UNIQUE (stable_id); | ||
|
Member
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. Before merging this PR, we must fix => #1061 |
||
| -- 1. Catalog of allowed keys + optional global values | ||
| CREATE TABLE config_key ( | ||
| namespace text NOT NULL, -- e.g. 'reverse_geolocation' | ||
| key text NOT NULL, -- e.g. 'country_fallback' | ||
| description text, | ||
| default_value jsonb, -- fallback if nothing else | ||
| updated_at timestamptz NOT NULL DEFAULT now(), | ||
| PRIMARY KEY (namespace, key) | ||
| ); | ||
|
|
||
| -- 2. Per-feed overrides | ||
| CREATE TABLE config_value_feed ( | ||
| feed_id varchar(255) NOT NULL, | ||
| feed_stable_id varchar(255) NOT NULL, | ||
| namespace text NOT NULL, | ||
| key text NOT NULL, | ||
| value jsonb NOT NULL, | ||
| updated_at timestamptz NOT NULL DEFAULT now(), | ||
| PRIMARY KEY (feed_id, namespace, key), | ||
| FOREIGN KEY (namespace, key) REFERENCES config_key(namespace, key) ON DELETE CASCADE | ||
| ); | ||
|
|
||
| -- Helpful index | ||
| CREATE INDEX config_value_feed_gin ON config_value_feed USING GIN (value); | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️