Open source alternative to Semrush and Ahrefs
TypeScript backlink-analysisgoogle-search-console-mcpkeyword-researchmcpseoseo-agentseo-auditseo-automationseo-skillsseo-toolssite-audit
import { getDatabaseProvider } from "./provider";
import * as sqliteApp from "./app.schema";
import * as sqliteProjectContext from "./project-context.schema";
import * as sqliteReports from "./reports.schema";
import * as sqliteReportTemplates from "./report-templates.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 sqliteGa4 from "./ga4.schema";
import * as sqliteGsc from "./gsc.schema";
import * as sqliteTelemetry from "./telemetry.schema";
import * as sqliteAiVisibility from "./ai-visibility.schema";
import * as sqliteLocalSeo from "./local-seo.schema";
import * as pgApp from "./pg/app.schema";
import * as pgProjectContext from "./pg/project-context.schema";
import * as pgReports from "./pg/reports.schema";
import * as pgReportTemplates from "./pg/report-templates.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 pgGa4 from "./pg/ga4.schema";
import * as pgGsc from "./pg/gsc.schema";
import * as pgTelemetry from "./pg/telemetry.schema";
import * as pgAiVisibility from "./pg/ai-visibility.schema";
import * as pgLocalSeo from "./pg/local-seo.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 sqliteProjectContext &
typeof sqliteReports &
typeof sqliteReportTemplates &
typeof sqliteAudit &
typeof sqliteSam &
typeof sqliteAuth &
typeof sqliteBilling &
typeof sqliteGa4 &
typeof sqliteGsc &
typeof sqliteTelemetry &
typeof sqliteAiVisibility &
typeof sqliteLocalSeo;
const runtimeSchema =
getDatabaseProvider() === "postgres"
? {
...pgApp,
...pgProjectContext,
...pgReports,
...pgReportTemplates,
...pgAudit,
...pgSam,
...pgAuth,
...pgBilling,
...pgGa4,
...pgGsc,
...pgTelemetry,
...pgAiVisibility,
...pgLocalSeo,
}
: {
...sqliteApp,
...sqliteProjectContext,
...sqliteReports,
...sqliteReportTemplates,
...sqliteAudit,
...sqliteSam,
...sqliteAuth,
...sqliteBilling,
...sqliteGa4,
...sqliteGsc,
...sqliteTelemetry,
...sqliteAiVisibility,
...sqliteLocalSeo,
};
// 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,
userSignupCampaigns,
projects,
savedKeywords,
savedKeywordTags,
savedKeywordTagAssignments,
keywordMetrics,
rankTrackingConfigs,
rankTrackingKeywords,
rankCheckRuns,
rankSnapshots,
organizationActivationState,
projectActivationState,
dashboardStepDismissals,
backlinkSnapshots,
dataRefreshClaims,
crawlerCredentials,
projectContextSections,
projectCompetitors,
projectKeyPages,
projectResearchLog,
reports,
reportTemplates,
audits,
auditPages,
auditIssues,
auditLighthouseResults,
samSessions,
user,
session,
account,
apikey,
verification,
organization,
member,
invitation,
billingCustomerStatus,
ga4Connections,
gscConnections,
telemetryState,
aiTrackers,
aiPrompts,
aiRuns,
aiObservations,
aiSources,
aiMatches,
localRankTrackers,
localRankChecks,
localRankKeywords,
localRankScans,
localRankPoints,
localRankBusinesses,
localRankResults,
} = schema;