|
| 1 | +# Storage Rules |
| 2 | + |
| 3 | +Read this file before changing SQLite, PostgreSQL, CockroachDB, DuckDB, archive |
| 4 | +resync, or storage queries. |
| 5 | + |
| 6 | +## SQLite Archive |
| 7 | + |
| 8 | +SQLite is the persistent archive. Never delete, drop, truncate, or recreate it |
| 9 | +to handle a data-version change. |
| 10 | + |
| 11 | +Use non-destructive schema migrations such as `ALTER TABLE` and `UPDATE`. A |
| 12 | +parser change that needs a full resync must build a fresh database, sync source |
| 13 | +files, copy orphaned sessions from the old database, and swap the files |
| 14 | +atomically. Preserve sessions even when their source files no longer exist. |
| 15 | + |
| 16 | +## Backend Parity |
| 17 | + |
| 18 | +- Keep observable behavior and query shape aligned between SQLite and |
| 19 | + PostgreSQL/CockroachDB when practical. Match queries, indexes, aggregations, |
| 20 | + filters, and ordering unless a documented constraint requires a difference. |
| 21 | +- Do not fix correctness or performance in only one primary backend unless the |
| 22 | + user limits the task to that backend. If implementations must differ, |
| 23 | + explain why and preserve the same behavior. |
| 24 | +- DuckDB is a derived mirror and is not part of this parity rule. |
| 25 | + |
| 26 | +## DuckDB Mirror |
| 27 | + |
| 28 | +- Treat DuckDB as a disposable read mirror of SQLite, never as a system of |
| 29 | + record. Deleting the mirror must lose nothing. |
| 30 | +- Do not add in-place mirror migrations. A schema or source-data version change |
| 31 | + must bump `internal/duckdb.SchemaVersion`, rebuild a fresh file, validate |
| 32 | + it, and swap it atomically. Do not add `ALTER` migrations, version-bridging |
| 33 | + reads, or compatibility shims for old mirrors. |
| 34 | +- Store every DuckDB push cursor and version in the mirror's `sync_metadata`. |
| 35 | + Never store DuckDB sync state in SQLite. |
| 36 | +- Replace whole sessions during incremental updates and gate them with |
| 37 | + per-session fingerprints. Do not add per-table, per-column, or diff-based |
| 38 | + updates. |
| 39 | +- Keep Quack read-only. `duckdb push` writes the local mirror; it never writes |
| 40 | + to a remote DuckDB service. |
| 41 | +- Replace a file only after identifying it as an agentsview DuckDB mirror. Fail |
| 42 | + closed for unknown files. |
| 43 | + |
| 44 | +## PostgreSQL Integration Tests |
| 45 | + |
| 46 | +Run PostgreSQL integration tests only against a dedicated test database. The |
| 47 | +tests create and drop the `agentsview` schema. |
| 48 | + |
| 49 | +Use `make test-postgres` to start the test container and run the suite. It |
| 50 | +leaves the container running. If you started that container, use |
| 51 | +`make postgres-down` when it is no longer needed. |
| 52 | + |
| 53 | +To use an existing dedicated instance, run: |
| 54 | + |
| 55 | +```bash |
| 56 | +TEST_PG_URL="postgres://user:pass@host:5432/dbname?sslmode=disable" \ |
| 57 | + CGO_ENABLED=1 go test -tags "fts5,pgtest" ./internal/postgres/... -v |
| 58 | +``` |
0 commit comments