forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgrade_downgrade_test.js
80 lines (68 loc) · 2.52 KB
/
upgrade_downgrade_test.js
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
const assert = require('assert').strict;
const testing = require('taskcluster-lib-testing');
const tcdb = require('taskcluster-db');
const helper = require('./helper');
suite(testing.suiteName(), function() {
helper.withDbForVersion();
const schema = tcdb.schema({ useDbDirectory: true });
const latestVersion = schema.latestVersion();
// upgrade and downgrade *twice*, to detect any issues where the downgrade leaves
// resources in place that later conflict with the upgrade. Note that these tests
// are inter-dependent.
const assertEmptySchema = async () => {
await helper.withDbClient(async client => {
const tables = await client.query(`
select * from pg_catalog.pg_tables
where schemaname = 'public'
and tablename != 'tcversion'
`);
assert.deepEqual(tables.rows, []);
const sequences = await client.query(`
select * from pg_catalog.pg_sequences
where schemaname = 'public'
`);
assert.deepEqual(sequences.rows, []);
const indexes = await client.query(`
select * from pg_catalog.pg_indexes
where schemaname = 'public'
`);
assert.deepEqual(indexes.rows, []);
// note that stored functions might remain -- that's expected
});
};
const assertNoPermissions = async () => {
await helper.withDbClient(async client => {
const res = await client.query(`
select grantee, table_name, privilege_type
from information_schema.table_privileges
where table_schema = 'public'
and grantee like $1 || '\\_%'
and table_catalog = current_catalog
and table_name != 'tcversion'
union
select grantee, table_name, privilege_type
from information_schema.column_privileges
where table_schema = 'public'
and grantee like $1 || '\\_%'
and table_catalog = current_catalog
and table_name != 'tcversion'`, ['test']);
assert.deepEqual(res.rows, []);
});
};
test('upgrade to latest version', async function() {
await helper.upgradeTo(latestVersion.version);
});
test('downgrade to version 0', async function() {
await helper.downgradeTo(0);
await assertEmptySchema();
await assertNoPermissions();
});
test('upgrade to latest version again', async function() {
await helper.upgradeTo(latestVersion.version);
});
test('downgrade to version 0', async function() {
await helper.downgradeTo(0);
await assertEmptySchema();
await assertNoPermissions();
});
});