knex 0.21.20 → 0.21.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/CONTRIBUTING.md +184 -184
- package/LICENSE +22 -22
- package/README.md +95 -95
- package/bin/cli.js +414 -414
- package/bin/utils/cli-config-utils.js +151 -151
- package/bin/utils/constants.js +7 -7
- package/bin/utils/migrationsLister.js +37 -37
- package/knex.js +8 -8
- package/lib/client.js +413 -413
- package/lib/config-resolver.js +61 -61
- package/lib/constants.js +44 -44
- package/lib/dialects/mssql/index.js +390 -390
- package/lib/dialects/mssql/query/compiler.js +444 -444
- package/lib/dialects/mssql/schema/columncompiler.js +103 -103
- package/lib/dialects/mssql/schema/compiler.js +59 -59
- package/lib/dialects/mssql/schema/tablecompiler.js +245 -245
- package/lib/dialects/mssql/transaction.js +97 -97
- package/lib/dialects/mysql/index.js +191 -191
- package/lib/dialects/mysql/query/compiler.js +142 -142
- package/lib/dialects/mysql/schema/columncompiler.js +171 -171
- package/lib/dialects/mysql/schema/compiler.js +60 -60
- package/lib/dialects/mysql/schema/tablecompiler.js +262 -262
- package/lib/dialects/mysql/transaction.js +48 -48
- package/lib/dialects/mysql2/index.js +35 -35
- package/lib/dialects/mysql2/transaction.js +46 -46
- package/lib/dialects/oracle/DEAD_CODE.md +5 -5
- package/lib/dialects/oracle/formatter.js +20 -20
- package/lib/dialects/oracle/index.js +79 -79
- package/lib/dialects/oracle/query/compiler.js +327 -327
- package/lib/dialects/oracle/schema/columnbuilder.js +18 -18
- package/lib/dialects/oracle/schema/columncompiler.js +139 -139
- package/lib/dialects/oracle/schema/compiler.js +81 -81
- package/lib/dialects/oracle/schema/tablecompiler.js +165 -165
- package/lib/dialects/oracle/schema/trigger.js +126 -126
- package/lib/dialects/oracle/utils.js +86 -86
- package/lib/dialects/oracledb/index.js +489 -489
- package/lib/dialects/oracledb/query/compiler.js +363 -363
- package/lib/dialects/oracledb/schema/columncompiler.js +35 -35
- package/lib/dialects/oracledb/transaction.js +76 -76
- package/lib/dialects/oracledb/utils.js +14 -14
- package/lib/dialects/postgres/index.js +319 -319
- package/lib/dialects/postgres/query/compiler.js +206 -206
- package/lib/dialects/postgres/schema/columncompiler.js +125 -125
- package/lib/dialects/postgres/schema/compiler.js +109 -109
- package/lib/dialects/postgres/schema/tablecompiler.js +183 -183
- package/lib/dialects/redshift/index.js +73 -73
- package/lib/dialects/redshift/query/compiler.js +119 -119
- package/lib/dialects/redshift/schema/columnbuilder.js +20 -20
- package/lib/dialects/redshift/schema/columncompiler.js +60 -60
- package/lib/dialects/redshift/schema/compiler.js +14 -14
- package/lib/dialects/redshift/schema/tablecompiler.js +123 -123
- package/lib/dialects/redshift/transaction.js +18 -18
- package/lib/dialects/sqlite3/formatter.js +21 -21
- package/lib/dialects/sqlite3/index.js +169 -169
- package/lib/dialects/sqlite3/query/compiler.js +222 -222
- package/lib/dialects/sqlite3/schema/columncompiler.js +27 -27
- package/lib/dialects/sqlite3/schema/compiler.js +49 -49
- package/lib/dialects/sqlite3/schema/ddl.js +525 -525
- package/lib/dialects/sqlite3/schema/tablecompiler.js +238 -238
- package/lib/formatter.js +295 -295
- package/lib/functionhelper.js +14 -14
- package/lib/helpers.js +92 -92
- package/lib/index.js +3 -3
- package/lib/interface.js +115 -115
- package/lib/knex.js +42 -42
- package/lib/logger.js +76 -76
- package/lib/migrate/MigrationGenerator.js +82 -82
- package/lib/migrate/Migrator.js +611 -611
- package/lib/migrate/configuration-merger.js +60 -60
- package/lib/migrate/migrate-stub.js +17 -17
- package/lib/migrate/migration-list-resolver.js +36 -36
- package/lib/migrate/sources/fs-migrations.js +99 -99
- package/lib/migrate/stub/cjs.stub +15 -15
- package/lib/migrate/stub/coffee.stub +13 -13
- package/lib/migrate/stub/eg.stub +14 -14
- package/lib/migrate/stub/js.stub +15 -15
- package/lib/migrate/stub/knexfile-coffee.stub +34 -34
- package/lib/migrate/stub/knexfile-eg.stub +43 -43
- package/lib/migrate/stub/knexfile-js.stub +44 -44
- package/lib/migrate/stub/knexfile-ls.stub +35 -35
- package/lib/migrate/stub/knexfile-ts.stub +44 -44
- package/lib/migrate/stub/ls.stub +14 -14
- package/lib/migrate/stub/ts.stub +21 -21
- package/lib/migrate/table-creator.js +67 -67
- package/lib/migrate/table-resolver.js +27 -27
- package/lib/query/builder.js +1372 -1372
- package/lib/query/compiler.js +889 -889
- package/lib/query/constants.js +13 -13
- package/lib/query/joinclause.js +263 -263
- package/lib/query/methods.js +92 -92
- package/lib/query/string.js +190 -190
- package/lib/raw.js +188 -188
- package/lib/ref.js +39 -39
- package/lib/runner.js +285 -285
- package/lib/schema/builder.js +82 -82
- package/lib/schema/columnbuilder.js +117 -117
- package/lib/schema/columncompiler.js +177 -177
- package/lib/schema/compiler.js +101 -101
- package/lib/schema/helpers.js +51 -51
- package/lib/schema/tablebuilder.js +288 -288
- package/lib/schema/tablecompiler.js +296 -296
- package/lib/seed/Seeder.js +203 -203
- package/lib/seed/seed-stub.js +13 -13
- package/lib/seed/stub/coffee.stub +9 -9
- package/lib/seed/stub/eg.stub +11 -11
- package/lib/seed/stub/js.stub +13 -13
- package/lib/seed/stub/ls.stub +11 -11
- package/lib/seed/stub/ts.stub +13 -13
- package/lib/transaction.js +363 -363
- package/lib/util/batchInsert.js +59 -59
- package/lib/util/delay.js +6 -6
- package/lib/util/fake-client.js +9 -9
- package/lib/util/finally-mixin.js +13 -13
- package/lib/util/fs.js +76 -76
- package/lib/util/import-file.js +13 -13
- package/lib/util/is-module-type.js +14 -14
- package/lib/util/is.js +32 -32
- package/lib/util/make-knex.js +338 -338
- package/lib/util/nanoid.js +29 -29
- package/lib/util/noop.js +1 -1
- package/lib/util/parse-connection.js +66 -66
- package/lib/util/save-async-stack.js +14 -14
- package/lib/util/template.js +52 -52
- package/lib/util/timeout.js +29 -29
- package/lib/util/timestamp.js +16 -16
- package/package.json +1 -1
- package/scripts/build.js +125 -125
- package/scripts/docker-compose.yml +111 -111
- package/scripts/next-release-howto.md +24 -24
- package/scripts/release.sh +34 -34
- package/scripts/runkit-example.js +34 -34
- package/scripts/stress-test/README.txt +18 -18
- package/scripts/stress-test/docker-compose.yml +47 -47
- package/scripts/stress-test/knex-stress-test.js +196 -196
- package/scripts/stress-test/mysql2-random-hanging-every-now-and-then.js +145 -145
- package/scripts/stress-test/mysql2-sudden-exit-without-error.js +100 -100
- package/scripts/stress-test/reconnect-test-mysql-based-drivers.js +184 -184
- package/types/index.d.ts +2249 -2249
- package/types/result.d.ts +27 -27
- package/types/tables.d.ts +4 -4
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
const { inherits } = require('util');
|
|
2
|
-
const ColumnBuilder = require('../../../schema/columnbuilder');
|
|
3
|
-
|
|
4
|
-
const toArray = require('lodash/toArray');
|
|
5
|
-
|
|
6
|
-
function ColumnBuilder_Oracle() {
|
|
7
|
-
ColumnBuilder.apply(this, arguments);
|
|
8
|
-
}
|
|
9
|
-
inherits(ColumnBuilder_Oracle, ColumnBuilder);
|
|
10
|
-
|
|
11
|
-
// checkIn added to the builder to allow the column compiler to change the
|
|
12
|
-
// order via the modifiers ("check" must be after "default")
|
|
13
|
-
ColumnBuilder_Oracle.prototype.checkIn = function () {
|
|
14
|
-
this._modifiers.checkIn = toArray(arguments);
|
|
15
|
-
return this;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
module.exports = ColumnBuilder_Oracle;
|
|
1
|
+
const { inherits } = require('util');
|
|
2
|
+
const ColumnBuilder = require('../../../schema/columnbuilder');
|
|
3
|
+
|
|
4
|
+
const toArray = require('lodash/toArray');
|
|
5
|
+
|
|
6
|
+
function ColumnBuilder_Oracle() {
|
|
7
|
+
ColumnBuilder.apply(this, arguments);
|
|
8
|
+
}
|
|
9
|
+
inherits(ColumnBuilder_Oracle, ColumnBuilder);
|
|
10
|
+
|
|
11
|
+
// checkIn added to the builder to allow the column compiler to change the
|
|
12
|
+
// order via the modifiers ("check" must be after "default")
|
|
13
|
+
ColumnBuilder_Oracle.prototype.checkIn = function () {
|
|
14
|
+
this._modifiers.checkIn = toArray(arguments);
|
|
15
|
+
return this;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
module.exports = ColumnBuilder_Oracle;
|
|
@@ -1,139 +1,139 @@
|
|
|
1
|
-
const uniq = require('lodash/uniq');
|
|
2
|
-
const { inherits } = require('util');
|
|
3
|
-
const Raw = require('../../../raw');
|
|
4
|
-
const ColumnCompiler = require('../../../schema/columncompiler');
|
|
5
|
-
const Trigger = require('./trigger');
|
|
6
|
-
|
|
7
|
-
// Column Compiler
|
|
8
|
-
// -------
|
|
9
|
-
|
|
10
|
-
function ColumnCompiler_Oracle() {
|
|
11
|
-
ColumnCompiler.apply(this, arguments);
|
|
12
|
-
this.modifiers = ['defaultTo', 'checkIn', 'nullable', 'comment'];
|
|
13
|
-
}
|
|
14
|
-
inherits(ColumnCompiler_Oracle, ColumnCompiler);
|
|
15
|
-
|
|
16
|
-
Object.assign(ColumnCompiler_Oracle.prototype, {
|
|
17
|
-
// helper function for pushAdditional in increments() and bigincrements()
|
|
18
|
-
_createAutoIncrementTriggerAndSequence() {
|
|
19
|
-
// TODO Add warning that sequence etc is created
|
|
20
|
-
this.pushAdditional(function () {
|
|
21
|
-
const tableName = this.tableCompiler.tableNameRaw;
|
|
22
|
-
const createTriggerSQL = Trigger.createAutoIncrementTrigger(
|
|
23
|
-
this.client.logger,
|
|
24
|
-
tableName
|
|
25
|
-
);
|
|
26
|
-
this.pushQuery(createTriggerSQL);
|
|
27
|
-
});
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
increments() {
|
|
31
|
-
this._createAutoIncrementTriggerAndSequence();
|
|
32
|
-
return 'integer not null primary key';
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
bigincrements() {
|
|
36
|
-
this._createAutoIncrementTriggerAndSequence();
|
|
37
|
-
return 'number(20, 0) not null primary key';
|
|
38
|
-
},
|
|
39
|
-
|
|
40
|
-
floating(precision) {
|
|
41
|
-
const parsedPrecision = this._num(precision, 0);
|
|
42
|
-
return `float${parsedPrecision ? `(${parsedPrecision})` : ''}`;
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
double(precision, scale) {
|
|
46
|
-
// if (!precision) return 'number'; // TODO: Check If default is ok
|
|
47
|
-
return `number(${this._num(precision, 8)}, ${this._num(scale, 2)})`;
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
decimal(precision, scale) {
|
|
51
|
-
if (precision === null) return 'decimal';
|
|
52
|
-
return `decimal(${this._num(precision, 8)}, ${this._num(scale, 2)})`;
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
integer(length) {
|
|
56
|
-
return length ? `number(${this._num(length, 11)})` : 'integer';
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
tinyint: 'smallint',
|
|
60
|
-
|
|
61
|
-
smallint: 'smallint',
|
|
62
|
-
|
|
63
|
-
mediumint: 'integer',
|
|
64
|
-
|
|
65
|
-
biginteger: 'number(20, 0)',
|
|
66
|
-
|
|
67
|
-
text: 'clob',
|
|
68
|
-
|
|
69
|
-
enu(allowed) {
|
|
70
|
-
allowed = uniq(allowed);
|
|
71
|
-
const maxLength = (allowed || []).reduce(
|
|
72
|
-
(maxLength, name) => Math.max(maxLength, String(name).length),
|
|
73
|
-
1
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
// implicitly add the enum values as checked values
|
|
77
|
-
this.columnBuilder._modifiers.checkIn = [allowed];
|
|
78
|
-
|
|
79
|
-
return `varchar2(${maxLength})`;
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
time: 'timestamp with time zone',
|
|
83
|
-
|
|
84
|
-
datetime(without) {
|
|
85
|
-
return without ? 'timestamp' : 'timestamp with time zone';
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
timestamp(without) {
|
|
89
|
-
return without ? 'timestamp' : 'timestamp with time zone';
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
bit: 'clob',
|
|
93
|
-
|
|
94
|
-
json: 'clob',
|
|
95
|
-
|
|
96
|
-
bool() {
|
|
97
|
-
// implicitly add the check for 0 and 1
|
|
98
|
-
this.columnBuilder._modifiers.checkIn = [[0, 1]];
|
|
99
|
-
return 'number(1, 0)';
|
|
100
|
-
},
|
|
101
|
-
|
|
102
|
-
varchar(length) {
|
|
103
|
-
return `varchar2(${this._num(length, 255)})`;
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
// Modifiers
|
|
107
|
-
// ------
|
|
108
|
-
|
|
109
|
-
comment(comment) {
|
|
110
|
-
const columnName = this.args[0] || this.defaults('columnName');
|
|
111
|
-
|
|
112
|
-
this.pushAdditional(function () {
|
|
113
|
-
this.pushQuery(
|
|
114
|
-
`comment on column ${this.tableCompiler.tableName()}.` +
|
|
115
|
-
this.formatter.wrap(columnName) +
|
|
116
|
-
" is '" +
|
|
117
|
-
(comment || '') +
|
|
118
|
-
"'"
|
|
119
|
-
);
|
|
120
|
-
}, comment);
|
|
121
|
-
},
|
|
122
|
-
|
|
123
|
-
checkIn(value) {
|
|
124
|
-
// TODO: Maybe accept arguments also as array
|
|
125
|
-
// TODO: value(s) should be escaped properly
|
|
126
|
-
if (value === undefined) {
|
|
127
|
-
return '';
|
|
128
|
-
} else if (value instanceof Raw) {
|
|
129
|
-
value = value.toQuery();
|
|
130
|
-
} else if (Array.isArray(value)) {
|
|
131
|
-
value = value.map((v) => `'${v}'`).join(', ');
|
|
132
|
-
} else {
|
|
133
|
-
value = `'${value}'`;
|
|
134
|
-
}
|
|
135
|
-
return `check (${this.formatter.wrap(this.args[0])} in (${value}))`;
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
module.exports = ColumnCompiler_Oracle;
|
|
1
|
+
const uniq = require('lodash/uniq');
|
|
2
|
+
const { inherits } = require('util');
|
|
3
|
+
const Raw = require('../../../raw');
|
|
4
|
+
const ColumnCompiler = require('../../../schema/columncompiler');
|
|
5
|
+
const Trigger = require('./trigger');
|
|
6
|
+
|
|
7
|
+
// Column Compiler
|
|
8
|
+
// -------
|
|
9
|
+
|
|
10
|
+
function ColumnCompiler_Oracle() {
|
|
11
|
+
ColumnCompiler.apply(this, arguments);
|
|
12
|
+
this.modifiers = ['defaultTo', 'checkIn', 'nullable', 'comment'];
|
|
13
|
+
}
|
|
14
|
+
inherits(ColumnCompiler_Oracle, ColumnCompiler);
|
|
15
|
+
|
|
16
|
+
Object.assign(ColumnCompiler_Oracle.prototype, {
|
|
17
|
+
// helper function for pushAdditional in increments() and bigincrements()
|
|
18
|
+
_createAutoIncrementTriggerAndSequence() {
|
|
19
|
+
// TODO Add warning that sequence etc is created
|
|
20
|
+
this.pushAdditional(function () {
|
|
21
|
+
const tableName = this.tableCompiler.tableNameRaw;
|
|
22
|
+
const createTriggerSQL = Trigger.createAutoIncrementTrigger(
|
|
23
|
+
this.client.logger,
|
|
24
|
+
tableName
|
|
25
|
+
);
|
|
26
|
+
this.pushQuery(createTriggerSQL);
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
increments() {
|
|
31
|
+
this._createAutoIncrementTriggerAndSequence();
|
|
32
|
+
return 'integer not null primary key';
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
bigincrements() {
|
|
36
|
+
this._createAutoIncrementTriggerAndSequence();
|
|
37
|
+
return 'number(20, 0) not null primary key';
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
floating(precision) {
|
|
41
|
+
const parsedPrecision = this._num(precision, 0);
|
|
42
|
+
return `float${parsedPrecision ? `(${parsedPrecision})` : ''}`;
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
double(precision, scale) {
|
|
46
|
+
// if (!precision) return 'number'; // TODO: Check If default is ok
|
|
47
|
+
return `number(${this._num(precision, 8)}, ${this._num(scale, 2)})`;
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
decimal(precision, scale) {
|
|
51
|
+
if (precision === null) return 'decimal';
|
|
52
|
+
return `decimal(${this._num(precision, 8)}, ${this._num(scale, 2)})`;
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
integer(length) {
|
|
56
|
+
return length ? `number(${this._num(length, 11)})` : 'integer';
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
tinyint: 'smallint',
|
|
60
|
+
|
|
61
|
+
smallint: 'smallint',
|
|
62
|
+
|
|
63
|
+
mediumint: 'integer',
|
|
64
|
+
|
|
65
|
+
biginteger: 'number(20, 0)',
|
|
66
|
+
|
|
67
|
+
text: 'clob',
|
|
68
|
+
|
|
69
|
+
enu(allowed) {
|
|
70
|
+
allowed = uniq(allowed);
|
|
71
|
+
const maxLength = (allowed || []).reduce(
|
|
72
|
+
(maxLength, name) => Math.max(maxLength, String(name).length),
|
|
73
|
+
1
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
// implicitly add the enum values as checked values
|
|
77
|
+
this.columnBuilder._modifiers.checkIn = [allowed];
|
|
78
|
+
|
|
79
|
+
return `varchar2(${maxLength})`;
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
time: 'timestamp with time zone',
|
|
83
|
+
|
|
84
|
+
datetime(without) {
|
|
85
|
+
return without ? 'timestamp' : 'timestamp with time zone';
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
timestamp(without) {
|
|
89
|
+
return without ? 'timestamp' : 'timestamp with time zone';
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
bit: 'clob',
|
|
93
|
+
|
|
94
|
+
json: 'clob',
|
|
95
|
+
|
|
96
|
+
bool() {
|
|
97
|
+
// implicitly add the check for 0 and 1
|
|
98
|
+
this.columnBuilder._modifiers.checkIn = [[0, 1]];
|
|
99
|
+
return 'number(1, 0)';
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
varchar(length) {
|
|
103
|
+
return `varchar2(${this._num(length, 255)})`;
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
// Modifiers
|
|
107
|
+
// ------
|
|
108
|
+
|
|
109
|
+
comment(comment) {
|
|
110
|
+
const columnName = this.args[0] || this.defaults('columnName');
|
|
111
|
+
|
|
112
|
+
this.pushAdditional(function () {
|
|
113
|
+
this.pushQuery(
|
|
114
|
+
`comment on column ${this.tableCompiler.tableName()}.` +
|
|
115
|
+
this.formatter.wrap(columnName) +
|
|
116
|
+
" is '" +
|
|
117
|
+
(comment || '') +
|
|
118
|
+
"'"
|
|
119
|
+
);
|
|
120
|
+
}, comment);
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
checkIn(value) {
|
|
124
|
+
// TODO: Maybe accept arguments also as array
|
|
125
|
+
// TODO: value(s) should be escaped properly
|
|
126
|
+
if (value === undefined) {
|
|
127
|
+
return '';
|
|
128
|
+
} else if (value instanceof Raw) {
|
|
129
|
+
value = value.toQuery();
|
|
130
|
+
} else if (Array.isArray(value)) {
|
|
131
|
+
value = value.map((v) => `'${v}'`).join(', ');
|
|
132
|
+
} else {
|
|
133
|
+
value = `'${value}'`;
|
|
134
|
+
}
|
|
135
|
+
return `check (${this.formatter.wrap(this.args[0])} in (${value}))`;
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
module.exports = ColumnCompiler_Oracle;
|
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
// Oracle Schema Compiler
|
|
2
|
-
// -------
|
|
3
|
-
const { inherits } = require('util');
|
|
4
|
-
const SchemaCompiler = require('../../../schema/compiler');
|
|
5
|
-
const utils = require('../utils');
|
|
6
|
-
const Trigger = require('./trigger');
|
|
7
|
-
|
|
8
|
-
function SchemaCompiler_Oracle() {
|
|
9
|
-
SchemaCompiler.apply(this, arguments);
|
|
10
|
-
}
|
|
11
|
-
inherits(SchemaCompiler_Oracle, SchemaCompiler);
|
|
12
|
-
|
|
13
|
-
// Rename a table on the schema.
|
|
14
|
-
SchemaCompiler_Oracle.prototype.renameTable = function (tableName, to) {
|
|
15
|
-
const renameTable = Trigger.renameTableAndAutoIncrementTrigger(
|
|
16
|
-
this.client.logger,
|
|
17
|
-
tableName,
|
|
18
|
-
to
|
|
19
|
-
);
|
|
20
|
-
this.pushQuery(renameTable);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
// Check whether a table exists on the query.
|
|
24
|
-
SchemaCompiler_Oracle.prototype.hasTable = function (tableName) {
|
|
25
|
-
this.pushQuery({
|
|
26
|
-
sql:
|
|
27
|
-
'select TABLE_NAME from USER_TABLES where TABLE_NAME = ' +
|
|
28
|
-
this.formatter.parameter(tableName),
|
|
29
|
-
output(resp) {
|
|
30
|
-
return resp.length > 0;
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// Check whether a column exists on the schema.
|
|
36
|
-
SchemaCompiler_Oracle.prototype.hasColumn = function (tableName, column) {
|
|
37
|
-
const sql =
|
|
38
|
-
`select COLUMN_NAME from ALL_TAB_COLUMNS ` +
|
|
39
|
-
`where TABLE_NAME = ${this.formatter.parameter(tableName)} ` +
|
|
40
|
-
`and COLUMN_NAME = ${this.formatter.parameter(column)}`;
|
|
41
|
-
this.pushQuery({ sql, output: (resp) => resp.length > 0 });
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
SchemaCompiler_Oracle.prototype.dropSequenceIfExists = function (sequenceName) {
|
|
45
|
-
this.pushQuery(
|
|
46
|
-
utils.wrapSqlWithCatch(
|
|
47
|
-
`drop sequence ${this.formatter.wrap(sequenceName)}`,
|
|
48
|
-
-2289
|
|
49
|
-
)
|
|
50
|
-
);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
SchemaCompiler_Oracle.prototype._dropRelatedSequenceIfExists = function (
|
|
54
|
-
tableName
|
|
55
|
-
) {
|
|
56
|
-
// removing the sequence that was possibly generated by increments() column
|
|
57
|
-
const sequenceName = utils.generateCombinedName(
|
|
58
|
-
this.client.logger,
|
|
59
|
-
'seq',
|
|
60
|
-
tableName
|
|
61
|
-
);
|
|
62
|
-
this.dropSequenceIfExists(sequenceName);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
SchemaCompiler_Oracle.prototype.dropTable = function (tableName) {
|
|
66
|
-
this.pushQuery(`drop table ${this.formatter.wrap(tableName)}`);
|
|
67
|
-
|
|
68
|
-
// removing the sequence that was possibly generated by increments() column
|
|
69
|
-
this._dropRelatedSequenceIfExists(tableName);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
SchemaCompiler_Oracle.prototype.dropTableIfExists = function (tableName) {
|
|
73
|
-
this.pushQuery(
|
|
74
|
-
utils.wrapSqlWithCatch(`drop table ${this.formatter.wrap(tableName)}`, -942)
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
// removing the sequence that was possibly generated by increments() column
|
|
78
|
-
this._dropRelatedSequenceIfExists(tableName);
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
module.exports = SchemaCompiler_Oracle;
|
|
1
|
+
// Oracle Schema Compiler
|
|
2
|
+
// -------
|
|
3
|
+
const { inherits } = require('util');
|
|
4
|
+
const SchemaCompiler = require('../../../schema/compiler');
|
|
5
|
+
const utils = require('../utils');
|
|
6
|
+
const Trigger = require('./trigger');
|
|
7
|
+
|
|
8
|
+
function SchemaCompiler_Oracle() {
|
|
9
|
+
SchemaCompiler.apply(this, arguments);
|
|
10
|
+
}
|
|
11
|
+
inherits(SchemaCompiler_Oracle, SchemaCompiler);
|
|
12
|
+
|
|
13
|
+
// Rename a table on the schema.
|
|
14
|
+
SchemaCompiler_Oracle.prototype.renameTable = function (tableName, to) {
|
|
15
|
+
const renameTable = Trigger.renameTableAndAutoIncrementTrigger(
|
|
16
|
+
this.client.logger,
|
|
17
|
+
tableName,
|
|
18
|
+
to
|
|
19
|
+
);
|
|
20
|
+
this.pushQuery(renameTable);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// Check whether a table exists on the query.
|
|
24
|
+
SchemaCompiler_Oracle.prototype.hasTable = function (tableName) {
|
|
25
|
+
this.pushQuery({
|
|
26
|
+
sql:
|
|
27
|
+
'select TABLE_NAME from USER_TABLES where TABLE_NAME = ' +
|
|
28
|
+
this.formatter.parameter(tableName),
|
|
29
|
+
output(resp) {
|
|
30
|
+
return resp.length > 0;
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Check whether a column exists on the schema.
|
|
36
|
+
SchemaCompiler_Oracle.prototype.hasColumn = function (tableName, column) {
|
|
37
|
+
const sql =
|
|
38
|
+
`select COLUMN_NAME from ALL_TAB_COLUMNS ` +
|
|
39
|
+
`where TABLE_NAME = ${this.formatter.parameter(tableName)} ` +
|
|
40
|
+
`and COLUMN_NAME = ${this.formatter.parameter(column)}`;
|
|
41
|
+
this.pushQuery({ sql, output: (resp) => resp.length > 0 });
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
SchemaCompiler_Oracle.prototype.dropSequenceIfExists = function (sequenceName) {
|
|
45
|
+
this.pushQuery(
|
|
46
|
+
utils.wrapSqlWithCatch(
|
|
47
|
+
`drop sequence ${this.formatter.wrap(sequenceName)}`,
|
|
48
|
+
-2289
|
|
49
|
+
)
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
SchemaCompiler_Oracle.prototype._dropRelatedSequenceIfExists = function (
|
|
54
|
+
tableName
|
|
55
|
+
) {
|
|
56
|
+
// removing the sequence that was possibly generated by increments() column
|
|
57
|
+
const sequenceName = utils.generateCombinedName(
|
|
58
|
+
this.client.logger,
|
|
59
|
+
'seq',
|
|
60
|
+
tableName
|
|
61
|
+
);
|
|
62
|
+
this.dropSequenceIfExists(sequenceName);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
SchemaCompiler_Oracle.prototype.dropTable = function (tableName) {
|
|
66
|
+
this.pushQuery(`drop table ${this.formatter.wrap(tableName)}`);
|
|
67
|
+
|
|
68
|
+
// removing the sequence that was possibly generated by increments() column
|
|
69
|
+
this._dropRelatedSequenceIfExists(tableName);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
SchemaCompiler_Oracle.prototype.dropTableIfExists = function (tableName) {
|
|
73
|
+
this.pushQuery(
|
|
74
|
+
utils.wrapSqlWithCatch(`drop table ${this.formatter.wrap(tableName)}`, -942)
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
// removing the sequence that was possibly generated by increments() column
|
|
78
|
+
this._dropRelatedSequenceIfExists(tableName);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
module.exports = SchemaCompiler_Oracle;
|