@dbos-inc/typeorm-datasource 4.26.5-preview → 4.26.6-preview
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 +1 -1
- package/tests/usersuppliedds.test.ts +24 -4
package/package.json
CHANGED
|
@@ -7,6 +7,7 @@ import { DataSource } from 'typeorm';
|
|
|
7
7
|
import { TypeOrmDataSource } from '..';
|
|
8
8
|
|
|
9
9
|
import { DBOS } from '@dbos-inc/dbos-sdk';
|
|
10
|
+
import { Client } from 'pg';
|
|
10
11
|
import { ensurePGDatabase } from '../../../dist/src/database_utils';
|
|
11
12
|
|
|
12
13
|
const config = { user: process.env.PGUSER || 'postgres', database: 'typeorm_ds_test_datasource' };
|
|
@@ -51,12 +52,31 @@ const workflow = DBOS.registerWorkflow(
|
|
|
51
52
|
{ name: 'testTypeOrm' },
|
|
52
53
|
);
|
|
53
54
|
|
|
55
|
+
// ensurePGDatabase swallows every failure, so verify the postcondition and fail with the reason.
|
|
56
|
+
async function ensureTestDatabase(databaseUrl: string) {
|
|
57
|
+
const notes: string[] = [];
|
|
58
|
+
const record = (msg: string) => {
|
|
59
|
+
notes.push(msg);
|
|
60
|
+
};
|
|
61
|
+
await ensurePGDatabase(databaseUrl, { info: record, warn: record });
|
|
62
|
+
const client = new Client({ connectionString: databaseUrl });
|
|
63
|
+
try {
|
|
64
|
+
await client.connect();
|
|
65
|
+
// CockroachDB connects to a nonexistent database, so hit a catalog that requires it to exist.
|
|
66
|
+
await client.query('SELECT 1 FROM information_schema.schemata LIMIT 1');
|
|
67
|
+
} catch (e) {
|
|
68
|
+
const why = notes.length ? ` [${notes.join('; ')}]` : '';
|
|
69
|
+
throw new Error(`Could not provision the test database: ${(e as Error).message}${why}`);
|
|
70
|
+
} finally {
|
|
71
|
+
await client.end().catch(() => {});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
54
75
|
describe('TypeOrmDataSourceDemo', () => {
|
|
55
76
|
beforeEach(async () => {
|
|
56
|
-
await
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
});
|
|
77
|
+
await ensureTestDatabase(
|
|
78
|
+
`postgresql://${config.user}:${process.env['PGPASSWORD'] || 'dbos'}@${process.env['PGHOST'] || 'localhost'}:${process.env['PGPORT'] || '5432'}/typeorm_demo_ds`,
|
|
79
|
+
);
|
|
60
80
|
await TypeOrmDataSource.initializeDBOSSchema(config);
|
|
61
81
|
await AppDataSource.initialize();
|
|
62
82
|
|