Skip to content

Commit 3fd9fd4

Browse files
authored
Add support for local dbs in config (#1751)
1 parent f485671 commit 3fd9fd4

File tree

8 files changed

+196
-9
lines changed

8 files changed

+196
-9
lines changed

extensions/ql-vscode/src/databases/db-config-store.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ export class DbConfigStore extends DisposableObject {
9999
repositoryLists: [],
100100
owners: [],
101101
repositories: [],
102-
}
102+
},
103+
local: {
104+
lists: [],
105+
databases: [],
106+
},
103107
};
104108
}
105109
}

extensions/ql-vscode/src/databases/db-config.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
export interface DbConfig {
44
remote: RemoteDbConfig;
5+
local: LocalDbConfig;
56
}
67

78
export interface RemoteDbConfig {
@@ -15,6 +16,23 @@ export interface RemoteRepositoryList {
1516
repositories: string[];
1617
}
1718

19+
export interface LocalDbConfig {
20+
lists: LocalList[];
21+
databases: LocalDatabase[];
22+
}
23+
24+
export interface LocalList {
25+
name: string;
26+
databases: LocalDatabase[];
27+
}
28+
29+
export interface LocalDatabase {
30+
name: string;
31+
dateAdded: number;
32+
language: string;
33+
storagePath: string;
34+
}
35+
1836
export function cloneDbConfig(config: DbConfig): DbConfig {
1937
return {
2038
remote: {
@@ -24,6 +42,13 @@ export function cloneDbConfig(config: DbConfig): DbConfig {
2442
})),
2543
owners: [...config.remote.owners],
2644
repositories: [...config.remote.repositories],
27-
}
45+
},
46+
local: {
47+
lists: config.local.lists.map((list) => ({
48+
name: list.name,
49+
databases: list.databases.map((db) => ({ ...db })),
50+
})),
51+
databases: config.local.databases.map((db) => ({ ...db })),
52+
},
2853
};
2954
}

extensions/ql-vscode/src/vscode-tests/minimal-workspace/databases/db-panel.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ describe('db panel', async () => {
5858
owners: [],
5959
repositories: []
6060
},
61+
local: {
62+
lists: [],
63+
databases: []
64+
},
6165
};
6266

6367
await saveDbConfig(dbConfig);
@@ -116,6 +120,10 @@ describe('db panel', async () => {
116120
owners: [],
117121
repositories: []
118122
},
123+
local: {
124+
lists: [],
125+
databases: []
126+
},
119127
};
120128

121129
await saveDbConfig(dbConfig);
@@ -148,6 +156,10 @@ describe('db panel', async () => {
148156
owners: ['owner1', 'owner2'],
149157
repositories: []
150158
},
159+
local: {
160+
lists: [],
161+
databases: []
162+
},
151163
};
152164

153165
await saveDbConfig(dbConfig);
@@ -177,6 +189,10 @@ describe('db panel', async () => {
177189
owners: [],
178190
repositories: ['owner1/repo1', 'owner1/repo2']
179191
},
192+
local: {
193+
lists: [],
194+
databases: []
195+
},
180196
};
181197

182198
await saveDbConfig(dbConfig);

extensions/ql-vscode/test/pure-tests/databases/data/workspace-databases.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,39 @@
88
],
99
"owners": [],
1010
"repositories": ["owner/repo1", "owner/repo2", "owner/repo3"]
11+
},
12+
"local": {
13+
"lists": [
14+
{
15+
"name": "localList1",
16+
"databases": [
17+
{
18+
"name": "foo/bar",
19+
"dateAdded": 1668096745193,
20+
"language": "go",
21+
"storagePath": "/path/to/database/"
22+
}
23+
]
24+
},
25+
{
26+
"name": "localList2",
27+
"databases": [
28+
{
29+
"name": "foo/baz",
30+
"dateAdded": 1668096760848,
31+
"language": "javascript",
32+
"storagePath": "/path/to/database/"
33+
}
34+
]
35+
}
36+
],
37+
"databases": [
38+
{
39+
"name": "example-db",
40+
"dateAdded": 1668096927267,
41+
"language": "ruby",
42+
"storagePath": "/path/to/database/"
43+
}
44+
]
1145
}
1246
}

extensions/ql-vscode/test/pure-tests/databases/db-config-store.test.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ describe('db config store', async () => {
2727
expect(config.remote.repositoryLists).to.be.empty;
2828
expect(config.remote.owners).to.be.empty;
2929
expect(config.remote.repositories).to.be.empty;
30+
expect(config.local.lists).to.be.empty;
31+
expect(config.local.databases).to.be.empty;
3032
});
3133

