97 lines
2.8 KiB
TypeScript
97 lines
2.8 KiB
TypeScript
import { getDatabaseProvider } from "./provider";
|
|
import * as sqliteApp from "./app.schema";
|
|
import * as sqliteAudit from "./audit.schema";
|
|
import * as sqliteSam from "./sam.schema";
|
|
import * as sqliteAuth from "./better-auth-schema";
|
|
import * as sqliteBilling from "./billing.schema";
|
|
import * as sqliteGsc from "./gsc.schema";
|
|
import * as sqliteReddit from "./reddit-attribution.schema";
|
|
import * as sqliteTelemetry from "./telemetry.schema";
|
|
import * as pgApp from "./pg/app.schema";
|
|
import * as pgAudit from "./pg/audit.schema";
|
|
import * as pgSam from "./pg/sam.schema";
|
|
import * as pgAuth from "./pg/better-auth-schema";
|
|
import * as pgBilling from "./pg/billing.schema";
|
|
import * as pgGsc from "./pg/gsc.schema";
|
|
import * as pgReddit from "./pg/reddit-attribution.schema";
|
|
import * as pgTelemetry from "./pg/telemetry.schema";
|
|
|
|
// Canonical schema barrel. Repositories import their tables from here and the
|
|
// provider-aware `db` from "@/db", so each repository is written ONCE for both
|
|
// backends.
|
|
//
|
|
// The TYPE identity is the SQLite definitions; the runtime VALUES are whichever
|
|
// provider is active. `schema-parity.test.ts` asserts the two dialect schemas
|
|
// are structurally interchangeable (same tables/columns/nullability/PKs/unique
|
|
// indexes), which is what makes the single cast below sound. The Postgres
|
|
// schema is the one structural artifact NOT regenerated by `db:generate`, so the
|
|
// parity test is its drift guard.
|
|
type AppSchema = typeof sqliteApp &
|
|
typeof sqliteAudit &
|
|
typeof sqliteSam &
|
|
typeof sqliteAuth &
|
|
typeof sqliteBilling &
|
|
typeof sqliteGsc &
|
|
typeof sqliteReddit &
|
|
typeof sqliteTelemetry;
|
|
|
|
const runtimeSchema =
|
|
getDatabaseProvider() === "postgres"
|
|
? {
|
|
...pgApp,
|
|
...pgAudit,
|
|
...pgSam,
|
|
...pgAuth,
|
|
...pgBilling,
|
|
...pgGsc,
|
|
...pgReddit,
|
|
...pgTelemetry,
|
|
}
|
|
: {
|
|
...sqliteApp,
|
|
...sqliteAudit,
|
|
...sqliteSam,
|
|
...sqliteAuth,
|
|
...sqliteBilling,
|
|
...sqliteGsc,
|
|
...sqliteReddit,
|
|
...sqliteTelemetry,
|
|
};
|
|
|
|
// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- guarded by schema-parity.test.ts
|
|
const schema = runtimeSchema as unknown as AppSchema;
|
|
|
|
export const {
|
|
userOnboardingAnswers,
|
|
projects,
|
|
savedKeywords,
|
|
savedKeywordTags,
|
|
savedKeywordTagAssignments,
|
|
keywordMetrics,
|
|
rankTrackingConfigs,
|
|
rankTrackingKeywords,
|
|
rankCheckRuns,
|
|
rankSnapshots,
|
|
organizationActivationState,
|
|
projectActivationState,
|
|
backlinkSnapshots,
|
|
audits,
|
|
auditPages,
|
|
auditLinks,
|
|
auditIssues,
|
|
auditLighthouseResults,
|
|
samSessions,
|
|
samProjectMemory,
|
|
user,
|
|
session,
|
|
account,
|
|
verification,
|
|
organization,
|
|
member,
|
|
invitation,
|
|
billingCustomerStatus,
|
|
gscConnections,
|
|
redditAttributions,
|
|
telemetryState,
|
|
} = schema;
|