mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 10:06:00 +00:00
Merge branch 'master' of https://github.com/dbgate/dbgate
This commit is contained in:
@@ -132,7 +132,9 @@ class MsSqlDumper extends SqlDumper {
|
||||
} else {
|
||||
this.dropDefault(oldcol);
|
||||
if (oldcol.columnName != newcol.columnName) this.renameColumn(oldcol, newcol.columnName);
|
||||
this.fillNewNotNullDefaults(newcol);
|
||||
if (!oldcol.notNull) {
|
||||
this.fillNewNotNullDefaults(newcol);
|
||||
}
|
||||
this.put('^alter ^table %f ^alter ^column %i ', oldcol, oldcol.columnName, newcol.columnName);
|
||||
this.columnDefinition(newcol, { includeDefault: false });
|
||||
this.endCommand();
|
||||
|
||||
@@ -32,10 +32,12 @@ class Dumper extends SqlDumper {
|
||||
}
|
||||
|
||||
changeColumn(oldcol, newcol, constraints) {
|
||||
this.fillNewNotNullDefaults({
|
||||
...newcol,
|
||||
columnName: oldcol.columnName,
|
||||
});
|
||||
if (!oldcol.notNull) {
|
||||
this.fillNewNotNullDefaults({
|
||||
...newcol,
|
||||
columnName: oldcol.columnName,
|
||||
});
|
||||
}
|
||||
this.put('^alter ^table %f ^change ^column %i %i ', oldcol, oldcol.columnName, newcol.columnName);
|
||||
this.columnDefinition(newcol);
|
||||
this.inlineConstraints(constraints);
|
||||
|
||||
@@ -23,7 +23,7 @@ function getColumnInfo(
|
||||
columnName: column_name,
|
||||
dataType: fullDataType,
|
||||
notNull: is_nullable == 'N',
|
||||
defaultValue: autoIncrement ? undefined : default_value,
|
||||
defaultValue: autoIncrement ? undefined : default_value?.trim(),
|
||||
autoIncrement,
|
||||
};
|
||||
}
|
||||
@@ -40,7 +40,7 @@ class Analyser extends DatabaseAnalyser {
|
||||
}
|
||||
|
||||
async _computeSingleObjectId() {
|
||||
const { typeField, pureName } = this.singleObjectFilter;
|
||||
const { typeField, pureName } = this.singleObjectFilter;
|
||||
this.singleObjectId = `${typeField}:${pureName}`;
|
||||
}
|
||||
|
||||
@@ -114,7 +114,8 @@ class Analyser extends DatabaseAnalyser {
|
||||
indexes.rows.filter(
|
||||
idx =>
|
||||
idx.tableName == newTable.pureName &&
|
||||
!uniqueNames.rows.find(x => x.constraintName == idx.constraintName)
|
||||
!uniqueNames.rows.find(x => x.constraintName == idx.constraintName) &&
|
||||
!idx.constraintName.startsWith('SYS_C')
|
||||
),
|
||||
'constraintName'
|
||||
).map(idx => ({
|
||||
@@ -141,6 +142,9 @@ class Analyser extends DatabaseAnalyser {
|
||||
..._.pick(col, ['columnName']),
|
||||
})),
|
||||
})),
|
||||
identitySequenceName: (columnsGrouped[columnGroup(table)] || [])
|
||||
.find(x => x?.default_value?.endsWith('.nextval'))
|
||||
?.default_value?.match(/\"([^"]+)\"\.nextval/)?.[1],
|
||||
};
|
||||
}),
|
||||
views: views.rows.map(view => ({
|
||||
@@ -167,14 +171,14 @@ class Analyser extends DatabaseAnalyser {
|
||||
objectId: `procedures:${proc.pure_name}`,
|
||||
pureName: proc.pure_name,
|
||||
// schemaName: proc.schema_name,
|
||||
createSql: `CREATE PROCEDURE "${proc.pure_name}"() LANGUAGE ${proc.language}\nAS\n$$\n${proc.definition}\n$$`,
|
||||
createSql: `SET SQLTERMINATOR "/"\nCREATE ${proc.source_code}\n/\n`,
|
||||
contentHash: proc.hash_code,
|
||||
})),
|
||||
functions: routines.rows
|
||||
.filter(x => x.object_type == 'FUNCTION')
|
||||
.map(func => ({
|
||||
objectId: `functions:${func.pure_name}`,
|
||||
createSql: `CREATE FUNCTION "${func.pure_name}"() RETURNS ${func.data_type} LANGUAGE ${func.language}\nAS\n$$\n${func.definition}\n$$`,
|
||||
createSql: `SET SQLTERMINATOR "/"\nCREATE ${func.source_code}\n/\n`,
|
||||
pureName: func.pure_name,
|
||||
// schemaName: func.schema_name,
|
||||
contentHash: func.hash_code,
|
||||
|
||||
@@ -1,41 +1,10 @@
|
||||
module.exports = `
|
||||
select
|
||||
routine_name as "pure_name",
|
||||
-- routine_schema as "schema_name",
|
||||
routine_definition as "definition",
|
||||
ora_hash(routine_definition) as "hash_code",
|
||||
routine_type as "object_type",
|
||||
'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 = '$owner' and
|
||||
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
|
||||
SELECT
|
||||
name as "pure_name",
|
||||
type as "object_type",
|
||||
LISTAGG(text, '') WITHIN GROUP (ORDER BY line) AS "source_code",
|
||||
ora_hash(LISTAGG(text, '') WITHIN GROUP (ORDER BY line)) AS "hash_code"
|
||||
FROM all_source
|
||||
WHERE type in ('FUNCTION', 'PROCEDURE') AND OWNER = '$owner'
|
||||
GROUP BY name, type
|
||||
`;
|
||||
|
||||
@@ -4,7 +4,7 @@ from (select
|
||||
view_name as "pure_name",
|
||||
text as "create_sql"
|
||||
from all_views av
|
||||
where owner = 'C##test' and text is not null
|
||||
where owner = '$owner' and text is not null
|
||||
) avv
|
||||
where 'views:' || "pure_name" is not null
|
||||
`;
|
||||
|
||||
@@ -60,9 +60,9 @@ class Dumper extends SqlDumper {
|
||||
// this.putCmd('^alter ^table %f ^rename ^to %i', obj, newname);
|
||||
// }
|
||||
|
||||
// renameColumn(column, newcol) {
|
||||
// this.putCmd('^alter ^table %f ^rename ^column %i ^to %i', column, column.columnName, newcol);
|
||||
// }
|
||||
renameColumn(column, newcol) {
|
||||
this.putCmd('^alter ^table %f ^rename ^column %i ^to %i', column, column.columnName, newcol);
|
||||
}
|
||||
|
||||
// dropTable(obj, options = {}) {
|
||||
// this.put('^drop ^table');
|
||||
@@ -87,30 +87,48 @@ class Dumper extends SqlDumper {
|
||||
// super.columnDefinition(col, options);
|
||||
// }
|
||||
|
||||
// changeColumn(oldcol, newcol, constraints) {
|
||||
// if (oldcol.columnName != newcol.columnName) {
|
||||
// this.putCmd('^alter ^table %f ^rename ^column %i ^to %i', oldcol, oldcol.columnName, newcol.columnName);
|
||||
// }
|
||||
// if (!testEqualTypes(oldcol, newcol)) {
|
||||
// this.putCmd('^alter ^table %f ^alter ^column %i ^type %s', oldcol, newcol.columnName, newcol.dataType);
|
||||
// }
|
||||
// if (oldcol.notNull != newcol.notNull) {
|
||||
// if (newcol.notNull) this.putCmd('^alter ^table %f ^alter ^column %i ^set ^not ^null', newcol, newcol.columnName);
|
||||
// else this.putCmd('^alter ^table %f ^alter ^column %i ^drop ^not ^null', newcol, newcol.columnName);
|
||||
// }
|
||||
// if (oldcol.defaultValue != newcol.defaultValue) {
|
||||
// if (newcol.defaultValue == null) {
|
||||
// this.putCmd('^alter ^table %f ^alter ^column %i ^drop ^default', newcol, newcol.columnName);
|
||||
// } else {
|
||||
// this.putCmd(
|
||||
// '^alter ^table %f ^alter ^column %i ^set ^default %s',
|
||||
// newcol,
|
||||
// newcol.columnName,
|
||||
// newcol.defaultValue
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
changeColumn(oldcol, newcol, constraints) {
|
||||
if (oldcol.columnName != newcol.columnName) {
|
||||
this.putCmd('^alter ^table %f ^rename ^column %i ^to %i', oldcol, oldcol.columnName, newcol.columnName);
|
||||
}
|
||||
|
||||
if (!oldcol.notNull) {
|
||||
this.fillNewNotNullDefaults(newcol);
|
||||
}
|
||||
|
||||
if (!testEqualTypes(oldcol, newcol) || oldcol.notNull != newcol.notNull) {
|
||||
this.putCmd(
|
||||
'^alter ^table %f ^modify (%i %s %k)',
|
||||
newcol,
|
||||
newcol.columnName,
|
||||
newcol.dataType,
|
||||
newcol.notNull ? 'not null' : 'null'
|
||||
);
|
||||
}
|
||||
|
||||
if (oldcol.defaultValue != newcol.defaultValue) {
|
||||
if (newcol.defaultValue?.trim()) {
|
||||
this.putCmd('^alter ^table %f ^modify (%i ^default %s)', newcol, newcol.columnName, newcol.defaultValue);
|
||||
} else {
|
||||
this.putCmd('^alter ^table %f ^modify (%i ^default ^null)', newcol, newcol.columnName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
selectScopeIdentity(table) {
|
||||
const sequence = table.identitySequenceName;
|
||||
if (sequence) {
|
||||
this.put('^select %i.CURRVAL FROM DUAL', sequence);
|
||||
}
|
||||
}
|
||||
|
||||
renameTable(obj, newname) {
|
||||
this.putCmd('^alter ^table %f ^rename ^to %i', obj, newname);
|
||||
}
|
||||
|
||||
renameSqlObject(obj, newname) {
|
||||
this.putCmd('^rename %f ^to %i', obj, newname);
|
||||
}
|
||||
|
||||
// putValue(value) {
|
||||
// if (value === true) this.putRaw('true');
|
||||
|
||||
@@ -13,7 +13,7 @@ const dialect = {
|
||||
ilike: true,
|
||||
// stringEscapeChar: '\\',
|
||||
stringEscapeChar: "'",
|
||||
fallbackDataType: 'varchar',
|
||||
fallbackDataType: 'varchar(250)',
|
||||
anonymousPrimaryKey: false,
|
||||
enableConstraintsPerTable: true,
|
||||
dropColumnDependencies: ['dependencies'],
|
||||
@@ -22,6 +22,7 @@ const dialect = {
|
||||
},
|
||||
userDatabaseNamePrefix: 'C##',
|
||||
upperCaseAllDbObjectNames: true,
|
||||
requireStandaloneSelectForScopeIdentity: true,
|
||||
|
||||
createColumn: true,
|
||||
dropColumn: true,
|
||||
@@ -36,6 +37,7 @@ const dialect = {
|
||||
dropUnique: true,
|
||||
createCheck: true,
|
||||
dropCheck: true,
|
||||
renameSqlObject: true,
|
||||
|
||||
dropReferencesWhenDropTable: true,
|
||||
requireFromDual: true,
|
||||
|
||||
@@ -89,7 +89,9 @@ class Dumper extends SqlDumper {
|
||||
}
|
||||
}
|
||||
if (oldcol.notNull != newcol.notNull) {
|
||||
this.fillNewNotNullDefaults(newcol);
|
||||
if (!oldcol.notNull) {
|
||||
this.fillNewNotNullDefaults(newcol);
|
||||
}
|
||||
if (newcol.notNull) this.putCmd('^alter ^table %f ^alter ^column %i ^set ^not ^null', newcol, newcol.columnName);
|
||||
else this.putCmd('^alter ^table %f ^alter ^column %i ^drop ^not ^null', newcol, newcol.columnName);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user