mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-24 08:01:56 -05:00
feat(cli): allow cli to use custom adapter createSchema if implemented (#3006)
* the cli now uses createSchema from custom adapters * rename function misnomer and keep old name as deprecated
This commit is contained in:
@@ -9,7 +9,7 @@ export const adapters = {
|
||||
kysely: generateMigrations,
|
||||
};
|
||||
|
||||
export const getGenerator = (opts: {
|
||||
export const generateSchema = (opts: {
|
||||
adapter: Adapter;
|
||||
file?: string;
|
||||
options: BetterAuthOptions;
|
||||
@@ -19,9 +19,29 @@ export const getGenerator = (opts: {
|
||||
adapter.id in adapters
|
||||
? adapters[adapter.id as keyof typeof adapters]
|
||||
: null;
|
||||
if (!generator) {
|
||||
logger.error(`${adapter.id} is not supported.`);
|
||||
process.exit(1);
|
||||
if (generator) {
|
||||
// generator from the built-in list above
|
||||
return generator(opts);
|
||||
}
|
||||
return generator(opts);
|
||||
if (adapter.createSchema) {
|
||||
// use the custom adapter's createSchema method
|
||||
return adapter
|
||||
.createSchema(opts.options, opts.file)
|
||||
.then(({ code, path: fileName, overwrite }) => ({
|
||||
code,
|
||||
fileName,
|
||||
overwrite,
|
||||
}));
|
||||
}
|
||||
|
||||
logger.error(
|
||||
`${adapter.id} is not supported. If it is a custom adapter, please request the maintainer to implement createSchema`,
|
||||
);
|
||||
process.exit(1);
|
||||
};
|
||||
|
||||
/**
|
||||
* @deprecated getGenerator is a misnomer as this function gets a generator AND uses it to generate
|
||||
* and return the schema. Use generateSchema instead
|
||||
*/
|
||||
export const getGenerator = generateSchema;
|
||||
|
||||
Reference in New Issue
Block a user