Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"dependencies": {
"@astrojs/starlight": "^0.37.6",
"astro": "^5.6.1",
"sharp": "^0.34.2",
"zod": "^3.25.76"
"sharp": "^0.34.2"
}
}
20 changes: 9 additions & 11 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@
"clean": "rm -rf dist"
},
"dependencies": {
"@clickhouse/client": "^1.11.0",
"fast-glob": "^3.3.2",
"@chkit/clickhouse": "workspace:*",
"@chkit/codegen": "workspace:*",
"@chkit/core": "workspace:*",
"@logtape/logtape": "^2.0.5",
"fast-glob": "^3.3.2"
"@logtape/logtape": "^2.0.5"
}
}
2 changes: 1 addition & 1 deletion packages/cli/src/bin/command-dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { loadSchemaDefinitions } from './schema-loader.js'
import { resolveTableScope, tableKeysFromDefinitions } from './table-scope.js'

export function stripGlobalFlags(argv: string[]): {
function stripGlobalFlags(argv: string[]): {

Check warning on line 13 in packages/cli/src/bin/command-dispatch.ts

View workflow job for this annotation

GitHub Actions / verify

High CRAP score (high)

Function 'stripGlobalFlags' has a CRAP score of 56.0 (threshold: 30.0). • Severity: high • Cyclomatic: 7 • Cognitive: 9 • CRAP: 56.0 (threshold: 30.0) • Lines: 29 CRAP combines complexity with coverage: high CRAP means changes here carry high risk. Consider adding tests, simplifying the function, or both.
jsonMode: boolean
tableSelector: string | undefined
rest: string[]
Expand Down Expand Up @@ -65,7 +65,7 @@
}
}

