Skip to content
Draft
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
15 changes: 15 additions & 0 deletions apps/web/src/frontend/lib/sqlEditorSamples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
38 changes: 38 additions & 0 deletions apps/web/src/frontend/lib/sqlEditorSamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
`,
},
{
Expand Down
Loading