( client: Connection, initSchema: MysqlSchema, testName: string, schema: string, casing?: CasingType | undefined, )
| 2432 | }; |
| 2433 | |
| 2434 | export const introspectMySQLToFile = async ( |
| 2435 | client: Connection, |
| 2436 | initSchema: MysqlSchema, |
| 2437 | testName: string, |
| 2438 | schema: string, |
| 2439 | casing?: CasingType | undefined, |
| 2440 | ) => { |
| 2441 | // put in db |
| 2442 | const { sqlStatements } = await applyMySqlDiffs(initSchema, casing); |
| 2443 | for (const st of sqlStatements) { |
| 2444 | await client.query(st); |
| 2445 | } |
| 2446 | |
| 2447 | // introspect to schema |
| 2448 | const introspectedSchema = await fromMySqlDatabase( |
| 2449 | { |
| 2450 | query: async (sql: string, params?: any[] | undefined) => { |
| 2451 | const res = await client.execute(sql, params); |
| 2452 | return res[0] as any; |
| 2453 | }, |
| 2454 | }, |
| 2455 | schema, |
| 2456 | ); |
| 2457 | |
| 2458 | const { version: initV, dialect: initD, ...initRest } = introspectedSchema; |
| 2459 | |
| 2460 | const initSch = { |
| 2461 | version: '5', |
| 2462 | dialect: 'mysql', |
| 2463 | id: '0', |
| 2464 | prevId: '0', |
| 2465 | ...initRest, |
| 2466 | } as const; |
| 2467 | |
| 2468 | const initSn = squashMysqlScheme(initSch); |
| 2469 | const validatedCur = mysqlSchema.parse(initSch); |
| 2470 | |
| 2471 | const file = schemaToTypeScriptMySQL(introspectedSchema, 'camel'); |
| 2472 | |
| 2473 | fs.writeFileSync(`tests/introspect/mysql/${testName}.ts`, file.file); |
| 2474 | |
| 2475 | const response = await prepareFromMySqlImports([ |
| 2476 | `tests/introspect/mysql/${testName}.ts`, |
| 2477 | ]); |
| 2478 | |
| 2479 | const afterFileImports = generateMySqlSnapshot( |
| 2480 | response.tables, |
| 2481 | response.views, |
| 2482 | casing, |
| 2483 | ); |
| 2484 | |
| 2485 | const { version: v2, dialect: d2, ...rest2 } = afterFileImports; |
| 2486 | |
| 2487 | const sch2 = { |
| 2488 | version: '5', |
| 2489 | dialect: 'mysql', |
| 2490 | id: '0', |
| 2491 | prevId: '0', |
no test coverage detected