mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 03:53:57 +00:00
indexes in yaml model
This commit is contained in:
@@ -22,12 +22,22 @@ export interface DatabaseModelFile {
|
|||||||
text: string;
|
text: string;
|
||||||
json: {};
|
json: {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IndexInfoYaml {
|
||||||
|
name: string;
|
||||||
|
unique?: boolean;
|
||||||
|
filter?: string;
|
||||||
|
columns: string[];
|
||||||
|
included?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface TableInfoYaml {
|
export interface TableInfoYaml {
|
||||||
name: string;
|
name: string;
|
||||||
// schema?: string;
|
// schema?: string;
|
||||||
columns: ColumnInfoYaml[];
|
columns: ColumnInfoYaml[];
|
||||||
primaryKey?: string[];
|
primaryKey?: string[];
|
||||||
sortingKey?: string[];
|
sortingKey?: string[];
|
||||||
|
indexes?: IndexInfoYaml[];
|
||||||
|
|
||||||
insertKey?: string[];
|
insertKey?: string[];
|
||||||
insertOnly?: string[];
|
insertOnly?: string[];
|
||||||
@@ -97,6 +107,20 @@ export function tableInfoToYaml(table: TableInfo): TableInfoYaml {
|
|||||||
res.sortingKey = tableCopy.sortingKey.columns.map(x => x.columnName);
|
res.sortingKey = tableCopy.sortingKey.columns.map(x => x.columnName);
|
||||||
}
|
}
|
||||||
// const foreignKeys = (tableCopy.foreignKeys || []).filter(x => !x['_dumped']).map(foreignKeyInfoToYaml);
|
// const foreignKeys = (tableCopy.foreignKeys || []).filter(x => !x['_dumped']).map(foreignKeyInfoToYaml);
|
||||||
|
if (tableCopy.indexes?.length > 0) {
|
||||||
|
res.indexes = tableCopy.indexes.map(index => {
|
||||||
|
const idx: IndexInfoYaml = {
|
||||||
|
name: index.constraintName,
|
||||||
|
unique: index.isUnique,
|
||||||
|
filter: index.filterDefinition,
|
||||||
|
columns: index.columns.filter(x => !x.isIncludedColumn).map(x => x.columnName),
|
||||||
|
};
|
||||||
|
if (index.columns.some(x => x.isIncludedColumn)) {
|
||||||
|
idx.included = index.columns.filter(x => x.isIncludedColumn).map(x => x.columnName);
|
||||||
|
}
|
||||||
|
return idx;
|
||||||
|
});
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,6 +154,16 @@ export function tableInfoFromYaml(table: TableInfoYaml, allTables: TableInfoYaml
|
|||||||
foreignKeys: _compact(
|
foreignKeys: _compact(
|
||||||
table.columns.filter(x => x.references).map(col => convertForeignKeyFromYaml(col, table, allTables))
|
table.columns.filter(x => x.references).map(col => convertForeignKeyFromYaml(col, table, allTables))
|
||||||
),
|
),
|
||||||
|
indexes: table.indexes?.map(index => ({
|
||||||
|
constraintName: index.name,
|
||||||
|
pureName: table.name,
|
||||||
|
isUnique: index.unique,
|
||||||
|
constraintType: 'index',
|
||||||
|
columns: [
|
||||||
|
...index.columns.map(columnName => ({ columnName })),
|
||||||
|
...(index.included || []).map(columnName => ({ columnName, isIncludedColumn: true })),
|
||||||
|
],
|
||||||
|
})),
|
||||||
};
|
};
|
||||||
if (table.primaryKey) {
|
if (table.primaryKey) {
|
||||||
res.primaryKey = {
|
res.primaryKey = {
|
||||||
|
|||||||
4
packages/types/dbinfo.d.ts
vendored
4
packages/types/dbinfo.d.ts
vendored
@@ -34,7 +34,9 @@ export interface ForeignKeyInfo extends ColumnsConstraintInfo {
|
|||||||
export interface IndexInfo extends ColumnsConstraintInfo {
|
export interface IndexInfo extends ColumnsConstraintInfo {
|
||||||
isUnique: boolean;
|
isUnique: boolean;
|
||||||
// indexType: 'normal' | 'clustered' | 'xml' | 'spatial' | 'fulltext';
|
// indexType: 'normal' | 'clustered' | 'xml' | 'spatial' | 'fulltext';
|
||||||
indexType: string;
|
indexType?: string;
|
||||||
|
// condition for filtered index (SQL Server)
|
||||||
|
filterDefinition?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UniqueInfo extends ColumnsConstraintInfo {}
|
export interface UniqueInfo extends ColumnsConstraintInfo {}
|
||||||
|
|||||||
Reference in New Issue
Block a user