mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 12:13:57 +00:00
drop unique column works
This commit is contained in:
parent
2cb3a6b446
commit
0ef5ac04d8
@ -9,7 +9,9 @@ const { getAlterTableScript, extendDatabaseInfo, generateDbPairingId } = require
|
||||
function pickImportantTableInfo(table) {
|
||||
return {
|
||||
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'];
|
||||
// const TESTED_COLUMNS = ['col_pk'];
|
||||
// const TESTED_COLUMNS = ['col_idx'];
|
||||
// const TESTED_COLUMNS = ['col_fk'];
|
||||
const TESTED_COLUMNS = ['col_uq'];
|
||||
// const TESTED_COLUMNS = ['col_std'];
|
||||
|
||||
function engines_columns_source() {
|
||||
|
@ -16,7 +16,7 @@ const matviews = {
|
||||
const engines = [
|
||||
{
|
||||
label: 'MySQL',
|
||||
// skipLocal: true,
|
||||
skipLocal: true,
|
||||
connection: {
|
||||
engine: 'mysql@dbgate-plugin-mysql',
|
||||
password: 'Pwd2020Db',
|
||||
@ -34,7 +34,7 @@ const engines = [
|
||||
},
|
||||
{
|
||||
label: 'PostgreSQL',
|
||||
// skipLocal: true,
|
||||
skipLocal: true,
|
||||
connection: {
|
||||
engine: 'postgres@dbgate-plugin-postgres',
|
||||
password: 'Pwd2020Db',
|
||||
@ -103,7 +103,7 @@ const engines = [
|
||||
},
|
||||
{
|
||||
label: 'CockroachDB',
|
||||
// skipLocal: true,
|
||||
skipLocal: true,
|
||||
connection: {
|
||||
engine: 'cockroach@dbgate-plugin-postgres',
|
||||
user: 'root',
|
||||
|
@ -244,6 +244,8 @@ export class AlterPlan {
|
||||
if (cnt.constraintType == 'primaryKey') return this.dialect.createPrimaryKey;
|
||||
if (cnt.constraintType == 'foreignKey') return this.dialect.createForeignKey;
|
||||
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;
|
||||
}
|
||||
|
||||
@ -251,6 +253,8 @@ export class AlterPlan {
|
||||
if (cnt.constraintType == 'primaryKey') return this.dialect.dropPrimaryKey;
|
||||
if (cnt.constraintType == 'foreignKey') return this.dialect.dropForeignKey;
|
||||
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;
|
||||
}
|
||||
|
||||
@ -364,9 +368,11 @@ export function runAlterOperation(op: AlterOperation, processor: AlterProcessor)
|
||||
const newTable = _.cloneDeep(op.table);
|
||||
const newDb = DatabaseAnalyser.createEmptyStructure();
|
||||
newDb.tables.push(newTable);
|
||||
// console.log('////////////////////////////newTable1', newTable);
|
||||
op.operations.forEach(child => runAlterOperation(child, new DatabaseInfoAlterProcessor(newDb)));
|
||||
// console.log('////////////////////////////op.operations', op.operations);
|
||||
// console.log('////////////////////////////op.table', op.table);
|
||||
// console.log('////////////////////////////newTable', newTable);
|
||||
// console.log('////////////////////////////newTable2', newTable);
|
||||
processor.recreateTable(op.table, newTable);
|
||||
}
|
||||
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 {
|
||||
constructor(public db: DatabaseInfo) {}
|
||||
@ -35,6 +45,15 @@ export class DatabaseInfoAlterProcessor {
|
||||
case 'foreignKey':
|
||||
table.foreignKeys.push(constraint as ForeignKeyInfo);
|
||||
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':
|
||||
table.foreignKeys = table.foreignKeys.filter(x => x.constraintName != constraint.constraintName);
|
||||
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;
|
||||
createPrimaryKey?: boolean;
|
||||
dropPrimaryKey?: boolean;
|
||||
createUnique?: boolean;
|
||||
dropUnique?: boolean;
|
||||
createCheck?: boolean;
|
||||
dropCheck?: boolean;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ const dialect = {
|
||||
fallbackDataType: 'nvarchar(max)',
|
||||
explicitDropConstraint: false,
|
||||
enableConstraintsPerTable: true,
|
||||
dropColumnDependencies: ['default', 'dependencies', 'indexes', 'primaryKey'],
|
||||
dropColumnDependencies: ['default', 'dependencies', 'indexes', 'primaryKey', 'foreignKeys', 'uniques'],
|
||||
changeColumnDependencies: ['indexes'],
|
||||
anonymousPrimaryKey: false,
|
||||
dropIndexContainsTableSpec: true,
|
||||
@ -28,6 +28,10 @@ const dialect = {
|
||||
dropForeignKey: true,
|
||||
createPrimaryKey: true,
|
||||
dropPrimaryKey: true,
|
||||
createUnique: true,
|
||||
dropUnique: true,
|
||||
createCheck: true,
|
||||
dropCheck: true,
|
||||
};
|
||||
|
||||
/** @type {import('dbgate-types').EngineDriver} */
|
||||
|
@ -23,6 +23,10 @@ const dialect = {
|
||||
createPrimaryKey: true,
|
||||
dropPrimaryKey: true,
|
||||
dropIndexContainsTableSpec: true,
|
||||
createUnique: true,
|
||||
dropUnique: true,
|
||||
createCheck: true,
|
||||
dropCheck: true,
|
||||
};
|
||||
|
||||
const mysqlDriverBase = {
|
||||
|
@ -24,6 +24,10 @@ const dialect = {
|
||||
dropForeignKey: true,
|
||||
createPrimaryKey: true,
|
||||
dropPrimaryKey: true,
|
||||
createUnique: true,
|
||||
dropUnique: true,
|
||||
createCheck: true,
|
||||
dropCheck: true,
|
||||
};
|
||||
|
||||
const postgresDriverBase = {
|
||||
|
@ -17,7 +17,7 @@ const dialect = {
|
||||
explicitDropConstraint: true,
|
||||
stringEscapeChar: "'",
|
||||
fallbackDataType: 'nvarchar(max)',
|
||||
dropColumnDependencies: ['indexes', 'primaryKey'],
|
||||
dropColumnDependencies: ['indexes', 'primaryKey', 'uniques'],
|
||||
quoteIdentifier(s) {
|
||||
return `[${s}]`;
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user