Allow @better-auth/cli to work with custom adapters that implement createSchema #1347

Closed
opened 2026-03-13 08:34:13 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @taivo on GitHub (Jun 12, 2025).

Is this suited for github?

  • Yes, this is suited for github

Currently, the cli restricts schema generation to kysely, drizzle, and prisma and uses built-in generators defined in the cli's source code.

However, custom adapters can optionally implement the createSchema method. IMO if the adapter implements this method, we should use it. If not, then we finally exit.

Describe the solution you'd like

I believe the restriction happens here https://github.com/better-auth/better-auth/blob/main/packages/cli/src/generators/index.ts#L18-L25

Assuming the adapter passed to getGenerator was not restricted to only be for kysely, drizzle, and prisma, the fix could be as simple as changing getGenerator to

export const getGenerator = (opts: {
	adapter: Adapter;
	file?: string;
	options: BetterAuthOptions;
}) => {
	const adapter = opts.adapter;
	const generator =
		adapter.id in adapters
			? adapters[adapter.id as keyof typeof adapters]
			: null
        if(generator) {
          return generator(opts)
        }

        if(!generator && adapter.createSchema) {
          // wrap createSchema and return it as a generator
          return async({options, file}) {
            const {code, path: fileName, overwrite} = await adapter.createSchema(options, file)
            return {code, fileName, overwrite}
          }
        }
	
	logger.error(`${adapter.id} is not supported.`);
	process.exit(1);
};

Describe alternatives you've considered

I recently implemented https://www.npmjs.com/package/@nerdfolio/remult-better-auth and just built a cli for it that requires the --config parameter.

Additional context

Will drop a PR soon to help with this

Originally created by @taivo on GitHub (Jun 12, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Currently, the cli restricts schema generation to kysely, drizzle, and prisma and uses built-in generators defined in the cli's source code. However, custom adapters can optionally implement the createSchema method. IMO if the adapter implements this method, we should use it. If not, then we finally exit. ### Describe the solution you'd like I believe the restriction happens here https://github.com/better-auth/better-auth/blob/main/packages/cli/src/generators/index.ts#L18-L25 Assuming the `adapter` passed to `getGenerator` was not restricted to only be for kysely, drizzle, and prisma, the fix could be as simple as changing `getGenerator` to ```typescript export const getGenerator = (opts: { adapter: Adapter; file?: string; options: BetterAuthOptions; }) => { const adapter = opts.adapter; const generator = adapter.id in adapters ? adapters[adapter.id as keyof typeof adapters] : null if(generator) { return generator(opts) } if(!generator && adapter.createSchema) { // wrap createSchema and return it as a generator return async({options, file}) { const {code, path: fileName, overwrite} = await adapter.createSchema(options, file) return {code, fileName, overwrite} } } logger.error(`${adapter.id} is not supported.`); process.exit(1); }; ``` ### Describe alternatives you've considered I recently implemented https://www.npmjs.com/package/@nerdfolio/remult-better-auth and just built a cli for it that requires the `--config` parameter. ### Additional context Will drop a PR soon to help with this
GiteaMirror added the adapter label 2026-03-13 08:34:13 -05:00
Author
Owner

@taivo commented on GitHub (Jun 13, 2025):

PR https://github.com/better-auth/better-auth/pull/3006

@taivo commented on GitHub (Jun 13, 2025): PR https://github.com/better-auth/better-auth/pull/3006
Author
Owner

@daveycodez commented on GitHub (Jun 21, 2025):

Are there docs on how to set this up

@daveycodez commented on GitHub (Jun 21, 2025): Are there docs on how to set this up
Author
Owner

@taivo commented on GitHub (Jun 23, 2025):

There is nothing to setup now that 3006 has been merged. You just use @better-auth/cli as before. Prior to the merge, even if you use a database adapter that implements createSchema, the cli still exit and not use it. Now it will.

Here's an example createSchema I implemented for the Remult ORM: https://github.com/nerdfolio/remult-better-auth/blob/main/src/remult-ba.ts#L72-L77

I used the adapter writing guide on better-auth's website

@taivo commented on GitHub (Jun 23, 2025): There is nothing to setup now that 3006 has been merged. You just use @better-auth/cli as before. Prior to the merge, even if you use a database adapter that implements `createSchema`, the cli still exit and not use it. Now it will. Here's an example createSchema I implemented for the Remult ORM: https://github.com/nerdfolio/remult-better-auth/blob/main/src/remult-ba.ts#L72-L77 I used the adapter writing guide on better-auth's website
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1347