Repository navigation
feat(settings): store user overrides in PostgreSQL #758
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
Ferryx349
wants to merge
4
commits into
main
Choose a base branch
from
feat/settings-db-overrides
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+550
−22
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
04e4e29
feat(settings): store user overrides in PostgreSQL
Ferryx349 24b2014
Merge branch 'main' into feat/settings-db-overrides
Ferryx349 e9f3bb2
Merge branch 'main' into feat/settings-db-overrides
cameri a351a51
fix(settings): address db override persistence and reload gaps
Ferryx349 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,5 @@ | ||
| --- | ||
| "nostream": minor | ||
| --- | ||
|
|
||
| feat: store relay settings overrides in PostgreSQL when SETTINGS_BACKEND=db |
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
11 changes: 11 additions & 0 deletions
11
migrations/20260905_120000_create_settings_overrides_table.js
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,11 @@ | ||
| exports.up = async function (knex) { | ||
| await knex.schema.createTable('settings_overrides', (table) => { | ||
| table.text('path').primary() | ||
| table.jsonb('value').notNullable() | ||
| table.timestamp('updated_at', { useTz: true }).notNullable().defaultTo(knex.fn.now()) | ||
| }) | ||
| } | ||
|
|
||
| exports.down = async function (knex) { | ||
| await knex.schema.dropTableIfExists('settings_overrides') | ||
| } |
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,44 @@ | ||
| import { DatabaseClient } from '../@types/base' | ||
| import { Settings } from '../@types/settings' | ||
| import { createLogger } from '../factories/logger-factory' | ||
| import { flattenSettingsToPaths, setByPath } from '../utils/settings-config' | ||
|
|
||
| const logger = createLogger('settings-override-repository') | ||
|
|
||
| export class SettingsOverrideRepository { | ||
| public constructor(private readonly dbClient: DatabaseClient) {} | ||
|
|
||
| public async loadOverrides(): Promise<Settings> { | ||
| const rows = await this.dbClient('settings_overrides').select('path', 'value') | ||
|
|
||
| let settings: Record<string, unknown> = {} | ||
| for (const row of rows) { | ||
| settings = setByPath(settings, row.path, row.value) | ||
| } | ||
|
|
||
| return settings as unknown as Settings | ||
| } | ||
|
|
||
| public async replaceOverrides(overrides: Settings): Promise<void> { | ||
| const entries = flattenSettingsToPaths(overrides) | ||
|
|
||
| await this.dbClient.transaction(async (transaction) => { | ||
| await transaction('settings_overrides').delete() | ||
|
|
||
| if (entries.length === 0) { | ||
| return | ||
| } | ||
|
|
||
| const now = new Date() | ||
| await transaction('settings_overrides').insert( | ||
| entries.map((entry) => ({ | ||
| path: entry.path, | ||
| value: JSON.stringify(entry.value), | ||
| updated_at: now, | ||
| })), | ||
| ) | ||
| }) | ||
|
|
||
| logger('replaced %d settings override paths', entries.length) | ||
| } | ||
| } |
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.
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.
With
SETTINGS_BACKEND=db, the config commands now open the shared database pool but never close it. Returning from the command does not exit the CLI because the database connections remain open. With the default settings, commands wait for the 60-second idle timeout after printing their result. IfDB_MIN_POOL_SIZEis above zero, they can remain open indefinitely.Close the database client after each one-shot command, including error paths.