({
aggregatedIndexes,
fields,
}: {
aggregatedIndexes: AggregatedIndexInfo[];
fields: DBField[];
})
| 3 | import { generateId } from '@/lib/utils'; |
| 4 | |
| 5 | export const createIndexesFromMetadata = ({ |
| 6 | aggregatedIndexes, |
| 7 | fields, |
| 8 | }: { |
| 9 | aggregatedIndexes: AggregatedIndexInfo[]; |
| 10 | fields: DBField[]; |
| 11 | }): DBIndex[] => |
| 12 | aggregatedIndexes.map( |
| 13 | (idx): DBIndex => ({ |
| 14 | id: generateId(), |
| 15 | name: idx.name, |
| 16 | unique: Boolean(idx.unique), |
| 17 | fieldIds: idx.columns |
| 18 | .sort((a, b) => a.position - b.position) |
| 19 | .map((c) => fields.find((f) => f.name === c.name)?.id) |
| 20 | .filter((id): id is string => id !== undefined), |
| 21 | createdAt: Date.now(), |
| 22 | type: idx.index_type?.toLowerCase() as IndexType, |
| 23 | }) |
| 24 | ); |
no test coverage detected