Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/architecture/provisioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
2 changes: 1 addition & 1 deletion docs/architecture/verification.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
9 changes: 9 additions & 0 deletions internal/provision/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions sql/semiplot_groups.sql
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
Loading