async function runPluginCommand(input: {

Check failure on line 68 in packages/cli/src/bin/command-dispatch.ts

View workflow job for this annotation

GitHub Actions / verify

High CRAP score (critical)

Function 'runPluginCommand' has a CRAP score of 182.0 (threshold: 30.0). • Severity: critical • Cyclomatic: 13 • Cognitive: 15 • CRAP: 182.0 (threshold: 30.0) • Lines: 72 CRAP combines complexity with coverage: high CRAP means changes here carry high risk. Consider adding tests, simplifying the function, or both.
argv: string[]
commandName: string
resolved: RegisteredCommand
Expand Down Expand Up @@ -138,7 +138,7 @@
if (exitCode !== 0) process.exitCode = exitCode
}

async function runCoreOrBuiltinCommand(input: {

Check warning on line 141 in packages/cli/src/bin/command-dispatch.ts

View workflow job for this annotation

GitHub Actions / verify

High CRAP score (high)

Function 'runCoreOrBuiltinCommand' has a CRAP score of 56.0 (threshold: 30.0). • Severity: high • Cyclomatic: 7 • Cognitive: 9 • CRAP: 56.0 (threshold: 30.0) • Lines: 65 CRAP combines complexity with coverage: high CRAP means changes here carry high risk. Consider adding tests, simplifying the function, or both.
argv: string[]
commandName: string
resolved: RegisteredCommand
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/bin/commands/drift.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { join } from 'node:path'

import { isUnknownDatabaseError, type ClickHouseExecutor, type SchemaObjectRef } from '@chkit/clickhouse'
Expand All @@ -16,7 +16,7 @@
import { readSnapshot } from '../migration-store.js'
import { resolveTableScope, tableKeysFromDefinitions, type TableScope } from '../table-scope.js'

export interface DriftPayload {
interface DriftPayload {
scope?: TableScope
snapshotFile: string
expectedCount: number
Expand All @@ -38,7 +38,7 @@
run: cmdDrift,
}

export async function buildDriftPayload(

Check failure on line 41 in packages/cli/src/bin/commands/drift.ts

View workflow job for this annotation

GitHub Actions / verify

High CRAP score (critical)

Function 'buildDriftPayload' has a CRAP score of 156.0 (threshold: 30.0). • Severity: critical • Cyclomatic: 12 • Cognitive: 7 • CRAP: 156.0 (threshold: 30.0) • Lines: 100 CRAP combines complexity with coverage: high CRAP means changes here carry high risk. Consider adding tests, simplifying the function, or both.
config: ChxConfig,
metaDir: string,
snapshot: Snapshot,
Expand Down Expand Up @@ -139,7 +139,7 @@
}
}

async function cmdDrift(runCtx: CommandRunContext): Promise<void> {

Check failure on line 142 in packages/cli/src/bin/commands/drift.ts

View workflow job for this annotation

GitHub Actions / verify

High CRAP score (critical)

Function 'cmdDrift' has a CRAP score of 1722.0 (threshold: 30.0). • Severity: critical • Cyclomatic: 41 • Cognitive: 72 • CRAP: 1722.0 (threshold: 30.0) • Lines: 104 CRAP combines complexity with coverage: high CRAP means changes here carry high risk. Consider adding tests, simplifying the function, or both.
const { flags, config, dirs, ctx } = runCtx
const f = typedFlags(flags, GLOBAL_FLAGS)
const tableSelector = f['--table']
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/bin/internal-plugins/skill-hint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type AgentKind = 'claude' | 'cursor' | 'copilot' | 'windsurf' | 'roo' | '

interface AgentInfo { name: string; skillsDir: string }

export const AGENT_REGISTRY: Record<Exclude<AgentKind, 'unknown'>, AgentInfo> = {
const AGENT_REGISTRY: Record<Exclude<AgentKind, 'unknown'>, AgentInfo> = {
claude: { name: 'Claude Code', skillsDir: '.claude/skills' },
cursor: { name: 'Cursor', skillsDir: '.agents/skills' },
copilot: { name: 'Copilot', skillsDir: '.agents/skills' },
Expand All @@ -33,7 +33,7 @@ const AGENT_MARKERS: { path: string; agent: AgentKind }[] = [
{ path: '.trae', agent: 'trae' },
]

export interface AgentRootResult { root: string; agent: AgentKind }
interface AgentRootResult { root: string; agent: AgentKind }

/**
* Walk up from `cwd` to find the best directory for installing agent skills.
Expand Down
12 changes: 2 additions & 10 deletions packages/cli/src/bin/journal-store.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { createClickHouseExecutor, isUnknownDatabaseError, type ClickHouseExecutor } from '@chkit/clickhouse'
import type { ChxConfig } from '@chkit/core'
import { isUnknownDatabaseError, type ClickHouseExecutor } from '@chkit/clickhouse'

import type { MigrationJournal, MigrationJournalEntry } from './migration-store.js'
import { CLI_VERSION } from './version.js'
import { debug } from './debug.js'

export interface JournalStore {
interface JournalStore {
readJournal(): Promise<MigrationJournal>
appendEntry(entry: MigrationJournalEntry): Promise<void>
readonly databaseMissing: boolean
Expand Down Expand Up @@ -51,7 +50,7 @@
let bootstrapped = false
let _databaseMissing = false

async function ensureTable(): Promise<void> {

Check warning on line 53 in packages/cli/src/bin/journal-store.ts

View workflow job for this annotation

GitHub Actions / verify

High CRAP score (high)

Function 'ensureTable' has a CRAP score of 72.0 (threshold: 30.0). • Severity: high • Cyclomatic: 8 • Cognitive: 10 • CRAP: 72.0 (threshold: 30.0) • Lines: 39 CRAP combines complexity with coverage: high CRAP means changes here carry high risk. Consider adding tests, simplifying the function, or both.
if (bootstrapped) return
debug('journal', `probing journal table "${journalTable}"`)
try {
Expand Down Expand Up @@ -152,10 +151,3 @@
},
}
}

export function createJournalStoreFromConfig(
clickhouseConfig: NonNullable<ChxConfig['clickhouse']>
): { journalStore: JournalStore; db: ClickHouseExecutor } {
const db = createClickHouseExecutor(clickhouseConfig)
return { journalStore: createJournalStore(db), db }
}
4 changes: 2 additions & 2 deletions packages/cli/src/bin/json-output.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type Command =
type Command =
| 'generate'
| 'migrate'
| 'status'
Expand All @@ -18,7 +18,7 @@ export function printOutput(value: unknown, jsonMode: boolean): void {
}
}

export function jsonPayload<T extends object>(command: Command, payload: T): T & {
function jsonPayload<T extends object>(command: Command, payload: T): T & {
command: Command
schemaVersion: number
} {
Expand Down
35 changes: 2 additions & 33 deletions packages/cli/src/bin/lib.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,5 @@
export { CLI_VERSION } from './version.js'

export {
DEFAULT_CONFIG_FILE,
loadConfig,
resolveDirs,
writeIfMissing,
} from './config.js'
export {
createJournalStore,
createJournalStoreFromConfig,
type JournalStore,
} from './journal-store.js'
export {
checksumSQL,
findChecksumMismatches,
listMigrations,
parseJSONOrThrow,
readSnapshot,
summarizePlan,
type ChecksumMismatch,
type MigrationJournal,
type MigrationJournalEntry,
} from './migration-store.js'
export { emitJson, jsonPayload, printOutput, type Command } from './json-output.js'
export {
collectDestructiveOperationMarkers,
extractMigrationOperationSummaries,
extractDestructiveOperationSummaries,
extractExecutableStatements,
migrationContainsDangerOperation,
parseOperationLine,
type MigrationOperationSummary,
type DestructiveOperationMarker,
} from './safety-markers.js'
export { readSnapshot, summarizePlan } from './migration-store.js'
export { emitJson } from './json-output.js'
export { loadSchemaDefinitions } from './schema-loader.js'
4 changes: 2 additions & 2 deletions packages/cli/src/bin/migration-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ export interface MigrationJournal {
applied: MigrationJournalEntry[]
}

export interface ChecksumMismatch {
interface ChecksumMismatch {
name: string
expected: string
actual: string
}

export function parseJSONOrThrow<T>(raw: string, filePath: string, kind: string): T {
function parseJSONOrThrow<T>(raw: string, filePath: string, kind: string): T {
try {
return JSON.parse(raw) as T
} catch {
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/bin/safety-markers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface DestructiveOperationMarker {
summary: string
}

export interface MigrationOperationSummary {
interface MigrationOperationSummary {
type: string
key: string
risk: string
Expand All @@ -25,15 +25,15 @@ export function migrationContainsDangerOperation(sql: string): boolean {
return extractDestructiveOperationSummaries(sql).length > 0
}

export function extractDestructiveOperationSummaries(sql: string): string[] {
function extractDestructiveOperationSummaries(sql: string): string[] {
return sql
.split('\n')
.map((line) => line.trim())
.filter((line) => line.startsWith('-- operation:') && line.includes('risk=danger'))
.map((line) => line.replace(/^-- operation:\s*/, ''))
}

export function parseOperationLine(summary: string): MigrationOperationSummary | null {
function parseOperationLine(summary: string): MigrationOperationSummary | null {
const match = summary.match(/^([a-z_]+)\s+key=([^\s]+)\s+risk=([a-z_]+)$/)
if (!match) return null
return {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/bin/table-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
matchCount: number
}

export interface TableScopeFilterResult {
interface TableScopeFilterResult {
plan: MigrationPlan
omittedOperationCount: number
}
Expand All @@ -30,7 +30,7 @@
newName: string
}

export function tableKey(database: string, name: string): string {
function tableKey(database: string, name: string): string {
return `${database}.${name}`
}

Expand Down Expand Up @@ -198,7 +198,7 @@
}
}

export function buildScopedSnapshotDefinitions(input: {

Check warning on line 201 in packages/cli/src/bin/table-scope.ts

View workflow job for this annotation

GitHub Actions / verify

High CRAP score (high)

Function 'buildScopedSnapshotDefinitions' has a CRAP score of 56.3 (threshold: 30.0). • Severity: high • Cyclomatic: 14 • Cognitive: 19 • CRAP: 56.3 (threshold: 30.0) • Lines: 43 CRAP combines complexity with coverage: high CRAP means changes here carry high risk. Consider adding tests, simplifying the function, or both.
previousDefinitions: SchemaDefinition[]
nextDefinitions: SchemaDefinition[]
matchedTables: ReadonlySet<string>
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/drift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
} from '@chkit/core'
import { diffByName, diffNamedShapeMaps, diffSettings } from './drift-diff.js'

export type TableDriftReasonCode =
type TableDriftReasonCode =
| 'missing_column'
| 'extra_column'
| 'changed_column'
Expand All @@ -22,10 +22,10 @@
| 'unique_key_mismatch'
| 'projection_mismatch'

export type ObjectDriftReasonCode = 'missing_object' | 'extra_object' | 'kind_mismatch'
export type DriftReasonCode = ObjectDriftReasonCode | TableDriftReasonCode
type ObjectDriftReasonCode = 'missing_object' | 'extra_object' | 'kind_mismatch'
type DriftReasonCode = ObjectDriftReasonCode | TableDriftReasonCode

export interface SchemaObjectShape {
interface SchemaObjectShape {
kind: 'table' | 'view' | 'materialized_view'
database: string
name: string
Expand All @@ -38,7 +38,7 @@
actualKind?: SchemaObjectShape['kind']
}

export interface ActualTableShape {
interface ActualTableShape {
columns: ColumnDefinition[]
settings: Record<string, string>
indexes: SkipIndexDefinition[]
Expand Down Expand Up @@ -68,7 +68,7 @@
projectionDiffs: string[]
}

export interface DriftReasonSummary {
interface DriftReasonSummary {
counts: Partial<Record<DriftReasonCode, number>>
total: number
object: number
Expand Down Expand Up @@ -242,7 +242,7 @@
return coreNormalizeEngine(normalizeSQLFragment(value)).toLowerCase()
}

export function compareTableShape(expected: TableDefinition, actual: ActualTableShape): TableDriftDetail | null {

Check warning on line 245 in packages/cli/src/drift.ts

View workflow job for this annotation

GitHub Actions / verify

High cognitive complexity (moderate)

Function 'compareTableShape' is hard to understand (cognitive: 19, threshold: 15). • Severity: moderate • Cyclomatic: 20 • Cognitive: 19 • Lines: 81 High cognitive complexity means deeply nested or interleaved logic. Consider flattening control flow or extracting helper functions.
const columnDiff = diffByName(
expected.columns,
actual.columns,
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/diff-primitives.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export interface NamedDiffChange<T> {
interface NamedDiffChange<T> {
name: string
oldItem: T
newItem: T
}

export interface NamedDiffResult<T> {
interface NamedDiffResult<T> {
added: T[]
removed: T[]
changed: NamedDiffChange<T>[]
Expand Down Expand Up @@ -48,7 +48,7 @@ export function diffByName<T>(
}
}

export interface SettingDiffResult {
interface SettingDiffResult {
changes: Array<
| { kind: 'modify'; key: string; value: string | number | boolean }
| { kind: 'reset'; key: string }
Expand Down Expand Up @@ -79,7 +79,7 @@ export function diffSettings(
}
}

export interface ClauseComparison {
interface ClauseComparison {
oldValue: string
newValue: string
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/sql.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import type {
ColumnDefinition,
MaterializedViewDefinition,
Expand Down Expand Up @@ -50,7 +50,7 @@
}
}

function renderTableSQL(def: TableDefinition): string {

Check warning on line 53 in packages/core/src/sql.ts

View workflow job for this annotation

GitHub Actions / verify

High CRAP score (moderate)

Function 'renderTableSQL' has a CRAP score of 31.6 (threshold: 30.0). • Severity: moderate • Cyclomatic: 10 • Cognitive: 9 • CRAP: 31.6 (threshold: 30.0) • Lines: 30 CRAP combines complexity with coverage: high CRAP means changes here carry high risk. Consider adding tests, simplifying the function, or both.
const columns = def.columns.map(renderColumn)
const indexes = (def.indexes ?? []).map(
(idx) =>
Expand Down Expand Up @@ -101,7 +101,7 @@
* [DEPENDS ON <list>] [SETTINGS <kv>] [APPEND]
* Note: EMPTY belongs after TO in CREATE, so it's NOT included here.
*/
export function renderRefreshClause(refresh: MaterializedViewRefresh): string {
function renderRefreshClause(refresh: MaterializedViewRefresh): string {

Check warning on line 104 in packages/core/src/sql.ts

View workflow job for this annotation

GitHub Actions / verify

High CRAP score (moderate)

Function 'renderRefreshClause' has a CRAP score of 31.6 (threshold: 30.0). • Severity: moderate • Cyclomatic: 10 • Cognitive: 9 • CRAP: 31.6 (threshold: 30.0) • Lines: 15 CRAP combines complexity with coverage: high CRAP means changes here carry high risk. Consider adding tests, simplifying the function, or both.
const parts: string[] = []
if (refresh.every) parts.push(`REFRESH EVERY ${refresh.every}`)
else if (refresh.after) parts.push(`REFRESH AFTER ${refresh.after}`)
Expand Down
Loading
Loading