-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ensure atomic access to and creation of components in mqtt-task
- Loading branch information
1 parent
1340a46
commit 250807a
Showing
8 changed files
with
57 additions
and
20 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
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
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,23 @@ | ||
class UniqueIndexOnComponents < ActiveRecord::Migration[6.1] | ||
def up | ||
remove_index :components, [:device_id, :sensor_id] | ||
add_index :components, [:device_id, :sensor_id], unique: true | ||
execute %{ | ||
ALTER TABLE components ADD CONSTRAINT unique_sensor_for_device UNIQUE (device_id, sensor_id) | ||
} | ||
execute %{ | ||
ALTER TABLE components ADD CONSTRAINT unique_key_for_device UNIQUE (device_id, key) | ||
} | ||
end | ||
|
||
def down | ||
execute %{ | ||
ALTER TABLE components DROP CONSTRAINT IF EXISTS unique_key_for_device | ||
} | ||
execute %{ | ||
ALTER TABLE components DROP CONSTRAINT IF EXISTS unique_sensor_for_device | ||
} | ||
remove_index :components, [:device_id, :sensor_id], unique: true | ||
add_index :components, [:device_id, :sensor_id] | ||
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
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