chore(tfstated): change database state id and version id formats to uuidv7

This commit is contained in:
Julien Dessaux 2025-02-22 13:35:17 +01:00
parent 169e2d0d9d
commit 6fd1663d8c
Signed by: adyxax
GPG key ID: F92E51B86E07177E
9 changed files with 73 additions and 57 deletions

View file

@ -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 {