({
diagram,
newDiagram,
options = {},
}: {
diagram: Diagram;
newDiagram: Diagram;
options?: GenerateDiffOptions;
})
| 169 | } |
| 170 | |
| 171 | export function generateDiff({ |
| 172 | diagram, |
| 173 | newDiagram, |
| 174 | options = {}, |
| 175 | }: { |
| 176 | diagram: Diagram; |
| 177 | newDiagram: Diagram; |
| 178 | options?: GenerateDiffOptions; |
| 179 | }): { |
| 180 | diffMap: DiffMap; |
| 181 | changedTables: Map<string, boolean>; |
| 182 | changedFields: Map<string, boolean>; |
| 183 | changedIndexes: Map<string, boolean>; |
| 184 | changedCheckConstraints: Map<string, boolean>; |
| 185 | changedRelationships: Map<string, boolean>; |
| 186 | changedAreas: Map<string, boolean>; |
| 187 | changedNotes: Map<string, boolean>; |
| 188 | relationshipIdMap: Map<string, string>; |
| 189 | } { |
| 190 | // Merge with default options |
| 191 | const mergedOptions: GenerateDiffOptions = { |
| 192 | includeTables: options.includeTables ?? true, |
| 193 | includeFields: options.includeFields ?? true, |
| 194 | includeIndexes: options.includeIndexes ?? true, |
| 195 | includeCheckConstraints: options.includeCheckConstraints ?? true, |
| 196 | includeRelationships: options.includeRelationships ?? true, |
| 197 | includeAreas: options.includeAreas ?? false, |
| 198 | includeNotes: options.includeNotes ?? false, |
| 199 | attributes: options.attributes ?? {}, |
| 200 | changedMaps: options.changedMaps, |
| 201 | changeTypes: options.changeTypes ?? {}, |
| 202 | matchers: options.matchers ?? {}, |
| 203 | }; |
| 204 | |
| 205 | const newDiffs = new Map<string, ChartDBDiff>(); |
| 206 | const changedTables = new Map<string, boolean>(); |
| 207 | const changedFields = new Map<string, boolean>(); |
| 208 | const changedIndexes = new Map<string, boolean>(); |
| 209 | const changedCheckConstraints = new Map<string, boolean>(); |
| 210 | const changedRelationships = new Map<string, boolean>(); |
| 211 | const changedAreas = new Map<string, boolean>(); |
| 212 | const changedNotes = new Map<string, boolean>(); |
| 213 | const relationshipIdMap = new Map<string, string>(); |
| 214 | |
| 215 | // Use provided matchers or default ones |
| 216 | const tableMatcher = mergedOptions.matchers?.table ?? defaultTableMatcher; |
| 217 | const fieldMatcher = mergedOptions.matchers?.field ?? defaultFieldMatcher; |
| 218 | const indexMatcher = mergedOptions.matchers?.index ?? defaultIndexMatcher; |
| 219 | const checkConstraintMatcher = |
| 220 | mergedOptions.matchers?.checkConstraint ?? |
| 221 | defaultCheckConstraintMatcher; |
| 222 | const relationshipMatcher = |
| 223 | mergedOptions.matchers?.relationship ?? defaultRelationshipMatcher; |
| 224 | const areaMatcher = mergedOptions.matchers?.area ?? defaultAreaMatcher; |
| 225 | const noteMatcher = mergedOptions.matchers?.note ?? defaultNoteMatcher; |
| 226 | |
| 227 | // Compare tables |
| 228 | if (mergedOptions.includeTables) { |
no test coverage detected