feat: persist and dispatch client command input
This commit is contained in:
@@ -13,7 +13,10 @@ type migration struct {
|
||||
sql string
|
||||
}
|
||||
|
||||
var migrations = []migration{{version: 1, sql: schemaV1}}
|
||||
var migrations = []migration{
|
||||
{version: 1, sql: schemaV1},
|
||||
{version: 2, sql: schemaV2},
|
||||
}
|
||||
|
||||
func applyMigrations(ctx context.Context, db *sql.DB) error {
|
||||
if _, err := db.ExecContext(ctx, `CREATE TABLE IF NOT EXISTS schema_migrations (
|
||||
@@ -113,3 +116,19 @@ CREATE TABLE command_tombstones (
|
||||
) STRICT;
|
||||
CREATE INDEX tombstones_fifo ON command_tombstones(acknowledged_at, issue_uuid);
|
||||
`
|
||||
|
||||
// schemaV2 adds the immutable execution specification retained with every
|
||||
// accepted dispatch. Keeping it in its own table lets old commands created by
|
||||
// early development builds (which have no specification) remain readable and
|
||||
// makes the payload's quota charge independently auditable.
|
||||
const schemaV2 = `
|
||||
CREATE TABLE command_specs (
|
||||
issue_uuid BLOB PRIMARY KEY REFERENCES commands(issue_uuid) ON DELETE CASCADE CHECK(length(issue_uuid) = 16),
|
||||
raw_bytes INTEGER NOT NULL CHECK(raw_bytes > 0),
|
||||
stored_bytes INTEGER NOT NULL CHECK(stored_bytes > 0),
|
||||
compression INTEGER NOT NULL CHECK(compression = 2),
|
||||
payload BLOB NOT NULL,
|
||||
payload_sha256 BLOB NOT NULL CHECK(length(payload_sha256) = 32),
|
||||
charged_bytes INTEGER NOT NULL CHECK(charged_bytes > 0)
|
||||
) STRICT, WITHOUT ROWID;
|
||||
`
|
||||
|
||||
Reference in New Issue
Block a user