feat(tfstated): preserve lock information in states versions
This commit is contained in:
parent
5959766cbd
commit
0e58781daa
2 changed files with 8 additions and 1 deletions
|
@ -13,6 +13,7 @@ CREATE TABLE versions (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
state_id INTEGER,
|
state_id INTEGER,
|
||||||
data BLOB,
|
data BLOB,
|
||||||
|
lock TEXT,
|
||||||
created INTEGER DEFAULT (unixepoch()),
|
created INTEGER DEFAULT (unixepoch()),
|
||||||
FOREIGN KEY(state_id) REFERENCES states(id) ON DELETE CASCADE
|
FOREIGN KEY(state_id) REFERENCES states(id) ON DELETE CASCADE
|
||||||
) STRICT;
|
) STRICT;
|
||||||
|
|
|
@ -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")
|
err = fmt.Errorf("failed to update state, lock ID does not match")
|
||||||
return true, err
|
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 {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue