(opts: SchemaGenerateOptions)
| 18 | }; |
| 19 | |
| 20 | const schemaGenerateAction = async (opts: SchemaGenerateOptions) => { |
| 21 | const cwd = path.resolve(opts.cwd); |
| 22 | if (!existsSync(cwd)) { |
| 23 | console.error(`The directory "${cwd}" does not exist.`); |
| 24 | process.exit(1); |
| 25 | } |
| 26 | |
| 27 | if (opts.adapter !== "drizzle") { |
| 28 | console.error(`Unsupported schema adapter "${opts.adapter}". Supported adapters: drizzle.`); |
| 29 | process.exit(1); |
| 30 | } |
| 31 | if (opts.provider !== "mysql" && opts.provider !== "postgresql" && opts.provider !== "sqlite") { |
| 32 | console.error( |
| 33 | `Unsupported drizzle provider "${opts.provider}". Supported providers: mysql, postgresql, sqlite.`, |
| 34 | ); |
| 35 | process.exit(1); |
| 36 | } |
| 37 | |
| 38 | const [{ fumadb }, { drizzleAdapter }, { schema: fumaSchema }] = await Promise.all([ |
| 39 | import("@executor-js/fumadb"), |
| 40 | import("@executor-js/fumadb/adapters/drizzle"), |
| 41 | import("@executor-js/fumadb/schema"), |
| 42 | ]); |
| 43 | |
| 44 | const schema = fumaSchema({ |
| 45 | version: opts.version, |
| 46 | tables: collectTables(), |
| 47 | }); |
| 48 | const factory = fumadb({ |
| 49 | namespace: opts.namespace, |
| 50 | schemas: [schema], |
| 51 | }); |
| 52 | const generated = factory |
| 53 | .client( |
| 54 | drizzleAdapter({ |
| 55 | db: {}, |
| 56 | provider: opts.provider, |
| 57 | }), |
| 58 | ) |
| 59 | .generateSchema("latest", opts.namespace); |
| 60 | |
| 61 | const output = opts.output ?? generated.path; |
| 62 | const outPath = path.resolve(cwd, output); |
| 63 | await fs.mkdir(path.dirname(outPath), { recursive: true }); |
| 64 | await fs.writeFile(outPath, generated.code); |
| 65 | console.log(`Schema generated: ${path.relative(cwd, outPath)}`); |
| 66 | }; |
| 67 | |
| 68 | export const schema = new Command("schema") |
| 69 | .description("Database schema utilities") |
nothing calls this directly
no test coverage detected