diff options
author | Julien Dessaux | 2025-02-22 13:35:17 +0100 |
---|---|---|
committer | Julien Dessaux | 2025-02-22 13:35:17 +0100 |
commit | 6fd1663d8c27fbfd5adc93a3aa973f78a2eeb719 (patch) | |
tree | c2e5afc41acdf42cd4a43a324c80bd35ad714261 /pkg/database/locks.go | |
parent | chore(webui): refactored state creation page and route (diff) | |
download | tfstated-6fd1663d8c27fbfd5adc93a3aa973f78a2eeb719.tar.gz tfstated-6fd1663d8c27fbfd5adc93a3aa973f78a2eeb719.tar.bz2 tfstated-6fd1663d8c27fbfd5adc93a3aa973f78a2eeb719.zip |
Diffstat (limited to '')
-rw-r--r-- | pkg/database/locks.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/pkg/database/locks.go b/pkg/database/locks.go index e78fd0c..6c0bdfb 100644 --- a/pkg/database/locks.go +++ b/pkg/database/locks.go @@ -4,6 +4,9 @@ import ( "database/sql" "encoding/json" "errors" + "fmt" + + "go.n16f.net/uuid" ) // Atomically check the lock status of a state and lock it if unlocked. Returns @@ -18,7 +21,11 @@ func (db *DB) SetLockOrGetExistingLock(path string, lock any) (bool, error) { if lockData, err = json.Marshal(lock); err != nil { return err } - _, err = tx.ExecContext(db.ctx, `INSERT INTO states(path, lock) VALUES (?, json(?))`, path, lockData) + var stateId uuid.UUID + if err := stateId.Generate(uuid.V7); err != nil { + return fmt.Errorf("failed to generate state id: %w", err) + } + _, err = tx.ExecContext(db.ctx, `INSERT INTO states(id, path, lock) VALUES (?, ?, json(?))`, stateId, path, lockData) ret = true return err } else { |