@balena/abstract-sql-compiler 11.0.0-build-11-x-45529f014aa1c181f338c0f7348767f2990a9084-1 → 11.0.0-build-11-x-7511b8ebe5a9461f20add0ed97d0670ed3b5a479-1
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/package.json +5 -2
- package/.github/workflows/flowzone.yml +0 -21
- package/.husky/pre-commit +0 -2
- package/.versionbot/CHANGELOG.yml +0 -10729
- package/CHANGELOG.md +0 -3515
- package/repo.yml +0 -12
- package/src/abstract-sql-compiler.ts +0 -1138
- package/src/abstract-sql-optimizer.ts +0 -1632
- package/src/abstract-sql-rules-to-sql.ts +0 -1730
- package/src/abstract-sql-schema-optimizer.ts +0 -172
- package/src/referenced-fields.ts +0 -600
- package/test/abstract-sql/aggregate-json.ts +0 -49
- package/test/abstract-sql/aggregate.ts +0 -161
- package/test/abstract-sql/and-or-boolean-optimisations.ts +0 -115
- package/test/abstract-sql/case-when-else.ts +0 -48
- package/test/abstract-sql/cast.ts +0 -25
- package/test/abstract-sql/coalesce.ts +0 -24
- package/test/abstract-sql/comparisons.ts +0 -360
- package/test/abstract-sql/dates.ts +0 -512
- package/test/abstract-sql/duration.ts +0 -56
- package/test/abstract-sql/empty-query-optimisations.ts +0 -54
- package/test/abstract-sql/functions-wrapper.ts +0 -70
- package/test/abstract-sql/get-referenced-fields.ts +0 -674
- package/test/abstract-sql/get-rule-referenced-fields.ts +0 -345
- package/test/abstract-sql/insert-query.ts +0 -22
- package/test/abstract-sql/is-distinct.ts +0 -102
- package/test/abstract-sql/joins.ts +0 -84
- package/test/abstract-sql/json.ts +0 -58
- package/test/abstract-sql/math.ts +0 -467
- package/test/abstract-sql/nested-in-optimisations.ts +0 -200
- package/test/abstract-sql/not-not-optimisations.ts +0 -15
- package/test/abstract-sql/schema-checks.ts +0 -168
- package/test/abstract-sql/schema-informative-reference.ts +0 -420
- package/test/abstract-sql/schema-rule-optimization.ts +0 -120
- package/test/abstract-sql/schema-rule-to-check.ts +0 -393
- package/test/abstract-sql/schema-views.ts +0 -73
- package/test/abstract-sql/test.ts +0 -192
- package/test/abstract-sql/text.ts +0 -168
- package/test/model.sbvr +0 -60
- package/test/odata/expand.ts +0 -674
- package/test/odata/fields.ts +0 -59
- package/test/odata/filterby.ts +0 -1517
- package/test/odata/orderby.ts +0 -96
- package/test/odata/paging.ts +0 -48
- package/test/odata/resource-parsing.ts +0 -568
- package/test/odata/select.ts +0 -119
- package/test/odata/stress.ts +0 -93
- package/test/odata/test.ts +0 -297
- package/test/sbvr/pilots.ts +0 -1097
- package/test/sbvr/reference-type.ts +0 -211
- package/test/sbvr/test.ts +0 -101
- package/tsconfig.build.json +0 -6
- package/tsconfig.json +0 -25
@@ -1,168 +0,0 @@
|
|
1
|
-
import * as AbstractSQLCompiler from '../../out/abstract-sql-compiler.js';
|
2
|
-
import { expect } from 'chai';
|
3
|
-
|
4
|
-
it('an empty abstractSql model should produce an empty schema', () => {
|
5
|
-
expect(
|
6
|
-
AbstractSQLCompiler.postgres.compileSchema({
|
7
|
-
synonyms: {},
|
8
|
-
relationships: {},
|
9
|
-
tables: {},
|
10
|
-
rules: [],
|
11
|
-
lfInfo: { rules: {} },
|
12
|
-
}),
|
13
|
-
)
|
14
|
-
.to.have.property('createSchema')
|
15
|
-
.that.is.an('array').that.is.empty;
|
16
|
-
});
|
17
|
-
|
18
|
-
it('a single table abstractSql model should produce an appropriate schema', () => {
|
19
|
-
expect(
|
20
|
-
AbstractSQLCompiler.postgres.compileSchema({
|
21
|
-
synonyms: {},
|
22
|
-
relationships: {},
|
23
|
-
tables: {
|
24
|
-
test: {
|
25
|
-
name: 'test',
|
26
|
-
resourceName: 'test',
|
27
|
-
idField: 'id',
|
28
|
-
fields: [
|
29
|
-
{
|
30
|
-
fieldName: 'id',
|
31
|
-
dataType: 'Integer',
|
32
|
-
index: 'PRIMARY KEY',
|
33
|
-
},
|
34
|
-
],
|
35
|
-
indexes: [],
|
36
|
-
primitive: false,
|
37
|
-
},
|
38
|
-
},
|
39
|
-
rules: [],
|
40
|
-
lfInfo: { rules: {} },
|
41
|
-
}),
|
42
|
-
)
|
43
|
-
.to.have.property('createSchema')
|
44
|
-
.that.deep.equals([
|
45
|
-
`\
|
46
|
-
CREATE TABLE IF NOT EXISTS "test" (
|
47
|
-
"id" INTEGER NULL PRIMARY KEY
|
48
|
-
);`,
|
49
|
-
]);
|
50
|
-
});
|
51
|
-
|
52
|
-
it('an abstractSql model with a check on a field should produce an appropriate schema', () => {
|
53
|
-
expect(
|
54
|
-
AbstractSQLCompiler.postgres.compileSchema({
|
55
|
-
synonyms: {},
|
56
|
-
relationships: {},
|
57
|
-
tables: {
|
58
|
-
test: {
|
59
|
-
name: 'test',
|
60
|
-
resourceName: 'test',
|
61
|
-
idField: 'id',
|
62
|
-
fields: [
|
63
|
-
{
|
64
|
-
fieldName: 'id',
|
65
|
-
dataType: 'Integer',
|
66
|
-
index: 'PRIMARY KEY',
|
67
|
-
checks: [['GreaterThan', ['Field', 'id'], ['Number', 0]]],
|
68
|
-
},
|
69
|
-
],
|
70
|
-
indexes: [],
|
71
|
-
primitive: false,
|
72
|
-
},
|
73
|
-
},
|
74
|
-
rules: [],
|
75
|
-
lfInfo: { rules: {} },
|
76
|
-
}),
|
77
|
-
)
|
78
|
-
.to.have.property('createSchema')
|
79
|
-
.that.deep.equals([
|
80
|
-
`\
|
81
|
-
CREATE TABLE IF NOT EXISTS "test" (
|
82
|
-
"id" INTEGER NULL CHECK ("id" > 0) PRIMARY KEY
|
83
|
-
);`,
|
84
|
-
]);
|
85
|
-
});
|
86
|
-
|
87
|
-
describe('check constraints on table level', () => {
|
88
|
-
it('with just the abstractSql should produce an appropriate schema', () => {
|
89
|
-
expect(
|
90
|
-
AbstractSQLCompiler.postgres.compileSchema({
|
91
|
-
synonyms: {},
|
92
|
-
relationships: {},
|
93
|
-
tables: {
|
94
|
-
test: {
|
95
|
-
name: 'test',
|
96
|
-
resourceName: 'test',
|
97
|
-
idField: 'id',
|
98
|
-
fields: [
|
99
|
-
{
|
100
|
-
fieldName: 'id',
|
101
|
-
dataType: 'Integer',
|
102
|
-
index: 'PRIMARY KEY',
|
103
|
-
},
|
104
|
-
],
|
105
|
-
indexes: [],
|
106
|
-
primitive: false,
|
107
|
-
checks: [
|
108
|
-
{ abstractSql: ['GreaterThan', ['Field', 'id'], ['Number', 0]] },
|
109
|
-
],
|
110
|
-
},
|
111
|
-
},
|
112
|
-
rules: [],
|
113
|
-
lfInfo: { rules: {} },
|
114
|
-
}),
|
115
|
-
)
|
116
|
-
.to.have.property('createSchema')
|
117
|
-
.that.deep.equals([
|
118
|
-
`\
|
119
|
-
CREATE TABLE IF NOT EXISTS "test" (
|
120
|
-
"id" INTEGER NULL PRIMARY KEY
|
121
|
-
, CHECK ("id" > 0)
|
122
|
-
);`,
|
123
|
-
]);
|
124
|
-
});
|
125
|
-
|
126
|
-
it('with description and name should produce an appropriate schema', () => {
|
127
|
-
expect(
|
128
|
-
AbstractSQLCompiler.postgres.compileSchema({
|
129
|
-
synonyms: {},
|
130
|
-
relationships: {},
|
131
|
-
tables: {
|
132
|
-
test: {
|
133
|
-
name: 'test',
|
134
|
-
resourceName: 'test',
|
135
|
-
idField: 'id',
|
136
|
-
fields: [
|
137
|
-
{
|
138
|
-
fieldName: 'id',
|
139
|
-
dataType: 'Integer',
|
140
|
-
index: 'PRIMARY KEY',
|
141
|
-
},
|
142
|
-
],
|
143
|
-
indexes: [],
|
144
|
-
primitive: false,
|
145
|
-
checks: [
|
146
|
-
{
|
147
|
-
description: 'id must be positive',
|
148
|
-
name: 'positive id',
|
149
|
-
abstractSql: ['GreaterThan', ['Field', 'id'], ['Number', 0]],
|
150
|
-
},
|
151
|
-
],
|
152
|
-
},
|
153
|
-
},
|
154
|
-
rules: [],
|
155
|
-
lfInfo: { rules: {} },
|
156
|
-
}),
|
157
|
-
)
|
158
|
-
.to.have.property('createSchema')
|
159
|
-
.that.deep.equals([
|
160
|
-
`\
|
161
|
-
CREATE TABLE IF NOT EXISTS "test" (
|
162
|
-
"id" INTEGER NULL PRIMARY KEY
|
163
|
-
, -- id must be positive
|
164
|
-
CONSTRAINT "positive id" CHECK ("id" > 0)
|
165
|
-
);`,
|
166
|
-
]);
|
167
|
-
});
|
168
|
-
});
|
@@ -1,420 +0,0 @@
|
|
1
|
-
import * as AbstractSQLCompiler from '../../out/abstract-sql-compiler.js';
|
2
|
-
import { expect } from 'chai';
|
3
|
-
|
4
|
-
describe('generate informative reference schema', () => {
|
5
|
-
it('reference type informative produces just a column without foreign key / constraint', () => {
|
6
|
-
expect(
|
7
|
-
AbstractSQLCompiler.postgres.compileSchema({
|
8
|
-
tables: {
|
9
|
-
term: {
|
10
|
-
fields: [
|
11
|
-
{
|
12
|
-
dataType: 'Date Time',
|
13
|
-
fieldName: 'created at',
|
14
|
-
required: true,
|
15
|
-
defaultValue: 'CURRENT_TIMESTAMP',
|
16
|
-
},
|
17
|
-
{
|
18
|
-
dataType: 'Date Time',
|
19
|
-
fieldName: 'modified at',
|
20
|
-
required: true,
|
21
|
-
defaultValue: 'CURRENT_TIMESTAMP',
|
22
|
-
},
|
23
|
-
{
|
24
|
-
dataType: 'Serial',
|
25
|
-
fieldName: 'id',
|
26
|
-
required: true,
|
27
|
-
index: 'PRIMARY KEY',
|
28
|
-
},
|
29
|
-
],
|
30
|
-
primitive: false,
|
31
|
-
name: 'term',
|
32
|
-
indexes: [],
|
33
|
-
idField: 'id',
|
34
|
-
resourceName: 'term',
|
35
|
-
},
|
36
|
-
'term history': {
|
37
|
-
fields: [
|
38
|
-
{
|
39
|
-
dataType: 'Date Time',
|
40
|
-
fieldName: 'created at',
|
41
|
-
required: true,
|
42
|
-
defaultValue: 'CURRENT_TIMESTAMP',
|
43
|
-
},
|
44
|
-
{
|
45
|
-
dataType: 'Date Time',
|
46
|
-
fieldName: 'modified at',
|
47
|
-
required: true,
|
48
|
-
defaultValue: 'CURRENT_TIMESTAMP',
|
49
|
-
},
|
50
|
-
{
|
51
|
-
dataType: 'Serial',
|
52
|
-
fieldName: 'id',
|
53
|
-
required: true,
|
54
|
-
index: 'PRIMARY KEY',
|
55
|
-
},
|
56
|
-
{
|
57
|
-
dataType: 'ForeignKey',
|
58
|
-
fieldName: 'references-term',
|
59
|
-
required: true,
|
60
|
-
references: {
|
61
|
-
resourceName: 'term',
|
62
|
-
fieldName: 'id',
|
63
|
-
type: 'informative',
|
64
|
-
},
|
65
|
-
},
|
66
|
-
],
|
67
|
-
primitive: false,
|
68
|
-
name: 'term history',
|
69
|
-
indexes: [],
|
70
|
-
idField: 'id',
|
71
|
-
resourceName: 'term history',
|
72
|
-
},
|
73
|
-
},
|
74
|
-
relationships: {},
|
75
|
-
rules: [],
|
76
|
-
synonyms: {},
|
77
|
-
lfInfo: { rules: {} },
|
78
|
-
}),
|
79
|
-
)
|
80
|
-
.to.have.property('createSchema')
|
81
|
-
.that.deep.equals([
|
82
|
-
`\
|
83
|
-
CREATE TABLE IF NOT EXISTS "term" (
|
84
|
-
"created at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
85
|
-
, "modified at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
86
|
-
, "id" SERIAL NOT NULL PRIMARY KEY
|
87
|
-
);`,
|
88
|
-
`\
|
89
|
-
CREATE TABLE IF NOT EXISTS "term history" (
|
90
|
-
"created at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
91
|
-
, "modified at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
92
|
-
, "id" SERIAL NOT NULL PRIMARY KEY
|
93
|
-
, "references-term" INTEGER NOT NULL
|
94
|
-
);`,
|
95
|
-
]);
|
96
|
-
});
|
97
|
-
|
98
|
-
it('reference type informative produces just a column without foreign key / constraint - mixed mode', () => {
|
99
|
-
expect(
|
100
|
-
AbstractSQLCompiler.postgres.compileSchema({
|
101
|
-
tables: {
|
102
|
-
term: {
|
103
|
-
fields: [
|
104
|
-
{
|
105
|
-
dataType: 'Date Time',
|
106
|
-
fieldName: 'created at',
|
107
|
-
required: true,
|
108
|
-
defaultValue: 'CURRENT_TIMESTAMP',
|
109
|
-
},
|
110
|
-
{
|
111
|
-
dataType: 'Date Time',
|
112
|
-
fieldName: 'modified at',
|
113
|
-
required: true,
|
114
|
-
defaultValue: 'CURRENT_TIMESTAMP',
|
115
|
-
},
|
116
|
-
{
|
117
|
-
dataType: 'Serial',
|
118
|
-
fieldName: 'id',
|
119
|
-
required: true,
|
120
|
-
index: 'PRIMARY KEY',
|
121
|
-
},
|
122
|
-
],
|
123
|
-
primitive: false,
|
124
|
-
name: 'term',
|
125
|
-
indexes: [],
|
126
|
-
idField: 'id',
|
127
|
-
resourceName: 'term',
|
128
|
-
},
|
129
|
-
termterm: {
|
130
|
-
fields: [
|
131
|
-
{
|
132
|
-
dataType: 'Date Time',
|
133
|
-
fieldName: 'created at',
|
134
|
-
required: true,
|
135
|
-
defaultValue: 'CURRENT_TIMESTAMP',
|
136
|
-
},
|
137
|
-
{
|
138
|
-
dataType: 'Date Time',
|
139
|
-
fieldName: 'modified at',
|
140
|
-
required: true,
|
141
|
-
defaultValue: 'CURRENT_TIMESTAMP',
|
142
|
-
},
|
143
|
-
{
|
144
|
-
dataType: 'Serial',
|
145
|
-
fieldName: 'id',
|
146
|
-
required: true,
|
147
|
-
index: 'PRIMARY KEY',
|
148
|
-
},
|
149
|
-
],
|
150
|
-
primitive: false,
|
151
|
-
name: 'termterm',
|
152
|
-
indexes: [],
|
153
|
-
idField: 'id',
|
154
|
-
resourceName: 'termterm',
|
155
|
-
},
|
156
|
-
'term history': {
|
157
|
-
fields: [
|
158
|
-
{
|
159
|
-
dataType: 'Date Time',
|
160
|
-
fieldName: 'created at',
|
161
|
-
required: true,
|
162
|
-
defaultValue: 'CURRENT_TIMESTAMP',
|
163
|
-
},
|
164
|
-
{
|
165
|
-
dataType: 'Date Time',
|
166
|
-
fieldName: 'modified at',
|
167
|
-
required: true,
|
168
|
-
defaultValue: 'CURRENT_TIMESTAMP',
|
169
|
-
},
|
170
|
-
{
|
171
|
-
dataType: 'Serial',
|
172
|
-
fieldName: 'id',
|
173
|
-
required: true,
|
174
|
-
index: 'PRIMARY KEY',
|
175
|
-
},
|
176
|
-
{
|
177
|
-
dataType: 'ForeignKey',
|
178
|
-
fieldName: 'references-term',
|
179
|
-
required: true,
|
180
|
-
references: {
|
181
|
-
resourceName: 'term',
|
182
|
-
fieldName: 'id',
|
183
|
-
type: 'informative',
|
184
|
-
},
|
185
|
-
},
|
186
|
-
{
|
187
|
-
dataType: 'ForeignKey',
|
188
|
-
fieldName: 'references-termterm',
|
189
|
-
required: true,
|
190
|
-
references: {
|
191
|
-
resourceName: 'termterm',
|
192
|
-
fieldName: 'id',
|
193
|
-
},
|
194
|
-
},
|
195
|
-
],
|
196
|
-
primitive: false,
|
197
|
-
name: 'term history',
|
198
|
-
indexes: [],
|
199
|
-
idField: 'id',
|
200
|
-
resourceName: 'term history',
|
201
|
-
},
|
202
|
-
},
|
203
|
-
relationships: {},
|
204
|
-
rules: [],
|
205
|
-
synonyms: {},
|
206
|
-
lfInfo: { rules: {} },
|
207
|
-
}),
|
208
|
-
)
|
209
|
-
.to.have.property('createSchema')
|
210
|
-
.that.deep.equals([
|
211
|
-
`\
|
212
|
-
CREATE TABLE IF NOT EXISTS "term" (
|
213
|
-
"created at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
214
|
-
, "modified at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
215
|
-
, "id" SERIAL NOT NULL PRIMARY KEY
|
216
|
-
);`,
|
217
|
-
`\
|
218
|
-
CREATE TABLE IF NOT EXISTS "termterm" (
|
219
|
-
"created at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
220
|
-
, "modified at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
221
|
-
, "id" SERIAL NOT NULL PRIMARY KEY
|
222
|
-
);`,
|
223
|
-
`\
|
224
|
-
CREATE TABLE IF NOT EXISTS "term history" (
|
225
|
-
"created at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
226
|
-
, "modified at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
227
|
-
, "id" SERIAL NOT NULL PRIMARY KEY
|
228
|
-
, "references-term" INTEGER NOT NULL
|
229
|
-
, "references-termterm" INTEGER NOT NULL
|
230
|
-
, FOREIGN KEY ("references-termterm") REFERENCES "termterm" ("id")
|
231
|
-
);`,
|
232
|
-
]);
|
233
|
-
});
|
234
|
-
it('reference type strict produces a column foreign key / constraint', () => {
|
235
|
-
expect(
|
236
|
-
AbstractSQLCompiler.postgres.compileSchema({
|
237
|
-
tables: {
|
238
|
-
term: {
|
239
|
-
fields: [
|
240
|
-
{
|
241
|
-
dataType: 'Date Time',
|
242
|
-
fieldName: 'created at',
|
243
|
-
required: true,
|
244
|
-
defaultValue: 'CURRENT_TIMESTAMP',
|
245
|
-
},
|
246
|
-
{
|
247
|
-
dataType: 'Date Time',
|
248
|
-
fieldName: 'modified at',
|
249
|
-
required: true,
|
250
|
-
defaultValue: 'CURRENT_TIMESTAMP',
|
251
|
-
},
|
252
|
-
{
|
253
|
-
dataType: 'Serial',
|
254
|
-
fieldName: 'id',
|
255
|
-
required: true,
|
256
|
-
index: 'PRIMARY KEY',
|
257
|
-
},
|
258
|
-
],
|
259
|
-
primitive: false,
|
260
|
-
name: 'term',
|
261
|
-
indexes: [],
|
262
|
-
idField: 'id',
|
263
|
-
resourceName: 'term',
|
264
|
-
},
|
265
|
-
'term history': {
|
266
|
-
fields: [
|
267
|
-
{
|
268
|
-
dataType: 'Date Time',
|
269
|
-
fieldName: 'created at',
|
270
|
-
required: true,
|
271
|
-
defaultValue: 'CURRENT_TIMESTAMP',
|
272
|
-
},
|
273
|
-
{
|
274
|
-
dataType: 'Date Time',
|
275
|
-
fieldName: 'modified at',
|
276
|
-
required: true,
|
277
|
-
defaultValue: 'CURRENT_TIMESTAMP',
|
278
|
-
},
|
279
|
-
{
|
280
|
-
dataType: 'Serial',
|
281
|
-
fieldName: 'id',
|
282
|
-
required: true,
|
283
|
-
index: 'PRIMARY KEY',
|
284
|
-
},
|
285
|
-
{
|
286
|
-
dataType: 'ForeignKey',
|
287
|
-
fieldName: 'references-term',
|
288
|
-
required: true,
|
289
|
-
references: {
|
290
|
-
resourceName: 'term',
|
291
|
-
fieldName: 'id',
|
292
|
-
type: 'strict',
|
293
|
-
},
|
294
|
-
},
|
295
|
-
],
|
296
|
-
primitive: false,
|
297
|
-
name: 'term history',
|
298
|
-
indexes: [],
|
299
|
-
idField: 'id',
|
300
|
-
resourceName: 'term history',
|
301
|
-
},
|
302
|
-
},
|
303
|
-
relationships: {},
|
304
|
-
rules: [],
|
305
|
-
synonyms: {},
|
306
|
-
lfInfo: { rules: {} },
|
307
|
-
}),
|
308
|
-
)
|
309
|
-
.to.have.property('createSchema')
|
310
|
-
.that.deep.equals([
|
311
|
-
`\
|
312
|
-
CREATE TABLE IF NOT EXISTS "term" (
|
313
|
-
"created at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
314
|
-
, "modified at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
315
|
-
, "id" SERIAL NOT NULL PRIMARY KEY
|
316
|
-
);`,
|
317
|
-
`\
|
318
|
-
CREATE TABLE IF NOT EXISTS "term history" (
|
319
|
-
"created at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
320
|
-
, "modified at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
321
|
-
, "id" SERIAL NOT NULL PRIMARY KEY
|
322
|
-
, "references-term" INTEGER NOT NULL
|
323
|
-
, FOREIGN KEY ("references-term") REFERENCES "term" ("id")
|
324
|
-
);`,
|
325
|
-
]);
|
326
|
-
});
|
327
|
-
|
328
|
-
it('reference type undefined produces a column foreign key / constraint', () => {
|
329
|
-
expect(
|
330
|
-
AbstractSQLCompiler.postgres.compileSchema({
|
331
|
-
tables: {
|
332
|
-
term: {
|
333
|
-
fields: [
|
334
|
-
{
|
335
|
-
dataType: 'Date Time',
|
336
|
-
fieldName: 'created at',
|
337
|
-
required: true,
|
338
|
-
defaultValue: 'CURRENT_TIMESTAMP',
|
339
|
-
},
|
340
|
-
{
|
341
|
-
dataType: 'Date Time',
|
342
|
-
fieldName: 'modified at',
|
343
|
-
required: true,
|
344
|
-
defaultValue: 'CURRENT_TIMESTAMP',
|
345
|
-
},
|
346
|
-
{
|
347
|
-
dataType: 'Serial',
|
348
|
-
fieldName: 'id',
|
349
|
-
required: true,
|
350
|
-
index: 'PRIMARY KEY',
|
351
|
-
},
|
352
|
-
],
|
353
|
-
primitive: false,
|
354
|
-
name: 'term',
|
355
|
-
indexes: [],
|
356
|
-
idField: 'id',
|
357
|
-
resourceName: 'term',
|
358
|
-
},
|
359
|
-
'term history': {
|
360
|
-
fields: [
|
361
|
-
{
|
362
|
-
dataType: 'Date Time',
|
363
|
-
fieldName: 'created at',
|
364
|
-
required: true,
|
365
|
-
defaultValue: 'CURRENT_TIMESTAMP',
|
366
|
-
},
|
367
|
-
{
|
368
|
-
dataType: 'Date Time',
|
369
|
-
fieldName: 'modified at',
|
370
|
-
required: true,
|
371
|
-
defaultValue: 'CURRENT_TIMESTAMP',
|
372
|
-
},
|
373
|
-
{
|
374
|
-
dataType: 'Serial',
|
375
|
-
fieldName: 'id',
|
376
|
-
required: true,
|
377
|
-
index: 'PRIMARY KEY',
|
378
|
-
},
|
379
|
-
{
|
380
|
-
dataType: 'ForeignKey',
|
381
|
-
fieldName: 'references-term',
|
382
|
-
required: true,
|
383
|
-
references: {
|
384
|
-
resourceName: 'term',
|
385
|
-
fieldName: 'id',
|
386
|
-
},
|
387
|
-
},
|
388
|
-
],
|
389
|
-
primitive: false,
|
390
|
-
name: 'term history',
|
391
|
-
indexes: [],
|
392
|
-
idField: 'id',
|
393
|
-
resourceName: 'term history',
|
394
|
-
},
|
395
|
-
},
|
396
|
-
relationships: {},
|
397
|
-
rules: [],
|
398
|
-
synonyms: {},
|
399
|
-
lfInfo: { rules: {} },
|
400
|
-
}),
|
401
|
-
)
|
402
|
-
.to.have.property('createSchema')
|
403
|
-
.that.deep.equals([
|
404
|
-
`\
|
405
|
-
CREATE TABLE IF NOT EXISTS "term" (
|
406
|
-
"created at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
407
|
-
, "modified at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
408
|
-
, "id" SERIAL NOT NULL PRIMARY KEY
|
409
|
-
);`,
|
410
|
-
`\
|
411
|
-
CREATE TABLE IF NOT EXISTS "term history" (
|
412
|
-
"created at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
413
|
-
, "modified at" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL
|
414
|
-
, "id" SERIAL NOT NULL PRIMARY KEY
|
415
|
-
, "references-term" INTEGER NOT NULL
|
416
|
-
, FOREIGN KEY ("references-term") REFERENCES "term" ("id")
|
417
|
-
);`,
|
418
|
-
]);
|
419
|
-
});
|
420
|
-
});
|
@@ -1,120 +0,0 @@
|
|
1
|
-
import * as AbstractSQLCompiler from '../../out/abstract-sql-compiler.js';
|
2
|
-
import { expect } from 'chai';
|
3
|
-
|
4
|
-
const generateSchema = (
|
5
|
-
abstractSqlModel: AbstractSQLCompiler.AbstractSqlModel,
|
6
|
-
) => AbstractSQLCompiler.postgres.optimizeSchema(abstractSqlModel);
|
7
|
-
|
8
|
-
it('should convert a basic rule to a check', () => {
|
9
|
-
expect(
|
10
|
-
generateSchema({
|
11
|
-
synonyms: {},
|
12
|
-
relationships: {},
|
13
|
-
tables: {
|
14
|
-
test: {
|
15
|
-
name: 'test',
|
16
|
-
resourceName: 'test',
|
17
|
-
idField: 'id',
|
18
|
-
fields: [
|
19
|
-
{
|
20
|
-
fieldName: 'id',
|
21
|
-
dataType: 'Integer',
|
22
|
-
index: 'PRIMARY KEY',
|
23
|
-
},
|
24
|
-
],
|
25
|
-
indexes: [],
|
26
|
-
primitive: false,
|
27
|
-
},
|
28
|
-
},
|
29
|
-
rules: [
|
30
|
-
[
|
31
|
-
'Rule',
|
32
|
-
[
|
33
|
-
'Body',
|
34
|
-
[
|
35
|
-
'Not',
|
36
|
-
[
|
37
|
-
'Exists',
|
38
|
-
[
|
39
|
-
'SelectQuery',
|
40
|
-
['Select', []],
|
41
|
-
['From', ['Alias', ['Table', 'test'], 'test.0']],
|
42
|
-
['From', ['Alias', ['Table', 'test'], 'test.1']],
|
43
|
-
[
|
44
|
-
'Where',
|
45
|
-
[
|
46
|
-
'Not',
|
47
|
-
[
|
48
|
-
'And',
|
49
|
-
[
|
50
|
-
'And',
|
51
|
-
[
|
52
|
-
'LessThan',
|
53
|
-
['Integer', 0],
|
54
|
-
['ReferencedField', 'test.0', 'id'],
|
55
|
-
],
|
56
|
-
['Exists', ['ReferencedField', 'test.0', 'id']],
|
57
|
-
],
|
58
|
-
[
|
59
|
-
'And',
|
60
|
-
[
|
61
|
-
'LessThan',
|
62
|
-
['Integer', 0],
|
63
|
-
['ReferencedField', 'test.1', 'id'],
|
64
|
-
],
|
65
|
-
['Exists', ['ReferencedField', 'test.1', 'id']],
|
66
|
-
],
|
67
|
-
],
|
68
|
-
],
|
69
|
-
],
|
70
|
-
],
|
71
|
-
],
|
72
|
-
],
|
73
|
-
],
|
74
|
-
['StructuredEnglish', 'Test rule abstract sql optimization'],
|
75
|
-
],
|
76
|
-
],
|
77
|
-
lfInfo: { rules: {} },
|
78
|
-
}),
|
79
|
-
)
|
80
|
-
.to.have.property('rules')
|
81
|
-
.that.deep.equals([
|
82
|
-
[
|
83
|
-
'Rule',
|
84
|
-
[
|
85
|
-
'Body',
|
86
|
-
[
|
87
|
-
'NotExists',
|
88
|
-
[
|
89
|
-
'SelectQuery',
|
90
|
-
['Select', []],
|
91
|
-
['From', ['Alias', ['Table', 'test'], 'test.0']],
|
92
|
-
['From', ['Alias', ['Table', 'test'], 'test.1']],
|
93
|
-
[
|
94
|
-
'Where',
|
95
|
-
[
|
96
|
-
'Not',
|
97
|
-
[
|
98
|
-
'And',
|
99
|
-
[
|
100
|
-
'LessThan',
|
101
|
-
['Integer', 0],
|
102
|
-
['ReferencedField', 'test.0', 'id'],
|
103
|
-
],
|
104
|
-
['Exists', ['ReferencedField', 'test.0', 'id']],
|
105
|
-
[
|
106
|
-
'LessThan',
|
107
|
-
['Integer', 0],
|
108
|
-
['ReferencedField', 'test.1', 'id'],
|
109
|
-
],
|
110
|
-
['Exists', ['ReferencedField', 'test.1', 'id']],
|
111
|
-
],
|
112
|
-
],
|
113
|
-
],
|
114
|
-
],
|
115
|
-
],
|
116
|
-
] as AbstractSQLCompiler.AbstractSqlQuery,
|
117
|
-
['StructuredEnglish', 'Test rule abstract sql optimization'],
|
118
|
-
],
|
119
|
-
]);
|
120
|
-
});
|