mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-28 21:05:59 +00:00
postgre, mysql uniques, recreate table WIP, drop index works
This commit is contained in:
@@ -15,6 +15,7 @@ const dialect = {
|
||||
dropColumnDependencies: ['default', 'dependencies', 'indexes', 'primaryKey'],
|
||||
changeColumnDependencies: ['indexes'],
|
||||
anonymousPrimaryKey: false,
|
||||
dropIndexContainsTableSpec: true,
|
||||
quoteIdentifier(s) {
|
||||
return `[${s}]`;
|
||||
},
|
||||
|
||||
@@ -75,6 +75,7 @@ class Analyser extends DatabaseAnalyser {
|
||||
|
||||
const viewTexts = await this.getViewTexts(views.rows.map(x => x.pureName));
|
||||
const indexes = await this.driver.query(this.pool, this.createQuery('indexes', ['tables']));
|
||||
const uniqueNames = await this.driver.query(this.pool, this.createQuery('uniqueNames', ['tables']));
|
||||
|
||||
return {
|
||||
tables: tables.rows.map(table => ({
|
||||
@@ -84,9 +85,11 @@ class Analyser extends DatabaseAnalyser {
|
||||
columns: columns.rows.filter(col => col.pureName == table.pureName).map(getColumnInfo),
|
||||
primaryKey: DatabaseAnalyser.extractPrimaryKeys(table, pkColumns.rows),
|
||||
foreignKeys: DatabaseAnalyser.extractForeignKeys(table, fkColumns.rows),
|
||||
uniques: [],
|
||||
indexes: _.uniqBy(
|
||||
indexes.rows.filter(idx => idx.tableName == table.pureName),
|
||||
indexes.rows.filter(
|
||||
idx =>
|
||||
idx.tableName == table.pureName && !uniqueNames.rows.find(x => x.constraintName == idx.constraintName)
|
||||
),
|
||||
'constraintName'
|
||||
).map(idx => ({
|
||||
..._.pick(idx, ['constraintName', 'indexType']),
|
||||
@@ -97,6 +100,21 @@ class Analyser extends DatabaseAnalyser {
|
||||
..._.pick(col, ['columnName']),
|
||||
})),
|
||||
})),
|
||||
|
||||
uniques: _.uniqBy(
|
||||
indexes.rows.filter(
|
||||
idx =>
|
||||
idx.tableName == table.pureName && uniqueNames.rows.find(x => x.constraintName == idx.constraintName)
|
||||
),
|
||||
'constraintName'
|
||||
).map(idx => ({
|
||||
..._.pick(idx, ['constraintName']),
|
||||
columns: indexes.rows
|
||||
.filter(col => col.tableName == idx.tableName && col.constraintName == idx.constraintName)
|
||||
.map(col => ({
|
||||
..._.pick(col, ['columnName']),
|
||||
})),
|
||||
})),
|
||||
})),
|
||||
views: views.rows.map(view => ({
|
||||
...view,
|
||||
|
||||
@@ -8,6 +8,7 @@ const indexes = require('./indexes');
|
||||
const programmables = require('./programmables');
|
||||
const procedureModifications = require('./procedureModifications');
|
||||
const functionModifications = require('./functionModifications');
|
||||
const uniqueNames = require('./uniqueNames');
|
||||
|
||||
module.exports = {
|
||||
columns,
|
||||
@@ -20,4 +21,5 @@ module.exports = {
|
||||
procedureModifications,
|
||||
functionModifications,
|
||||
indexes,
|
||||
uniqueNames,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
module.exports = `
|
||||
select CONSTRAINT_NAME as constraintName
|
||||
from information_schema.TABLE_CONSTRAINTS
|
||||
where CONSTRAINT_SCHEMA = '#DATABASE#' and constraint_type = 'UNIQUE'
|
||||
`;
|
||||
@@ -22,6 +22,7 @@ const dialect = {
|
||||
dropForeignKey: true,
|
||||
createPrimaryKey: true,
|
||||
dropPrimaryKey: true,
|
||||
dropIndexContainsTableSpec: true,
|
||||
};
|
||||
|
||||
const mysqlDriverBase = {
|
||||
|
||||
@@ -67,6 +67,7 @@ class Analyser extends DatabaseAnalyser {
|
||||
const routines = await this.driver.query(this.pool, this.createQuery('routines', ['procedures', 'functions']));
|
||||
const indexes = await this.driver.query(this.pool, this.createQuery('indexes', ['tables']));
|
||||
const indexcols = await this.driver.query(this.pool, this.createQuery('indexcols', ['tables']));
|
||||
const uniqueNames = await this.driver.query(this.pool, this.createQuery('uniqueNames', ['tables']));
|
||||
|
||||
return {
|
||||
tables: tables.rows.map(table => {
|
||||
@@ -107,7 +108,12 @@ class Analyser extends DatabaseAnalyser {
|
||||
}))
|
||||
),
|
||||
indexes: indexes.rows
|
||||
.filter(x => x.table_name == table.pure_name && x.schema_name == table.schema_name)
|
||||
.filter(
|
||||
x =>
|
||||
x.table_name == table.pure_name &&
|
||||
x.schema_name == table.schema_name &&
|
||||
!uniqueNames.rows.find(y => y.constraint_name == x.index_name)
|
||||
)
|
||||
.map(idx => ({
|
||||
constraintName: idx.index_name,
|
||||
isUnique: idx.is_unique,
|
||||
@@ -120,7 +126,24 @@ class Analyser extends DatabaseAnalyser {
|
||||
}))
|
||||
),
|
||||
})),
|
||||
uniques: [],
|
||||
uniques: indexes.rows
|
||||
.filter(
|
||||
x =>
|
||||
x.table_name == table.pure_name &&
|
||||
x.schema_name == table.schema_name &&
|
||||
uniqueNames.rows.find(y => y.constraint_name == x.index_name)
|
||||
)
|
||||
.map(idx => ({
|
||||
constraintName: idx.index_name,
|
||||
columns: _.compact(
|
||||
idx.indkey
|
||||
.split(' ')
|
||||
.map(colid => indexcols.rows.find(col => col.oid == idx.oid && col.attnum == colid))
|
||||
.map(col => ({
|
||||
columnName: col.column_name,
|
||||
}))
|
||||
),
|
||||
})),
|
||||
};
|
||||
}),
|
||||
views: views.rows.map(view => ({
|
||||
|
||||
@@ -12,6 +12,7 @@ const routineModifications = require('./routineModifications');
|
||||
const matviewColumns = require('./matviewColumns');
|
||||
const indexes = require('./indexes');
|
||||
const indexcols = require('./indexcols');
|
||||
const uniqueNames = require('./uniqueNames');
|
||||
|
||||
module.exports = {
|
||||
columns,
|
||||
@@ -28,4 +29,5 @@ module.exports = {
|
||||
matviewColumns,
|
||||
indexes,
|
||||
indexcols,
|
||||
uniqueNames,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = `
|
||||
select conname as "constraint_name" from pg_constraint where contype = 'u'
|
||||
`;
|
||||
@@ -15,6 +15,15 @@ const dialect = {
|
||||
return '"' + s + '"';
|
||||
},
|
||||
stringAgg: true,
|
||||
|
||||
createColumn: true,
|
||||
dropColumn: true,
|
||||
createIndex: true,
|
||||
dropIndex: true,
|
||||
createForeignKey: true,
|
||||
dropForeignKey: true,
|
||||
createPrimaryKey: true,
|
||||
dropPrimaryKey: true,
|
||||
};
|
||||
|
||||
const postgresDriverBase = {
|
||||
@@ -35,15 +44,6 @@ const postgresDriver = {
|
||||
dialect: {
|
||||
...dialect,
|
||||
materializedViews: true,
|
||||
|
||||
createColumn: true,
|
||||
dropColumn: true,
|
||||
createIndex: true,
|
||||
dropIndex: true,
|
||||
createForeignKey: true,
|
||||
dropForeignKey: true,
|
||||
createPrimaryKey: true,
|
||||
dropPrimaryKey: true,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ const dialect = {
|
||||
explicitDropConstraint: true,
|
||||
stringEscapeChar: "'",
|
||||
fallbackDataType: 'nvarchar(max)',
|
||||
dropColumnDependencies: ['index', 'primaryKey'],
|
||||
dropColumnDependencies: ['indexes', 'primaryKey'],
|
||||
quoteIdentifier(s) {
|
||||
return `[${s}]`;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user