ingraph 0.1.0

A declaration-driven indexing framework: records and nodes are written as Rust types, and the storage rows, the dataflow between them and the GraphQL query surface are emitted from the declaration.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
//! WHAT A COMPOSITE UNIQUE CREATES — one `CREATE UNIQUE INDEX` per constraint, over the columns its
//! entries resolve to, named by the ENTRIES and filled by the LEAVES.
//!
//! A suite of its own beside [`super::unique_tests`], for the reason that suite gives for sitting
//! beside [`super::index_tests`]: what is asserted here is ONE declaration's effect on the schema —
//! [`Table::with_composite_uniques`] — held apart from the single-column word's so a change to
//! either stays visible.
//!
//! # The three claims, and why each needs its own fixture
//!
//! | fixture | what only it can show |
//! |---|---|
//! | `Scene`, FLAT | several constraints on one table, the authored column ORDER, and the ONE-entry form |
//! | `Clip`, SHAPED | a CITIZEN fanning to its VALUE leaves, with the derived pair excluded |
//! | `mod live` | that the engine enforces the TUPLE — a row differing in one column is ADMITTED |
//!
//! The live suite carries the claim no rendering can make, and it is not *a unique index exists*:
//! [`super::unique_tests`] already proves that for one column. It is that the constraint is over the
//! TUPLE — `(media, track, index)` refuses a repeat of all three and takes a row that differs in any
//! one of them — which is the whole difference between this declaration and three single-column
//! ones, and is invisible in the statement text.
//!
//! # The DERIVED leaves are the load-bearing exclusion
//!
//! `span: MediaTimeRange` spans six columns and FOUR of them are the value. The golden below names
//! exactly those four, and the two it omits are the reason: `span_start_nanos` and `span_end_nanos`
//! are `NULL` past the nanosecond ceiling, `NULL`s do not collide in a SQL unique index, and a
//! constraint that named them would admit twice the very pair the value columns call equal. See
//! [`CompositeUnique`], where the law and this argument are written down.
//!
//! # What was MEASURED, and what was only RENDERED
//!
//! [`super::unique_tests`]'s own posture, unchanged: SQLite is put to an engine, PostgreSQL and
//! MySQL are RENDERED, this repository provisioning no server.

#![cfg(any(feature = "sqlite", feature = "postgres", feature = "mysql"))]

use crate::{
  Column, CompositeUnique, Describe, FieldName, RecordAddress, Table, TypeVisitor,
  query::sql::Create,
};

/// A record with a NATURAL KEY its address is not — three columns that identify a scene within its
/// media, beside a `run` pair that identifies the same row a second way.
///
/// Two constraints rather than one, because a single one could not show that each is named and
/// rendered independently; and `checksum` is a THIRD, one entry wide, which is the form the
/// per-database road exists for — a constraint on THIS dialect alone, which the field marker
/// (speaking to every declared database) cannot say.
struct Scene;

const SCENE: RecordAddress = RecordAddress::new(FieldName::new("scene"), &[FieldName::new("id")]);

/// The constraints, in the order the declaration wrote them — which is the order they render in.
///
/// `(media, track, index)` and `(run, ordinal)` are two natural keys of one row. The third names one
/// column, and it is legal: see [`CompositeUnique::new`], where arity one is admitted and the reason
/// is that this road is per-database where the field marker is not.
const COMPOSITES: &[CompositeUnique] = &[
  CompositeUnique::new(&[
    FieldName::new("media"),
    FieldName::new("track"),
    FieldName::new("index"),
  ]),
  CompositeUnique::new(&[FieldName::new("run"), FieldName::new("ordinal")]),
  CompositeUnique::new(&[FieldName::new("checksum")]),
];

