mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-14 00:19:16 +01:00
task: make setting service handle conflict on insert (#9160)
Currently, in enterprise we're struggling with setting service and transactionality; all our verfications says that the setting key is not present, so setting-store happily tries to insert a new row with a new PK. However, somehow at the same time, the key already exists. This commit adds conflict handling to the insertNewRow.
This commit is contained in:
parent
1036fb6012
commit
8de801025f
@ -32,10 +32,6 @@ export default class SettingStore implements ISettingStore {
|
||||
});
|
||||
}
|
||||
|
||||
async insertNewRow(name: string, content: any) {
|
||||
return this.db(TABLE).insert({ name, content });
|
||||
}
|
||||
|
||||
async exists(name: string): Promise<boolean> {
|
||||
const result = await this.db.raw(
|
||||
`SELECT EXISTS (SELECT 1 FROM ${TABLE} WHERE name = ?) AS present`,
|
||||
@ -58,13 +54,12 @@ export default class SettingStore implements ISettingStore {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Is actually an upsert
|
||||
async insert(name: string, content: any): Promise<void> {
|
||||
const exists = await this.exists(name);
|
||||
if (exists) {
|
||||
await this.updateRow(name, content);
|
||||
} else {
|
||||
await this.insertNewRow(name, content);
|
||||
}
|
||||
await this.db(TABLE)
|
||||
.insert({ name, content })
|
||||
.onConflict('name')
|
||||
.merge();
|
||||
}
|
||||
|
||||
async delete(name: string): Promise<void> {
|
||||
|
Loading…
Reference in New Issue
Block a user