Oracle driver first data

This commit is contained in:
Rinie Kervel
2022-10-11 17:04:38 +02:00
parent 4939b74179
commit 51952ecfdd
25 changed files with 259 additions and 381 deletions

View File

@@ -1,23 +1,15 @@
module.exports = `
select
table_schema as "schema_name",
table_name as "pure_name",
column_name as "column_name",
is_nullable as "is_nullable",
data_type as "data_type",
character_maximum_length as "char_max_length",
numeric_precision as "numeric_precision",
numeric_scale as "numeric_scale",
column_default as "default_value"
from information_schema.columns
where
table_schema <> 'information_schema'
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
select
owner as "schema_name",
table_name as "pure_name",
column_name as "column_name",
nullable as "is_nullable",
data_type as "data_type",
data_length as "char_max_length",
data_precision as "numeric_precision",
data_scale as "numeric_scale",
data_default as "default_value"
FROM all_tab_columns av
where TABLE_NAME =OBJECT_ID_CONDITION
order by column_id
`;

View File

@@ -1,10 +1,2 @@
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
`;

View File

@@ -1,10 +1,2 @@
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
`;

View File

@@ -1,8 +1,2 @@
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
`;

View File

@@ -1,24 +1,24 @@
module.exports = `
select
fk.constraint_name as "constraint_name",
fk.constraint_schema as "constraint_schema",
base.table_name as "pure_name",
base.table_schema as "schema_name",
fk.update_rule as "update_action",
fk.delete_rule as "delete_action",
ref.table_name as "ref_table_name",
ref.table_schema as "ref_schema_name",
basecol.column_name as "column_name",
refcol.column_name as "ref_column_name"
from information_schema.referential_constraints fk
inner join information_schema.table_constraints base on fk.constraint_name = base.constraint_name and fk.constraint_schema = base.constraint_schema
inner join information_schema.table_constraints ref on fk.unique_constraint_name = ref.constraint_name and fk.unique_constraint_schema = ref.constraint_schema #REFTABLECOND#
inner join information_schema.key_column_usage basecol on base.table_name = basecol.table_name and base.constraint_name = basecol.constraint_name
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
where
base.table_schema <> 'information_schema'
and base.table_schema <> 'pg_catalog'
and base.table_schema !~ '^pg_toast'
and ('tables:' || base.table_schema || '.' || base.table_name) =OBJECT_ID_CONDITION
order by basecol.ordinal_position
select fk.constraint_name as "constraint_name",
fk.owner as "constraint_schema",
fk.table_name as "pure_name",
fk.owner as "schema_name",
fk.delete_rule as "update_action",
fk.delete_rule as "delete_action",
ref.table_name as "ref_table_name",
ref.owner as "ref_schema_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'
and ref.owner = fk.r_owner
and ref.constraint_name = fk.r_constraint_name
and basecol.owner = fk.owner
and basecol.constraint_name = fk.constraint_name
and basecol.table_name = fk.table_name
and refcol.owner = ref.owner
and refcol.constraint_name = ref.constraint_name
and refcol.table_name = ref.table_name
AND fk.constraint_name =OBJECT_ID_CONDITION
order by basecol.position
`;

View File

@@ -1,8 +1,2 @@
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
`;

View File

@@ -1,8 +1,2 @@
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
`;

View File

@@ -2,23 +2,23 @@ const columns = require('./columns');
const tableModifications = require('./tableList');
const tableList = require('./tableList');
const viewModifications = require('./views');
const matviewModifications = require('./matviewModifications');
const matviewModifications = require('./matviews');
const primaryKeys = require('./primaryKeys');
const foreignKeys = require('./foreignKeys');
const views = require('./views');
const matviews = require('./matviews');
const routines = require('./routines');
const routineModifications = require('./routineModifications');
const routineModifications = require('./routines');
const matviewColumns = require('./matviewColumns');
const indexes = require('./indexes');
const indexcols = require('./indexcols');
const indexes = require('./indexes'); // use mysql
//const indexcols = require('./indexcols');
const uniqueNames = require('./uniqueNames');
const geometryColumns = require('./geometryColumns');
const geographyColumns = require('./geographyColumns');
//const geometryColumns = require('./geometryColumns');
//const geographyColumns = require('./geographyColumns');
const fk_keyColumnUsage = require('./fk_key_column_usage');
const fk_referentialConstraints = require('./fk_referential_constraints');
const fk_tableConstraints = require('./fk_table_constraints');
//const fk_keyColumnUsage = require('./fk_key_column_usage');
//const fk_referentialConstraints = require('./fk_referential_constraints');
//const fk_tableConstraints = require('./fk_table_constraints');
module.exports = {
columns,
@@ -27,9 +27,6 @@ module.exports = {
viewModifications,
primaryKeys,
foreignKeys,
fk_keyColumnUsage,
fk_referentialConstraints,
fk_tableConstraints,
views,
routines,
routineModifications,
@@ -37,8 +34,8 @@ module.exports = {
matviewModifications,
matviewColumns,
indexes,
indexcols,
// indexcols,
uniqueNames,
geometryColumns,
geographyColumns,
//geometryColumns,
//geographyColumns,
};

View File

@@ -1,24 +1,2 @@
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
`;

View File

