/**
 * SQL analysis tools — analyze_schema and trace_query.
 * Hidden/discoverable: not in CORE_TOOL_NAMES.
 */
export type SqlDialect = "mysql" | "postgres" | "sqlite" | "mssql" | "unknown";
export interface AnalyzeSchemaOptions {
    file_pattern?: string;
    output_format?: "json" | "mermaid";
    include_columns?: boolean;
    /**
     * Force a specific dialect. When omitted (or set to "auto"), the dialect is
     * inferred from schema source via {@link detectSqlDialect} — content fingerprints
     * like ENGINE=InnoDB, AUTO_INCREMENT, SERIAL, JSONB, AUTOINCREMENT, IDENTITY.
     */
    dialect?: SqlDialect | "auto";
}
export interface TableInfo {
    name: string;
    file: string;
    line: number;
    columns: Array<{
        name: string;
        type: string;
    }>;
}
export interface Relationship {
    from_table: string;
    from_column: string;
    to_table: string;
    to_column: string;
    type: "fk" | "self_reference" | "circular";
}
export interface SchemaAnalysisResult {
    tables: TableInfo[];
    views: Array<{
        name: string;
        file: string;
        line: number;
    }>;
    relationships: Relationship[];
    warnings: string[];
    mermaid?: string;
    /**
     * Detected (or forced) SQL dialect. "unknown" when no fingerprint matched
     * — typical for ORM-only repos where the canonical schema lives in TS/Prisma.
     */
    detected_dialect: SqlDialect;
}
/**
 * Infer SQL dialect from schema source fingerprints.
 *
 * Signals (in priority order):
 *   - mysql:    ENGINE=InnoDB / ENGINE=MyISAM / AUTO_INCREMENT / utf8mb4 / backtick idents
 *   - postgres: SERIAL / BIGSERIAL / JSONB / RETURNING / USING gist / CITEXT
 *   - sqlite:   AUTOINCREMENT (one word) / WITHOUT ROWID / sqlite_master
 *   - mssql:    NVARCHAR / IDENTITY(\d, \d) / GO\n batch separator / [bracket] idents
 *
 * Returns "unknown" if no signal fires (e.g. dialect-neutral CREATE TABLE).
 * Exported for unit-test independence and for callers that want a quick check
 * without going through {@link analyzeSchema}.
 */
export declare function detectSqlDialect(source: string): SqlDialect;
export declare function analyzeSchema(repo: string, options?: AnalyzeSchemaOptions): Promise<SchemaAnalysisResult>;
export interface TraceQueryOptions {
    table: string;
    include_orm?: boolean;
    file_pattern?: string;
    max_references?: number;
}
export interface SqlReference {
    file: string;
    line: number;
    context: string;
    type: "ddl" | "dml" | "view" | "fk";
}
export interface OrmReference {
    file: string;
    line: number;
    orm: "prisma" | "drizzle";
    model_name: string;
}
export interface TraceQueryResult {
    table_definition: {
        file: string;
        line: number;
        kind: "table" | "view";
    } | null;
    sql_references: SqlReference[];
    orm_references: OrmReference[];
    warnings: string[];
    truncated: boolean;
}
export declare function traceQuery(repo: string, options: TraceQueryOptions): Promise<TraceQueryResult>;
export interface SearchColumnsOptions {
    /** Substring to match against column name (case-insensitive). Empty string = no name filter. */
    query: string;
    /** Optional: filter by normalized column type (int, string, float, bool, datetime, json, uuid, bytes) */
    type?: string;
    /** Optional: substring to match against table name */
    table?: string;
    /** Optional: file_pattern to scope */
    file_pattern?: string;
    /** Maximum columns to return (default: 100) */
    max_results?: number;
}
export interface ColumnSearchHit {
    name: string;
    type: string;
    normalized_type: string;
    table: string;
    file: string;
    line: number;
}
export interface SearchColumnsResult {
    columns: ColumnSearchHit[];
    total: number;
    truncated: boolean;
}
export declare function searchColumns(repo: string, options: SearchColumnsOptions): Promise<SearchColumnsResult>;
export interface TableComplexity {
    name: string;
    file: string;
    line: number;
    column_count: number;
    fk_count: number;
    index_count: number;
    score: number;
}
export interface SchemaComplexityResult {
    tables: TableComplexity[];
}
/**
 * Per-table complexity score: column count + FK count + index count.
 * Identifies "god tables" that need refactoring. Sorted by score desc.
 */
