mirror of
https://github.com/chartdb/chartdb.git
synced 2026-02-10 05:29:57 -06:00
fix: export ddl index order (#1028)
* fix: export ddl index order * fix
This commit is contained in:
@@ -228,7 +228,8 @@ export function exportMSSQL({
|
||||
? `CREATE ${index.unique ? 'UNIQUE ' : ''}INDEX ${indexName}\nON ${tableName} (${indexFields.join(', ')});`
|
||||
: '';
|
||||
})
|
||||
.filter(Boolean);
|
||||
.filter(Boolean)
|
||||
.sort((a, b) => a.localeCompare(b)); // Sort for consistent output
|
||||
|
||||
return validIndexes.length > 0
|
||||
? `\n-- Indexes\n${validIndexes.join('\n')}`
|
||||
|
||||
@@ -418,7 +418,8 @@ export function exportMySQL({
|
||||
? `CREATE ${index.unique ? 'UNIQUE ' : ''}INDEX ${indexName} ON ${tableName} (${indexFieldsWithPrefix.join(', ')});`
|
||||
: '';
|
||||
})
|
||||
.filter(Boolean);
|
||||
.filter(Boolean)
|
||||
.sort((a, b) => a.localeCompare(b)); // Sort for consistent output
|
||||
|
||||
return validIndexes.length > 0
|
||||
? `\n-- Indexes\n${validIndexes.join('\n')}`
|
||||
|
||||
@@ -421,7 +421,8 @@ export function exportPostgreSQL({
|
||||
? `CREATE ${index.unique ? 'UNIQUE ' : ''}INDEX ${indexName} ON ${tableName}${index.type && index.type !== 'btree' ? ` USING ${index.type.toUpperCase()}` : ''} (${indexFieldNames.join(', ')});`
|
||||
: '';
|
||||
})
|
||||
.filter(Boolean);
|
||||
.filter(Boolean)
|
||||
.sort((a, b) => a.localeCompare(b)); // Sort for consistent output
|
||||
|
||||
return validIndexes.length > 0
|
||||
? `\n-- Indexes\n${validIndexes.join('\n')}`
|
||||
|
||||
@@ -444,7 +444,8 @@ export function exportSQLite({
|
||||
? `CREATE ${index.unique ? 'UNIQUE ' : ''}INDEX IF NOT EXISTS "${safeIndexName}"\nON ${tableName} (${indexFieldNames.join(', ')});`
|
||||
: '';
|
||||
})
|
||||
.filter(Boolean);
|
||||
.filter(Boolean)
|
||||
.sort((a, b) => a.localeCompare(b)); // Sort for consistent output
|
||||
|
||||
return validIndexes.length > 0
|
||||
? `\n-- Indexes\n${validIndexes.join('\n')}`
|
||||
|
||||
@@ -540,7 +540,9 @@ export const exportBaseSQL = ({
|
||||
}
|
||||
});
|
||||
|
||||
// Generate SQL for indexes
|
||||
// Generate SQL for indexes - collect, then sort by the full CREATE INDEX statement
|
||||
const indexStatements: string[] = [];
|
||||
|
||||
table.indexes.forEach((index) => {
|
||||
// Skip the primary key index (it's already handled as a constraint)
|
||||
if (index.isPrimaryKey) {
|
||||
@@ -582,9 +584,18 @@ export const exportBaseSQL = ({
|
||||
const indexName = needsQuoting
|
||||
? `"${rawIndexName}"`
|
||||
: rawIndexName;
|
||||
sqlScript += `CREATE ${index.unique ? 'UNIQUE ' : ''}INDEX ${indexName} ON ${tableName} (${fieldNames});\n`;
|
||||
indexStatements.push(
|
||||
`CREATE ${index.unique ? 'UNIQUE ' : ''}INDEX ${indexName} ON ${tableName} (${fieldNames});`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Sort index statements alphabetically for consistent, deterministic output
|
||||
indexStatements.sort((a, b) => a.localeCompare(b));
|
||||
sqlScript += indexStatements.join('\n');
|
||||
if (indexStatements.length > 0) {
|
||||
sqlScript += '\n';
|
||||
}
|
||||
});
|
||||
|
||||
if (nonViewTables.length > 0 && (relationships?.length ?? 0) > 0) {
|
||||
|
||||
@@ -2973,9 +2973,9 @@ Table "data"."Products_20" {
|
||||
"field_32" text
|
||||
|
||||
Indexes {
|
||||
geom [name: "idx_Products_20_3"]
|
||||
updated_at [unique, name: "idx_Products_20_1"]
|
||||
updated_at [unique, name: "idx_Products_20_2"]
|
||||
geom [name: "idx_Products_20_3"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6449,8 +6449,8 @@ Table "admin"."Transactions_2" {
|
||||
"amount" nvarchar(500)
|
||||
|
||||
Indexes {
|
||||
updated_at [unique, name: "idx_Transactions_2_1"]
|
||||
geom [name: "idx_Transactions_2_2"]
|
||||
updated_at [unique, name: "idx_Transactions_2_1"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6802,8 +6802,8 @@ Table "admin"."Transactions_14" {
|
||||
"field_65" date
|
||||
|
||||
Indexes {
|
||||
updated_at [unique, name: "idx_Transactions_14_1"]
|
||||
geom [name: "idx_Transactions_14_2"]
|
||||
updated_at [unique, name: "idx_Transactions_14_1"]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ Table "pokemon"."pokemon_abilities" {
|
||||
|
||||
Indexes {
|
||||
(pok_id, slot) [pk]
|
||||
is_hidden [name: "pokemon_abilities_pokemon_ix_pokemon_abilities_is_hidden"]
|
||||
abil_id [name: "pokemon_abilities_pokemon_abil_id"]
|
||||
is_hidden [name: "pokemon_abilities_pokemon_ix_pokemon_abilities_is_hidden"]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ Table "pokemon"."pokemon_abilities" {
|
||||
|
||||
Indexes {
|
||||
(pok_id, slot) [pk]
|
||||
is_hidden [name: "pokemon_abilities_pokemon_ix_pokemon_abilities_is_hidden"]
|
||||
abil_id [name: "pokemon_abilities_pokemon_abil_id"]
|
||||
is_hidden [name: "pokemon_abilities_pokemon_ix_pokemon_abilities_is_hidden"]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user