forked from ab-pm/node-pg-migrate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindexes-test.ts
82 lines (76 loc) · 3.22 KB
/
indexes-test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { expect } from 'chai'
import * as Indexes from '../src/operations/indexes'
import { options1, options2 } from './utils'
type CreateIndexParams = Parameters<ReturnType<typeof Indexes.createIndex>>
describe('src/operations/indexes', () => {
describe('.create', () => {
it('check schema not included in index name', () => {
const args: CreateIndexParams = [{ schema: 'mySchema', name: 'myTable' }, ['colA', 'colB']]
const sql1 = Indexes.createIndex(options1)(...args)
const sql2 = Indexes.createIndex(options2)(...args)
expect(sql1).to.equal('CREATE INDEX "myTable_colA_colB_index" ON "mySchema"."myTable" ("colA", "colB");')
expect(sql2).to.equal('CREATE INDEX "my_table_col_a_col_b_index" ON "my_schema"."my_table" ("col_a", "col_b");')
})
it('add opclass option (deprecated)', () => {
const args: CreateIndexParams = [
'xTable',
['yName'],
{
method: 'gist',
name: 'zIndex',
opclass: 'someOpclass',
where: 'some condition',
},
]
const sql1 = Indexes.createIndex(options1)(...args)
const sql2 = Indexes.createIndex(options2)(...args)
expect(sql1).to.equal(
'CREATE INDEX "zIndex" ON "xTable" USING gist ("yName" "someOpclass") WHERE some condition;',
)
expect(sql2).to.equal(
'CREATE INDEX "z_index" ON "x_table" USING gist ("y_name" "some_opclass") WHERE some condition;',
)
})
it('add opclass option', () => {
const args: CreateIndexParams = [
'xTable',
[{ name: 'yName', opclass: { schema: 'someSchema', name: 'someOpclass' } }],
{
method: 'gist',
name: 'zIndex',
where: 'some condition',
},
]
const sql1 = Indexes.createIndex(options1)(...args)
const sql2 = Indexes.createIndex(options2)(...args)
expect(sql1).to.equal(
'CREATE INDEX "zIndex" ON "xTable" USING gist ("yName" "someSchema"."someOpclass") WHERE some condition;',
)
expect(sql2).to.equal(
'CREATE INDEX "z_index" ON "x_table" USING gist ("y_name" "some_schema"."some_opclass") WHERE some condition;',
)
})
it('add sort option', () => {
const args: CreateIndexParams = [
'xTable',
[{ name: 'yName', sort: 'DESC' }],
{
method: 'gist',
name: 'zIndex',
where: 'some condition',
},
]
const sql1 = Indexes.createIndex(options1)(...args)
const sql2 = Indexes.createIndex(options2)(...args)
expect(sql1).to.equal('CREATE INDEX "zIndex" ON "xTable" USING gist ("yName" DESC) WHERE some condition;')
expect(sql2).to.equal('CREATE INDEX "z_index" ON "x_table" USING gist ("y_name" DESC) WHERE some condition;')
})
it('add include option', () => {
const args: CreateIndexParams = ['xTable', ['yName'], { name: 'zIndex', include: 'someOtherColumn' }]
const sql1 = Indexes.createIndex(options1)(...args)
const sql2 = Indexes.createIndex(options2)(...args)
expect(sql1).to.equal('CREATE INDEX "zIndex" ON "xTable" ("yName") INCLUDE ("someOtherColumn");')
expect(sql2).to.equal('CREATE INDEX "z_index" ON "x_table" ("y_name") INCLUDE ("some_other_column");')
})
})
})