fix(core): consolidate rateLimit table schema definition (#7551)

This commit is contained in:
Taesu
2026-01-28 17:06:03 -08:00
committed by Alex Yang
parent 663d43eb37
commit ea589eef0a
2 changed files with 5 additions and 36 deletions
-36
View File
@@ -1284,42 +1284,6 @@ export const createAdapterFactory =
delete tables.session;
}
if (
options.rateLimit &&
options.rateLimit.storage === "database" &&
// rate-limit will default to enabled in production,
// and given storage is database, it will try to use the rate-limit table,
// so we should make sure to generate rate-limit table schema
(typeof options.rateLimit.enabled === "undefined" ||
// and of course if they forcefully set to true, then they want rate-limit,
// thus we should also generate rate-limit table schema
options.rateLimit.enabled === true)
) {
tables.ratelimit = {
modelName: options.rateLimit.modelName ?? "ratelimit",
fields: {
key: {
type: "string",
unique: true,
required: true,
fieldName: options.rateLimit.fields?.key ?? "key",
},
count: {
type: "number",
required: true,
fieldName: options.rateLimit.fields?.count ?? "count",
},
lastRequest: {
type: "number",
required: true,
bigint: true,
defaultValue: () => Date.now(),
fieldName:
options.rateLimit.fields?.lastRequest ?? "lastRequest",
},
},
};
}
return adapterInstance.createSchema!({ file, tables });
}
: undefined,
+5
View File
@@ -32,16 +32,21 @@ export const getAuthTables = (
fields: {
key: {
type: "string",
unique: true,
required: true,
fieldName: options.rateLimit?.fields?.key || "key",
},
count: {
type: "number",
required: true,
fieldName: options.rateLimit?.fields?.count || "count",
},
lastRequest: {
type: "number",
bigint: true,
required: true,
fieldName: options.rateLimit?.fields?.lastRequest || "lastRequest",
defaultValue: () => Date.now(),
},
},
},