freshyo/apps/migrator/src/lib/schema-maps.ts
2026-03-23 10:57:28 +05:30

21 lines
726 B
TypeScript

import type { TableName } from './table-order'
import * as postgresSchema from '../../../backend/src/db/schema-postgres'
import * as sqliteSchema from '../../../backend/src/db/schema-sqlite'
import { tableOrder } from './table-order'
export type TableMap = Record<TableName, any>
const buildMap = (schema: Record<string, unknown>): TableMap => {
const map = {} as TableMap
tableOrder.forEach((name) => {
const table = schema[name]
if (!table) {
throw new Error(`Missing table export for ${name}`)
}
map[name] = table
})
return map
}
export const postgresTables = buildMap(postgresSchema as Record<string, unknown>)
export const sqliteTables = buildMap(sqliteSchema as Record<string, unknown>)