Issue with custom table names

I've added such custom table names so it matches my db schema:
user: {
deleteUser: {
enabled: true
},
fields: {
createdAt: 'created_at',
updatedAt: 'updated_at',
emailVerified: 'email_verified',
normalized_email: 'normalized_email',
banReason: 'ban_reason',
banExpires: 'ban_expires'
}
},
account: {
fields: {
accountId: 'account_id',
providerId: 'provider_id',
userId: 'user_id',
accessToken: 'access_token',
refreshToken: 'refresh_token',
idToken: 'id_token',
accessTokenExpiresAt: 'access_token_expires_at',
refreshTokenExpiresAt: 'refresh_token_expires_at',
createdAt: 'created_at',
updatedAt: 'updated_at'
}
},
verification: {
fields: {
expiresAt: 'expires_at',
createdAt: 'created_at',
updatedAt: 'updated_at'
}
}
user: {
deleteUser: {
enabled: true
},
fields: {
createdAt: 'created_at',
updatedAt: 'updated_at',
emailVerified: 'email_verified',
normalized_email: 'normalized_email',
banReason: 'ban_reason',
banExpires: 'ban_expires'
}
},
account: {
fields: {
accountId: 'account_id',
providerId: 'provider_id',
userId: 'user_id',
accessToken: 'access_token',
refreshToken: 'refresh_token',
idToken: 'id_token',
accessTokenExpiresAt: 'access_token_expires_at',
refreshTokenExpiresAt: 'refresh_token_expires_at',
createdAt: 'created_at',
updatedAt: 'updated_at'
}
},
verification: {
fields: {
expiresAt: 'expires_at',
createdAt: 'created_at',
updatedAt: 'updated_at'
}
}
And I've found an issue: when I run npx @better-auth/cli generate it generates me such migration file:
alter table "user" add column "banReason" text;

alter table "user" add column "banExpires" timestamp;

alter table "user" add column "normalizedEmail" text unique;
alter table "user" add column "banReason" text;

alter table "user" add column "banExpires" timestamp;

alter table "user" add column "normalizedEmail" text unique;
So the issue here is that it wants to create columns with camelCase, even though I indicated I want them snake_case (banReason: 'ban_reason' -> ban_reason: 'ban_reason' didn't help neither)
3 Replies
0xJJW
0xJJW3mo ago
When it comes to overriding additional fields (created by plugins). You will need to pass the field map (schema) to the plugins schema property. For example the admin plugin adds “banReason” so you will need to pass:
admin({
adminRoles: ["admin", "other"],
schema: {
“user”: {
“fields”: {
“banReason”: “ban_reason”
}
}
}
})
admin({
adminRoles: ["admin", "other"],
schema: {
“user”: {
“fields”: {
“banReason”: “ban_reason”
}
}
}
})
You can view the admin plugin schema here. https://www.better-auth.com/docs/plugins/admin#schema
radek1313
radek1313OP3mo ago
okay, for email plugin it works as expected, but I'm also using emailHarmony plugin from better-auth-harmony and there is no option change. Any idea what to do in this case?
0xJJW
0xJJW3mo ago
I had a quick look and that plugin does not support overriding fields. I recommend creating an issue or implement the functionality. The api-plugin is a good one to see how it's implemented. In summary before returning the schema you should merge the schema with the custom options
const schema = mergeSchema(
apiKeySchema({
rateLimitMax: opts.rateLimit.maxRequests,
timeWindow: opts.rateLimit.timeWindow,
}),
opts.schema,
);
const schema = mergeSchema(
apiKeySchema({
rateLimitMax: opts.rateLimit.maxRequests,
timeWindow: opts.rateLimit.timeWindow,
}),
opts.schema,
);

Did you find this page helpful?