@contember/schema-utils 1.2.0-alpha.15 → 1.2.0-alpha.16

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.
@@ -0,0 +1,69 @@
1
+ import { assert, test } from 'vitest'
2
+ import { Model } from '@contember/schema'
3
+ import { ModelValidator } from '../../../src'
4
+
5
+
6
+ const model: Model.Schema = {
7
+ enums: {},
8
+ entities: {
9
+ Foo: {
10
+ fields: {
11
+ id: {
12
+ columnName: 'id',
13
+ name: 'id',
14
+ nullable: false,
15
+ type: Model.ColumnType.Uuid,
16
+ columnType: 'uuid',
17
+ },
18
+ },
19
+ name: 'Foo',
20
+ primary: 'id',
21
+ primaryColumn: 'id',
22
+ tableName: 'foo',
23
+ unique: {},
24
+ eventLog: {
25
+ enabled: true,
26
+ },
27
+ indexes: {
28
+ test: { fields: ['id'], name: 'test' },
29
+ },
30
+ },
31
+ Bar: {
32
+ fields: {
33
+ id: {
34
+ columnName: 'id',
35
+ name: 'id',
36
+ nullable: false,
37
+ type: Model.ColumnType.Uuid,
38
+ columnType: 'uuid',
39
+ },
40
+ },
41
+ name: 'Bar',
42
+ primary: 'id',
43
+ primaryColumn: 'id',
44
+ tableName: 'bar',
45
+ unique: {
46
+ test: { fields: ['id'], name: 'test' },
47
+ },
48
+ eventLog: {
49
+ enabled: true,
50
+ },
51
+ indexes: {
52
+ foo: { fields: ['id'], name: 'foo' },
53
+ },
54
+ },
55
+ },
56
+ }
57
+ test('index name collision', () => {
58
+ const validator = new ModelValidator(model)
59
+ assert.deepStrictEqual(validator.validate(), [
60
+ {
61
+ message: 'index name foo of entity Bar collides with table name foo of entity Foo',
62
+ path: ['entities', 'Bar'],
63
+ },
64
+ {
65
+ message: 'unique index name test of entity Bar collides with index name test of entity Foo',
66
+ path: ['entities', 'Bar'],
67
+ },
68
+ ])
69
+ })