Skip to content

Commit 5b83098

Browse files
committed
test(driver-sql): read the issued autonumber back from the stored row on every dialect cell
The live mysql cell failed every case, controls included: knex does not support `.returning()` on MySQL, so `SqlDriver.create` hands back the insert id (measured `0` on a live MySQL 8.0.46) instead of the row, and the pin asserted `create`'s return value. The row itself was stored with the right number. The pin now creates with an id it chose and reads the autonumber back through the driver's `findOne`, a reading every cell can make. Claude-Session: https://claude.ai/code/session_017xfMoEjKUuSh2xYB8sCozp Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7b7fcaf commit 5b83098

1 file changed

Lines changed: 25 additions & 10 deletions

File tree

‎packages/drivers/driver-sql/src/sql-driver-21163-autonumber-prefix-like-escape.test.ts‎

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,16 @@
3636
*
3737
* # What is asserted
3838
*
39-
* The issued value — the caller-visible answer — on a cold bootstrap over a
40-
* stored row, and on the create that follows a bypass write landing ABOVE a
41-
* warm counter. Per dialect cell: SQLite always runs; live Postgres and MySQL
39+
* The number the create issued, on a cold bootstrap over a stored row and on
40+
* the create that follows a bypass write landing ABOVE a warm counter — read
41+
* back from the stored row through the driver's own `findOne`, by an id the
42+
* test chose. Not from `create`'s return value: on MySQL that is not the row.
43+
* Knex does not support `.returning()` there, so `create` hands back the insert
44+
* id (measured on a live MySQL 8.0.46: `0`, with the row stored correctly), and
45+
* an assertion on it fails every case, controls included, whatever the scan
46+
* does. The stored row is the one reading every cell can make.
47+
*
48+
* Per dialect cell: SQLite always runs; live Postgres and MySQL
4249
* run where provisioned (the `Temporal Conformance (live PG + MySQL)` job runs
4350
* this whole package against both) and are declared un-run otherwise. On those
4451
* two the backslash was already the default escape, so their cells pin that
@@ -109,6 +116,17 @@ function suite(cell: DialectCell) {
109116
);
110117
};
111118

119+
let seq = 0;
120+
121+
/** Create one row and answer the autonumber it was STORED with (see the header). */
122+
const issue = async (data: Record<string, unknown>): Promise<unknown> => {
123+
const id = `issued-${++seq}`;
124+
await driver.create(TABLE, { id, ...data });
125+
const row = await driver.findOne(TABLE, { where: { id } });
126+
expect(row, `row ${id} was not stored`).not.toBeNull();
127+
return row!.so_no;
128+
};
129+
112130
beforeEach(async () => {
113131
driver = new SqlDriver(cell.config());
114132
await reset();
@@ -126,31 +144,28 @@ function suite(cell: DialectCell) {
126144
await driver.initObjects([objectWith(c.format)]);
127145
await bypassInsert([c.render(7)]);
128146

129-
const created = await driver.create(TABLE, { title: 'first issued' });
130-
expect(created.so_no).toBe(c.render(8));
147+
expect(await issue({ title: 'first issued' })).toBe(c.render(8));
131148
});
132149

133150
it(`${c.label}: the #5495 re-seed moves a warm counter past rows a bypass write landed (${role})`, async () => {
134151
await driver.initObjects([objectWith(c.format)]);
135152

136153
// Warm the counter on an EMPTY table, so this test does not depend on
137154
// the cold scan above: there is nothing for the bootstrap to find.
138-
expect((await driver.create(TABLE, { title: 'warm' })).so_no).toBe(c.render(1));
155+
expect(await issue({ title: 'warm' })).toBe(c.render(1));
139156

140157
// Rows 2..30 land above the counter. Nothing tells the sequence.
141158
await bypassInsert(Array.from({ length: 29 }, (_, i) => c.render(i + 2)));
142159

143-
const created = await driver.create(TABLE, { title: 'after the seeds' });
144-
expect(created.so_no).toBe(c.render(31));
160+
expect(await issue({ title: 'after the seeds' })).toBe(c.render(31));
145161
});
146162
}
147163

148164
it('a `_` that arrives from DATA through `{field}` interpolation seeds from the stored MAX (red before the fix on SQLite)', async () => {
149165
await driver.initObjects([objectWith('{region}-{0000}')]);
150166
await bypassInsert(['north_east-0007'], 'north_east');
151167

152-
const created = await driver.create(TABLE, { region: 'north_east', title: 'first issued' });
153-
expect(created.so_no).toBe('north_east-0008');
168+
expect(await issue({ region: 'north_east', title: 'first issued' })).toBe('north_east-0008');
154169
});
155170
});
156171
}

0 commit comments

Comments
 (0)