feature: every write of an instance's variable files is kept as a revision with the schema version of their layout and the application that wrote them.
Release / release (push) Successful in 1m8s

This commit is contained in:
slawek committed 2026-11-06 22:22:35 +01:00
1 parent 7c335c7ed2
commit 5e62e143b6
11 files changed
+286 -37

No files matched your search

+37 -5
View File
@@ -180,6 +180,7 @@ which edit their variables. `createTfvarsStore(pool)` takes a `pg` pool and appl
| `tf_modules` | `name`, `root`, the folder of the Terraform code, `description` and `configurator_url` |
| `tf_instances` | `module`, `name` and `state_schema`, the schema of the instance's state in the pg backend, unique, and `created` |
| `tf_variable_files` | `module`, `instance`, `name` (`*.tfvars.json`), `content` and `previous`, the object it replaced, as `jsonb`, and `updated` |
| `tf_variable_revisions` | `module`, `instance`, `revision`, numbered from 1 for each instance, `files`, all its files after a write as a `jsonb` object by name, `schema`, the schema version of their layout or null, `producer` and `saved` |
Names of modules and instances are `TF_NAME_PATTERN`, of variable files `TFVARS_FILE_PATTERN`,
of state schemas `STATE_SCHEMA_PATTERN`.
@@ -187,11 +188,42 @@ of state schemas `STATE_SCHEMA_PATTERN`.
- `modules.list()`, `modules.put(module)`, which creates or changes, and `modules.delete(name)`.
- `instances.list(module)`, `instances.create(module, name, stateSchema)` and
`instances.delete(module, name)`, which deletes its variable files too.
- `variables(module, instance)`: `read()` answers the files, their sizes and times and the
version, `versionOf` the files, the name and the SHA-256 of each in name order. `write(version,
contents)` writes files given by name as JSON text and `remove(version, name)` deletes one; both
lock the table, compare the version and change in one transaction, and answer `false`, changing
nothing, when the files changed since the version.
- `variables(module, instance)`: `read()` answers the files, their sizes and times, the version,
`versionOf` the files, the name and the SHA-256 of each in name order, and the newest revision.
`write(version, contents, meta)` writes files given by name as JSON text and `remove(version,
name, meta)` deletes one; both lock the table, compare the version, change and record all files
as the next revision with `meta`, `{ schema, producer }`, in one transaction, and answer
`false`, changing nothing, when the files changed since the version. A write of no file records
no revision. `revisions()` lists the revisions, newest first, without their files, and
`revision(n)` answers one with its files, or `null`.
Every revision is kept. The files of an instance without any revision, as those written before
revisions existed, are recorded as its revision 1, of the producer `unknown` and no schema, when
the store is first used.
### Purging revisions
Revisions are removed by hand, with `psql` connected to the database of the store as the owner of
its tables, in the schema the applications use (`SET search_path TO <schema>;` when it is not the
default). Each statement removes the revisions of one instance, here `router`/`platform`:
```sql
-- All revisions but the newest.
DELETE FROM tf_variable_revisions
WHERE module = 'router' AND instance = 'platform'
AND revision < (SELECT max(revision) FROM tf_variable_revisions WHERE module = 'router' AND instance = 'platform');
-- The revisions before revision 10.
DELETE FROM tf_variable_revisions WHERE module = 'router' AND instance = 'platform' AND revision < 10;
-- All revisions of the instance.
DELETE FROM tf_variable_revisions WHERE module = 'router' AND instance = 'platform';
```
Leaving out `AND instance = ...` applies a statement to every instance of the module. The next
write numbers its revision after the newest one left. An instance whose revisions are all removed
gets its current files back as revision 1, of the producer `unknown` and no schema, when the store
is next first used, so its schema is unknown until the next write by its configurator.
A change the tables refuse throws `HttpError`: 409 for a name or a state schema in use and for a
module that has instances, 404 for a module or an instance that does not exist, 400 for a name or