mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 09:36:01 +00:00
sorting key support, clickhouse recreate table support
This commit is contained in:
@@ -46,6 +46,14 @@ export function generateTablePairingId(table: TableInfo): TableInfo {
|
||||
if (!table.pairingId) {
|
||||
return {
|
||||
...table,
|
||||
primaryKey: table.primaryKey && {
|
||||
...table.primaryKey,
|
||||
pairingId: table.primaryKey.pairingId || uuidv1(),
|
||||
},
|
||||
sortingKey: table.sortingKey && {
|
||||
...table.sortingKey,
|
||||
pairingId: table.sortingKey.pairingId || uuidv1(),
|
||||
},
|
||||
columns: table.columns?.map(col => ({
|
||||
...col,
|
||||
pairingId: col.pairingId || uuidv1(),
|
||||
@@ -335,6 +343,7 @@ export function testEqualTypes(a: ColumnInfo, b: ColumnInfo, opts: DbDiffOptions
|
||||
function getTableConstraints(table: TableInfo) {
|
||||
const res = [];
|
||||
if (table.primaryKey) res.push(table.primaryKey);
|
||||
if (table.sortingKey) res.push(table.sortingKey);
|
||||
if (table.foreignKeys) res.push(...table.foreignKeys);
|
||||
if (table.indexes) res.push(...table.indexes);
|
||||
if (table.uniques) res.push(...table.uniques);
|
||||
@@ -345,7 +354,9 @@ function getTableConstraints(table: TableInfo) {
|
||||
function createPairs(oldList, newList, additionalCondition = null) {
|
||||
const res = [];
|
||||
for (const a of oldList) {
|
||||
const b = newList.find(x => x.pairingId == a.pairingId || (additionalCondition && additionalCondition(a, x)));
|
||||
const b = newList.find(
|
||||
x => (a.pairingId && x.pairingId == a.pairingId) || (additionalCondition && additionalCondition(a, x))
|
||||
);
|
||||
if (b) {
|
||||
res.push([a, b]);
|
||||
} else {
|
||||
@@ -381,9 +392,14 @@ function planAlterTable(plan: AlterPlan, oldTable: TableInfo, newTable: TableInf
|
||||
const constraintPairs = createPairs(
|
||||
getTableConstraints(oldTable),
|
||||
getTableConstraints(newTable),
|
||||
(a, b) => a.constraintType == 'primaryKey' && b.constraintType == 'primaryKey'
|
||||
(a, b) =>
|
||||
(a.constraintType == 'primaryKey' && b.constraintType == 'primaryKey') ||
|
||||
(a.constraintType == 'sortingKey' && b.constraintType == 'sortingKey')
|
||||
);
|
||||
// console.log('constraintPairs SOURCE', getTableConstraints(oldTable), getTableConstraints(newTable));
|
||||
// console.log('constraintPairs OLD TABLE', oldTable);
|
||||
// console.log('constraintPairs NEW TABLE', newTable);
|
||||
// console.log('constraintPairs SOURCE OLD', getTableConstraints(oldTable));
|
||||
// console.log('constraintPairs SOURCE NEW', getTableConstraints(newTable));
|
||||
// console.log('constraintPairs', constraintPairs);
|
||||
|
||||
if (!opts.noDropConstraint) {
|
||||
@@ -427,6 +443,10 @@ function planAlterTable(plan: AlterPlan, oldTable: TableInfo, newTable: TableInf
|
||||
planTablePreload(plan, oldTable, newTable);
|
||||
|
||||
planChangeTableOptions(plan, oldTable, newTable, opts);
|
||||
|
||||
// console.log('oldTable', oldTable);
|
||||
// console.log('newTable', newTable);
|
||||
// console.log('plan.operations', plan.operations);
|
||||
}
|
||||
|
||||
function planChangeTableOptions(plan: AlterPlan, oldTable: TableInfo, newTable: TableInfo, opts: DbDiffOptions) {
|
||||
|
||||
Reference in New Issue
Block a user