#[cfg(feature = "sqlite")]
impl Describe<sqlx::Sqlite> for Scene {
  const BLUEPRINT: Table = Table::new(
    SCENE,
    &[
      Column::new(FieldName::new("id"), "INTEGER", false),
      Column::new(FieldName::new("media"), "INTEGER", false),
      Column::new(FieldName::new("track"), "INTEGER", false),
      Column::new(FieldName::new("index"), "INTEGER", false),
      Column::new(FieldName::new("run"), "INTEGER", false),
      Column::new(FieldName::new("ordinal"), "INTEGER", false),
      Column::new(FieldName::new("checksum"), "TEXT", false),
    ],
  )
  .with_composite_uniques(COMPOSITES);
}

#[cfg(feature = "postgres")]
impl Describe<sqlx::Postgres> for Scene {
  const BLUEPRINT: Table = Table::new(
    SCENE,
    &[
      Column::new(FieldName::new("id"), "bigint", false),
      Column::new(FieldName::new("media"), "bigint", false),
      Column::new(FieldName::new("track"), "bigint", false),
      Column::new(FieldName::new("index"), "bigint", false),
      Column::new(FieldName::new("run"), "bigint", false),
      Column::new(FieldName::new("ordinal"), "bigint", false),
      Column::new(FieldName::new("checksum"), "text", false),
    ],
  )
  .with_composite_uniques(COMPOSITES);
}

#[cfg(feature = "mysql")]
impl Describe<sqlx::MySql> for Scene {
  const BLUEPRINT: Table = Table::new(
    SCENE,
    &[
      Column::new(FieldName::new("id"), "BIGINT", false),
      Column::new(FieldName::new("media"), "BIGINT", false),
      Column::new(FieldName::new("track"), "BIGINT", false),
      Column::new(FieldName::new("index"), "BIGINT", false),
      Column::new(FieldName::new("run"), "BIGINT", false),
      Column::new(FieldName::new("ordinal"), "BIGINT", false),
      Column::new(FieldName::new("checksum"), "VARCHAR(255)", false),
    ],
  )
  .with_composite_uniques(COMPOSITES);
}

/// The walk a graph root writes, over the one node this suite declares.
fn type_iter<V>(v: &mut V) -> Result<(), V::Error>
where
  V: TypeVisitor,
  Scene: Describe<V::Db>,
{
  v.next_type::<Scene>()
}

/// Every statement the node renders for one dialect, in walk order.
fn schema<Db>() -> Vec<String>
where
  Db: super::AsyncSchemaDialect,
  Scene: Describe<Db>,
{
  let mut create = Create::<Db>::new();
  type_iter(&mut create).expect("this descriptor renders");
  create.statements().to_vec()
}

/// **SQLite: THREE CONSTRAINTS, EACH NAMED BY ITS ENTRIES AND FILLED IN THE AUTHORED ORDER.**
///
/// The names are `__ig_<table>_<entry>_<entry>…` — [`super::index_tests`]'s rule spent over several
/// entries rather than one — and the column lists are the entries as written: `(media, track,
/// index)` and not any sorted or canonicalised permutation of them, which is what makes the
/// declaration's order the structure's order.
///
/// The third statement is the ONE-ENTRY form, and its name is exactly `__ig_scene_checksum` — the
/// name a field-level `unique` on `checksum` would derive. That is not an accident: it is the collision
/// [`Table::with_composite_uniques`] refuses the pair by, asserted here as the fact the refusal
/// rests on.
#[cfg(feature = "sqlite")]
#[test]
fn sqlite_renders_one_statement_per_composite_in_the_authored_order() {
  assert_eq!(
    schema::<sqlx::Sqlite>(),
    [
      r#"CREATE TABLE IF NOT EXISTS "scene" ("id" INTEGER NOT NULL, "media" INTEGER NOT NULL, "track" INTEGER NOT NULL, "index" INTEGER NOT NULL, "run" INTEGER NOT NULL, "ordinal" INTEGER NOT NULL, "checksum" TEXT NOT NULL, PRIMARY KEY ("id"))"#,
      r#"CREATE UNIQUE INDEX IF NOT EXISTS "__ig_scene_media_track_index" ON "scene" ("media", "track", "index")"#,
      r#"CREATE UNIQUE INDEX IF NOT EXISTS "__ig_scene_run_ordinal" ON "scene" ("run", "ordinal")"#,
      r#"CREATE UNIQUE INDEX IF NOT EXISTS "__ig_scene_checksum" ON "scene" ("checksum")"#,
    ]
  );
}

