mirror of
https://github.com/System-End/hackatime.git
synced 2026-04-19 21:05:15 +00:00
Add unique index for fields_hash when not deleted
This commit is contained in:
parent
8682cff9c3
commit
29d40d5a2a
2 changed files with 11 additions and 1 deletions
|
|
@ -0,0 +1,9 @@
|
|||
class AddPartialUniqueIndexToHeartbeatFieldsHash < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
# Add a partial index that only applies to non-deleted records
|
||||
add_index :heartbeats, :fields_hash,
|
||||
unique: true,
|
||||
where: "deleted_at IS NULL",
|
||||
name: "index_heartbeats_on_fields_hash_when_not_deleted"
|
||||
end
|
||||
end
|
||||
3
db/schema.rb
generated
3
db/schema.rb
generated
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[8.0].define(version: 2025_05_07_182617) do
|
||||
ActiveRecord::Schema[8.0].define(version: 2025_05_07_183451) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pg_catalog.plpgsql"
|
||||
|
||||
|
|
@ -210,6 +210,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_05_07_182617) do
|
|||
t.datetime "deleted_at"
|
||||
t.index ["category", "time"], name: "index_heartbeats_on_category_and_time"
|
||||
t.index ["fields_hash"], name: "index_heartbeats_on_fields_hash", unique: true
|
||||
t.index ["fields_hash"], name: "index_heartbeats_on_fields_hash_when_not_deleted", unique: true, where: "(deleted_at IS NULL)"
|
||||
t.index ["user_id"], name: "index_heartbeats_on_user_id"
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue