-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle concurrent settings saving operations
- Loading branch information
1 parent
bc6238a
commit 0757d3b
Showing
4 changed files
with
80 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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 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
28 changes: 28 additions & 0 deletions
28
priv/repo/migrations/20240214153742_add_uniqueness_to_software_updates_settings.exs
This file contains 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,28 @@ | ||
defmodule Trento.Repo.Migrations.AddUniquenessToSoftwareUpdatesSettings do | ||
use Ecto.Migration | ||
|
||
def change do | ||
%Postgrex.Result{rows: rows} = | ||
repo().query!("SELECT id FROM software_update_settings;", [], log: false) | ||
|
||
settings_identifier = | ||
case rows do | ||
[] -> UUID.uuid4() | ||
[[binary_uuid | _] | _] -> UUID.binary_to_string!(binary_uuid) | ||
end | ||
|
||
alter table(:software_update_settings) do | ||
modify :id, :uuid, default: settings_identifier | ||
end | ||
|
||
create constraint("software_update_settings", :only_one_record, | ||
check: "id ='#{settings_identifier}'" | ||
) | ||
|
||
execute "INSERT INTO software_update_settings(id, inserted_at, updated_at) VALUES('#{settings_identifier}', NOW(), NOW()) ON CONFLICT DO NOTHING;" | ||
end | ||
|
||
def down do | ||
drop constraint("software_update_settings", :only_one_record) | ||
end | ||
end |
This file contains 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