@@ -1,25 +1,18 @@
module.exports = `
select
t.relname as "table_name",
c.nspname as "schema_name",
i.relname as "index_name",
ix.indisprimary as "is_primary",
ix.indisunique as "is_unique",
ix.indkey as "indkey",
t.oid as "oid"
from
pg_class t,
pg_class i,
pg_index ix,
pg_namespace c
where
t.oid = ix.indrelid
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
select i.table_name as "tableName",
i.table_owner as "schemaName",
i.index_name as "constraintName",
i.index_type as "indexType",
i.uniqueness as "Unique",
ic.column_name as "columnName",
ic.column_position as "postion",
ic.descend as "descending"
from all_ind_columns ic, all_indexes i
where ic.index_owner = i.owner
and ic.index_name = i.index_name
and i.index_name =OBJECT_ID_CONDITION
order by i.table_owner,
i.table_name,
i.index_name,
ic.column_position
`;

View File

@@ -1,17 +1,9 @@
module.exports = `
SELECT pg_namespace.nspname AS "schema_name"
, pg_class.relname AS "pure_name"
, pg_attribute.attname AS "column_name"
, pg_catalog.format_type(pg_attribute.atttypid, pg_attribute.atttypmod) AS "data_type"
FROM pg_catalog.pg_class
INNER JOIN pg_catalog.pg_namespace
ON pg_class.relnamespace = pg_namespace.oid
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
SELECT owner "schema_name"
, table_name "pure_name"
, column_name "column_name"
, data_type "data_type"
FROM all_tab_columns av
where table_name =OBJECT_ID_CONDITION
order by column_id
`;

View File

@@ -1,8 +1,2 @@
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_%'
`;

View File

@@ -1,10 +1,15 @@
module.exports = `
select
matviewname as "pure_name",
schemaname as "schema_name",
definition as "definition",
md5(definition) as "hash_code"
from
pg_catalog.pg_matviews WHERE schemaname NOT LIKE 'pg_%'
and ('matviews:' || schemaname || '.' || matviewname) =OBJECT_ID_CONDITION
select owner as schema_name,
mview_name pure_name,
container_name,
query as definition,
ora_hash(query, 'MD5') as "hash_code"
--refresh_mode,
--refresh_method,
--build_mode,
--last_refresh_date,
--ompile_state
from all_mviews
where mview_name=OBJECT_ID_CONDITION
order by owner, mview_name
`;

View File

@@ -1,17 +1,16 @@
module.exports = `
select
table_constraints.constraint_schema as "constraint_schema",
table_constraints.constraint_name as "constraint_name",
table_constraints.table_schema as "schema_name",
table_constraints.table_name as "pure_name",
key_column_usage.column_name as "column_name"
from information_schema.table_constraints
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
where
table_constraints.table_schema <> 'information_schema'
and table_constraints.table_schema <> 'pg_catalog'
and table_constraints.table_schema !~ '^pg_toast'
and table_constraints.constraint_type = 'PRIMARY KEY'
and ('tables:' || table_constraints.table_schema || '.' || table_constraints.table_name) =OBJECT_ID_CONDITION
order by key_column_usage.ordinal_position
select
pk.owner as "constraint_schema",
pk.constraint_name as "constraint_name",
pk.owner as "schema_name",
pk.table_name as "pure_name",
basecol.column_name as "column_name"
from all_cons_columns basecol,
all_constraints pk
where constraint_type = 'P'
and basecol.owner = pk.owner
and basecol.constraint_name = pk.constraint_name
and basecol.table_name = pk.table_name
and pk.constraint_name =OBJECT_ID_CONDITION
order by basecol.position
`;

View File

@@ -1,10 +1,2 @@
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')
`;

View File

@@ -1,17 +1,40 @@
module.exports = `
select
select
routine_name as "pure_name",
routine_schema as "schema_name",
routine_definition as "definition",
md5(routine_definition) as "hash_code",
standard_hash(routine_definition, 'MD5') as "hash_code",
routine_type as "object_type",
data_type as "data_type",
external_language as "language"
from
information_schema.routines where routine_schema != 'information_schema' and routine_schema != 'pg_catalog'
and (
(routine_type = 'PROCEDURE' and ('procedures:' || routine_schema || '.' || routine_name) =OBJECT_ID_CONDITION)
or
(routine_type = 'FUNCTION' and ('functions:' || routine_schema || '.' || routine_name) =OBJECT_ID_CONDITION)
)
'fixme_data_type' as "data_type",
'fixme_external_language' as "language"
from (select
sys_context('userenv', 'DB_NAME') routine_catalog,
sys_context('userenv', 'DB_NAME') specific_catalog,
ap.owner specific_schema,
ap.owner routine_schema,
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
`;

View File

@@ -1,18 +1,27 @@
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"
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%'
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'
and table_name =OBJECT_ID_CONDITION
`;
*/

View File

@@ -1,28 +1,2 @@
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'
`;

View File

@@ -1,3 +1,6 @@
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
`;

View File

@@ -1,8 +1,2 @@
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'
`;

View File

@@ -1,9 +1,36 @@
module.exports = `
select
ao.owner as "schema_name", ao.object_name as "pure_name",
'later' as "create_sql",
object_id as "hash_code"
from all_objects ao
where exists(select null from user_objects uo where uo.object_id = ao.object_id)
and object_type = 'VIEW'
table_name as "pure_name",
table_schema as "schema_name",
table_name as "create_sql",
ora_hash(view_definition, 3768421) as "hash_code" -- fixme
from (select
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
`;