/// PostgreSQL: the same four statements, in this dialect's own type words.
#[cfg(feature = "postgres")]
#[test]
fn postgres_renders_one_statement_per_composite_in_the_authored_order() {
  assert_eq!(
    schema::<sqlx::Postgres>(),
    [
      r#"CREATE TABLE IF NOT EXISTS "scene" ("id" bigint NOT NULL, "media" bigint NOT NULL, "track" bigint NOT NULL, "index" bigint NOT NULL, "run" bigint NOT NULL, "ordinal" bigint NOT NULL, "checksum" text NOT NULL, PRIMARY KEY ("id"))"#,
      r#"CREATE UNIQUE INDEX IF NOT EXISTS "__ig_scene_media_track_index" ON "scene" ("media", "track", "index")"#,
      r#"CREATE UNIQUE INDEX IF NOT EXISTS "__ig_scene_run_ordinal" ON "scene" ("run", "ordinal")"#,
      r#"CREATE UNIQUE INDEX IF NOT EXISTS "__ig_scene_checksum" ON "scene" ("checksum")"#,
    ]
  );
}

/// MySQL: the backtick bracket, and the same posture [`super::index_tests`] records — this dialect's
/// own `CREATE UNIQUE INDEX` takes no `IF NOT EXISTS`, so this golden is what MySQL is SENT and not
/// what an engine answered.
#[cfg(feature = "mysql")]
#[test]
fn mysql_renders_one_statement_per_composite_in_the_authored_order() {
  assert_eq!(
    schema::<sqlx::MySql>(),
    [
      "CREATE TABLE IF NOT EXISTS `scene` (`id` BIGINT NOT NULL, `media` BIGINT NOT NULL, \
       `track` BIGINT NOT NULL, `index` BIGINT NOT NULL, `run` BIGINT NOT NULL, \
       `ordinal` BIGINT NOT NULL, `checksum` VARCHAR(255) NOT NULL, PRIMARY KEY (`id`))",
      "CREATE UNIQUE INDEX IF NOT EXISTS `__ig_scene_media_track_index` ON `scene` \
       (`media`, `track`, `index`)",
      "CREATE UNIQUE INDEX IF NOT EXISTS `__ig_scene_run_ordinal` ON `scene` (`run`, `ordinal`)",
      "CREATE UNIQUE INDEX IF NOT EXISTS `__ig_scene_checksum` ON `scene` (`checksum`)",
    ]
  );
}

/// **THE AUTHORED ORDER IS THE STRUCTURE'S ORDER** — the same three columns declared the other way
/// round are a DIFFERENT constraint, with a different name, and neither collides with the other.
///
/// It is the property [`CompositeUnique`] states and the one a reader is most likely to assume away:
/// a composite index answers a seek by a leading PREFIX of its columns, so `(media, track)` is a
/// question `__ig_scene_media_track_index` answers and `__ig_scene_index_track_media` does not.
#[cfg(feature = "sqlite")]
#[test]
fn the_same_entries_in_another_order_are_another_constraint() {
  const REVERSED: Table = Table::new(
    SCENE,
    &[
      Column::new(FieldName::new("id"), "INTEGER", false),
      Column::new(FieldName::new("media"), "INTEGER", false),
      Column::new(FieldName::new("track"), "INTEGER", false),
      Column::new(FieldName::new("index"), "INTEGER", false),
    ],
  )
  .with_composite_uniques(&[
    CompositeUnique::new(&[
      FieldName::new("media"),
      FieldName::new("track"),
      FieldName::new("index"),
    ]),
    CompositeUnique::new(&[
      FieldName::new("index"),
      FieldName::new("track"),
      FieldName::new("media"),
    ]),
  ]);

  assert_eq!(
    REVERSED
      .create::<sqlx::Sqlite>()
      .expect("this descriptor renders")[1..],
    [
      r#"CREATE UNIQUE INDEX IF NOT EXISTS "__ig_scene_media_track_index" ON "scene" ("media", "track", "index")"#,
      r#"CREATE UNIQUE INDEX IF NOT EXISTS "__ig_scene_index_track_media" ON "scene" ("index", "track", "media")"#,
    ]
  );
}

