fix: resolve coverage gap and migration filename collision

- Add getTableConfig FK reference tests to cover deferred .references()
  callbacks in schema.ts (fixes Codecov patch coverage < 94.98%)
- Rename 0011_image-hosting → 0012_image-hosting to avoid filename
  collision with pre-existing 0011_notifications migration

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Bob
2026-04-21 03:12:31 -04:00
parent 2b84164fad
commit ef1fab8909
4 changed files with 21 additions and 1 deletions
+1 -1
View File
@@ -83,7 +83,7 @@
"idx": 11,
"version": "6",
"when": 1776749333797,
"tag": "0011_image-hosting",
"tag": "0012_image-hosting",
"breakpoints": true
}
]
+20
View File
@@ -1,3 +1,4 @@
import { getTableConfig } from 'drizzle-orm/sqlite-core'
import { describe, expect, it } from 'vitest'
import { apikey } from './auth-schema.js'
import { imageHostingConfigs, imageHostings } from './schema.js'
@@ -40,6 +41,14 @@ describe('imageHostingConfigs table', () => {
expect(imageHostingConfigs.createdAt.notNull).toBe(true)
expect(imageHostingConfigs.updatedAt.notNull).toBe(true)
})
it('org_id has a cascade-delete FK to organization', () => {
const { foreignKeys } = getTableConfig(imageHostingConfigs)
expect(foreignKeys).toHaveLength(1)
const ref = foreignKeys[0].reference()
expect(ref.foreignColumns).toHaveLength(1)
expect(ref.foreignColumns[0].name).toBe('id')
})
})
describe('imageHostings table', () => {
@@ -97,6 +106,17 @@ describe('imageHostings table', () => {
it('has not-null created_at timestamp', () => {
expect(imageHostings.createdAt.notNull).toBe(true)
})
it('org_id and storage_id have cascade/no-action FKs', () => {
const { foreignKeys } = getTableConfig(imageHostings)
expect(foreignKeys).toHaveLength(2)
// Both FKs resolve to a single-column reference on 'id'
for (const fk of foreignKeys) {
const ref = fk.reference()
expect(ref.foreignColumns).toHaveLength(1)
expect(ref.foreignColumns[0].name).toBe('id')
}
})
})
describe('apikey table', () => {