/** * Constraint Definitions Module * Handles constraint definition, comparison, and generation logic */ import type { ILegacySyncOptions, TNullable } from '../types'; import { type SyncDbSide } from '../sync/syncClient'; import type { Client } from 'pg'; interface IConstraintRow { table_name: string; constraint_name: string; constraint_type: string; column_name: TNullable; foreign_table_name: TNullable; foreign_column_name: TNullable; update_rule: TNullable; delete_rule: TNullable; check_clause?: TNullable; } interface IConstraintClauseParams { constraintType: string; columns: string; foreignTableName?: TNullable; foreignColumnName?: TNullable; updateRule?: TNullable; deleteRule?: TNullable; checkClause?: TNullable; targetSchema: string; } export declare class ConstraintDefinitions { private sourceClient; private targetClient; private options; constructor(sourceClient: Client, targetClient: Client, options: ILegacySyncOptions); /** * Get detailed constraint definition from the given database side. * * Reads pg_constraint.conkey/confkey directly (via unnest ... WITH ORDINALITY) * instead of joining information_schema.key_column_usage x constraint_column_usage: * that join is keyed only on constraint_name, so composite constraints produce a * cross product of local x referenced column rows with no positional pairing, * silently corrupting which local column maps to which referenced column. * Always resolves to at most one row per constraint. */ getConstraintDefinition(side: SyncDbSide, constraintName: string, tableName: string): Promise; /** * Generate constraint type specific clause */ generateConstraintClause(params: IConstraintClauseParams): string; /** * Compare two constraint definitions to detect changes */ compareConstraintDefinitions(sourceConstraint: IConstraintRow, targetConstraint: IConstraintRow): boolean; /** * Generate CREATE CONSTRAINT statement. * * `getConstraintDefinition` resolves to at most one row per constraint, with * `column_name` / `foreign_column_name` already aggregated in the correct * positional order (see its query), so no further merging is needed here. */ generateCreateConstraintStatement(constraintRows: IConstraintRow[] | null, targetSchema: string): string; /** * Generate a proper constraint name * Uses consistent naming strategy with gen command */ private generateProperConstraintName; } export {}; //# sourceMappingURL=constraintDefinitions.d.ts.map