oracle: code cleanup, not null detection

This commit is contained in:
Jan Prochazka 2024-05-31 17:03:35 +02:00
parent ebdcd9ad94
commit 1f75a818c8

View File

@ -13,9 +13,7 @@ function normalizeTypeName(dataType) {
function getColumnInfo( function getColumnInfo(
{ is_nullable, column_name, data_type, char_max_length, numeric_precision, numeric_ccale, default_value }, { is_nullable, column_name, data_type, char_max_length, numeric_precision, numeric_ccale, default_value },
table = undefined, table = undefined
geometryColumns = undefined,
geographyColumns = undefined
) { ) {
const normDataType = normalizeTypeName(data_type); const normDataType = normalizeTypeName(data_type);
let fullDataType = normDataType; let fullDataType = normDataType;
@ -26,7 +24,7 @@ function getColumnInfo(
return { return {
columnName: column_name, columnName: column_name,
dataType: fullDataType, dataType: fullDataType,
notNull: !is_nullable || is_nullable == 'NO' || is_nullable == 'no', notNull: is_nullable == 'N',
defaultValue: autoIncrement ? undefined : default_value, defaultValue: autoIncrement ? undefined : default_value,
autoIncrement, autoIncrement,
}; };
@ -63,8 +61,6 @@ class Analyser extends DatabaseAnalyser {
const fkColumns = await this.analyserQuery('foreignKeys', ['tables'], { $owner: this.pool._schema_name }); const fkColumns = await this.analyserQuery('foreignKeys', ['tables'], { $owner: this.pool._schema_name });
this.feedback({ analysingMessage: 'Loading views' }); this.feedback({ analysingMessage: 'Loading views' });
const views = await this.analyserQuery('views', ['views'], { $owner: this.pool._schema_name }); const views = await this.analyserQuery('views', ['views'], { $owner: this.pool._schema_name });
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
@ -113,15 +109,14 @@ class Analyser extends DatabaseAnalyser {
}; };
return { return {
...newTable, ...newTable,
columns: (columnsGrouped[columnGroup(table)] || []).map(col => columns: (columnsGrouped[columnGroup(table)] || []).map(col => getColumnInfo(col, newTable)),
getColumnInfo(col, newTable, geometryColumns, geographyColumns)
),
primaryKey: DatabaseAnalyser.extractPrimaryKeys(newTable, pkColumnsMapped), primaryKey: DatabaseAnalyser.extractPrimaryKeys(newTable, pkColumnsMapped),
foreignKeys: DatabaseAnalyser.extractForeignKeys(newTable, fkColumnsMapped), foreignKeys: DatabaseAnalyser.extractForeignKeys(newTable, fkColumnsMapped),
indexes: _.uniqBy( indexes: _.uniqBy(
indexes.rows.filter( indexes.rows.filter(
idx => idx =>
idx.tableName == newTable.pureName && !uniqueNames.rows.find(x => x.constraintName == idx.constraintName) idx.tableName == newTable.pureName &&
!uniqueNames.rows.find(x => x.constraintName == idx.constraintName)
), ),
'constraintName' 'constraintName'
).map(idx => ({ ).map(idx => ({
@ -188,69 +183,10 @@ class Analyser extends DatabaseAnalyser {
})), })),
}; };
// this.feedback({ analysingMessage: 'Debug sleep' });
// await new Promise(resolve => setTimeout(resolve, 90 * 1000));
this.feedback({ analysingMessage: null }); this.feedback({ analysingMessage: null });
return res; return res;
} }
async _getFastSnapshot() {
return null;
const tableModificationsQueryData = this.driver.dialect.stringAgg
? await this.analyserQuery('tableModifications')
: null;
const viewModificationsQueryData = await this.analyserQuery('viewModifications');
const matviewModificationsQueryData = this.driver.dialect.materializedViews
? await this.analyserQuery('matviewModifications')
: null;
const routineModificationsQueryData = await this.analyserQuery('routineModifications');
return {
tables: tableModificationsQueryData
? tableModificationsQueryData.rows.map(x => ({
objectId: `tables:${x.schema_name}.${x.pure_name}`,
pureName: x.pure_name,
schemaName: x.schema_name,
contentHash: `${x.hash_code_columns}-${x.hash_code_constraints}`,
}))
: null,
views: viewModificationsQueryData
? viewModificationsQueryData.rows.map(x => ({
objectId: `views:${x.schema_name}.${x.pure_name}`,
pureName: x.pure_name,
schemaName: x.schema_name,
contentHash: x.hash_code,
}))
: undefined,
matviews: matviewModificationsQueryData
? matviewModificationsQueryData.rows.map(x => ({
objectId: `matviews:${x.schema_name}.${x.pure_name}`,
pureName: x.pure_name,
schemaName: x.schema_name,
contentHash: x.hash_code,
}))
: undefined,
procedures: routineModificationsQueryData.rows
.filter(x => x.object_type == 'PROCEDURE')
.map(x => ({
objectId: `procedures:${x.schema_name}.${x.pure_name}`,
pureName: x.pure_name,
schemaName: x.schema_name,
contentHash: x.hash_code,
})),
functions: routineModificationsQueryData.rows
.filter(x => x.object_type == 'FUNCTION')
.map(x => ({
objectId: `functions:${x.schema_name}.${x.pure_name}`,
pureName: x.pure_name,
schemaName: x.schema_name,
contentHash: x.hash_code,
})),
};
}
} }
module.exports = Analyser; module.exports = Analyser;