diff options
| author | Teddy Wing | 2019-06-10 02:08:51 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2019-06-10 02:08:51 +0200 | 
| commit | 21534162124501f0410ee31cd31130aa3b92a9f3 (patch) | |
| tree | f618796415ca2739c6e835beec0f075a9c496cbc /code-review-database | |
| parent | b2768485750f267cd9ad93a161ee963a6102d402 (diff) | |
| download | code-review-21534162124501f0410ee31cd31130aa3b92a9f3.tar.bz2 | |
code-review-database(create_merge_base): Upsert merge base
Don't duplicate rows if we call `create_merge_base` multiple times.
Doing so would mean we'd get multiple merge base rows for the same head.
Instead, overwrite the existing merge base for a given head using an
upsert.
Thanks a bunch to MarqueIV
(https://stackoverflow.com/users/168179/marqueiv) on Stack Overflow for
demonstrating a way to do an upsert without the UPSERT syntax. This
enables us to do an upsert on SQLite < 3.24.0. Neat trick.
https://stackoverflow.com/questions/15277373/sqlite-upsert-update-or-insert/38463024#38463024
Diffstat (limited to 'code-review-database')
| -rw-r--r-- | code-review-database | 13 | 
1 files changed, 8 insertions, 5 deletions
| diff --git a/code-review-database b/code-review-database index 642f9c4..eb18818 100644 --- a/code-review-database +++ b/code-review-database @@ -31,13 +31,16 @@ function create_merge_base () {  	sqlite3 "$DATABASE" <<-SQL  		BEGIN TRANSACTION; +		UPDATE merge_bases +		SET base = '$base' +		WHERE head = '$head'; +  		INSERT INTO merge_bases  			(head, base) -		VALUES -			( -				'$head', -				'$base' -			); +		SELECT +			'$head', +			'$base' +		WHERE (SELECT changes() = 0);  		COMMIT;  	SQL | 
