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:
@@ -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
@@ -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;
|
||||
|
||||
@@ -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"');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user