mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 10:46:00 +00:00
oracle analyser per schema
This commit is contained in:
@@ -55,8 +55,8 @@ class Analyser extends DatabaseAnalyser {
|
||||
super(pool, driver, version);
|
||||
}
|
||||
|
||||
createQuery(resFileName, typeFields) {
|
||||
const query = super.createQuery(sql[resFileName], typeFields);
|
||||
createQuery(resFileName, typeFields, replacements = {}) {
|
||||
const query = super.createQuery(sql[resFileName], typeFields, replacements);
|
||||
//if (query) return query.replace('#REFTABLECOND#', this.driver.__analyserInternals.refTableCond);
|
||||
return query;
|
||||
}
|
||||
@@ -68,40 +68,39 @@ class Analyser extends DatabaseAnalyser {
|
||||
|
||||
async _runAnalysis() {
|
||||
this.feedback({ analysingMessage: 'Loading tables' });
|
||||
const tables = await this.analyserQuery(this.driver.dialect.stringAgg ? 'tableList' : 'tableList', ['tables']);
|
||||
const tables = await this.analyserQuery('tableList', ['tables'], { $owner: this.pool._schema_name });
|
||||
this.feedback({ analysingMessage: 'Loading columns' });
|
||||
const columns = await this.analyserQuery('columns', ['tables', 'views']);
|
||||
const columns = await this.analyserQuery('columns', ['tables', 'views'], { $owner: this.pool._schema_name });
|
||||
|
||||
this.feedback({ analysingMessage: 'Loading primary keys' });
|
||||
const pkColumns = await this.analyserQuery('primaryKeys', ['tables']);
|
||||
const pkColumns = await this.analyserQuery('primaryKeys', ['tables'], { $owner: this.pool._schema_name });
|
||||
|
||||
//let fkColumns = null;
|
||||
|
||||
this.feedback({ analysingMessage: 'Loading foreign keys' });
|
||||
const fkColumns = await this.analyserQuery('foreignKeys', ['tables']);
|
||||
const fkColumns = await this.analyserQuery('foreignKeys', ['tables'], { $owner: this.pool._schema_name });
|
||||
this.feedback({ analysingMessage: 'Loading views' });
|
||||
const views = await this.analyserQuery('views', ['views']);
|
||||
const views = await this.analyserQuery('views', ['views'], { $owner: this.pool._schema_name });
|
||||
let geometryColumns = { rows: [] };
|
||||
let geographyColumns = { rows: [] };
|
||||
|
||||
this.feedback({ analysingMessage: 'Loading materialized views' });
|
||||
const matviews = this.driver.dialect.materializedViews ? await this.analyserQuery('matviews', ['matviews']) : null;
|
||||
const matviews = this.driver.dialect.materializedViews
|
||||
? await this.analyserQuery('matviews', ['matviews'], { $owner: this.pool._schema_name })
|
||||
: null;
|
||||
this.feedback({ analysingMessage: 'Loading materialized view columns' });
|
||||
const matviewColumns = this.driver.dialect.materializedViews
|
||||
? await this.analyserQuery('matviewColumns', ['matviews'])
|
||||
? await this.analyserQuery('matviewColumns', ['matviews'], { $owner: this.pool._schema_name })
|
||||
: null;
|
||||
this.feedback({ analysingMessage: 'Loading routines' });
|
||||
const routines = await this.analyserQuery('routines', ['procedures', 'functions']);
|
||||
const routines = await this.analyserQuery('routines', ['procedures', 'functions'], {
|
||||
$owner: this.pool._schema_name,
|
||||
});
|
||||
this.feedback({ analysingMessage: 'Loading indexes' });
|
||||
const indexes = this.driver.__analyserInternals.skipIndexes
|
||||
? { rows: [] }
|
||||
: await this.analyserQuery('indexes', ['tables']);
|
||||
const indexes = await this.analyserQuery('indexes', ['tables'], { $owner: this.pool._schema_name });
|
||||
this.feedback({ analysingMessage: 'Loading index columns' });
|
||||
// const indexcols = this.driver.__analyserInternals.skipIndexes
|
||||
// ? { rows: [] }
|
||||
// : await this.driver.query(this.pool, this.createQuery('indexcols', ['tables']));
|
||||
this.feedback({ analysingMessage: 'Loading unique names' });
|
||||
const uniqueNames = await this.analyserQuery('uniqueNames', ['tables']);
|
||||
const uniqueNames = await this.analyserQuery('uniqueNames', ['tables'], { $owner: this.pool._schema_name });
|
||||
this.feedback({ analysingMessage: 'Finalizing DB structure' });
|
||||
|
||||
const fkColumnsMapped = fkColumns.rows.map(x => ({
|
||||
|
||||
@@ -7,7 +7,6 @@ const Analyser = require('./Analyser');
|
||||
const oracledb = require('oracledb');
|
||||
const { createBulkInsertStreamBase, makeUniqueColumnNames } = require('dbgate-tools');
|
||||
|
||||
|
||||
/*
|
||||
pg.types.setTypeParser(1082, 'text', val => val); // date
|
||||
pg.types.setTypeParser(1114, 'text', val => val); // timestamp without timezone
|
||||
@@ -47,6 +46,7 @@ const drivers = driverBases.map(driverBase => ({
|
||||
database,
|
||||
databaseUrl,
|
||||
useDatabaseUrl,
|
||||
serviceName,
|
||||
ssl,
|
||||
isReadOnly,
|
||||
authType,
|
||||
@@ -55,8 +55,9 @@ const drivers = driverBases.map(driverBase => ({
|
||||
client = await oracledb.getConnection({
|
||||
user,
|
||||
password,
|
||||
connectString: useDatabaseUrl ? databaseUrl : port ? `${server}:${port}` : server,
|
||||
connectString: useDatabaseUrl ? databaseUrl : port ? `${server}:${port}/${serviceName}` : server,
|
||||
});
|
||||
client._schema_name = database;
|
||||
return client;
|
||||
},
|
||||
async close(pool) {
|
||||
@@ -64,7 +65,7 @@ const drivers = driverBases.map(driverBase => ({
|
||||
},
|
||||
async query(client, sql) {
|
||||
//console.log('query sql', sql);
|
||||
if (sql == null) {
|
||||
if (sql == null) {a
|
||||
return {
|
||||
rows: [],
|
||||
columns: [],
|
||||
@@ -250,12 +251,12 @@ const drivers = driverBases.map(driverBase => ({
|
||||
|
||||
return pass;
|
||||
},
|
||||
async writeTable(pool, name, options) {
|
||||
async writeTable(pootl, name, options) {
|
||||
// @ts-ignore
|
||||
return createBulkInsertStreamBase(this, stream, pool, name, options);
|
||||
},
|
||||
async listDatabases(client) {
|
||||
const { rows } = await this.query(client, 'SELECT instance_name AS "name" FROM v$instance');
|
||||
const { rows } = await this.query(client, 'SELECT username as "name" from all_users order by username');
|
||||
return rows;
|
||||
},
|
||||
|
||||
|
||||
@@ -10,6 +10,6 @@ select
|
||||
data_scale as "numeric_scale",
|
||||
data_default as "default_value"
|
||||
FROM all_tab_columns av
|
||||
where TABLE_NAME =OBJECT_ID_CONDITION
|
||||
where OWNER='$owner' AND TABLE_NAME =OBJECT_ID_CONDITION
|
||||
order by column_id
|
||||
`;
|
||||
@@ -10,7 +10,7 @@ select fk.constraint_name as "constraint_name",
|
||||
basecol.column_name as "column_name",
|
||||
refcol.column_name as "ref_column_name"
|
||||
from all_cons_columns refcol, all_cons_columns basecol, all_constraints ref, all_constraints fk
|
||||
where fk.constraint_type = 'R'
|
||||
where fk.OWNER = '$owner' AND fk.constraint_type = 'R'
|
||||
and ref.owner = fk.r_owner
|
||||
and ref.constraint_name = fk.r_constraint_name
|
||||
and basecol.owner = fk.owner
|
||||
|
||||
@@ -8,7 +8,7 @@ select i.table_name as "tableName",
|
||||
ic.column_position as "postion",
|
||||
ic.descend as "descending"
|
||||
from all_ind_columns ic, all_indexes i
|
||||
where ic.index_owner = i.owner
|
||||
where INDEX_OWNER = '$owner' AND ic.index_owner = i.owner
|
||||
and ic.index_name = i.index_name
|
||||
and i.index_name =OBJECT_ID_CONDITION
|
||||
order by i.table_owner,
|
||||
|
||||
@@ -4,6 +4,6 @@ SELECT owner "schema_name"
|
||||
, column_name "column_name"
|
||||
, data_type "data_type"
|
||||
FROM all_tab_columns av
|
||||
where table_name =OBJECT_ID_CONDITION
|
||||
where OWNER = '$owner' AND table_name =OBJECT_ID_CONDITION
|
||||
order by column_id
|
||||
`;
|
||||
|
||||
@@ -14,6 +14,6 @@ SELECT owner as schema_name,
|
||||
'//text()'
|
||||
)) definition
|
||||
FROM all_mviews
|
||||
where mview_name=OBJECT_ID_CONDITION
|
||||
where OWNER = '$owner' AND mview_name=OBJECT_ID_CONDITION
|
||||
order by owner, mview_name
|
||||
`;
|
||||
@@ -32,6 +32,7 @@ from (select
|
||||
all_procedures ap,
|
||||
all_objects ao
|
||||
where
|
||||
ap.owner = '$owner' and
|
||||
ap.owner = ao.owner and
|
||||
ap.object_name = ao.object_name and
|
||||
ao.object_type in ('PACKAGE', 'PROCEDURE', 'FUNCTION')
|
||||
|
||||
@@ -4,6 +4,6 @@ select
|
||||
table_name "pure_name"
|
||||
from
|
||||
all_tables
|
||||
where TABLE_NAME =OBJECT_ID_CONDITION
|
||||
where OWNER='$owner' AND TABLE_NAME =OBJECT_ID_CONDITION
|
||||
`;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module.exports = `
|
||||
select constraint_name
|
||||
from all_constraints
|
||||
where constraint_type = 'U'
|
||||
where OWNER='$owner' and constraint_type = 'U'
|
||||
and constraint_name =OBJECT_ID_CONDITION
|
||||
`;
|
||||
|
||||
@@ -6,7 +6,7 @@ from (select
|
||||
owner as "schema_name",
|
||||
SUBSTR(text_vc, 1, 3900) AS "create_sql"
|
||||
from all_views av
|
||||
where text_vc is not null
|
||||
where owner = '$owner' and text_vc is not null
|
||||
) avv
|
||||
where "pure_name" =OBJECT_ID_CONDITION
|
||||
`;
|
||||
|
||||
@@ -19,7 +19,6 @@ const dialect = {
|
||||
quoteIdentifier(s) {
|
||||
return '"' + s + '"';
|
||||
},
|
||||
stringAgg: true,
|
||||
|
||||
createColumn: true,
|
||||
dropColumn: true,
|
||||
@@ -110,32 +109,15 @@ const oracleDriverBase = {
|
||||
getQuerySplitterOptions: () => oracleSplitterOptions,
|
||||
readOnlySessions: true,
|
||||
|
||||
databaseUrlPlaceholder: 'e.g. oracledb://user:password@localhost:1521',
|
||||
databaseUrlPlaceholder: 'e.g. localhost:1521/orcl',
|
||||
|
||||
showConnectionField: (field, values) => {
|
||||
if (field == 'useDatabaseUrl') return true;
|
||||
if (values.useDatabaseUrl) {
|
||||
return ['databaseUrl', 'isReadOnly'].includes(field);
|
||||
return ['databaseUrl', 'user', 'password'].includes(field);
|
||||
}
|
||||
|
||||
return ['user', 'password', 'defaultDatabase', 'singleDatabase', 'isReadOnly', 'server', 'port'].includes(field);
|
||||
},
|
||||
|
||||
beforeConnectionSave: connection => {
|
||||
const { databaseUrl } = connection;
|
||||
if (databaseUrl) {
|
||||
const m = databaseUrl.match(/\/([^/]+)($|\?)/);
|
||||
return {
|
||||
...connection,
|
||||
singleDatabase: !!m,
|
||||
defaultDatabase: m ? m[1] : null,
|
||||
};
|
||||
}
|
||||
return connection;
|
||||
},
|
||||
|
||||
__analyserInternals: {
|
||||
refTableCond: '',
|
||||
return ['user', 'password', 'server', 'port', 'serviceName'].includes(field);
|
||||
},
|
||||
|
||||
getNewObjectTemplates() {
|
||||
@@ -189,7 +171,7 @@ const oracleDriver = {
|
||||
return dialect;
|
||||
},
|
||||
|
||||
showConnectionTab: (field) => field == 'sshTunnel',
|
||||
showConnectionTab: field => field == 'sshTunnel',
|
||||
};
|
||||
|
||||
module.exports = [oracleDriver];
|
||||
|
||||
Reference in New Issue
Block a user