2021-01-01 17:46:10 +02:00
|
|
|
// Oracle Schema Compiler
|
|
|
|
// -------
|
|
|
|
const SchemaCompiler = require('../../../schema/compiler');
|
|
|
|
const utils = require('../utils');
|
2021-01-06 23:21:10 +02:00
|
|
|
const Trigger = require('./internal/trigger');
|
2021-01-01 17:46:10 +02:00
|
|
|
|
|
|
|
class SchemaCompiler_Oracle extends SchemaCompiler {
|
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rename a table on the schema.
|
|
|
|
renameTable(tableName, to) {
|
|
|
|
const renameTable = Trigger.renameTableAndAutoIncrementTrigger(
|
|
|
|
this.client.logger,
|
|
|
|
tableName,
|
|
|
|
to
|
|
|
|
);
|
|
|
|
this.pushQuery(renameTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether a table exists on the query.
|
|
|
|
hasTable(tableName) {
|
|
|
|
this.pushQuery({
|
|
|
|
sql:
|
|
|
|
'select TABLE_NAME from USER_TABLES where TABLE_NAME = ' +
|
2021-02-04 15:54:26 +02:00
|
|
|
this.client.parameter(tableName, this.builder, this.bindingsHolder),
|
2021-01-01 17:46:10 +02:00
|
|
|
output(resp) {
|
|
|
|
return resp.length > 0;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether a column exists on the schema.
|
|
|
|
hasColumn(tableName, column) {
|
|
|
|
const sql =
|
|
|
|
`select COLUMN_NAME from ALL_TAB_COLUMNS ` +
|
2021-02-04 15:54:26 +02:00
|
|
|
`where TABLE_NAME = ${this.client.parameter(
|
|
|
|
tableName,
|
|
|
|
this.builder,
|
|
|
|
this.bindingsHolder
|
|
|
|
)} ` +
|
|
|
|
`and COLUMN_NAME = ${this.client.parameter(
|
|
|
|
column,
|
|
|
|
this.builder,
|
|
|
|
this.bindingsHolder
|
|
|
|
)}`;
|
2021-01-01 17:46:10 +02:00
|
|
|
this.pushQuery({ sql, output: (resp) => resp.length > 0 });
|
|
|
|
}
|
|
|
|
|
|
|
|
dropSequenceIfExists(sequenceName) {
|
2021-07-31 19:25:37 +03:00
|
|
|
const prefix = this.schema ? `"${this.schema}".` : '';
|
2021-01-01 17:46:10 +02:00
|
|
|
this.pushQuery(
|
|
|
|
utils.wrapSqlWithCatch(
|
2021-07-31 19:25:37 +03:00
|
|
|
`drop sequence ${prefix}${this.formatter.wrap(sequenceName)}`,
|
2021-01-01 17:46:10 +02:00
|
|
|
-2289
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_dropRelatedSequenceIfExists(tableName) {
|
|
|
|
// removing the sequence that was possibly generated by increments() column
|
|
|
|
const sequenceName = utils.generateCombinedName(
|
|
|
|
this.client.logger,
|
|
|
|
'seq',
|
|
|
|
tableName
|
|
|
|
);
|
|
|
|
this.dropSequenceIfExists(sequenceName);
|
|
|
|
}
|
|
|
|
|
|
|
|
dropTable(tableName) {
|
2021-07-31 19:25:37 +03:00
|
|
|
const prefix = this.schema ? `"${this.schema}".` : '';
|
|
|
|
this.pushQuery(`drop table ${prefix}${this.formatter.wrap(tableName)}`);
|
2021-01-01 17:46:10 +02:00
|
|
|
|
|
|
|
// removing the sequence that was possibly generated by increments() column
|
|
|
|
this._dropRelatedSequenceIfExists(tableName);
|
|
|
|
}
|
|
|
|
|
|
|
|
dropTableIfExists(tableName) {
|
2021-07-31 19:25:37 +03:00
|
|
|
const prefix = this.schema ? `"${this.schema}".` : '';
|
2021-01-01 17:46:10 +02:00
|
|
|
this.pushQuery(
|
|
|
|
utils.wrapSqlWithCatch(
|
2021-07-31 19:25:37 +03:00
|
|
|
`drop table ${prefix}${this.formatter.wrap(tableName)}`,
|
2021-01-01 17:46:10 +02:00
|
|
|
-942
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// removing the sequence that was possibly generated by increments() column
|
|
|
|
this._dropRelatedSequenceIfExists(tableName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = SchemaCompiler_Oracle;
|