Add initial version of dijkstra backend cloudron image
This commit is contained in:
18
node_modules/knex/lib/dialects/oracle/schema/columnbuilder.js
generated
vendored
Normal file
18
node_modules/knex/lib/dialects/oracle/schema/columnbuilder.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
const inherits = require('inherits');
|
||||
const ColumnBuilder = require('../../../schema/columnbuilder');
|
||||
|
||||
const { toArray } = require('lodash');
|
||||
|
||||
function ColumnBuilder_Oracle() {
|
||||
ColumnBuilder.apply(this, arguments);
|
||||
}
|
||||
inherits(ColumnBuilder_Oracle, ColumnBuilder);
|
||||
|
||||
// checkIn added to the builder to allow the column compiler to change the
|
||||
// order via the modifiers ("check" must be after "default")
|
||||
ColumnBuilder_Oracle.prototype.checkIn = function() {
|
||||
this._modifiers.checkIn = toArray(arguments);
|
||||
return this;
|
||||
};
|
||||
|
||||
module.exports = ColumnBuilder_Oracle;
|
||||
139
node_modules/knex/lib/dialects/oracle/schema/columncompiler.js
generated
vendored
Normal file
139
node_modules/knex/lib/dialects/oracle/schema/columncompiler.js
generated
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
const { uniq, map } = require('lodash');
|
||||
const inherits = require('inherits');
|
||||
const Raw = require('../../../raw');
|
||||
const ColumnCompiler = require('../../../schema/columncompiler');
|
||||
const Trigger = require('./trigger');
|
||||
|
||||
// Column Compiler
|
||||
// -------
|
||||
|
||||
function ColumnCompiler_Oracle() {
|
||||
ColumnCompiler.apply(this, arguments);
|
||||
this.modifiers = ['defaultTo', 'checkIn', 'nullable', 'comment'];
|
||||
}
|
||||
inherits(ColumnCompiler_Oracle, ColumnCompiler);
|
||||
|
||||
Object.assign(ColumnCompiler_Oracle.prototype, {
|
||||
// helper function for pushAdditional in increments() and bigincrements()
|
||||
_createAutoIncrementTriggerAndSequence() {
|
||||
// TODO Add warning that sequence etc is created
|
||||
this.pushAdditional(function() {
|
||||
const tableName = this.tableCompiler.tableNameRaw;
|
||||
const createTriggerSQL = Trigger.createAutoIncrementTrigger(
|
||||
this.client.logger,
|
||||
tableName
|
||||
);
|
||||
this.pushQuery(createTriggerSQL);
|
||||
});
|
||||
},
|
||||
|
||||
increments() {
|
||||
this._createAutoIncrementTriggerAndSequence();
|
||||
return 'integer not null primary key';
|
||||
},
|
||||
|
||||
bigincrements() {
|
||||
this._createAutoIncrementTriggerAndSequence();
|
||||
return 'number(20, 0) not null primary key';
|
||||
},
|
||||
|
||||
floating(precision) {
|
||||
const parsedPrecision = this._num(precision, 0);
|
||||
return `float${parsedPrecision ? `(${parsedPrecision})` : ''}`;
|
||||
},
|
||||
|
||||
double(precision, scale) {
|
||||
// if (!precision) return 'number'; // TODO: Check If default is ok
|
||||
return `number(${this._num(precision, 8)}, ${this._num(scale, 2)})`;
|
||||
},
|
||||
|
||||
decimal(precision, scale) {
|
||||
if (precision === null) return 'decimal';
|
||||
return `decimal(${this._num(precision, 8)}, ${this._num(scale, 2)})`;
|
||||
},
|
||||
|
||||
integer(length) {
|
||||
return length ? `number(${this._num(length, 11)})` : 'integer';
|
||||
},
|
||||
|
||||
tinyint: 'smallint',
|
||||
|
||||
smallint: 'smallint',
|
||||
|
||||
mediumint: 'integer',
|
||||
|
||||
biginteger: 'number(20, 0)',
|
||||
|
||||
text: 'clob',
|
||||
|
||||
enu(allowed) {
|
||||
allowed = uniq(allowed);
|
||||
const maxLength = (allowed || []).reduce(
|
||||
(maxLength, name) => Math.max(maxLength, String(name).length),
|
||||
1
|
||||
);
|
||||
|
||||
// implicitly add the enum values as checked values
|
||||
this.columnBuilder._modifiers.checkIn = [allowed];
|
||||
|
||||
return `varchar2(${maxLength})`;
|
||||
},
|
||||
|
||||
time: 'timestamp with time zone',
|
||||
|
||||
datetime(without) {
|
||||
return without ? 'timestamp' : 'timestamp with time zone';
|
||||
},
|
||||
|
||||
timestamp(without) {
|
||||
return without ? 'timestamp' : 'timestamp with time zone';
|
||||
},
|
||||
|
||||
bit: 'clob',
|
||||
|
||||
json: 'clob',
|
||||
|
||||
bool() {
|
||||
// implicitly add the check for 0 and 1
|
||||
this.columnBuilder._modifiers.checkIn = [[0, 1]];
|
||||
return 'number(1, 0)';
|
||||
},
|
||||
|
||||
varchar(length) {
|
||||
return `varchar2(${this._num(length, 255)})`;
|
||||
},
|
||||
|
||||
// Modifiers
|
||||
// ------
|
||||
|
||||
comment(comment) {
|
||||
const columnName = this.args[0] || this.defaults('columnName');
|
||||
|
||||
this.pushAdditional(function() {
|
||||
this.pushQuery(
|
||||
`comment on column ${this.tableCompiler.tableName()}.` +
|
||||
this.formatter.wrap(columnName) +
|
||||
" is '" +
|
||||
(comment || '') +
|
||||
"'"
|
||||
);
|
||||
}, comment);
|
||||
},
|
||||
|
||||
checkIn(value) {
|
||||
// TODO: Maybe accept arguments also as array
|
||||
// TODO: value(s) should be escaped properly
|
||||
if (value === undefined) {
|
||||
return '';
|
||||
} else if (value instanceof Raw) {
|
||||
value = value.toQuery();
|
||||
} else if (Array.isArray(value)) {
|
||||
value = map(value, (v) => `'${v}'`).join(', ');
|
||||
} else {
|
||||
value = `'${value}'`;
|
||||
}
|
||||
return `check (${this.formatter.wrap(this.args[0])} in (${value}))`;
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = ColumnCompiler_Oracle;
|
||||
81
node_modules/knex/lib/dialects/oracle/schema/compiler.js
generated
vendored
Normal file
81
node_modules/knex/lib/dialects/oracle/schema/compiler.js
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
// Oracle Schema Compiler
|
||||
// -------
|
||||
const inherits = require('inherits');
|
||||
const SchemaCompiler = require('../../../schema/compiler');
|
||||
const utils = require('../utils');
|
||||
const Trigger = require('./trigger');
|
||||
|
||||
function SchemaCompiler_Oracle() {
|
||||
SchemaCompiler.apply(this, arguments);
|
||||
}
|
||||
inherits(SchemaCompiler_Oracle, SchemaCompiler);
|
||||
|
||||
// Rename a table on the schema.
|
||||
SchemaCompiler_Oracle.prototype.renameTable = function(tableName, to) {
|
||||
const renameTable = Trigger.renameTableAndAutoIncrementTrigger(
|
||||
this.client.logger,
|
||||
tableName,
|
||||
to
|
||||
);
|
||||
this.pushQuery(renameTable);
|
||||
};
|
||||
|
||||
// Check whether a table exists on the query.
|
||||
SchemaCompiler_Oracle.prototype.hasTable = function(tableName) {
|
||||
this.pushQuery({
|
||||
sql:
|
||||
'select TABLE_NAME from USER_TABLES where TABLE_NAME = ' +
|
||||
this.formatter.parameter(tableName),
|
||||
output(resp) {
|
||||
return resp.length > 0;
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// Check whether a column exists on the schema.
|
||||
SchemaCompiler_Oracle.prototype.hasColumn = function(tableName, column) {
|
||||
const sql =
|
||||
`select COLUMN_NAME from USER_TAB_COLUMNS ` +
|
||||
`where TABLE_NAME = ${this.formatter.parameter(tableName)} ` +
|
||||
`and COLUMN_NAME = ${this.formatter.parameter(column)}`;
|
||||
this.pushQuery({ sql, output: (resp) => resp.length > 0 });
|
||||
};
|
||||
|
||||
SchemaCompiler_Oracle.prototype.dropSequenceIfExists = function(sequenceName) {
|
||||
this.pushQuery(
|
||||
utils.wrapSqlWithCatch(
|
||||
`drop sequence ${this.formatter.wrap(sequenceName)}`,
|
||||
-2289
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
SchemaCompiler_Oracle.prototype._dropRelatedSequenceIfExists = function(
|
||||
tableName
|
||||
) {
|
||||
// removing the sequence that was possibly generated by increments() column
|
||||
const sequenceName = utils.generateCombinedName(
|
||||
this.client.logger,
|
||||
'seq',
|
||||
tableName
|
||||
);
|
||||
this.dropSequenceIfExists(sequenceName);
|
||||
};
|
||||
|
||||
SchemaCompiler_Oracle.prototype.dropTable = function(tableName) {
|
||||
this.pushQuery(`drop table ${this.formatter.wrap(tableName)}`);
|
||||
|
||||
// removing the sequence that was possibly generated by increments() column
|
||||
this._dropRelatedSequenceIfExists(tableName);
|
||||
};
|
||||
|
||||
SchemaCompiler_Oracle.prototype.dropTableIfExists = function(tableName) {
|
||||
this.pushQuery(
|
||||
utils.wrapSqlWithCatch(`drop table ${this.formatter.wrap(tableName)}`, -942)
|
||||
);
|
||||
|
||||
// removing the sequence that was possibly generated by increments() column
|
||||
this._dropRelatedSequenceIfExists(tableName);
|
||||
};
|
||||
|
||||
module.exports = SchemaCompiler_Oracle;
|
||||
167
node_modules/knex/lib/dialects/oracle/schema/tablecompiler.js
generated
vendored
Normal file
167
node_modules/knex/lib/dialects/oracle/schema/tablecompiler.js
generated
vendored
Normal file
@@ -0,0 +1,167 @@
|
||||
/* eslint max-len:0 */
|
||||
|
||||
const inherits = require('inherits');
|
||||
const utils = require('../utils');
|
||||
const TableCompiler = require('../../../schema/tablecompiler');
|
||||
const helpers = require('../../../helpers');
|
||||
const Trigger = require('./trigger');
|
||||
|
||||
const { map } = require('lodash');
|
||||
|
||||
// Table Compiler
|
||||
// ------
|
||||
|
||||
function TableCompiler_Oracle() {
|
||||
TableCompiler.apply(this, arguments);
|
||||
}
|
||||
inherits(TableCompiler_Oracle, TableCompiler);
|
||||
|
||||
Object.assign(TableCompiler_Oracle.prototype, {
|
||||
addColumns(columns, prefix) {
|
||||
if (columns.sql.length > 0) {
|
||||
prefix = prefix || this.addColumnsPrefix;
|
||||
|
||||
const columnSql = map(columns.sql, (column) => column);
|
||||
const alter = this.lowerCase ? 'alter table ' : 'ALTER TABLE ';
|
||||
|
||||
let sql = `${alter}${this.tableName()} ${prefix}`;
|
||||
if (columns.sql.length > 1) {
|
||||
sql += `(${columnSql.join(', ')})`;
|
||||
} else {
|
||||
sql += columnSql.join(', ');
|
||||
}
|
||||
|
||||
this.pushQuery({
|
||||
sql,
|
||||
bindings: columns.bindings,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// Compile a rename column command.
|
||||
renameColumn(from, to) {
|
||||
// Remove quotes around tableName
|
||||
const tableName = this.tableName().slice(1, -1);
|
||||
return this.pushQuery(
|
||||
Trigger.renameColumnTrigger(this.client.logger, tableName, from, to)
|
||||
);
|
||||
},
|
||||
|
||||
compileAdd(builder) {
|
||||
const table = this.formatter.wrap(builder);
|
||||
const columns = this.prefixArray('add column', this.getColumns(builder));
|
||||
return this.pushQuery({
|
||||
sql: `alter table ${table} ${columns.join(', ')}`,
|
||||
});
|
||||
},
|
||||
|
||||
// Adds the "create" query to the query sequence.
|
||||
createQuery(columns, ifNot) {
|
||||
const sql = `create table ${this.tableName()} (${columns.sql.join(', ')})`;
|
||||
this.pushQuery({
|
||||
// catch "name is already used by an existing object" for workaround for "if not exists"
|
||||
sql: ifNot ? utils.wrapSqlWithCatch(sql, -955) : sql,
|
||||
bindings: columns.bindings,
|
||||
});
|
||||
if (this.single.comment) this.comment(this.single.comment);
|
||||
},
|
||||
|
||||
// Compiles the comment on the table.
|
||||
comment(comment) {
|
||||
this.pushQuery(`comment on table ${this.tableName()} is '${comment}'`);
|
||||
},
|
||||
|
||||
addColumnsPrefix: 'add ',
|
||||
|
||||
alterColumnsPrefix: 'modify ',
|
||||
|
||||
dropColumn() {
|
||||
const columns = helpers.normalizeArr.apply(null, arguments);
|
||||
this.pushQuery(
|
||||
`alter table ${this.tableName()} drop (${this.formatter.columnize(
|
||||
columns
|
||||
)})`
|
||||
);
|
||||
},
|
||||
|
||||
changeType() {
|
||||
// alter table + table + ' modify ' + wrapped + '// type';
|
||||
},
|
||||
|
||||
_indexCommand(type, tableName, columns) {
|
||||
return this.formatter.wrap(
|
||||
utils.generateCombinedName(this.client.logger, type, tableName, columns)
|
||||
);
|
||||
},
|
||||
|
||||
primary(columns, constraintName) {
|
||||
constraintName = constraintName
|
||||
? this.formatter.wrap(constraintName)
|
||||
: this.formatter.wrap(`${this.tableNameRaw}_pkey`);
|
||||
this.pushQuery(
|
||||
`alter table ${this.tableName()} add constraint ${constraintName} primary key (${this.formatter.columnize(
|
||||
columns
|
||||
)})`
|
||||
);
|
||||
},
|
||||
|
||||
dropPrimary(constraintName) {
|
||||
constraintName = constraintName
|
||||
? this.formatter.wrap(constraintName)
|
||||
: this.formatter.wrap(this.tableNameRaw + '_pkey');
|
||||
this.pushQuery(
|
||||
`alter table ${this.tableName()} drop constraint ${constraintName}`
|
||||
);
|
||||
},
|
||||
|
||||
index(columns, indexName) {
|
||||
indexName = indexName
|
||||
? this.formatter.wrap(indexName)
|
||||
: this._indexCommand('index', this.tableNameRaw, columns);
|
||||
this.pushQuery(
|
||||
`create index ${indexName} on ${this.tableName()}` +
|
||||
' (' +
|
||||
this.formatter.columnize(columns) +
|
||||
')'
|
||||
);
|
||||
},
|
||||
|
||||
dropIndex(columns, indexName) {
|
||||
indexName = indexName
|
||||
? this.formatter.wrap(indexName)
|
||||
: this._indexCommand('index', this.tableNameRaw, columns);
|
||||
this.pushQuery(`drop index ${indexName}`);
|
||||
},
|
||||
|
||||
unique(columns, indexName) {
|
||||
indexName = indexName
|
||||
? this.formatter.wrap(indexName)
|
||||
: this._indexCommand('unique', this.tableNameRaw, columns);
|
||||
this.pushQuery(
|
||||
`alter table ${this.tableName()} add constraint ${indexName}` +
|
||||
' unique (' +
|
||||
this.formatter.columnize(columns) +
|
||||
')'
|
||||
);
|
||||
},
|
||||
|
||||
dropUnique(columns, indexName) {
|
||||
indexName = indexName
|
||||
? this.formatter.wrap(indexName)
|
||||
: this._indexCommand('unique', this.tableNameRaw, columns);
|
||||
this.pushQuery(
|
||||
`alter table ${this.tableName()} drop constraint ${indexName}`
|
||||
);
|
||||
},
|
||||
|
||||
dropForeign(columns, indexName) {
|
||||
indexName = indexName
|
||||
? this.formatter.wrap(indexName)
|
||||
: this._indexCommand('foreign', this.tableNameRaw, columns);
|
||||
this.pushQuery(
|
||||
`alter table ${this.tableName()} drop constraint ${indexName}`
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = TableCompiler_Oracle;
|
||||
126
node_modules/knex/lib/dialects/oracle/schema/trigger.js
generated
vendored
Normal file
126
node_modules/knex/lib/dialects/oracle/schema/trigger.js
generated
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
const utils = require('../utils');
|
||||
|
||||
const trigger = {
|
||||
renameColumnTrigger: function(logger, tableName, columnName, to) {
|
||||
const triggerName = utils.generateCombinedName(
|
||||
logger,
|
||||
'autoinc_trg',
|
||||
tableName
|
||||
);
|
||||
const sequenceName = utils.generateCombinedName(logger, 'seq', tableName);
|
||||
return (
|
||||
`DECLARE ` +
|
||||
`PK_NAME VARCHAR(200); ` +
|
||||
`IS_AUTOINC NUMBER := 0; ` +
|
||||
`BEGIN` +
|
||||
` EXECUTE IMMEDIATE ('ALTER TABLE "${tableName}" RENAME COLUMN "${columnName}" TO "${to}"');` +
|
||||
` SELECT COUNT(*) INTO IS_AUTOINC from "USER_TRIGGERS" where trigger_name = '${triggerName}';` +
|
||||
` IF (IS_AUTOINC > 0) THEN` +
|
||||
` SELECT cols.column_name INTO PK_NAME` +
|
||||
` FROM all_constraints cons, all_cons_columns cols` +
|
||||
` WHERE cons.constraint_type = 'P'` +
|
||||
` AND cons.constraint_name = cols.constraint_name` +
|
||||
` AND cons.owner = cols.owner` +
|
||||
` AND cols.table_name = '${tableName}';` +
|
||||
` IF ('${to}' = PK_NAME) THEN` +
|
||||
` EXECUTE IMMEDIATE ('DROP TRIGGER "${triggerName}"');` +
|
||||
` EXECUTE IMMEDIATE ('create or replace trigger "${triggerName}"` +
|
||||
` BEFORE INSERT on "${tableName}" for each row` +
|
||||
` declare` +
|
||||
` checking number := 1;` +
|
||||
` begin` +
|
||||
` if (:new."${to}" is null) then` +
|
||||
` while checking >= 1 loop` +
|
||||
` select "${sequenceName}".nextval into :new."${to}" from dual;` +
|
||||
` select count("${to}") into checking from "${tableName}"` +
|
||||
` where "${to}" = :new."${to}";` +
|
||||
` end loop;` +
|
||||
` end if;` +
|
||||
` end;');` +
|
||||
` end if;` +
|
||||
` end if;` +
|
||||
`END;`
|
||||
);
|
||||
},
|
||||
|
||||
createAutoIncrementTrigger: function(logger, tableName) {
|
||||
const triggerName = utils.generateCombinedName(
|
||||
logger,
|
||||
'autoinc_trg',
|
||||
tableName
|
||||
);
|
||||
const sequenceName = utils.generateCombinedName(logger, 'seq', tableName);
|
||||
return (
|
||||
`DECLARE ` +
|
||||
`PK_NAME VARCHAR(200); ` +
|
||||
`BEGIN` +
|
||||
` EXECUTE IMMEDIATE ('CREATE SEQUENCE "${sequenceName}"');` +
|
||||
` SELECT cols.column_name INTO PK_NAME` +
|
||||
` FROM all_constraints cons, all_cons_columns cols` +
|
||||
` WHERE cons.constraint_type = 'P'` +
|
||||
` AND cons.constraint_name = cols.constraint_name` +
|
||||
` AND cons.owner = cols.owner` +
|
||||
` AND cols.table_name = '${tableName}';` +
|
||||
` execute immediate ('create or replace trigger "${triggerName}"` +
|
||||
` BEFORE INSERT on "${tableName}"` +
|
||||
` for each row` +
|
||||
` declare` +
|
||||
` checking number := 1;` +
|
||||
` begin` +
|
||||
` if (:new."' || PK_NAME || '" is null) then` +
|
||||
` while checking >= 1 loop` +
|
||||
` select "${sequenceName}".nextval into :new."' || PK_NAME || '" from dual;` +
|
||||
` select count("' || PK_NAME || '") into checking from "${tableName}"` +
|
||||
` where "' || PK_NAME || '" = :new."' || PK_NAME || '";` +
|
||||
` end loop;` +
|
||||
` end if;` +
|
||||
` end;'); ` +
|
||||
`END;`
|
||||
);
|
||||
},
|
||||
|
||||
renameTableAndAutoIncrementTrigger: function(logger, tableName, to) {
|
||||
const triggerName = utils.generateCombinedName(
|
||||
logger,
|
||||
'autoinc_trg',
|
||||
tableName
|
||||
);
|
||||
const sequenceName = utils.generateCombinedName(logger, 'seq', tableName);
|
||||
const toTriggerName = utils.generateCombinedName(logger, 'autoinc_trg', to);
|
||||
const toSequenceName = utils.generateCombinedName(logger, 'seq', to);
|
||||
return (
|
||||
`DECLARE ` +
|
||||
`PK_NAME VARCHAR(200); ` +
|
||||
`IS_AUTOINC NUMBER := 0; ` +
|
||||
`BEGIN` +
|
||||
` EXECUTE IMMEDIATE ('RENAME "${tableName}" TO "${to}"');` +
|
||||
` SELECT COUNT(*) INTO IS_AUTOINC from "USER_TRIGGERS" where trigger_name = '${triggerName}';` +
|
||||
` IF (IS_AUTOINC > 0) THEN` +
|
||||
` EXECUTE IMMEDIATE ('DROP TRIGGER "${triggerName}"');` +
|
||||
` EXECUTE IMMEDIATE ('RENAME "${sequenceName}" TO "${toSequenceName}"');` +
|
||||
` SELECT cols.column_name INTO PK_NAME` +
|
||||
` FROM all_constraints cons, all_cons_columns cols` +
|
||||
` WHERE cons.constraint_type = 'P'` +
|
||||
` AND cons.constraint_name = cols.constraint_name` +
|
||||
` AND cons.owner = cols.owner` +
|
||||
` AND cols.table_name = '${to}';` +
|
||||
` EXECUTE IMMEDIATE ('create or replace trigger "${toTriggerName}"` +
|
||||
` BEFORE INSERT on "${to}" for each row` +
|
||||
` declare` +
|
||||
` checking number := 1;` +
|
||||
` begin` +
|
||||
` if (:new."' || PK_NAME || '" is null) then` +
|
||||
` while checking >= 1 loop` +
|
||||
` select "${toSequenceName}".nextval into :new."' || PK_NAME || '" from dual;` +
|
||||
` select count("' || PK_NAME || '") into checking from "${to}"` +
|
||||
` where "' || PK_NAME || '" = :new."' || PK_NAME || '";` +
|
||||
` end loop;` +
|
||||
` end if;` +
|
||||
` end;');` +
|
||||
` end if;` +
|
||||
`END;`
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = trigger;
|
||||
Reference in New Issue
Block a user