mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02: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> {
 | 
					    async exists(name: string): Promise<boolean> {
 | 
				
			||||||
        const result = await this.db.raw(
 | 
					        const result = await this.db.raw(
 | 
				
			||||||
            `SELECT EXISTS (SELECT 1 FROM ${TABLE} WHERE name = ?) AS present`,
 | 
					            `SELECT EXISTS (SELECT 1 FROM ${TABLE} WHERE name = ?) AS present`,
 | 
				
			||||||
@ -58,13 +54,12 @@ export default class SettingStore implements ISettingStore {
 | 
				
			|||||||
        return undefined;
 | 
					        return undefined;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Is actually an upsert
 | 
				
			||||||
    async insert(name: string, content: any): Promise<void> {
 | 
					    async insert(name: string, content: any): Promise<void> {
 | 
				
			||||||
        const exists = await this.exists(name);
 | 
					        await this.db(TABLE)
 | 
				
			||||||
        if (exists) {
 | 
					            .insert({ name, content })
 | 
				
			||||||
            await this.updateRow(name, content);
 | 
					            .onConflict('name')
 | 
				
			||||||
        } else {
 | 
					            .merge();
 | 
				
			||||||
            await this.insertNewRow(name, content);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async delete(name: string): Promise<void> {
 | 
					    async delete(name: string): Promise<void> {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user