mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-26 09:56:00 +00:00
drop unique column works
This commit is contained in:
@@ -9,7 +9,9 @@ const { getAlterTableScript, extendDatabaseInfo, generateDbPairingId } = require
|
|||||||
function pickImportantTableInfo(table) {
|
function pickImportantTableInfo(table) {
|
||||||
return {
|
return {
|
||||||
pureName: table.pureName,
|
pureName: table.pureName,
|
||||||
columns: table.columns.map(fp.pick(['columnName', 'notNull', 'autoIncrement'])),
|
columns: table.columns
|
||||||
|
.filter(x => x.columnName != 'rowid')
|
||||||
|
.map(fp.pick(['columnName', 'notNull', 'autoIncrement'])),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,9 +58,9 @@ async function testTableDiff(conn, driver, mangle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// const TESTED_COLUMNS = ['col_pk', 'col_std', 'col_def', 'col_fk', 'col_ref', 'col_idx', 'col_uq'];
|
// const TESTED_COLUMNS = ['col_pk', 'col_std', 'col_def', 'col_fk', 'col_ref', 'col_idx', 'col_uq'];
|
||||||
const TESTED_COLUMNS = ['col_pk'];
|
// const TESTED_COLUMNS = ['col_pk'];
|
||||||
// const TESTED_COLUMNS = ['col_idx'];
|
// const TESTED_COLUMNS = ['col_idx'];
|
||||||
// const TESTED_COLUMNS = ['col_fk'];
|
const TESTED_COLUMNS = ['col_uq'];
|
||||||
// const TESTED_COLUMNS = ['col_std'];
|
// const TESTED_COLUMNS = ['col_std'];
|
||||||
|
|
||||||
function engines_columns_source() {
|
function engines_columns_source() {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const matviews = {
|
|||||||
const engines = [
|
const engines = [
|
||||||
{
|
{
|
||||||
label: 'MySQL',
|
label: 'MySQL',
|
||||||
// skipLocal: true,
|
skipLocal: true,
|
||||||
connection: {
|
connection: {
|
||||||
engine: 'mysql@dbgate-plugin-mysql',
|
engine: 'mysql@dbgate-plugin-mysql',
|
||||||
password: 'Pwd2020Db',
|
password: 'Pwd2020Db',
|
||||||
@@ -34,7 +34,7 @@ const engines = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'PostgreSQL',
|
label: 'PostgreSQL',
|
||||||
// skipLocal: true,
|
skipLocal: true,
|
||||||
connection: {
|
connection: {
|
||||||
engine: 'postgres@dbgate-plugin-postgres',
|
engine: 'postgres@dbgate-plugin-postgres',
|
||||||
password: 'Pwd2020Db',
|
password: 'Pwd2020Db',
|
||||||
@@ -103,7 +103,7 @@ const engines = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'CockroachDB',
|
label: 'CockroachDB',
|
||||||
// skipLocal: true,
|
skipLocal: true,
|
||||||
connection: {
|
connection: {
|
||||||
engine: 'cockroach@dbgate-plugin-postgres',
|
engine: 'cockroach@dbgate-plugin-postgres',
|
||||||
user: 'root',
|
user: 'root',
|
||||||
|
|||||||
@@ -244,6 +244,8 @@ export class AlterPlan {
|
|||||||
if (cnt.constraintType == 'primaryKey') return this.dialect.createPrimaryKey;
|
if (cnt.constraintType == 'primaryKey') return this.dialect.createPrimaryKey;
|
||||||
if (cnt.constraintType == 'foreignKey') return this.dialect.createForeignKey;
|
if (cnt.constraintType == 'foreignKey') return this.dialect.createForeignKey;
|
||||||
if (cnt.constraintType == 'index') return this.dialect.createIndex;
|
if (cnt.constraintType == 'index') return this.dialect.createIndex;
|
||||||
|
if (cnt.constraintType == 'unique') return this.dialect.createUnique;
|
||||||
|
if (cnt.constraintType == 'check') return this.dialect.createCheck;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,6 +253,8 @@ export class AlterPlan {
|
|||||||
if (cnt.constraintType == 'primaryKey') return this.dialect.dropPrimaryKey;
|
if (cnt.constraintType == 'primaryKey') return this.dialect.dropPrimaryKey;
|
||||||
if (cnt.constraintType == 'foreignKey') return this.dialect.dropForeignKey;
|
if (cnt.constraintType == 'foreignKey') return this.dialect.dropForeignKey;
|
||||||
if (cnt.constraintType == 'index') return this.dialect.dropIndex;
|
if (cnt.constraintType == 'index') return this.dialect.dropIndex;
|
||||||
|
if (cnt.constraintType == 'unique') return this.dialect.dropUnique;
|
||||||
|
if (cnt.constraintType == 'check') return this.dialect.dropCheck;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,9 +368,11 @@ export function runAlterOperation(op: AlterOperation, processor: AlterProcessor)
|
|||||||
const newTable = _.cloneDeep(op.table);
|
const newTable = _.cloneDeep(op.table);
|
||||||
const newDb = DatabaseAnalyser.createEmptyStructure();
|
const newDb = DatabaseAnalyser.createEmptyStructure();
|
||||||
newDb.tables.push(newTable);
|
newDb.tables.push(newTable);
|
||||||
|
// console.log('////////////////////////////newTable1', newTable);
|
||||||
op.operations.forEach(child => runAlterOperation(child, new DatabaseInfoAlterProcessor(newDb)));
|
op.operations.forEach(child => runAlterOperation(child, new DatabaseInfoAlterProcessor(newDb)));
|
||||||
|
// console.log('////////////////////////////op.operations', op.operations);
|
||||||
// console.log('////////////////////////////op.table', op.table);
|
// console.log('////////////////////////////op.table', op.table);
|
||||||
// console.log('////////////////////////////newTable', newTable);
|
// console.log('////////////////////////////newTable2', newTable);
|
||||||
processor.recreateTable(op.table, newTable);
|
processor.recreateTable(op.table, newTable);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,4 +1,14 @@
|
|||||||
import { ColumnInfo, ConstraintInfo, DatabaseInfo, ForeignKeyInfo, PrimaryKeyInfo, TableInfo } from '../../types';
|
import {
|
||||||
|
ColumnInfo,
|
||||||
|
ConstraintInfo,
|
||||||
|
DatabaseInfo,
|
||||||
|
ForeignKeyInfo,
|
||||||
|
PrimaryKeyInfo,
|
||||||
|
TableInfo,
|
||||||
|
IndexInfo,
|
||||||
|
CheckInfo,
|
||||||
|
UniqueInfo,
|
||||||
|
} from '../../types';
|
||||||
|
|
||||||
export class DatabaseInfoAlterProcessor {
|
export class DatabaseInfoAlterProcessor {
|
||||||
constructor(public db: DatabaseInfo) {}
|
constructor(public db: DatabaseInfo) {}
|
||||||
@@ -35,6 +45,15 @@ export class DatabaseInfoAlterProcessor {
|
|||||||
case 'foreignKey':
|
case 'foreignKey':
|
||||||
table.foreignKeys.push(constraint as ForeignKeyInfo);
|
table.foreignKeys.push(constraint as ForeignKeyInfo);
|
||||||
break;
|
break;
|
||||||
|
case 'index':
|
||||||
|
table.indexes.push(constraint as IndexInfo);
|
||||||
|
break;
|
||||||
|
case 'unique':
|
||||||
|
table.uniques.push(constraint as UniqueInfo);
|
||||||
|
break;
|
||||||
|
case 'check':
|
||||||
|
table.checks.push(constraint as CheckInfo);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,6 +72,15 @@ export class DatabaseInfoAlterProcessor {
|
|||||||
case 'foreignKey':
|
case 'foreignKey':
|
||||||
table.foreignKeys = table.foreignKeys.filter(x => x.constraintName != constraint.constraintName);
|
table.foreignKeys = table.foreignKeys.filter(x => x.constraintName != constraint.constraintName);
|
||||||
break;
|
break;
|
||||||
|
case 'index':
|
||||||
|
table.indexes = table.indexes.filter(x => x.constraintName != constraint.constraintName);
|
||||||
|
break;
|
||||||
|
case 'unique':
|
||||||
|
table.uniques = table.uniques.filter(x => x.constraintName != constraint.constraintName);
|
||||||
|
break;
|
||||||
|
case 'check':
|
||||||
|
table.checks = table.checks.filter(x => x.constraintName != constraint.constraintName);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
4
packages/types/dialect.d.ts
vendored
4
packages/types/dialect.d.ts
vendored
@@ -25,4 +25,8 @@ export interface SqlDialect {
|
|||||||
dropForeignKey?: boolean;
|
dropForeignKey?: boolean;
|
||||||
createPrimaryKey?: boolean;
|
createPrimaryKey?: boolean;
|
||||||
dropPrimaryKey?: boolean;
|
dropPrimaryKey?: boolean;
|
||||||
|
createUnique?: boolean;
|
||||||
|
dropUnique?: boolean;
|
||||||
|
createCheck?: boolean;
|
||||||
|
dropCheck?: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ const dialect = {
|
|||||||
fallbackDataType: 'nvarchar(max)',
|
fallbackDataType: 'nvarchar(max)',
|
||||||
explicitDropConstraint: false,
|
explicitDropConstraint: false,
|
||||||
enableConstraintsPerTable: true,
|
enableConstraintsPerTable: true,
|
||||||
dropColumnDependencies: ['default', 'dependencies', 'indexes', 'primaryKey'],
|
dropColumnDependencies: ['default', 'dependencies', 'indexes', 'primaryKey', 'foreignKeys', 'uniques'],
|
||||||
changeColumnDependencies: ['indexes'],
|
changeColumnDependencies: ['indexes'],
|
||||||
anonymousPrimaryKey: false,
|
anonymousPrimaryKey: false,
|
||||||
dropIndexContainsTableSpec: true,
|
dropIndexContainsTableSpec: true,
|
||||||
@@ -28,6 +28,10 @@ const dialect = {
|
|||||||
dropForeignKey: true,
|
dropForeignKey: true,
|
||||||
createPrimaryKey: true,
|
createPrimaryKey: true,
|
||||||
dropPrimaryKey: true,
|
dropPrimaryKey: true,
|
||||||
|
createUnique: true,
|
||||||
|
dropUnique: true,
|
||||||
|
createCheck: true,
|
||||||
|
dropCheck: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @type {import('dbgate-types').EngineDriver} */
|
/** @type {import('dbgate-types').EngineDriver} */
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ const dialect = {
|
|||||||
createPrimaryKey: true,
|
createPrimaryKey: true,
|
||||||
dropPrimaryKey: true,
|
dropPrimaryKey: true,
|
||||||
dropIndexContainsTableSpec: true,
|
dropIndexContainsTableSpec: true,
|
||||||
|
createUnique: true,
|
||||||
|
dropUnique: true,
|
||||||
|
createCheck: true,
|
||||||
|
dropCheck: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
const mysqlDriverBase = {
|
const mysqlDriverBase = {
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ const dialect = {
|
|||||||
dropForeignKey: true,
|
dropForeignKey: true,
|
||||||
createPrimaryKey: true,
|
createPrimaryKey: true,
|
||||||
dropPrimaryKey: true,
|
dropPrimaryKey: true,
|
||||||
|
createUnique: true,
|
||||||
|
dropUnique: true,
|
||||||
|
createCheck: true,
|
||||||
|
dropCheck: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
const postgresDriverBase = {
|
const postgresDriverBase = {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ const dialect = {
|
|||||||
explicitDropConstraint: true,
|
explicitDropConstraint: true,
|
||||||
stringEscapeChar: "'",
|
stringEscapeChar: "'",
|
||||||
fallbackDataType: 'nvarchar(max)',
|
fallbackDataType: 'nvarchar(max)',
|
||||||
dropColumnDependencies: ['indexes', 'primaryKey'],
|
dropColumnDependencies: ['indexes', 'primaryKey', 'uniques'],
|
||||||
quoteIdentifier(s) {
|
quoteIdentifier(s) {
|
||||||
return `[${s}]`;
|
return `[${s}]`;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user