From 5236ad17c00267b0ccd07d59add69922ea499929 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 13 Aug 2026 07:26:10 +0000 Subject: [PATCH] =?UTF-8?q?feat(sql-editor):=20add=20schema=20history=20sa?= =?UTF-8?q?mple=20for=20table=20v1=E2=80=A6vN?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bookmark walkthrough: CREATE TABLE, ADD email + index, ADD phone + view, with a playbook cell that says to Snapshot after each step and inspect fox_hist_customers in History (growth, column mutations, Revert). Co-authored-by: huy.phan9 --- .../src/frontend/lib/sqlEditorSamples.test.ts | 15 ++++++++ apps/web/src/frontend/lib/sqlEditorSamples.ts | 38 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/apps/web/src/frontend/lib/sqlEditorSamples.test.ts b/apps/web/src/frontend/lib/sqlEditorSamples.test.ts index b7981da6..5cb06e4b 100644 --- a/apps/web/src/frontend/lib/sqlEditorSamples.test.ts +++ b/apps/web/src/frontend/lib/sqlEditorSamples.test.ts @@ -129,6 +129,21 @@ describe('SQL Editor sample bookmarks', () => { expect(again.result.rows).toEqual(result.rows); }); + it('schema history sample splits into one playbook cell plus per-version SQL', () => { + const sample = SQL_EDITOR_SAMPLE_BOOKMARKS.find((s) => s.id === 'sample-schema-history-table'); + expect(sample).toBeTruthy(); + const stmts = splitSqlStatements(sample!.sql); + expect(stmts.filter((s) => s.kind === 'js')).toHaveLength(1); + const sql = stmts.filter((s) => s.kind === 'sql'); + expect(sql.length).toBeGreaterThanOrEqual(6); + expect(sql.some((s) => /CREATE TABLE fox_hist_customers/i.test(s.text))).toBe(true); + expect(sql.some((s) => /ADD COLUMN email/i.test(s.text))).toBe(true); + expect(sql.some((s) => /ADD COLUMN phone/i.test(s.text))).toBe(true); + expect(sql.some((s) => /CREATE VIEW fox_hist_v_customers/i.test(s.text))).toBe(true); + expect(sample!.sql).toMatch(/Snapshot/i); + expect(sample!.sql).toMatch(/Revert/i); + }); + it('runs the lodash aggregate sample against a synthetic prior grid', async () => { const sample = SQL_EDITOR_SAMPLE_BOOKMARKS.find((s) => s.id === 'sample-js-lodash-aggregate'); expect(sample).toBeTruthy(); diff --git a/apps/web/src/frontend/lib/sqlEditorSamples.ts b/apps/web/src/frontend/lib/sqlEditorSamples.ts index d0b83725..07a93eaf 100644 --- a/apps/web/src/frontend/lib/sqlEditorSamples.ts +++ b/apps/web/src/frontend/lib/sqlEditorSamples.ts @@ -419,6 +419,44 @@ return [{ runtime: 'node', }]; -- @end +`, + }, + { + id: 'sample-schema-history-table', + title: '★ Sample · Schema history (table v1…vN)', + sql: `-- WRITES — Safe mode OFF. SQLite, Postgres, or MySQL. +-- Play ONE SQL cell at a time (▶ on the strip), then Compare Schema → Snapshot +-- target. After v3, open History and click fox_hist_customers. + +-- @js +return [ + { step: 'prep', do: 'Safe mode OFF. Check a SQLite (or Postgres) credential.' }, + { step: 'v1', do: 'Play CREATE TABLE, then Schema Sync → Snapshot target.' }, + { step: 'v2', do: 'Play ADD email + CREATE INDEX, Snapshot. Inspector: email ADD.' }, + { step: 'v3', do: 'Play ADD phone + CREATE VIEW, Snapshot. Growth shows 3 cols.' }, + { step: 'history', do: 'History → click fox_hist_customers → v1…vN, Revert on v1.' }, +]; +-- @end + +DROP VIEW IF EXISTS fox_hist_v_customers; + +DROP TABLE IF EXISTS fox_hist_customers; + +-- v1 · initial table (id, name). Snapshot after this cell. +CREATE TABLE fox_hist_customers ( + id INTEGER PRIMARY KEY, + name VARCHAR(100) NOT NULL +); + +-- v2 · email appears. Snapshot after the index cell. +ALTER TABLE fox_hist_customers ADD COLUMN email VARCHAR(100); + +CREATE INDEX fox_hist_customers_email ON fox_hist_customers (email); + +-- v3 · phone + a view (enable Views in History if needed). Snapshot after the view. +ALTER TABLE fox_hist_customers ADD COLUMN phone VARCHAR(20); + +CREATE VIEW fox_hist_v_customers AS SELECT id, name, email FROM fox_hist_customers; `, }, {