summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--pkg/database/sql/000_init.sql1
-rw-r--r--pkg/database/states.go8
2 files changed, 8 insertions, 1 deletions
diff --git a/pkg/database/sql/000_init.sql b/pkg/database/sql/000_init.sql
index 08a58cd..9c9c07c 100644
--- a/pkg/database/sql/000_init.sql
+++ b/pkg/database/sql/000_init.sql
@@ -13,6 +13,7 @@ CREATE TABLE versions (
id INTEGER PRIMARY KEY,
state_id INTEGER,
data BLOB,
+ lock TEXT,
created INTEGER DEFAULT (unixepoch()),
FOREIGN KEY(state_id) REFERENCES states(id) ON DELETE CASCADE
) STRICT;
diff --git a/pkg/database/states.go b/pkg/database/states.go
index 9c35212..36011ab 100644
--- a/pkg/database/states.go
+++ b/pkg/database/states.go
@@ -74,7 +74,13 @@ func (db *DB) SetState(name string, data []byte, lockID string) (bool, error) {
err = fmt.Errorf("failed to update state, lock ID does not match")
return true, err
}
- _, err = tx.ExecContext(db.ctx, `INSERT INTO versions(state_id, data) VALUES (?, ?);`, stateID, encryptedData)
+ _, err = tx.ExecContext(db.ctx,
+ `INSERT INTO versions(state_id, data, lock)
+ SELECT :stateID, :data, lock
+ FROM states
+ WHERE states.id = :stateID;`,
+ sql.Named("stateID", stateID),
+ sql.Named("data", encryptedData))
if err != nil {
return false, err
}