export declare function analyzeSchemaComplexity(repo: string, options?: {
    file_pattern?: string;
    top_n?: number;
}): Promise<SchemaComplexityResult>;
export interface DmlFinding {
    rule: string;
    severity: "high" | "medium" | "info";
    file: string;
    line: number;
    context?: string;
    detail: string;
}
export interface ScanDmlSafetyResult {
    findings: DmlFinding[];
    summary: {
        total: number;
        by_rule: Record<string, number>;
        files_scanned: number;
    };
}
/**
 * Scan codebase for unsafe DML patterns in SQL strings.
 * Uses ripgrep to find DML statements, then classifies safety.
 */
export declare function scanDmlSafety(repo: string, options?: {
    file_pattern?: string;
    max_results?: number;
}): Promise<ScanDmlSafetyResult>;
export interface LintFinding {
    rule: string;
    severity: "warning" | "info";
    table: string;
    detail: string;
    file: string;
    line: number;
}
export interface LintSchemaResult {
    findings: LintFinding[];
    summary: {
        total: number;
        by_rule: Record<string, number>;
    };
    warnings: string[];
}
/**
 * Lint SQL schema for common anti-patterns.
 * Conservative ruleset with near-zero false positive rate:
 * - no-primary-key: table without PRIMARY KEY (serious design smell)
 * - wide-table: table with >20 columns (god table)
 * - duplicate-index-name: same index name defined multiple times
 */
export declare function lintSchema(repo: string, options?: {
    file_pattern?: string;
}): Promise<LintSchemaResult>;
export interface MigrationOp {
    operation: string;
    target: string;
    severity: "low" | "medium" | "high";
    file: string;
    line: number;
    raw: string;
}
export interface DiffMigrationsResult {
    additive: MigrationOp[];
    modifying: MigrationOp[];
    destructive: MigrationOp[];
    summary: {
        additive: number;
        modifying: number;
        destructive: number;
        total_files: number;
    };
}
export declare function diffMigrations(repo: string, options?: {
    file_pattern?: string;
}): Promise<DiffMigrationsResult>;
export interface OrphanTable {
    name: string;
    file: string;
    line: number;
    column_count: number;
}
export interface FindOrphanTablesResult {
    orphans: OrphanTable[];
    total_tables: number;
    orphan_count: number;
}
/**
 * Find SQL tables with zero references outside their own CREATE TABLE definition.
 * Uses ripgrep-backed literal search per table for speed.
 */
export declare function findOrphanTables(repo: string, options?: {
    file_pattern?: string;
}): Promise<FindOrphanTablesResult>;
export type DriftKind = "extra_in_orm" | "extra_in_sql" | "type_mismatch";
export interface SchemaDrift {
    kind: DriftKind;
    table: string;
    column?: string;
    orm: "prisma" | "drizzle" | "typeorm";
    orm_file?: string;
    orm_line?: number;
    sql_file?: string;
    sql_line?: number;
    orm_type?: string;
    sql_type?: string;
    detail: string;
}
export interface DriftSummary {
    extra_in_orm: number;
    extra_in_sql: number;
    type_mismatches: number;
    total: number;
}
export interface SchemaDriftResult {
    drifts: SchemaDrift[];
    summary: DriftSummary;
    orms_detected: Array<"prisma" | "drizzle" | "typeorm">;
    warnings: string[];
}
export interface AnalyzeSchemaDriftOptions {
    file_pattern?: string;
}
export declare function analyzeSchemaDrift(repo: string, options?: AnalyzeSchemaDriftOptions): Promise<SchemaDriftResult>;
export type SqlAuditCheck = "drift" | "orphan" | "lint" | "dml" | "complexity";
export interface SqlAuditOptions {
    /** Which checks to run (default: all) */
    checks?: SqlAuditCheck[];
    /** Scope to files matching pattern */
    file_pattern?: string;
    /** Optional: max_results for dml scan */
    max_results?: number;
}
export interface SqlAuditGate {
    check: SqlAuditCheck;
    pass: boolean;
    critical: boolean;
    finding_count: number;
    /** Per-check result shape differs; let consumers drill into .data if needed */
    data: unknown;
    /** One-line human-readable summary */
    summary: string;
}
export interface SqlAuditResult {
    gates: SqlAuditGate[];
    summary: {
        total_findings: number;
        critical_findings: number;
        gates_run: number;
        gates_passed: number;
        gates_failed: number;
    };
    warnings: string[];
}
/**
 * Composite SQL audit — runs multiple diagnostic gates in a single call.
 * Mirrors framework_audit / nest_audit / audit_scan pattern.
 *
 * Individual gate functions (analyzeSchemaDrift, findOrphanTables, lintSchema,
 * scanDmlSafety, analyzeSchemaComplexity) remain exported for internal use
 * but are NOT registered as separate MCP tools. sql_audit is the single
 * discoverable entry point.
 */
export declare function sqlAudit(repo: string, options?: SqlAuditOptions): Promise<SqlAuditResult>;
//# sourceMappingURL=sql-tools.d.ts.map