#!/usr/bin/env python3 """Rebuild the native deep-definition fixture on the canonical fresh schema. No old file is stamped as current. Only synthetic identity and one definition are inserted; the schema snapshot is the store's independently checked DDL. """ import json from pathlib import Path import re import sqlite3 import tempfile import zlib ROOT = Path(__file__).resolve().parent.parent version = int(re.search(r'pub const SCHEMA_VERSION: u32 = (\d+)', (ROOT / 'crates/cotton-store/src/schema/ddl.rs').read_text())[1]) schema = json.loads((ROOT / 'crates/cotton-store/tests/fixtures/schema-snapshot.json').read_text()) workspace = '11111111-1111-4111-8111-111111111111' now = '2026-10-01T09:00:00.000Z' payload = 'synthetic bottom' for _ in range(110): payload = {'next': payload} definition = dict(id='stack_probe', name='Stack probe', plural='Stack probes', builtin=False, columns=[dict(key='name', type='text')], title='name', slip=dict(title='name'), tile=dict(face='slip-list'), page=[dict(columns=['name'])], future_stack_payload=payload) with tempfile.TemporaryDirectory() as directory: path = Path(directory) / 'replica.db' db = sqlite3.connect(path) for kind in ['table', 'index', 'trigger', 'view']: for entry in schema: if entry['kind'] == kind: db.execute(entry['sql']) db.execute(f'PRAGMA user_version = {version}') db.execute('INSERT INTO _meta (only_one, workspace_id, owner_id, schema_version, device_id) VALUES (1, ?, ?, ?, ?)', (workspace, 'owner-synthetic', version, 'device:00000000000000000000000000')) db.execute('INSERT INTO cotton_workspaces (id, name, owner_user_id, created_at, kind, namespace) VALUES (?, ?, ?, ?, ?, ?)', (workspace, 'A synthetic life', 'owner-synthetic', now, 'personal', workspace)) db.execute('INSERT INTO cotton_table_definitions (id, workspace_id, definition, created_at, updated_at) VALUES (?, ?, ?, ?, ?)', ('stack_probe', workspace, json.dumps(definition, separators=(',', ':')), now, now)) db.commit() assert db.execute('PRAGMA integrity_check').fetchone()[0] == 'ok' db.close() (ROOT / 'apps/cotton/Tests/CottonKitTests/Fixtures/StackProbe.sqlite.zlib').write_bytes(zlib.compress(path.read_bytes(), 9)) print(f'StackProbe: fresh schema {version}, synthetic definition nested 110 levels')