postgre, mysql uniques, recreate table WIP, drop index works

This commit is contained in:
Jan Prochazka
2021-09-04 18:43:59 +02:00
parent b3b7d021c5
commit 04a6540890
15 changed files with 113 additions and 27 deletions

View File

@@ -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 => ({

View File

@@ -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,
};

View File

@@ -0,0 +1,3 @@
module.exports = `
select conname as "constraint_name" from pg_constraint where contype = 'u'
`;

View File

@@ -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,
},
};