3234
it('should load an existing config', async () => {
@@ -36,12 +38,35 @@ describe('db config store', async () => {
3638
const config = configStore.getConfig().value;
3739
expect(config.remote.repositoryLists).to.have.length(1);
3840
expect(config.remote.repositoryLists[0]).to.deep.equal({
39-
'name': 'repoList1',
40-
'repositories': ['foo/bar', 'foo/baz']
41+
name: 'repoList1',
42+
repositories: ['foo/bar', 'foo/baz']
4143
});
4244
expect(config.remote.owners).to.be.empty;
4345
expect(config.remote.repositories).to.have.length(3);
44-
expect(config.remote.repositories).to.deep.equal(['owner/repo1', 'owner/repo2', 'owner/repo3']);
46+
expect(config.remote.repositories).to.deep.equal([
47+
'owner/repo1',
48+
'owner/repo2',
49+
'owner/repo3',
50+
]);
51+
expect(config.local.lists).to.have.length(2);
52+
expect(config.local.lists[0]).to.deep.equal({
53+
name: 'localList1',
54+
databases: [
55+
{
56+
name: 'foo/bar',
57+
dateAdded: 1668096745193,
58+
language: 'go',
59+
storagePath: '/path/to/database/',
60+
},
61+
],
62+
});
63+
expect(config.local.databases).to.have.length(1);
64+
expect(config.local.databases[0]).to.deep.equal({
65+
name: 'example-db',
66+
dateAdded: 1668096927267,
67+
language: 'ruby',
68+
storagePath: '/path/to/database/',
69+
});
4570
});
4671

4772
it('should not allow modification of the config', async () => {

extensions/ql-vscode/test/pure-tests/databases/db-config-validator.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ describe('db config validation', async () => {
2525

2626
const validationOutput = configValidator.validate(dbConfig);
2727

28-
expect(validationOutput).to.have.length(2);
28+
expect(validationOutput).to.have.length(3);
2929

30-
expect(validationOutput[0]).to.deep.equal('/remote must have required property \'owners\'');
31-
expect(validationOutput[1]).to.deep.equal('/remote must NOT have additional properties');
30+
expect(validationOutput[0]).to.deep.equal(' must have required property \'local\'');
31+
expect(validationOutput[1]).to.deep.equal('/remote must have required property \'owners\'');
32+
expect(validationOutput[2]).to.deep.equal('/remote must NOT have additional properties');
3233
});
3334
});

extensions/ql-vscode/test/pure-tests/databases/db-tree-creator.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ describe('db tree creator', () => {
1212
repositoryLists: [],
1313
owners: [],
1414
repositories: []
15+
},
16+
local: {
17+
lists: [],
18+
databases: []
1519
}
1620
};
1721

@@ -63,6 +67,10 @@ describe('db tree creator', () => {
6367
],
6468
owners: [],
6569
repositories: []
70+
},
71+
local: {
72+
lists: [],
73+
databases: []
6674
}
6775
};
6876

@@ -102,6 +110,10 @@ describe('db tree creator', () => {
102110
'owner2'
103111
],
104112
repositories: []
113+
},
114+
local: {
115+
lists: [],
116+
databases: []
105117
}
106118
};
107119

@@ -134,6 +146,10 @@ describe('db tree creator', () => {
134146
'owner1/repo2',
135147
'owner2/repo1'
136148
]
149+
},
150+
local: {
151+
lists: [],
152+
databases: []
137153
}
138154
};
139155

extensions/ql-vscode/workspace-databases-schema.json

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,72 @@
4444
},
4545
"required": ["repositoryLists", "owners", "repositories"],
4646
"additionalProperties": false
47+
},
48+
"local": {
49+
"type": "object",
50+
"properties": {
51+
"lists": {
52+
"type": "array",
53+
"items": {
54+
"type": "object",
55+
"properties": {
56+
"name": {
57+
"type": "string"
58+
},
59+
"databases": {
60+
"type": "array",
61+
"items": {
62+
"type": "object",
63+
"properties": {
64+
"name": {
65+
"type": "string"
66+
},
67+
"dateAdded": {
68+
"type": "number"
69+
},
70+
"language": {
71+
"type": "string"
72+
},
73+
"storagePath": {
74+
"type": "string"
75+
}
76+
},
77+
"required": ["name", "dateAdded", "language", "storagePath"],
78+
"additionalProperties": false
79+
}
80+
}
81+
},
82+
"required": ["name", "databases"],
83+
"additionalProperties": false
84+
}
85+
},
86+
"databases": {
87+
"type": "array",
88+
"items": {
89+
"type": "object",
90+
"properties": {
91+
"name": {
92+
"type": "string"
93+
},
94+
"dateAdded": {
95+
"type": "number"
96+
},
97+
"language": {
98+
"type": "string"
99+
},
100+
"storagePath": {
101+
"type": "string"
102+
}
103+
},
104+
"required": ["name", "dateAdded", "language", "storagePath"],
105+
"additionalProperties": false
106+
}
107+
}
108+
},
109+
"required": ["lists", "databases"],
110+
"additionalProperties": false
47111
}
48-
}
112+
},
113+
"required": ["remote", "local"],
114+
"additionalProperties": false
49115
}

0 commit comments

Comments
 (0)