/// **A DESCRIPTOR THAT DECLARES NO COMPOSITE RENDERS NONE** — [`super::unique_tests`]'s own claim,
/// pinned over [`Table::composite_uniques`].
#[cfg(feature = "sqlite")]
#[test]
fn a_table_with_no_composite_renders_no_composite_statement() {
  const BARE: Table = Table::new(
    SCENE,
    &[Column::new(FieldName::new("id"), "INTEGER", false)],
  );

  assert!(BARE.composite_uniques().is_empty());
  assert_eq!(
    BARE
      .create::<sqlx::Sqlite>()
      .expect("this descriptor renders"),
    [r#"CREATE TABLE IF NOT EXISTS "scene" ("id" INTEGER NOT NULL, PRIMARY KEY ("id"))"#]
  );
}

/// A CITIZEN in a composite constraint — the fan, and the two leaves it leaves out.
#[cfg(all(feature = "mediatime", feature = "sqlite"))]
mod citizen {
  use crate::{
    ColumnName, ColumnShape, CompositeUnique, Describe, FieldName, RecordAddress, StoredAs, Table,
  };

  /// A record whose natural key is a plain column AND a shaped citizen — the case a composite over
  /// column NAMES could not express, since `span` is one entry of the declaration and six columns of
  /// the table.
  struct Clip;

  const CLIP: RecordAddress = RecordAddress::new(FieldName::new("clip"), &[FieldName::new("id")]);

  /// The row's own list, as a `SqlQuery<Db>` binding publishes it. `span` spans six columns and
  /// [`crate::shape`] reads that width off the type rather than restating it.
  const CLIP_COLUMNS: &[ColumnShape] = &[
    ColumnShape::Plain(ColumnName::new("id")),
    ColumnShape::Plain(ColumnName::new("media")),
    crate::shape::<crate::MediaTimeRange>(ColumnName::new("span")),
  ];

  impl Describe<sqlx::Sqlite> for Clip {
    const BLUEPRINT: Table = Table::shaped(
      CLIP,
      CLIP_COLUMNS,
      &[
        <i64 as StoredAs<sqlx::Sqlite>>::WORDS,
        <i64 as StoredAs<sqlx::Sqlite>>::WORDS,
        <crate::MediaTimeRange as StoredAs<sqlx::Sqlite>>::WORDS,
      ],
      &[false, false, false],
    )
    .with_composite_uniques(&[CompositeUnique::new(&[
      FieldName::new("media"),
      FieldName::new("span"),
    ])]);
  }

  /// **A CITIZEN FANS TO ITS VALUE LEAVES, AND THE DERIVED PAIR IS EXCLUDED.**
  ///
  /// Six columns are declared under `span` and FOUR are named by the constraint. The two omitted are
  /// `span_start_nanos` and `span_end_nanos` — [`ColumnShape::Nullable`], the derived index leaves —
  /// and the omission is the structural-judgment law rather than a width this test chose: see
  /// [`CompositeUnique`], where a `NULL` that does not collide is what including them would cost.
  ///
  /// The NAME carries `span` once, where the column list carries four of its leaves. That is the
  /// split stated at `create_composite_unique`: entries spell the name, leaves fill the statement —
  /// and a name built from the leaves instead would run past PostgreSQL's 63-byte identifier limit
  /// on any realistic citizen, where the server truncates rather than refusing.
  #[test]
  fn a_citizen_in_a_composite_constrains_its_value_leaves_alone() {
    let statements = <Clip as Describe<sqlx::Sqlite>>::BLUEPRINT
      .create::<sqlx::Sqlite>()
      .expect("this descriptor renders");

    assert_eq!(
      statements[1],
      r#"CREATE UNIQUE INDEX IF NOT EXISTS "__ig_clip_media_span" ON "clip" ("media", "span_start_pts", "span_end_pts", "span_timebase_num", "span_timebase_den")"#
    );
    assert!(
      !statements[1].contains("nanos"),
      "the derived leaves are named by the CREATE TABLE and by no constraint: {}",
      statements[1]
    );
    assert!(
      statements[0].contains(r#""span_start_nanos""#),
      "and they are still DECLARED, which is what makes their absence above a choice: {}",
      statements[0]
    );
  }
}

/// The half no statement's text can show, put to a real engine.
#[cfg(feature = "sqlite")]
mod live {
  use super::type_iter;
  use crate::query::sql::{Create, SqlSchemaError};

  /// An EMPTY in-memory database, on ONE connection — [`super::super::index_tests::live`]'s own
  /// reason for a bare connection over a pool.
  async fn empty() -> sqlx::sqlite::SqliteConnection {
    use sqlx::Connection as _;

    sqlx::sqlite::SqliteConnection::connect("sqlite::memory:")
      .await
      .expect("an in-memory database")
  }

  /// Create this suite's schema on `db`.
  async fn create(db: &mut sqlx::sqlite::SqliteConnection) -> Result<(), SqlSchemaError> {
    let mut create = Create::<sqlx::Sqlite>::new();
    type_iter(&mut create)?;
    create.run(db).await
  }

  /// Every index SQLite holds for `scene`, in name order, with whether the catalogue calls it
  /// UNIQUE, and how many columns it is over — the third being what only a COMPOSITE has, and what
  /// says the statement became a multi-column constraint rather than a one-column one.
  async fn index_widths(db: &mut sqlx::sqlite::SqliteConnection) -> Vec<(String, bool, i64)> {
    let listed = sqlx::query_as::<_, (String, i64)>(
      r#"SELECT name, "unique" FROM pragma_index_list('scene') ORDER BY name"#,
    )
    .fetch_all(&mut *db)
    .await
    .expect("the catalogue answers");

    let mut out = Vec::new();
    for (name, unique) in listed {
      let width = sqlx::query_scalar::<_, i64>("SELECT count(*) FROM pragma_index_info(?)")
        .bind(&name)
        .fetch_one(&mut *db)
        .await
        .expect("the catalogue answers");
      out.push((name, unique != 0, width));
    }
    out
  }

  /// One row, written with a RAW statement — [`super::super::unique_tests::live`]'s own posture and
  /// its reason: what is measured here is the DDL's constraint reaching the engine, not the write
  /// lane's binding machinery.
  /// The two natural keys arrive as TUPLES rather than as six positions, and the grouping is the
  /// suite's subject made visible at every call: `(media, track, index)` is one constraint and
  /// `(run, ordinal)` is the other, so a reader of a call below can see which columns a row is
  /// about to collide on.
  async fn insert_row(
    db: &mut sqlx::sqlite::SqliteConnection,
    id: i64,
    scene: (i64, i64, i64),
    run: (i64, i64),
    checksum: &str,
  ) -> Result<sqlx::sqlite::SqliteQueryResult, sqlx::Error> {
    sqlx::query(
      r#"INSERT INTO "scene" ("id", "media", "track", "index", "run", "ordinal", "checksum")
         VALUES (?, ?, ?, ?, ?, ?, ?)"#,
    )
    .bind(id)
    .bind(scene.0)
    .bind(scene.1)
    .bind(scene.2)
    .bind(run.0)
    .bind(run.1)
    .bind(checksum)
    .execute(db)
    .await
  }

  /// **EACH COMPOSITE BECAME A UNIQUE INDEX OVER THE COLUMNS IT NAMED** — the claim no rendering
  /// assertion can make, since the TEXT of a `CREATE UNIQUE INDEX` could be sent to an engine that
  /// silently kept only its first column.
  #[tokio::test]
  async fn the_engine_holds_each_composite_over_every_column_it_names() {
    let mut db = empty().await;
    create(&mut db).await.expect("an empty database takes it");

    assert_eq!(
      index_widths(&mut db).await,
      [
        ("__ig_scene_checksum".to_owned(), true, 1),
        ("__ig_scene_media_track_index".to_owned(), true, 3),
        ("__ig_scene_run_ordinal".to_owned(), true, 2),
      ]
    );
  }

  /// **A SECOND CREATE IS THE SAME CREATE** — [`super::super::unique_tests::live`]'s own claim, over
  /// a schema whose constraints are composite this time.
  #[tokio::test]
  async fn a_second_create_adds_no_second_composite_index() {
    let mut db = empty().await;
    create(&mut db).await.expect("the first create lands");
    create(&mut db).await.expect("and so does the second");

    assert_eq!(
      index_widths(&mut db).await,
      [
        ("__ig_scene_checksum".to_owned(), true, 1),
        ("__ig_scene_media_track_index".to_owned(), true, 3),
        ("__ig_scene_run_ordinal".to_owned(), true, 2),
      ]
    );
  }

  /// **A REPEAT OF THE WHOLE TUPLE REFUSES BY NAME, AND A ROW DIFFERING IN ONE COLUMN DOES NOT.**
  ///
  /// This is the suite's load-bearing live claim and the one thing a single-column constraint cannot
  /// do: the two rows below share `media` and `track` and differ in `index`, which three separate
  /// `unique` columns would have refused and this constraint admits. Then the exact triple repeats
  /// and the engine refuses it, naming all three columns in its own sentence.
  #[tokio::test]
  async fn a_repeated_tuple_refuses_and_a_row_differing_in_one_column_does_not() {
    let mut db = empty().await;
    create(&mut db).await.expect("an empty database takes it");
    insert_row(&mut db, 1, (7, 2, 0), (100, 0), "sha256:aaa")
      .await
      .expect("the first row lands");

    // SHARING two of the three, which is what makes this a tuple constraint rather than three.
    insert_row(&mut db, 2, (7, 2, 1), (100, 1), "sha256:bbb")
      .await
      .expect("a row differing in one column of the tuple is a different scene");

    let refused = insert_row(&mut db, 3, (7, 2, 0), (101, 0), "sha256:ccc").await;
    let Err(sqlx::Error::Database(why)) = refused else {
      panic!("a repeated tuple is the engine's own refusal, not a panic: {refused:?}");
    };
    assert!(
      why.is_unique_violation(),
      "the driver names it as one: {why}"
    );
    for column in ["scene.media", "scene.track", "scene.index"] {
      assert!(
        why.message().contains(column),
        "the engine's own sentence names every column of the constraint, and not this one: {why}"
      );
    }
    assert_eq!(
      sqlx::query_scalar::<_, i64>(r#"SELECT count(*) FROM "scene""#)
        .fetch_one(&mut db)
        .await
        .expect("the table is there"),
      2,
      "and the refused row was not written"
    );
  }

  /// **THE SECOND CONSTRAINT IS ITS OWN** — a row colliding on `(run, ordinal)` alone is refused,
  /// with the first constraint's columns all distinct.
  ///
  /// Two constraints on one table could be one constraint the renderer emitted twice, and nothing in
  /// the statement text would say otherwise. This is what says they are two.
  #[tokio::test]
  async fn the_second_composite_refuses_on_its_own_columns() {
    let mut db = empty().await;
    create(&mut db).await.expect("an empty database takes it");
    insert_row(&mut db, 1, (7, 2, 0), (100, 0), "sha256:aaa")
      .await
      .expect("the first row lands");

    let refused = insert_row(&mut db, 2, (8, 3, 1), (100, 0), "sha256:bbb").await;
    let Err(sqlx::Error::Database(why)) = refused else {
      panic!("a repeated tuple is the engine's own refusal, not a panic: {refused:?}");
    };
    assert!(
      why.is_unique_violation(),
      "the driver names it as one: {why}"
    );
    assert!(
      why.message().contains("scene.run") && why.message().contains("scene.ordinal"),
      "the SECOND constraint's own columns are what the engine names: {why}"
    );
  }
}