mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 03:16:01 +00:00
postgre, mysql uniques, recreate table WIP, drop index works
This commit is contained in:
@@ -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,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user