core-services-sdk 1.3.53 → 1.3.55
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
CHANGED
|
@@ -6,19 +6,35 @@ import { connectToPg } from './connect-to-pg.js'
|
|
|
6
6
|
* Checks all provided table names and collects any missing tables.
|
|
7
7
|
* Throws a single error listing all missing tables after validation completes.
|
|
8
8
|
*
|
|
9
|
-
* @param {
|
|
9
|
+
* @param {Object} params
|
|
10
|
+
* Parameters object.
|
|
11
|
+
*
|
|
12
|
+
* @param {string|Object} params.connection
|
|
10
13
|
* Database connection configuration.
|
|
11
14
|
* Can be a database connection URI or a Knex connection object.
|
|
12
15
|
*
|
|
13
|
-
* @param {string[]} tables
|
|
16
|
+
* @param {string[]} params.tables
|
|
14
17
|
* List of required table names to validate.
|
|
15
18
|
*
|
|
19
|
+
* @param {Object} [params.log]
|
|
20
|
+
* Optional logger object.
|
|
21
|
+
*
|
|
22
|
+
* @param {Function} [params.log.info]
|
|
23
|
+
* Logger function for informational messages.
|
|
24
|
+
*
|
|
25
|
+
* @param {Function} [params.log.error]
|
|
26
|
+
* Logger function for error messages.
|
|
27
|
+
*
|
|
16
28
|
* @returns {Promise<void>}
|
|
17
29
|
*
|
|
18
30
|
* @throws {Error}
|
|
19
31
|
* Throws an error if one or more required tables are missing.
|
|
20
32
|
*/
|
|
21
|
-
export async function validateSchema(
|
|
33
|
+
export async function validateSchema({
|
|
34
|
+
tables,
|
|
35
|
+
connection,
|
|
36
|
+
log = { info: console.info },
|
|
37
|
+
}) {
|
|
22
38
|
const db = connectToPg(connection)
|
|
23
39
|
|
|
24
40
|
const missingTables = []
|
|
@@ -32,8 +48,11 @@ export async function validateSchema(connection, tables) {
|
|
|
32
48
|
|
|
33
49
|
if (missingTables.length > 0) {
|
|
34
50
|
throw new Error(
|
|
35
|
-
`Missing the following tables: ${missingTables.join(', ')}.
|
|
36
|
-
`Did you run migrations?`,
|
|
51
|
+
`Missing the following tables: ${missingTables.join(', ')}. Did you run migrations?`,
|
|
37
52
|
)
|
|
38
53
|
}
|
|
54
|
+
|
|
55
|
+
if (tables.length) {
|
|
56
|
+
log.info(`All required tables are exists: ${tables.join(', ')}`)
|
|
57
|
+
}
|
|
39
58
|
}
|
|
@@ -37,18 +37,26 @@ describe('validateSchema', () => {
|
|
|
37
37
|
})
|
|
38
38
|
|
|
39
39
|
it('does not throw when all required tables exist', async () => {
|
|
40
|
-
await expect(
|
|
40
|
+
await expect(
|
|
41
|
+
validateSchema({ connection: DATABASE_URI, tables: ['files'] }),
|
|
42
|
+
).resolves.not.toThrow()
|
|
41
43
|
})
|
|
42
44
|
|
|
43
45
|
it('throws a single error listing missing tables', async () => {
|
|
44
46
|
await expect(
|
|
45
|
-
validateSchema(
|
|
47
|
+
validateSchema({
|
|
48
|
+
connection: DATABASE_URI,
|
|
49
|
+
tables: ['files', 'documents', 'attachments'],
|
|
50
|
+
}),
|
|
46
51
|
).rejects.toThrow('Missing the following tables: documents, attachments')
|
|
47
52
|
})
|
|
48
53
|
|
|
49
54
|
it('throws when all tables are missing', async () => {
|
|
50
55
|
await expect(
|
|
51
|
-
validateSchema(
|
|
56
|
+
validateSchema({
|
|
57
|
+
connection: DATABASE_URI,
|
|
58
|
+
tables: ['missing_a', 'missing_b'],
|
|
59
|
+
}),
|
|
52
60
|
).rejects.toThrow('Missing the following tables: missing_a, missing_b')
|
|
53
61
|
})
|
|
54
62
|
})
|
|
@@ -4,19 +4,39 @@
|
|
|
4
4
|
* Checks all provided table names and collects any missing tables.
|
|
5
5
|
* Throws a single error listing all missing tables after validation completes.
|
|
6
6
|
*
|
|
7
|
-
* @param {
|
|
7
|
+
* @param {Object} params
|
|
8
|
+
* Parameters object.
|
|
9
|
+
*
|
|
10
|
+
* @param {string|Object} params.connection
|
|
8
11
|
* Database connection configuration.
|
|
9
12
|
* Can be a database connection URI or a Knex connection object.
|
|
10
13
|
*
|
|
11
|
-
* @param {string[]} tables
|
|
14
|
+
* @param {string[]} params.tables
|
|
12
15
|
* List of required table names to validate.
|
|
13
16
|
*
|
|
17
|
+
* @param {Object} [params.log]
|
|
18
|
+
* Optional logger object.
|
|
19
|
+
*
|
|
20
|
+
* @param {Function} [params.log.info]
|
|
21
|
+
* Logger function for informational messages.
|
|
22
|
+
*
|
|
23
|
+
* @param {Function} [params.log.error]
|
|
24
|
+
* Logger function for error messages.
|
|
25
|
+
*
|
|
14
26
|
* @returns {Promise<void>}
|
|
15
27
|
*
|
|
16
28
|
* @throws {Error}
|
|
17
29
|
* Throws an error if one or more required tables are missing.
|
|
18
30
|
*/
|
|
19
|
-
export function validateSchema(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
31
|
+
export function validateSchema({
|
|
32
|
+
tables,
|
|
33
|
+
connection,
|
|
34
|
+
log,
|
|
35
|
+
}: {
|
|
36
|
+
connection: string | any
|
|
37
|
+
tables: string[]
|
|
38
|
+
log?: {
|
|
39
|
+
info?: Function
|
|
40
|
+
error?: Function
|
|
41
|
+
}
|
|
42
|
+
}): Promise<void>
|