From 6781f633bdd26d64b70fdd3d03a080dd394fa77a Mon Sep 17 00:00:00 2001 From: Diego Imbert Date: Thu, 26 Mar 2026 19:54:19 +0100 Subject: [PATCH] Revert "feat: add review drawer with YAML diff and SQL migration runner" This reverts commit 0a0deb5ddb7e88cd398f3908e325b029ccc05941. --- .../lib/components/DatatableSchemaDiff.svelte | 302 +++--------------- 1 file changed, 41 insertions(+), 261 deletions(-) diff --git a/frontend/src/lib/components/DatatableSchemaDiff.svelte b/frontend/src/lib/components/DatatableSchemaDiff.svelte index 69e657a958..8cfe81a774 100644 --- a/frontend/src/lib/components/DatatableSchemaDiff.svelte +++ b/frontend/src/lib/components/DatatableSchemaDiff.svelte @@ -6,13 +6,14 @@ } from '$lib/components/apps/components/display/dbtable/tableEditor' import { diffTableEditorValues, - type AlterTableValues, - makeAlterTableQueries + type AlterTableValues } from '$lib/components/apps/components/display/dbtable/queries/alterTable' import type { GetDatatableFullSchemaResponse } from '$lib/gen' + /** Full database schema: { schema_name: { table_name: TableEditorValues } } */ export type DatabaseSchema = Record> + /** Convert backend schema response to TableEditorValues format */ export function apiSchemaToEditorSchema( apiSchema: GetDatatableFullSchemaResponse ): DatabaseSchema { @@ -61,29 +62,34 @@ datatableName: string aheadChanges: TableDiff[] behindChanges: TableDiff[] - originalSchema: DatabaseSchema - parentSchema: DatabaseSchema - forkSchema: DatabaseSchema } + /** + * Diff two full database schemas, returning per-table diffs. + * Uses diffTableEditorValues for tables that exist in both. + */ export function diffDatabaseSchemas( original: DatabaseSchema, current: DatabaseSchema ): TableDiff[] { const diffs: TableDiff[] = [] + const allSchemas = new Set([...Object.keys(original), ...Object.keys(current)]) for (const schemaName of allSchemas) { const origTables = original[schemaName] ?? {} const currTables = current[schemaName] ?? {} const allTables = new Set([...Object.keys(origTables), ...Object.keys(currTables)]) + for (const tableName of allTables) { const origTable = origTables[tableName] const currTable = currTables[tableName] + if (!origTable && currTable) { diffs.push({ schemaName, tableName, kind: 'added' }) } else if (origTable && !currTable) { diffs.push({ schemaName, tableName, kind: 'removed' }) } else if (origTable && currTable) { + // Set initialName on current columns so diffTableEditorValues can track renames const currWithInitial: TableEditorValues = { ...currTable, columns: currTable.columns.map((col) => ({ @@ -98,9 +104,15 @@ } } } + return diffs } + /** + * For a forked datatable, compute ahead/behind diffs by comparing: + * - (original, parent) → behind changes (parent drifted) + * - (original, fork) → ahead changes (fork drifted) + */ export function computeDatatableDiff( datatableName: string, originalSchema: DatabaseSchema, @@ -110,60 +122,14 @@ return { datatableName, behindChanges: diffDatabaseSchemas(originalSchema, parentSchema), - aheadChanges: diffDatabaseSchemas(originalSchema, forkSchema), - originalSchema, - parentSchema, - forkSchema + aheadChanges: diffDatabaseSchemas(originalSchema, forkSchema) } } - - export function generateMigrationSql(change: TableDiff, sourceSchema: DatabaseSchema): string { - if (change.kind === 'modified' && change.operations) { - const queries = makeAlterTableQueries(change.operations, 'postgresql', change.schemaName) - if (queries.length === 0) return '' - return 'BEGIN;\n' + queries.join('\n') + '\nCOMMIT;' - } - if (change.kind === 'added') { - const table = sourceSchema[change.schemaName]?.[change.tableName] - if (!table) return '' - const colDefs = table.columns - .map((c) => { - let def = `"${c.name}" ${c.datatype}` - if (c.nullable === false) def += ' NOT NULL' - if (c.defaultValue) def += ` DEFAULT ${c.defaultValue}` - return def - }) - .join(',\n ') - const pkCols = table.columns.filter((c) => c.primaryKey).map((c) => `"${c.name}"`) - const pkLine = pkCols.length > 0 ? `,\n PRIMARY KEY (${pkCols.join(', ')})` : '' - return `BEGIN;\nCREATE TABLE "${change.schemaName}"."${change.tableName}" (\n ${colDefs}${pkLine}\n);\nCOMMIT;` - } - if (change.kind === 'removed') { - return `BEGIN;\nDROP TABLE IF EXISTS "${change.schemaName}"."${change.tableName}";\nCOMMIT;` - } - return '' - } {#if loading} @@ -401,27 +273,19 @@
{#if diff.aheadChanges.length > 0}
-
Fork changes (ahead)
+
Fork changes (ahead)
{#each diff.aheadChanges as change}
{#if change.kind === 'added'} - + {:else if change.kind === 'removed'} - + {:else} - + {/if} {change.schemaName}. {change.tableName} - {operationSummary(change)} - + {operationSummary(change)}
{/each}
@@ -434,23 +298,15 @@ {#each diff.behindChanges as change}
{#if change.kind === 'added'} - + {:else if change.kind === 'removed'} - + {:else} - + {/if} {change.schemaName}. {change.tableName} - {operationSummary(change)} - + {operationSummary(change)}
{/each}
@@ -461,79 +317,3 @@ {/each} {/if} - - - - {#if reviewChange && reviewDiff} - {@const yaml = getYamlDiff(reviewChange, reviewDiff)} -
-
-

- {reviewChange.schemaName}.{reviewChange.tableName} -

-
- - -
-
-
-
-
- Parent ({parentWorkspaceId}) -
-
{yaml.parent}
-
-
-
- Fork ({currentWorkspaceId}) -
-
{yaml.fork}
-
-
-
- {/if} -
- - - - {#if reviewChange && reviewDiff && migrationDirection} - {@const targetLabel = migrationDirection === 'to_fork' ? currentWorkspaceId : parentWorkspaceId} -
-
-

- Migrate {reviewChange.schemaName}.{reviewChange.tableName} → {targetLabel} -

-
-
- -
-
- - -
-
- {/if} -