mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 20:16:00 +00:00
Oracle driver first data
This commit is contained in:
@@ -57,8 +57,8 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
|
|
||||||
createQuery(resFileName, typeFields) {
|
createQuery(resFileName, typeFields) {
|
||||||
const query = super.createQuery(sql[resFileName], typeFields);
|
const query = super.createQuery(sql[resFileName], typeFields);
|
||||||
if (query) return query.replace('#REFTABLECOND#', this.driver.__analyserInternals.refTableCond);
|
//if (query) return query.replace('#REFTABLECOND#', this.driver.__analyserInternals.refTableCond);
|
||||||
return null;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
async _computeSingleObjectId() {
|
async _computeSingleObjectId() {
|
||||||
@@ -70,76 +70,22 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
this.feedback({ analysingMessage: 'Loading tables' });
|
this.feedback({ analysingMessage: 'Loading tables' });
|
||||||
const tables = await this.driver.query(
|
const tables = await this.driver.query(
|
||||||
this.pool,
|
this.pool,
|
||||||
this.createQuery(this.driver.dialect.stringAgg ? 'tableModifications' : 'tableList', ['tables'])
|
this.createQuery(this.driver.dialect.stringAgg ? 'tableList' : 'tableList', ['tables'])
|
||||||
);
|
);
|
||||||
this.feedback({ analysingMessage: 'Loading columns' });
|
this.feedback({ analysingMessage: 'Loading columns' });
|
||||||
const columns = await this.driver.query(this.pool, this.createQuery('columns', ['tables', 'views']));
|
const columns = await this.driver.query(this.pool, this.createQuery('columns', ['tables', 'views']));
|
||||||
this.feedback({ analysingMessage: 'Loading primary keys' });
|
this.feedback({ analysingMessage: 'Loading primary keys' });
|
||||||
const pkColumns = await this.driver.query(this.pool, this.createQuery('primaryKeys', ['tables']));
|
const pkColumns = await this.driver.query(this.pool, this.createQuery('primaryKeys', ['tables']));
|
||||||
|
|
||||||
let fkColumns = null;
|
//let fkColumns = null;
|
||||||
|
|
||||||
// if (true) {
|
|
||||||
if (this.containsObjectIdCondition(['tables']) || this.driver.__analyserInternals.refTableCond) {
|
|
||||||
this.feedback({ analysingMessage: 'Loading foreign keys' });
|
this.feedback({ analysingMessage: 'Loading foreign keys' });
|
||||||
fkColumns = await this.driver.query(this.pool, this.createQuery('foreignKeys', ['tables']));
|
const fkColumns = await this.driver.query(this.pool, this.createQuery('foreignKeys', ['tables']));
|
||||||
} else {
|
|
||||||
this.feedback({ analysingMessage: 'Loading foreign key constraints' });
|
|
||||||
const fk_tableConstraints = await this.driver.query(
|
|
||||||
this.pool,
|
|
||||||
this.createQuery('fk_tableConstraints', ['tables'])
|
|
||||||
);
|
|
||||||
|
|
||||||
this.feedback({ analysingMessage: 'Loading foreign key refs' });
|
|
||||||
const fk_referentialConstraints = await this.driver.query(
|
|
||||||
this.pool,
|
|
||||||
this.createQuery('fk_referentialConstraints', ['tables'])
|
|
||||||
);
|
|
||||||
|
|
||||||
this.feedback({ analysingMessage: 'Loading foreign key columns' });
|
|
||||||
const fk_keyColumnUsage = await this.driver.query(this.pool, this.createQuery('fk_keyColumnUsage', ['tables']));
|
|
||||||
|
|
||||||
const cntKey = x => `${x.constraint_name}|${x.constraint_schema}`;
|
|
||||||
const rows = [];
|
|
||||||
const constraintDct = _.keyBy(fk_tableConstraints.rows, cntKey);
|
|
||||||
for (const fkRef of fk_referentialConstraints.rows) {
|
|
||||||
const cntBase = constraintDct[cntKey(fkRef)];
|
|
||||||
const cntRef = constraintDct[`${fkRef.unique_constraint_name}|${fkRef.unique_constraint_schema}`];
|
|
||||||
if (!cntBase || !cntRef) continue;
|
|
||||||
const baseCols = _.sortBy(
|
|
||||||
fk_keyColumnUsage.rows.filter(
|
|
||||||
x => x.table_name == cntBase.table_name && x.constraint_name == cntBase.constraint_name
|
|
||||||
),
|
|
||||||
'ordinal_position'
|
|
||||||
);
|
|
||||||
const refCols = _.sortBy(
|
|
||||||
fk_keyColumnUsage.rows.filter(
|
|
||||||
x => x.table_name == cntRef.table_name && x.constraint_name == cntRef.constraint_name
|
|
||||||
),
|
|
||||||
'ordinal_position'
|
|
||||||
);
|
|
||||||
if (baseCols.length != refCols.length) continue;
|
|
||||||
|
|
||||||
for (let i = 0; i < baseCols.length; i++) {
|
|
||||||
const baseCol = baseCols[i];
|
|
||||||
const refCol = refCols[i];
|
|
||||||
|
|
||||||
rows.push({
|
|
||||||
...fkRef,
|
|
||||||
pure_name: cntBase.table_name,
|
|
||||||
schema_name: cntBase.table_schema,
|
|
||||||
ref_table_name: cntRef.table_name,
|
|
||||||
ref_schema_name: cntRef.table_schema,
|
|
||||||
column_name: baseCol.column_name,
|
|
||||||
ref_column_name: refCol.column_name,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fkColumns = { rows };
|
|
||||||
}
|
|
||||||
|
|
||||||
this.feedback({ analysingMessage: 'Loading views' });
|
this.feedback({ analysingMessage: 'Loading views' });
|
||||||
const views = await this.driver.query(this.pool, this.createQuery('views', ['views']));
|
const views = await this.driver.query(this.pool, this.createQuery('views', ['views']));
|
||||||
|
let geometryColumns = { rows: [] };
|
||||||
|
let geographyColumns = { rows: [] };
|
||||||
|
|
||||||
this.feedback({ analysingMessage: 'Loading materialized views' });
|
this.feedback({ analysingMessage: 'Loading materialized views' });
|
||||||
const matviews = this.driver.dialect.materializedViews
|
const matviews = this.driver.dialect.materializedViews
|
||||||
? await this.driver.query(this.pool, this.createQuery('matviews', ['matviews']))
|
? await this.driver.query(this.pool, this.createQuery('matviews', ['matviews']))
|
||||||
@@ -155,23 +101,11 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
? { rows: [] }
|
? { rows: [] }
|
||||||
: await this.driver.query(this.pool, this.createQuery('indexes', ['tables']));
|
: await this.driver.query(this.pool, this.createQuery('indexes', ['tables']));
|
||||||
this.feedback({ analysingMessage: 'Loading index columns' });
|
this.feedback({ analysingMessage: 'Loading index columns' });
|
||||||
const indexcols = this.driver.__analyserInternals.skipIndexes
|
// const indexcols = this.driver.__analyserInternals.skipIndexes
|
||||||
? { rows: [] }
|
// ? { rows: [] }
|
||||||
: await this.driver.query(this.pool, this.createQuery('indexcols', ['tables']));
|
// : await this.driver.query(this.pool, this.createQuery('indexcols', ['tables']));
|
||||||
this.feedback({ analysingMessage: 'Loading unique names' });
|
this.feedback({ analysingMessage: 'Loading unique names' });
|
||||||
const uniqueNames = await this.driver.query(this.pool, this.createQuery('uniqueNames', ['tables']));
|
const uniqueNames = await this.driver.query(this.pool, this.createQuery('uniqueNames', ['tables']));
|
||||||
|
|
||||||
let geometryColumns = { rows: [] };
|
|
||||||
if (views.rows.find(x => x.pure_name == 'geometry_columns' && x.schema_name == 'public')) {
|
|
||||||
this.feedback({ analysingMessage: 'Loading geometry columns' });
|
|
||||||
geometryColumns = await this.safeQuery(this.createQuery('geometryColumns', ['tables']));
|
|
||||||
}
|
|
||||||
let geographyColumns = { rows: [] };
|
|
||||||
if (views.rows.find(x => x.pure_name == 'geography_columns' && x.schema_name == 'public')) {
|
|
||||||
this.feedback({ analysingMessage: 'Loading geography columns' });
|
|
||||||
geographyColumns = await this.safeQuery(this.createQuery('geographyColumns', ['tables']));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.feedback({ analysingMessage: 'Finalizing DB structure' });
|
this.feedback({ analysingMessage: 'Finalizing DB structure' });
|
||||||
|
|
||||||
const columnColumnsMapped = fkColumns.rows.map(x => ({
|
const columnColumnsMapped = fkColumns.rows.map(x => ({
|
||||||
@@ -209,45 +143,34 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
.map(col => getColumnInfo(col, newTable, geometryColumns, geographyColumns)),
|
.map(col => getColumnInfo(col, newTable, geometryColumns, geographyColumns)),
|
||||||
primaryKey: DatabaseAnalyser.extractPrimaryKeys(newTable, pkColumnsMapped),
|
primaryKey: DatabaseAnalyser.extractPrimaryKeys(newTable, pkColumnsMapped),
|
||||||
foreignKeys: DatabaseAnalyser.extractForeignKeys(newTable, columnColumnsMapped),
|
foreignKeys: DatabaseAnalyser.extractForeignKeys(newTable, columnColumnsMapped),
|
||||||
indexes: indexes.rows
|
indexes: _.uniqBy(
|
||||||
.filter(
|
indexes.rows.filter(
|
||||||
x =>
|
idx =>
|
||||||
x.table_name == table.pure_name &&
|
idx.tableName == table.pureName && !uniqueNames.rows.find(x => x.constraintName == idx.constraintName)
|
||||||
x.schema_name == table.schema_name &&
|
),
|
||||||
!uniqueNames.rows.find(y => y.constraint_name == x.index_name)
|
'constraintName'
|
||||||
)
|
).map(idx => ({
|
||||||
.map(idx => ({
|
..._.pick(idx, ['constraintName', 'indexType']),
|
||||||
constraintName: idx.index_name,
|
isUnique: idx.Unique === 'UNIQUE',
|
||||||
isUnique: idx.is_unique,
|
columns: indexes.rows
|
||||||
columns: _.compact(
|
.filter(col => col.tableName == idx.tableName && col.constraintName == idx.constraintName)
|
||||||
idx.indkey
|
.map(col => ({
|
||||||
.split(' ')
|
..._.pick(col, ['columnName']),
|
||||||
.map(colid => indexcols.rows.find(col => col.oid == idx.oid && col.attnum == colid))
|
|
||||||
.filter(col => col != null)
|
|
||||||
.map(col => ({
|
|
||||||
columnName: col.column_name,
|
|
||||||
}))
|
|
||||||
),
|
|
||||||
})),
|
})),
|
||||||
uniques: indexes.rows
|
})),
|
||||||
.filter(
|
uniques: _.uniqBy(
|
||||||
x =>
|
indexes.rows.filter(
|
||||||
x.table_name == table.pure_name &&
|
idx => idx.tableName == table.pureName && uniqueNames.rows.find(x => x.constraintName == idx.constraintName)
|
||||||
x.schema_name == table.schema_name &&
|
),
|
||||||
uniqueNames.rows.find(y => y.constraint_name == x.index_name)
|
'constraintName'
|
||||||
)
|
).map(idx => ({
|
||||||
.map(idx => ({
|
..._.pick(idx, ['constraintName']),
|
||||||
constraintName: idx.index_name,
|
columns: indexes.rows
|
||||||
columns: _.compact(
|
.filter(col => col.tableName == idx.tableName && col.constraintName == idx.constraintName)
|
||||||
idx.indkey
|
.map(col => ({
|
||||||
.split(' ')
|
..._.pick(col, ['columnName']),
|
||||||
.map(colid => indexcols.rows.find(col => col.oid == idx.oid && col.attnum == colid))
|
|
||||||
.filter(col => col != null)
|
|
||||||
.map(col => ({
|
|
||||||
columnName: col.column_name,
|
|
||||||
}))
|
|
||||||
),
|
|
||||||
})),
|
})),
|
||||||
|
})),
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
views: views.rows.map(view => ({
|
views: views.rows.map(view => ({
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ pg.types.setTypeParser(1184, 'text', val => val); // timestamp
|
|||||||
|
|
||||||
function extractOracleColumns(result) {
|
function extractOracleColumns(result) {
|
||||||
console.log('result', result);
|
console.log('result', result);
|
||||||
console.log('result.name', result[0].name);
|
//console.log('result.name', result[0].name);
|
||||||
console.log('result.map', result.map(fld => ({
|
console.log('result.map', result.map(fld => ({
|
||||||
columnName: fld.name.toLowerCase(),
|
columnName: fld.name.toLowerCase(),
|
||||||
})));
|
})));
|
||||||
@@ -112,12 +112,21 @@ const drivers = driverBases.map(driverBase => ({
|
|||||||
columns: [],
|
columns: [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
console.log('sql', sql);
|
console.log('sql', sql);
|
||||||
const res = await client.execute(sql);
|
const res = await client.execute(sql);
|
||||||
console.log('res', res);
|
console.log('res', res);
|
||||||
const columns = extractOracleColumns(res.metaData);
|
const columns = extractOracleColumns(res.metaData);
|
||||||
console.log('columns', columns);
|
console.log('columns', columns);
|
||||||
return { rows: (res.rows || []).map(row => zipDataRow(row, columns)), columns };
|
return { rows: (res.rows || []).map(row => zipDataRow(row, columns)), columns };
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
console.log('Error query', err);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
console.log('finally', sql);
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
stream(client, sql, options) {
|
stream(client, sql, options) {
|
||||||
/*
|
/*
|
||||||
@@ -128,12 +137,14 @@ const drivers = driverBases.map(driverBase => ({
|
|||||||
*/
|
*/
|
||||||
console.log('queryStream', sql);
|
console.log('queryStream', sql);
|
||||||
const query = client.queryStream(sql);
|
const query = client.queryStream(sql);
|
||||||
|
// const consumeStream = new Promise((resolve, reject) => {
|
||||||
|
let rowcount = 0;
|
||||||
let wasHeader = false;
|
let wasHeader = false;
|
||||||
|
|
||||||
query.on('metaData', row => {
|
query.on('metadata', row => {
|
||||||
console.log('metaData', row);
|
console.log('metadata', row);
|
||||||
if (!wasHeader) {
|
if (!wasHeader) {
|
||||||
columns = extractOracleColumns(query.metaData);
|
columns = extractOracleColumns(row);
|
||||||
if (columns && columns.length > 0) {
|
if (columns && columns.length > 0) {
|
||||||
options.recordset(columns);
|
options.recordset(columns);
|
||||||
}
|
}
|
||||||
@@ -145,14 +156,6 @@ const drivers = driverBases.map(driverBase => ({
|
|||||||
|
|
||||||
query.on('data', row => {
|
query.on('data', row => {
|
||||||
console.log('DATA', row);
|
console.log('DATA', row);
|
||||||
if (!wasHeader) {
|
|
||||||
columns = extractOracleColumns(query._result);
|
|
||||||
if (columns && columns.length > 0) {
|
|
||||||
options.recordset(columns);
|
|
||||||
}
|
|
||||||
wasHeader = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
options.row(zipDataRow(row, columns));
|
options.row(zipDataRow(row, columns));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -190,7 +193,16 @@ const drivers = driverBases.map(driverBase => ({
|
|||||||
});
|
});
|
||||||
options.done();
|
options.done();
|
||||||
});
|
});
|
||||||
|
query.on('close', function() {
|
||||||
|
// console.log("stream 'close' event");
|
||||||
|
// The underlying ResultSet has been closed, so the connection can now
|
||||||
|
// be closed, if desired. Note: do not close connections on 'end'.
|
||||||
|
resolve(rowcount);
|
||||||
|
});
|
||||||
|
//});
|
||||||
|
|
||||||
|
//const numrows = await consumeStream;
|
||||||
|
//console.log('Rows selected: ' + numrows);
|
||||||
client.query(query);
|
client.query(query);
|
||||||
},
|
},
|
||||||
async getVersion(client) {
|
async getVersion(client) {
|
||||||
@@ -273,7 +285,7 @@ const drivers = driverBases.map(driverBase => ({
|
|||||||
pass.end();
|
pass.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
client.query(query);
|
//client.query(query);
|
||||||
|
|
||||||
return pass;
|
return pass;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,23 +1,15 @@
|
|||||||
module.exports = `
|
module.exports = `
|
||||||
select
|
select
|
||||||
table_schema as "schema_name",
|
owner as "schema_name",
|
||||||
table_name as "pure_name",
|
table_name as "pure_name",
|
||||||
column_name as "column_name",
|
column_name as "column_name",
|
||||||
is_nullable as "is_nullable",
|
nullable as "is_nullable",
|
||||||
data_type as "data_type",
|
data_type as "data_type",
|
||||||
character_maximum_length as "char_max_length",
|
data_length as "char_max_length",
|
||||||
numeric_precision as "numeric_precision",
|
data_precision as "numeric_precision",
|
||||||
numeric_scale as "numeric_scale",
|
data_scale as "numeric_scale",
|
||||||
column_default as "default_value"
|
data_default as "default_value"
|
||||||
from information_schema.columns
|
FROM all_tab_columns av
|
||||||
where
|
where TABLE_NAME =OBJECT_ID_CONDITION
|
||||||
table_schema <> 'information_schema'
|
order by column_id
|
||||||
and table_schema <> 'pg_catalog'
|
|
||||||
and table_schema !~ '^pg_toast'
|
|
||||||
and (
|
|
||||||
('tables:' || table_schema || '.' || table_name) =OBJECT_ID_CONDITION
|
|
||||||
or
|
|
||||||
('views:' || table_schema || '.' || table_name) =OBJECT_ID_CONDITION
|
|
||||||
)
|
|
||||||
order by ordinal_position
|
|
||||||
`;
|
`;
|
||||||
@@ -1,10 +1,2 @@
|
|||||||
module.exports = `
|
module.exports = `
|
||||||
select
|
|
||||||
basecol.constraint_name,
|
|
||||||
basecol.constraint_schema,
|
|
||||||
basecol.column_name as "column_name",
|
|
||||||
basecol.table_schema,
|
|
||||||
basecol.table_name,
|
|
||||||
basecol.ordinal_position
|
|
||||||
from information_schema.key_column_usage basecol
|
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,10 +1,2 @@
|
|||||||
module.exports = `
|
module.exports = `
|
||||||
select
|
|
||||||
fk.constraint_name as "constraint_name",
|
|
||||||
fk.constraint_schema as "constraint_schema",
|
|
||||||
fk.update_rule as "update_action",
|
|
||||||
fk.delete_rule as "delete_action",
|
|
||||||
fk.unique_constraint_name as "unique_constraint_name",
|
|
||||||
fk.unique_constraint_schema as "unique_constraint_schema"
|
|
||||||
from information_schema.referential_constraints fk
|
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,8 +1,2 @@
|
|||||||
module.exports = `
|
module.exports = `
|
||||||
select
|
|
||||||
base.table_name as "table_name",
|
|
||||||
base.table_schema as "table_schema",
|
|
||||||
base.constraint_name as "constraint_name",
|
|
||||||
base.constraint_schema as "constraint_schema"
|
|
||||||
from information_schema.table_constraints base
|
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
module.exports = `
|
module.exports = `
|
||||||
select
|
select fk.constraint_name as "constraint_name",
|
||||||
fk.constraint_name as "constraint_name",
|
fk.owner as "constraint_schema",
|
||||||
fk.constraint_schema as "constraint_schema",
|
fk.table_name as "pure_name",
|
||||||
base.table_name as "pure_name",
|
fk.owner as "schema_name",
|
||||||
base.table_schema as "schema_name",
|
fk.delete_rule as "update_action",
|
||||||
fk.update_rule as "update_action",
|
fk.delete_rule as "delete_action",
|
||||||
fk.delete_rule as "delete_action",
|
ref.table_name as "ref_table_name",
|
||||||
ref.table_name as "ref_table_name",
|
ref.owner as "ref_schema_name",
|
||||||
ref.table_schema as "ref_schema_name",
|
basecol.column_name as "column_name",
|
||||||
basecol.column_name as "column_name",
|
refcol.column_name as "ref_column_name"
|
||||||
refcol.column_name as "ref_column_name"
|
from all_cons_columns refcol, all_cons_columns basecol, all_constraints ref, all_constraints fk
|
||||||
from information_schema.referential_constraints fk
|
where fk.constraint_type = 'R'
|
||||||
inner join information_schema.table_constraints base on fk.constraint_name = base.constraint_name and fk.constraint_schema = base.constraint_schema
|
and ref.owner = fk.r_owner
|
||||||
inner join information_schema.table_constraints ref on fk.unique_constraint_name = ref.constraint_name and fk.unique_constraint_schema = ref.constraint_schema #REFTABLECOND#
|
and ref.constraint_name = fk.r_constraint_name
|
||||||
inner join information_schema.key_column_usage basecol on base.table_name = basecol.table_name and base.constraint_name = basecol.constraint_name
|
and basecol.owner = fk.owner
|
||||||
inner join information_schema.key_column_usage refcol on ref.table_name = refcol.table_name and ref.constraint_name = refcol.constraint_name and basecol.ordinal_position = refcol.ordinal_position
|
and basecol.constraint_name = fk.constraint_name
|
||||||
where
|
and basecol.table_name = fk.table_name
|
||||||
base.table_schema <> 'information_schema'
|
and refcol.owner = ref.owner
|
||||||
and base.table_schema <> 'pg_catalog'
|
and refcol.constraint_name = ref.constraint_name
|
||||||
and base.table_schema !~ '^pg_toast'
|
and refcol.table_name = ref.table_name
|
||||||
and ('tables:' || base.table_schema || '.' || base.table_name) =OBJECT_ID_CONDITION
|
AND fk.constraint_name =OBJECT_ID_CONDITION
|
||||||
order by basecol.ordinal_position
|
order by basecol.position
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,8 +1,2 @@
|
|||||||
module.exports = `
|
module.exports = `
|
||||||
select
|
|
||||||
f_table_schema as "schema_name",
|
|
||||||
f_table_name as "pure_name",
|
|
||||||
f_geography_column as "column_name"
|
|
||||||
from public.geography_columns
|
|
||||||
where ('tables:' || f_table_schema || '.' || f_table_name) =OBJECT_ID_CONDITION
|
|
||||||
`;
|
`;
|
||||||
@@ -1,8 +1,2 @@
|
|||||||
module.exports = `
|
module.exports = `
|
||||||
select
|
|
||||||
f_table_schema as "schema_name",
|
|
||||||
f_table_name as "pure_name",
|
|
||||||
f_geometry_column as "column_name"
|
|
||||||
from public.geometry_columns
|
|
||||||
where ('tables:' || f_table_schema || '.' || f_table_name) =OBJECT_ID_CONDITION
|
|
||||||
`;
|
`;
|
||||||
@@ -2,23 +2,23 @@ const columns = require('./columns');
|
|||||||
const tableModifications = require('./tableList');
|
const tableModifications = require('./tableList');
|
||||||
const tableList = require('./tableList');
|
const tableList = require('./tableList');
|
||||||
const viewModifications = require('./views');
|
const viewModifications = require('./views');
|
||||||
const matviewModifications = require('./matviewModifications');
|
const matviewModifications = require('./matviews');
|
||||||
const primaryKeys = require('./primaryKeys');
|
const primaryKeys = require('./primaryKeys');
|
||||||
const foreignKeys = require('./foreignKeys');
|
const foreignKeys = require('./foreignKeys');
|
||||||
const views = require('./views');
|
const views = require('./views');
|
||||||
const matviews = require('./matviews');
|
const matviews = require('./matviews');
|
||||||
const routines = require('./routines');
|
const routines = require('./routines');
|
||||||
const routineModifications = require('./routineModifications');
|
const routineModifications = require('./routines');
|
||||||
const matviewColumns = require('./matviewColumns');
|
const matviewColumns = require('./matviewColumns');
|
||||||
const indexes = require('./indexes');
|
const indexes = require('./indexes'); // use mysql
|
||||||
const indexcols = require('./indexcols');
|
//const indexcols = require('./indexcols');
|
||||||
const uniqueNames = require('./uniqueNames');
|
const uniqueNames = require('./uniqueNames');
|
||||||
const geometryColumns = require('./geometryColumns');
|
//const geometryColumns = require('./geometryColumns');
|
||||||
const geographyColumns = require('./geographyColumns');
|
//const geographyColumns = require('./geographyColumns');
|
||||||
|
|
||||||
const fk_keyColumnUsage = require('./fk_key_column_usage');
|
//const fk_keyColumnUsage = require('./fk_key_column_usage');
|
||||||
const fk_referentialConstraints = require('./fk_referential_constraints');
|
//const fk_referentialConstraints = require('./fk_referential_constraints');
|
||||||
const fk_tableConstraints = require('./fk_table_constraints');
|
//const fk_tableConstraints = require('./fk_table_constraints');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
columns,
|
columns,
|
||||||
@@ -27,9 +27,6 @@ module.exports = {
|
|||||||
viewModifications,
|
viewModifications,
|
||||||
primaryKeys,
|
primaryKeys,
|
||||||
foreignKeys,
|
foreignKeys,
|
||||||
fk_keyColumnUsage,
|
|
||||||
fk_referentialConstraints,
|
|
||||||
fk_tableConstraints,
|
|
||||||
views,
|
views,
|
||||||
routines,
|
routines,
|
||||||
routineModifications,
|
routineModifications,
|
||||||
@@ -37,8 +34,8 @@ module.exports = {
|
|||||||
matviewModifications,
|
matviewModifications,
|
||||||
matviewColumns,
|
matviewColumns,
|
||||||
indexes,
|
indexes,
|
||||||
indexcols,
|
// indexcols,
|
||||||
uniqueNames,
|
uniqueNames,
|
||||||
geometryColumns,
|
//geometryColumns,
|
||||||
geographyColumns,
|
//geographyColumns,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,24 +1,2 @@
|
|||||||
module.exports = `
|
module.exports = `
|
||||||
select
|
|
||||||
a.attname as "column_name",
|
|
||||||
a.attnum as "attnum",
|
|
||||||
a.attrelid as "oid"
|
|
||||||
from
|
|
||||||
pg_class t,
|
|
||||||
pg_class i,
|
|
||||||
pg_attribute a,
|
|
||||||
pg_index ix,
|
|
||||||
pg_namespace c
|
|
||||||
where
|
|
||||||
t.oid = ix.indrelid
|
|
||||||
and a.attnum = ANY(ix.indkey)
|
|
||||||
and a.attrelid = t.oid
|
|
||||||
and i.oid = ix.indexrelid
|
|
||||||
and t.relkind = 'r'
|
|
||||||
and ix.indisprimary = false
|
|
||||||
and t.relnamespace = c.oid
|
|
||||||
and c.nspname != 'pg_catalog'
|
|
||||||
and ('tables:' || c.nspname || '.' || t.relname) =OBJECT_ID_CONDITION
|
|
||||||
order by
|
|
||||||
t.relname
|
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,25 +1,18 @@
|
|||||||
module.exports = `
|
module.exports = `
|
||||||
select
|
select i.table_name as "tableName",
|
||||||
t.relname as "table_name",
|
i.table_owner as "schemaName",
|
||||||
c.nspname as "schema_name",
|
i.index_name as "constraintName",
|
||||||
i.relname as "index_name",
|
i.index_type as "indexType",
|
||||||
ix.indisprimary as "is_primary",
|
i.uniqueness as "Unique",
|
||||||
ix.indisunique as "is_unique",
|
ic.column_name as "columnName",
|
||||||
ix.indkey as "indkey",
|
ic.column_position as "postion",
|
||||||
t.oid as "oid"
|
ic.descend as "descending"
|
||||||
from
|
from all_ind_columns ic, all_indexes i
|
||||||
pg_class t,
|
where ic.index_owner = i.owner
|
||||||
pg_class i,
|
and ic.index_name = i.index_name
|
||||||
pg_index ix,
|
and i.index_name =OBJECT_ID_CONDITION
|
||||||
pg_namespace c
|
order by i.table_owner,
|
||||||
where
|
i.table_name,
|
||||||
t.oid = ix.indrelid
|
i.index_name,
|
||||||
and i.oid = ix.indexrelid
|
ic.column_position
|
||||||
and t.relkind = 'r'
|
|
||||||
and ix.indisprimary = false
|
|
||||||
and t.relnamespace = c.oid
|
|
||||||
and c.nspname != 'pg_catalog'
|
|
||||||
and ('tables:' || c.nspname || '.' || t.relname) =OBJECT_ID_CONDITION
|
|
||||||
order by
|
|
||||||
t.relname
|
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,17 +1,9 @@
|
|||||||
module.exports = `
|
module.exports = `
|
||||||
SELECT pg_namespace.nspname AS "schema_name"
|
SELECT owner "schema_name"
|
||||||
, pg_class.relname AS "pure_name"
|
, table_name "pure_name"
|
||||||
, pg_attribute.attname AS "column_name"
|
, column_name "column_name"
|
||||||
, pg_catalog.format_type(pg_attribute.atttypid, pg_attribute.atttypmod) AS "data_type"
|
, data_type "data_type"
|
||||||
FROM pg_catalog.pg_class
|
FROM all_tab_columns av
|
||||||
INNER JOIN pg_catalog.pg_namespace
|
where table_name =OBJECT_ID_CONDITION
|
||||||
ON pg_class.relnamespace = pg_namespace.oid
|
order by column_id
|
||||||
INNER JOIN pg_catalog.pg_attribute
|
|
||||||
ON pg_class.oid = pg_attribute.attrelid
|
|
||||||
-- Keeps only materialized views, and non-db/catalog/index columns
|
|
||||||
WHERE pg_class.relkind = 'm'
|
|
||||||
AND pg_attribute.attnum >= 1
|
|
||||||
AND ('matviews:' || pg_namespace.nspname || '.' || pg_class.relname) =OBJECT_ID_CONDITION
|
|
||||||
|
|
||||||
ORDER BY pg_attribute.attnum
|
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,8 +1,2 @@
|
|||||||
module.exports = `
|
module.exports = `
|
||||||
select
|
|
||||||
matviewname as "pure_name",
|
|
||||||
schemaname as "schema_name",
|
|
||||||
md5(definition) as "hash_code"
|
|
||||||
from
|
|
||||||
pg_catalog.pg_matviews WHERE schemaname NOT LIKE 'pg_%'
|
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
module.exports = `
|
module.exports = `
|
||||||
select
|
select owner as schema_name,
|
||||||
matviewname as "pure_name",
|
mview_name pure_name,
|
||||||
schemaname as "schema_name",
|
container_name,
|
||||||
definition as "definition",
|
query as definition,
|
||||||
md5(definition) as "hash_code"
|
ora_hash(query, 'MD5') as "hash_code"
|
||||||
from
|
--refresh_mode,
|
||||||
pg_catalog.pg_matviews WHERE schemaname NOT LIKE 'pg_%'
|
--refresh_method,
|
||||||
and ('matviews:' || schemaname || '.' || matviewname) =OBJECT_ID_CONDITION
|
--build_mode,
|
||||||
|
--last_refresh_date,
|
||||||
|
--ompile_state
|
||||||
|
from all_mviews
|
||||||
|
where mview_name=OBJECT_ID_CONDITION
|
||||||
|
order by owner, mview_name
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
module.exports = `
|
module.exports = `
|
||||||
select
|
select
|
||||||
table_constraints.constraint_schema as "constraint_schema",
|
pk.owner as "constraint_schema",
|
||||||
table_constraints.constraint_name as "constraint_name",
|
pk.constraint_name as "constraint_name",
|
||||||
table_constraints.table_schema as "schema_name",
|
pk.owner as "schema_name",
|
||||||
table_constraints.table_name as "pure_name",
|
pk.table_name as "pure_name",
|
||||||
key_column_usage.column_name as "column_name"
|
basecol.column_name as "column_name"
|
||||||
from information_schema.table_constraints
|
from all_cons_columns basecol,
|
||||||
inner join information_schema.key_column_usage on table_constraints.table_name = key_column_usage.table_name and table_constraints.constraint_name = key_column_usage.constraint_name
|
all_constraints pk
|
||||||
where
|
where constraint_type = 'P'
|
||||||
table_constraints.table_schema <> 'information_schema'
|
and basecol.owner = pk.owner
|
||||||
and table_constraints.table_schema <> 'pg_catalog'
|
and basecol.constraint_name = pk.constraint_name
|
||||||
and table_constraints.table_schema !~ '^pg_toast'
|
and basecol.table_name = pk.table_name
|
||||||
and table_constraints.constraint_type = 'PRIMARY KEY'
|
and pk.constraint_name =OBJECT_ID_CONDITION
|
||||||
and ('tables:' || table_constraints.table_schema || '.' || table_constraints.table_name) =OBJECT_ID_CONDITION
|
order by basecol.position
|
||||||
order by key_column_usage.ordinal_position
|
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,10 +1,2 @@
|
|||||||
module.exports = `
|
module.exports = `
|
||||||
select
|
|
||||||
routine_name as "pure_name",
|
|
||||||
routine_schema as "schema_name",
|
|
||||||
md5(routine_definition) as "hash_code",
|
|
||||||
routine_type as "object_type"
|
|
||||||
from
|
|
||||||
information_schema.routines where routine_schema != 'information_schema' and routine_schema != 'pg_catalog'
|
|
||||||
and routine_type in ('PROCEDURE', 'FUNCTION')
|
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,17 +1,40 @@
|
|||||||
module.exports = `
|
module.exports = `
|
||||||
select
|
select
|
||||||
routine_name as "pure_name",
|
routine_name as "pure_name",
|
||||||
routine_schema as "schema_name",
|
routine_schema as "schema_name",
|
||||||
routine_definition as "definition",
|
routine_definition as "definition",
|
||||||
md5(routine_definition) as "hash_code",
|
standard_hash(routine_definition, 'MD5') as "hash_code",
|
||||||
routine_type as "object_type",
|
routine_type as "object_type",
|
||||||
data_type as "data_type",
|
'fixme_data_type' as "data_type",
|
||||||
external_language as "language"
|
'fixme_external_language' as "language"
|
||||||
from
|
from (select
|
||||||
information_schema.routines where routine_schema != 'information_schema' and routine_schema != 'pg_catalog'
|
sys_context('userenv', 'DB_NAME') routine_catalog,
|
||||||
and (
|
sys_context('userenv', 'DB_NAME') specific_catalog,
|
||||||
(routine_type = 'PROCEDURE' and ('procedures:' || routine_schema || '.' || routine_name) =OBJECT_ID_CONDITION)
|
ap.owner specific_schema,
|
||||||
or
|
ap.owner routine_schema,
|
||||||
(routine_type = 'FUNCTION' and ('functions:' || routine_schema || '.' || routine_name) =OBJECT_ID_CONDITION)
|
decode( ap.procedure_name, null, ap.object_name || ap.procedure_name, ap.procedure_name ) specific_name,
|
||||||
)
|
decode( ap.procedure_name, null, ap.object_name || ap.procedure_name, ap.procedure_name ) routine_name,
|
||||||
|
ao.object_type routine_type,
|
||||||
|
decode(impltypeowner, null, to_char(null), SYS_CONTEXT('userenv', 'DB_NAME')) type_udt_catalog,
|
||||||
|
--to_clob(get_proc_text(ap.owner, ap.object_name, ao.object_type, 32767)) routine_body,
|
||||||
|
'fixme_routine_body.' || ap.owner || '.' || decode( ap.procedure_name, null, ap.object_name || ap.procedure_name, ap.procedure_name ) routine_body,
|
||||||
|
--to_clob(get_proc_text(ap.owner, ap.object_name, ao.object_type, 4000)) routine_definition,
|
||||||
|
'fixme_routine_definition.' || ap.owner || '.' || decode( ap.procedure_name, null, ap.object_name || ap.procedure_name, ap.procedure_name ) routine_definition,
|
||||||
|
sys_context('userenv', 'DB_NAME') character_set_catalog,
|
||||||
|
'SYS' character_set_schema,
|
||||||
|
sys_context('userenv', 'DB_NAME') collation_catalog,
|
||||||
|
'SYS' collation_schema,
|
||||||
|
deterministic is_deterministic,
|
||||||
|
pipelined is_pipelined ,
|
||||||
|
aggregate is_aggregate,
|
||||||
|
authid is_definer
|
||||||
|
from
|
||||||
|
all_procedures ap,
|
||||||
|
all_objects ao
|
||||||
|
where
|
||||||
|
ap.owner = ao.owner and
|
||||||
|
ap.object_name = ao.object_name and
|
||||||
|
ao.object_type in ('PACKAGE', 'PROCEDURE', 'FUNCTION')
|
||||||
|
and ao.object_name =OBJECT_ID_CONDITION
|
||||||
|
) routines
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,18 +1,27 @@
|
|||||||
module.exports = `
|
module.exports = `
|
||||||
select ao.owner as "schema_name", ao.object_name as "pure_name"
|
|
||||||
from all_objects ao
|
|
||||||
where exists(select null from user_objects uo where uo.object_id = ao.object_id)
|
|
||||||
and object_type = 'TABLE'
|
|
||||||
`;
|
|
||||||
/*
|
|
||||||
module.exports = `
|
|
||||||
select infoTables.table_schema as "schema_name", infoTables.table_name as "pure_name"
|
select infoTables.table_schema as "schema_name", infoTables.table_name as "pure_name"
|
||||||
from information_schema.tables infoTables
|
from (
|
||||||
|
select
|
||||||
|
sys_context('userenv', 'DB_NAME') table_catalog,
|
||||||
|
owner table_schema,
|
||||||
|
table_name table_name,
|
||||||
|
case
|
||||||
|
when iot_type = 'Y' then 'IOT'
|
||||||
|
when temporary = 'Y' then 'TEMP'
|
||||||
|
else 'BASE TABLE'
|
||||||
|
end table_type
|
||||||
|
from
|
||||||
|
all_tables
|
||||||
|
union all
|
||||||
|
select
|
||||||
|
sys_context('userenv', 'DB_NAME') table_catalog,
|
||||||
|
owner table_schema,
|
||||||
|
view_name table_name,
|
||||||
|
'VIEW' table_type
|
||||||
|
from
|
||||||
|
all_views
|
||||||
|
) infoTables
|
||||||
where infoTables.table_type not like '%VIEW%'
|
where infoTables.table_type not like '%VIEW%'
|
||||||
and ('tables:' || infoTables.table_schema || '.' || infoTables.table_name) =OBJECT_ID_CONDITION
|
and table_name =OBJECT_ID_CONDITION
|
||||||
and infoTables.table_schema <> 'pg_catalog'
|
|
||||||
and infoTables.table_schema <> 'information_schema'
|
|
||||||
and infoTables.table_schema <> 'pg_internal'
|
|
||||||
and infoTables.table_schema !~ '^pg_toast'
|
|
||||||
`;
|
`;
|
||||||
*/
|
|
||||||
|
|||||||
@@ -1,28 +1,2 @@
|
|||||||
module.exports = `
|
module.exports = `
|
||||||
select infoTables.table_schema as "schema_name", infoTables.table_name as "pure_name",
|
|
||||||
(
|
|
||||||
select md5(string_agg(
|
|
||||||
infoColumns.column_name || '|' || infoColumns.data_type || '|' || infoColumns.is_nullable::varchar(255) || '|' || coalesce(infoColumns.character_maximum_length, -1)::varchar(255)
|
|
||||||
|| '|' || coalesce(infoColumns.numeric_precision, -1)::varchar(255) ,
|
|
||||||
',' order by infoColumns.ordinal_position
|
|
||||||
)) as "hash_code_columns"
|
|
||||||
from information_schema.columns infoColumns
|
|
||||||
where infoColumns.table_schema = infoTables.table_schema and infoColumns.table_name = infoTables.table_name
|
|
||||||
),
|
|
||||||
(
|
|
||||||
select md5(string_agg(
|
|
||||||
infoConstraints.constraint_name || '|' || infoConstraints.constraint_type ,
|
|
||||||
',' order by infoConstraints.constraint_name
|
|
||||||
)) as "hash_code_constraints"
|
|
||||||
from information_schema.table_constraints infoConstraints
|
|
||||||
where infoConstraints.table_schema = infoTables.table_schema and infoConstraints.table_name = infoTables.table_name
|
|
||||||
)
|
|
||||||
|
|
||||||
from information_schema.tables infoTables
|
|
||||||
where infoTables.table_type not like '%VIEW%'
|
|
||||||
and ('tables:' || infoTables.table_schema || '.' || infoTables.table_name) =OBJECT_ID_CONDITION
|
|
||||||
and infoTables.table_schema <> 'pg_catalog'
|
|
||||||
and infoTables.table_schema <> 'information_schema'
|
|
||||||
and infoTables.table_schema <> 'pg_internal'
|
|
||||||
and infoTables.table_schema !~ '^pg_toast'
|
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
module.exports = `
|
module.exports = `
|
||||||
select conname as "constraint_name" from pg_constraint where contype = 'u'
|
select constraint_name
|
||||||
|
from all_constraints
|
||||||
|
where constraint_type = 'U'
|
||||||
|
and constraint_name =OBJECT_ID_CONDITION
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,8 +1,2 @@
|
|||||||
module.exports = `
|
module.exports = `
|
||||||
select
|
|
||||||
table_name as "pure_name",
|
|
||||||
table_schema as "schema_name",
|
|
||||||
md5(view_definition) as "hash_code"
|
|
||||||
from
|
|
||||||
information_schema.views where table_schema != 'information_schema' and table_schema != 'pg_catalog'
|
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,9 +1,36 @@
|
|||||||
module.exports = `
|
module.exports = `
|
||||||
select
|
select
|
||||||
ao.owner as "schema_name", ao.object_name as "pure_name",
|
table_name as "pure_name",
|
||||||
'later' as "create_sql",
|
table_schema as "schema_name",
|
||||||
object_id as "hash_code"
|
table_name as "create_sql",
|
||||||
from all_objects ao
|
ora_hash(view_definition, 3768421) as "hash_code" -- fixme
|
||||||
where exists(select null from user_objects uo where uo.object_id = ao.object_id)
|
from (select
|
||||||
and object_type = 'VIEW'
|
sys_context('userenv', 'DB_NAME') table_catalog,
|
||||||
|
owner table_schema,
|
||||||
|
view_name table_name,
|
||||||
|
text view_definition,
|
||||||
|
'VIEW' table_type,
|
||||||
|
(select max( case when uuc.updatable = 'YES' or
|
||||||
|
uuc.deletable = 'YES' or
|
||||||
|
uuc.insertable = 'YES' then 'YES' else 'NO' end
|
||||||
|
)
|
||||||
|
from
|
||||||
|
user_updatable_columns uuc
|
||||||
|
where
|
||||||
|
uuc.owner = av.owner and
|
||||||
|
uuc.table_name = av.view_name
|
||||||
|
) is_updatable,
|
||||||
|
decode(
|
||||||
|
(select 1
|
||||||
|
from
|
||||||
|
all_constraints ac
|
||||||
|
where
|
||||||
|
ac.owner = av.owner and
|
||||||
|
ac.table_name = av.view_name and
|
||||||
|
ac.constraint_type = 'V'), 1, 'CASCADE', 'NONE') check_option
|
||||||
|
from
|
||||||
|
all_views av
|
||||||
|
where text is not null
|
||||||
|
) views
|
||||||
|
where table_name =OBJECT_ID_CONDITION
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ const spatialTypes = ['GEOGRAPHY'];
|
|||||||
|
|
||||||
/** @type {import('dbgate-types').SqlDialect} */
|
/** @type {import('dbgate-types').SqlDialect} */
|
||||||
const dialect = {
|
const dialect = {
|
||||||
rangeSelect: true,
|
rangeSelect: false,
|
||||||
|
limitSelect: false,
|
||||||
ilike: true,
|
ilike: true,
|
||||||
// stringEscapeChar: '\\',
|
// stringEscapeChar: '\\',
|
||||||
stringEscapeChar: "'",
|
stringEscapeChar: "'",
|
||||||
|
|||||||
Reference in New Issue
Block a user