1
0
forked from boos/BoosAPI

fix: add downstream API key metadata and update proxy logs schema

# Conflicts:
#	src/server/db/generated/mysql.upgrade.sql
#	src/server/db/generated/postgres.upgrade.sql
#	src/server/db/index.ts
This commit is contained in:
ciat-777
2026-03-15 23:14:44 +08:00
parent b15da138d1
commit 4660c8ae0b
4 changed files with 29 additions and 1 deletions
@@ -1,2 +1,4 @@
ALTER TABLE `downstream_api_keys` ADD COLUMN `group_name` TEXT;
ALTER TABLE `downstream_api_keys` ADD COLUMN `tags` TEXT;
ALTER TABLE `proxy_logs` ADD COLUMN `downstream_api_key_id` INT;
CREATE INDEX `proxy_logs_downstream_api_key_created_at_idx` ON `proxy_logs` (`downstream_api_key_id`, `created_at`);
@@ -1,2 +1,4 @@
ALTER TABLE "downstream_api_keys" ADD COLUMN "group_name" TEXT;
ALTER TABLE "downstream_api_keys" ADD COLUMN "tags" TEXT;
ALTER TABLE "proxy_logs" ADD COLUMN "downstream_api_key_id" INTEGER;
CREATE INDEX "proxy_logs_downstream_api_key_created_at_idx" ON "proxy_logs" ("downstream_api_key_id", "created_at");
+12 -1
View File
@@ -550,6 +550,18 @@ function ensureProxyLogBillingDetailsSchema() {
proxyLogBillingDetailsColumnAvailable = true;
}
function ensureProxyLogDownstreamApiKeyIdSchema() {
if (!tableExists('proxy_logs')) {
return;
}
if (!tableColumnExists('proxy_logs', 'downstream_api_key_id')) {
execSqliteLegacyCompat('ALTER TABLE proxy_logs ADD COLUMN downstream_api_key_id integer;');
}
proxyLogDownstreamApiKeyIdColumnAvailable = true;
}
function normalizeSchemaErrorMessage(error: unknown): string {
if (typeof error === 'object' && error && 'message' in error) {
return String((error as { message?: unknown }).message || '');
@@ -639,7 +651,6 @@ function ensureProxyLogDownstreamApiKeyIdSchema() {
proxyLogDownstreamApiKeyIdColumnAvailable = true;
}
export async function hasProxyLogDownstreamApiKeyIdColumn(): Promise<boolean> {
if (proxyLogDownstreamApiKeyIdColumnAvailable !== null) {
return proxyLogDownstreamApiKeyIdColumnAvailable;
+13
View File
@@ -78,4 +78,17 @@ describe('database schema parity', () => {
expect(duplicatedSpecs).toEqual([]);
});
it('keeps proxy_logs downstream api key schema in the generated contract artifacts', () => {
const contract = JSON.parse(readFileSync(schemaContractPath, 'utf8')) as SchemaContract;
const mysqlBootstrap = readFileSync(resolve(generatedDir, 'mysql.bootstrap.sql'), 'utf8');
const postgresBootstrap = readFileSync(resolve(generatedDir, 'postgres.bootstrap.sql'), 'utf8');
expect(contract.tables.proxy_logs?.columns.downstream_api_key_id?.logicalType).toBe('integer');
expect(contract.indexes.some((index) => index.name === 'proxy_logs_downstream_api_key_created_at_idx')).toBe(true);
expect(mysqlBootstrap).toContain('`downstream_api_key_id`');
expect(mysqlBootstrap).toContain('`proxy_logs_downstream_api_key_created_at_idx`');
expect(postgresBootstrap).toContain('"downstream_api_key_id"');
expect(postgresBootstrap).toContain('"proxy_logs_downstream_api_key_created_at_idx"');
});
});