diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 875b053..a9e7aa3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -200,7 +200,7 @@ jobs: # Every other step runs semiplot_register_new_pens() over an empty # public.trends, so its INSERT adds nothing. - - name: Register pens and probe the semiplot_tags constraints + - name: Register pens and probe the semiplot constraints env: PGHOST: localhost PGDATABASE: semiplot_dev @@ -244,6 +244,11 @@ jobs: RAISE EXCEPTION 'semiplot_tags accepted a NULL log_scale_on_start'; EXCEPTION WHEN not_null_violation THEN NULL; END; + BEGIN + INSERT INTO semiplot_groups (name, folded_on_start) VALUES ('ci group', NULL); + RAISE EXCEPTION 'semiplot_groups accepted a NULL folded_on_start'; + EXCEPTION WHEN not_null_violation THEN NULL; + END; END $$ SQL diff --git a/docs/architecture/provisioning.md b/docs/architecture/provisioning.md index 0bbc3c4..6980342 100644 --- a/docs/architecture/provisioning.md +++ b/docs/architecture/provisioning.md @@ -370,7 +370,7 @@ relation and runs after them, and `semiplot_meta.sql` runs last. | Table | Holds | | --- | --- | | `semiplot_tags` | One pen: `id` matching `trends.id`, `name`, `unit`, `format` as a .NET numeric format string the viewer applies and the server does not validate, `color` as `#RRGGBB`, `line_style` (0 interpolated, 1 stepped), `enabled_on_start`, the `scale_min_on_start`/`scale_max_on_start` pair that bounds the pen's own Y axis (both `NULL` means autoscale), and `log_scale_on_start`, the type of that axis: `false` is linear, `true` is log10. A column with the `_on_start` suffix holds a start value: what the pen opens with in a new window; for the scale pair and the log flag, also what the viewer's "Restore initial scale" returns to. Editing the pen on the chart changes the current view and never a start value, and a changed start value never changes a chart already open. Every other settings column is a live setting, which a running chart applies at its next catalogue read | -| `semiplot_groups` | A group name. `GENERATED ALWAYS AS IDENTITY` rather than `serial`, so `semiplot` needs no `USAGE` on a sequence to insert one | +| `semiplot_groups` | One group: `name`, and `folded_on_start`, a start value as in `semiplot_tags`: `true` opens the group folded to its header in the viewer's sidebar. A group the editor creates takes the default `false`. `id` is `GENERATED ALWAYS AS IDENTITY` rather than `serial`, so `semiplot` needs no `USAGE` on a sequence to insert one | | `semiplot_pen_groups` | Membership, `(pen_id, group_id)`. A pen may sit in several groups and in none: a pen with no row here is legal and the viewer shows it ungrouped | | `semiplot_markers` | One time marker the operator placed on the chart: `id` as `bigint GENERATED ALWAYS AS IDENTITY`, the moment `t`, and an optional `label` of 1 to 80 characters. An unlabelled marker stores `NULL`, and the `CHECK` refuses `''`. `t` is `timestamptz`, not the naive local wall-clock time of `trends.t`: the viewer places an exact UTC moment, and a naive local value is ambiguous in the autumn repeated hour. No index, because the viewer reads the whole table. Not partitioned and outside any retention, so a marker outlives the day partition it points into | | `semiplot_meta` | One row: `schema_version`. A `singleton boolean PRIMARY KEY DEFAULT true CHECK (singleton)` admits no second row, and the value is written by one `INSERT ... ON CONFLICT (singleton) DO UPDATE`, so a failure cannot leave the table empty and a re-run cannot leave two rows | diff --git a/docs/architecture/verification.md b/docs/architecture/verification.md index caf4baf..6df599e 100644 --- a/docs/architecture/verification.md +++ b/docs/architecture/verification.md @@ -58,7 +58,7 @@ container is `postgres:17-alpine` on port 5432. `Shellcheck the shell scripts` c | --- | --- | | `Provision the service container` | `site --database semiplot_dev --expected-major 17` exits 0 twice: the tuning path and the idempotency check | | `Require the listen_addresses delta` | `listen_addresses` still pending and `localhost` from `postgresql.auto.conf` in `pg_file_settings`. The container is never restarted, so these two prove `site` wrote the delta | -| `Register pens and probe the semiplot_tags constraints` | As `scada_writer`: a day partition and four `trends` rows over keys 0, 13 and 40. As `semiplot`: `semiplot_register_new_pens()` returns 3, then 0, and `semiplot_tags` reads `0 0 #4E79A7 f f,13 13 #F28E2B f f,40 40 #59A14F f f`. Then pen 0 takes the bounds (1, 10), the scale-pair `CHECK` refuses (5, `NULL`) and (5, 1) with `check_violation` (23514), and `log_scale_on_start = NULL` fails with `not_null_violation` (23502). The only place the function body runs over a non-empty archive | +| `Register pens and probe the semiplot constraints` | As `scada_writer`: a day partition and four `trends` rows over keys 0, 13 and 40. As `semiplot`: `semiplot_register_new_pens()` returns 3, then 0, and `semiplot_tags` reads `0 0 #4E79A7 f f,13 13 #F28E2B f f,40 40 #59A14F f f`. Then pen 0 takes the bounds (1, 10), the scale-pair `CHECK` refuses (5, `NULL`) and (5, 1) with `check_violation` (23514), and `log_scale_on_start = NULL` fails with `not_null_violation` (23502), as does a `semiplot_groups` row with `folded_on_start = NULL`. The only place the function body runs over a non-empty archive | | `Keep the password statements out of the server log` | Sets `log_statement = 'all'`, runs `site` again with a random `semiplot` password (the `ALTER ROLE ... PASSWORD` path), then `check-server-log.sh` with that password and `ci-writer` | | `Provision a PostgreSQL 14 container, where the REVOKE bites` | `bench --host 127.0.0.1 --port 15434 --database semiplot_dev --expected-major 14` against `postgres:14-alpine`, started with `log_statement=all`, `log_min_error_statement=error`, `log_min_duration_statement=0`, `log_min_duration_sample=0` and `log_transaction_sample_rate=1` | | `Keep the CREATE ROLE password statements out of the PostgreSQL 14 log` | `check-server-log.sh` over that container with `ci-writer` and `ci-plot` (the `CREATE ROLE ... PASSWORD` path) | diff --git a/internal/provision/schema_test.go b/internal/provision/schema_test.go index 531821e..591a744 100644 --- a/internal/provision/schema_test.go +++ b/internal/provision/schema_test.go @@ -94,6 +94,15 @@ func TestSemiplotGroupsUseAnIdentityColumn(t *testing.T) { } } +// the viewer names these columns in its own statements, the same contract as semiplot_tags. +// columnNamesOf reads the first table of a file, and semiplot_groups.sql creates semiplot_groups first +func TestSemiplotGroupsColumns(t *testing.T) { + want := []string{"id", "name", "folded_on_start"} + if got := columnNamesOf(semibase.SemiplotGroupsSQL); !slices.Equal(got, want) { + t.Errorf("semiplot_groups.sql declares columns %v, want %v", got, want) + } +} + // the viewer inserts a marker and reads its id back, so the id needs no sequence grant either func TestSemiplotMarkersUseAnIdentityColumn(t *testing.T) { statements := sqlStatementsOf(semibase.SemiplotMarkersSQL) diff --git a/sql/semiplot_groups.sql b/sql/semiplot_groups.sql index 070a6d8..27962e3 100644 --- a/sql/semiplot_groups.sql +++ b/sql/semiplot_groups.sql @@ -1,8 +1,9 @@ -- docs/architecture/provisioning.md#the-semiplot-configuration-schema CREATE TABLE IF NOT EXISTS semiplot_groups ( - id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY, - name text NOT NULL UNIQUE + id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + name text NOT NULL UNIQUE, + folded_on_start boolean NOT NULL DEFAULT false ); CREATE TABLE IF NOT EXISTS semiplot_pen_groups (