(client)
| 40 | }; |
| 41 | |
| 42 | async function validateTables(client) { |
| 43 | const issues = []; |
| 44 | for (const table of TABLE_DEFINITIONS) { |
| 45 | try { |
| 46 | const datasource = await client.getDatasource(table.name); |
| 47 | if (!datasource) { |
| 48 | issues.push(`Missing data source ${table.name}`); |
| 49 | continue; |
| 50 | } |
| 51 | |
| 52 | const remoteSchema = datasource?.schema?.sql_schema; |
| 53 | if (!remoteSchema) { |
| 54 | issues.push( |
| 55 | `Data source ${table.name} does not expose schema metadata`, |
| 56 | ); |
| 57 | continue; |
| 58 | } |
| 59 | |
| 60 | const remoteColumns = splitSchema(remoteSchema).map(normalizeColumnDef); |
| 61 | const expectedColumns = buildExpectedSchema(table); |
| 62 | |
| 63 | let hasIssue = false; |
| 64 | |
| 65 | if (remoteColumns.length !== expectedColumns.length) { |
| 66 | issues.push( |
| 67 | `Schema mismatch for ${table.name}. Expected ${expectedColumns.length} columns, got ${remoteColumns.length}.`, |
| 68 | ); |
| 69 | hasIssue = true; |
| 70 | } |
| 71 | |
| 72 | const missingColumns = expectedColumns.filter( |
| 73 | (column, index) => remoteColumns[index] !== column, |
| 74 | ); |
| 75 | if (missingColumns.length > 0) { |
| 76 | issues.push( |
| 77 | `Schema mismatch for ${table.name}. Expected columns (${expectedColumns.join(", ")}), got (${remoteColumns.join(", ")}).`, |
| 78 | ); |
| 79 | hasIssue = true; |
| 80 | } |
| 81 | |
| 82 | if (table.engine) { |
| 83 | const actualEngine = |
| 84 | typeof datasource.engine === "string" |
| 85 | ? datasource.engine |
| 86 | : datasource.engine?.engine; |
| 87 | if (actualEngine && actualEngine !== table.engine) { |
| 88 | issues.push( |
| 89 | `Data source ${table.name} has engine ${actualEngine}, expected ${table.engine}.`, |
| 90 | ); |
| 91 | hasIssue = true; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | if (!hasIssue) { |
| 96 | console.log(`✔ Data source ${table.name} schema matches`); |
| 97 | } |
| 98 | } catch (error) { |
| 99 | issues.push( |
no test coverage detected