| 528 | } |
| 529 | |
| 530 | export function generateCreateIndexQuery( |
| 531 | indexes: readonly ModelIndexesOptions[], |
| 532 | schema: string, |
| 533 | tableName: string |
| 534 | ): string[] { |
| 535 | const indexQueries: string[] = []; |
| 536 | indexes.forEach((index) => { |
| 537 | const fieldsList = index.fields?.map((field) => `"${field}"`).join(', '); |
| 538 | const unique = index.unique ? 'UNIQUE' : ''; |
| 539 | const indexUsed = index.using ? `USING ${index.using}` : ''; |
| 540 | const indexName = index.name; |
| 541 | |
| 542 | const query = `CREATE ${unique} INDEX IF NOT EXISTS "${indexName}" ON "${schema}"."${tableName}" ${indexUsed} (${fieldsList});`; |
| 543 | indexQueries.push(query); |
| 544 | }); |
| 545 | |
| 546 | return indexQueries; |
| 547 | } |
| 548 | |
| 549 | export function sortModels(relations: GraphQLRelationsType[], models: GraphQLModelsType[]): GraphQLModelsType[] | null { |
| 550 | const sorter = new Toposort(); |