@aws/nx-plugin 1.0.0-rc.15 → 1.0.0-rc.16
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/src/ts/rdb/__snapshots__/generator.spec.ts.snap +74 -322
- package/src/ts/rdb/files/config.json.template +14 -0
- package/src/ts/rdb/files/prisma.config.ts.template +5 -4
- package/src/ts/rdb/files/src/index.ts.template +0 -1
- package/src/ts/rdb/files/src/prisma.ts.template +26 -21
- package/src/ts/rdb/generator.d.ts +0 -4
- package/src/ts/rdb/generator.js +15 -7
- package/src/ts/rdb/generator.js.map +1 -1
- package/src/utils/files/common/scripts/src/rdb/pull-image.ts.template +16 -0
- package/src/utils/files/common/scripts/src/rdb/start-container.ts.template +102 -0
- package/src/utils/files/common/scripts/src/rdb/wait-for-db.ts.template +59 -0
- package/src/utils/rdb-constructs/files/cdk/app/dbs/__nameKebabCase__.ts.template +12 -2
- package/src/utils/rdb-constructs/files/terraform/app/dbs/__nameKebabCase__/__nameKebabCase__.tf.template +6 -4
- package/src/utils/rdb-constructs/rdb-constructs.d.ts +1 -0
- package/src/utils/rdb-constructs/rdb-constructs.js.map +1 -1
- package/src/utils/shared-rdb-scripts.d.ts +11 -0
- package/src/utils/shared-rdb-scripts.js +20 -0
- package/src/utils/shared-rdb-scripts.js.map +1 -0
- package/src/ts/rdb/files/scripts/pull-image.ts.template +0 -15
- package/src/ts/rdb/files/scripts/start-container.ts.template +0 -84
- package/src/ts/rdb/files/scripts/wait-for-db.ts.template +0 -55
- package/src/ts/rdb/files/src/constants.ts.template +0 -8
package/package.json
CHANGED
|
@@ -22,137 +22,6 @@ datasource db {
|
|
|
22
22
|
"
|
|
23
23
|
`;
|
|
24
24
|
|
|
25
|
-
exports[`ts#rdb generator > should add mysql prisma dependencies when engine is MySQL > packages/db/scripts/pull-image.ts 1`] = `
|
|
26
|
-
"import { spawnSync } from 'child_process';
|
|
27
|
-
|
|
28
|
-
const ENGINE = 'docker';
|
|
29
|
-
const image = process.argv[2];
|
|
30
|
-
|
|
31
|
-
const inspect = spawnSync(ENGINE, ['image', 'inspect', image], {
|
|
32
|
-
stdio: 'ignore',
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
if (inspect.status !== 0) {
|
|
36
|
-
const pull = spawnSync(ENGINE, ['pull', image], { stdio: 'inherit' });
|
|
37
|
-
if (pull.status !== 0) {
|
|
38
|
-
process.exit(pull.status ?? 1);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
"
|
|
42
|
-
`;
|
|
43
|
-
|
|
44
|
-
exports[`ts#rdb generator > should add mysql prisma dependencies when engine is MySQL > packages/db/scripts/start-container.ts 1`] = `
|
|
45
|
-
"import { spawn, spawnSync } from 'child_process';
|
|
46
|
-
|
|
47
|
-
const ENGINE = 'docker';
|
|
48
|
-
|
|
49
|
-
const [containerName, image, hostPort, dbName, dbPassword] =
|
|
50
|
-
process.argv.slice(2);
|
|
51
|
-
|
|
52
|
-
const containerExists = (): boolean =>
|
|
53
|
-
spawnSync(ENGINE, ['container', 'inspect', containerName], {
|
|
54
|
-
stdio: 'ignore',
|
|
55
|
-
}).status === 0;
|
|
56
|
-
|
|
57
|
-
const isRunning = (): boolean => {
|
|
58
|
-
const result = spawnSync(
|
|
59
|
-
ENGINE,
|
|
60
|
-
['container', 'inspect', '-f', '{{.State.Running}}', containerName],
|
|
61
|
-
{ encoding: 'utf-8' },
|
|
62
|
-
);
|
|
63
|
-
return result.status === 0 && result.stdout.trim() === 'true';
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
if (containerExists()) {
|
|
67
|
-
if (!isRunning()) {
|
|
68
|
-
const start = spawnSync(ENGINE, ['start', containerName], {
|
|
69
|
-
stdio: 'inherit',
|
|
70
|
-
});
|
|
71
|
-
if (start.status !== 0) process.exit(start.status ?? 1);
|
|
72
|
-
}
|
|
73
|
-
} else {
|
|
74
|
-
const runArgs = (
|
|
75
|
-
\`run --rm --name \${containerName}\` +
|
|
76
|
-
\` -e MYSQL_DATABASE=\${dbName}\` +
|
|
77
|
-
\` -e MYSQL_ROOT_PASSWORD=\${dbPassword}\` +
|
|
78
|
-
\` -p \${hostPort}:3306\` +
|
|
79
|
-
\` -v \${containerName}-data:/var/lib/mysql\` +
|
|
80
|
-
\` -d \${image}\`
|
|
81
|
-
).split(' ');
|
|
82
|
-
const create = spawnSync(ENGINE, runArgs, { stdio: 'inherit' });
|
|
83
|
-
if (create.status !== 0) process.exit(create.status ?? 1);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const logs = spawn(ENGINE, ['logs', '-f', containerName], {
|
|
87
|
-
stdio: ['ignore', 'inherit', 'inherit'],
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
let exiting = false;
|
|
91
|
-
|
|
92
|
-
const cleanup = () => {
|
|
93
|
-
if (exiting) return;
|
|
94
|
-
exiting = true;
|
|
95
|
-
spawnSync(ENGINE, ['stop', containerName], { stdio: 'ignore' });
|
|
96
|
-
logs.kill();
|
|
97
|
-
process.exit(0);
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
process.on('SIGTERM', cleanup);
|
|
101
|
-
process.on('SIGINT', cleanup);
|
|
102
|
-
process.on('SIGHUP', cleanup);
|
|
103
|
-
|
|
104
|
-
logs.on('exit', (code) => {
|
|
105
|
-
if (!exiting) process.exit(code ?? 0);
|
|
106
|
-
});
|
|
107
|
-
"
|
|
108
|
-
`;
|
|
109
|
-
|
|
110
|
-
exports[`ts#rdb generator > should add mysql prisma dependencies when engine is MySQL > packages/db/scripts/wait-for-db.ts 1`] = `
|
|
111
|
-
"import { createConnection, Connection } from 'mariadb';
|
|
112
|
-
|
|
113
|
-
const noop = () => undefined;
|
|
114
|
-
|
|
115
|
-
const [portArg, dbArg, userArg, passwordArg] = process.argv.slice(2);
|
|
116
|
-
const timeoutAt = Date.now() + 60000;
|
|
117
|
-
|
|
118
|
-
while (Date.now() < timeoutAt) {
|
|
119
|
-
let conn: Connection | undefined;
|
|
120
|
-
try {
|
|
121
|
-
conn = await createConnection({
|
|
122
|
-
host: 'localhost',
|
|
123
|
-
port: parseInt(portArg),
|
|
124
|
-
user: userArg,
|
|
125
|
-
password: passwordArg,
|
|
126
|
-
database: dbArg,
|
|
127
|
-
connectTimeout: 500,
|
|
128
|
-
allowPublicKeyRetrieval: true,
|
|
129
|
-
});
|
|
130
|
-
await conn.end();
|
|
131
|
-
console.log('Database is ready.');
|
|
132
|
-
process.exit(0);
|
|
133
|
-
} catch {
|
|
134
|
-
console.log('Database is not ready.');
|
|
135
|
-
await conn?.end().catch(noop);
|
|
136
|
-
}
|
|
137
|
-
await new Promise((r) => setTimeout(r, 200));
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
throw new Error(\`Timed out waiting for mysql on port \${portArg}\`);
|
|
141
|
-
"
|
|
142
|
-
`;
|
|
143
|
-
|
|
144
|
-
exports[`ts#rdb generator > should add mysql prisma dependencies when engine is MySQL > packages/db/src/constants.ts 1`] = `
|
|
145
|
-
"export const DB_PACKAGE_NAME = 'Db';
|
|
146
|
-
|
|
147
|
-
// Local development connection details (used when SERVE_LOCAL=true, see serve-local Nx target)
|
|
148
|
-
export const LOCAL_DB_PORT = 3306;
|
|
149
|
-
export const LOCAL_DB_HOST = 'localhost';
|
|
150
|
-
export const LOCAL_DB_NAME = 'database_name';
|
|
151
|
-
export const LOCAL_DB_USER = 'root';
|
|
152
|
-
export const LOCAL_DB_PASSWORD = 'password';
|
|
153
|
-
"
|
|
154
|
-
`;
|
|
155
|
-
|
|
156
25
|
exports[`ts#rdb generator > should add mysql prisma dependencies when engine is MySQL > packages/db/src/create-db-user-handler.ts 1`] = `
|
|
157
26
|
"import type { CloudFormationCustomResourceEvent } from 'aws-lambda';
|
|
158
27
|
import { randomBytes } from 'node:crypto';
|
|
@@ -230,8 +99,7 @@ export const handler = async (
|
|
|
230
99
|
`;
|
|
231
100
|
|
|
232
101
|
exports[`ts#rdb generator > should add mysql prisma dependencies when engine is MySQL > packages/db/src/index.ts 1`] = `
|
|
233
|
-
"export {
|
|
234
|
-
export { getPrisma } from './prisma.js';
|
|
102
|
+
"export { getPrisma } from './prisma.js';
|
|
235
103
|
"
|
|
236
104
|
`;
|
|
237
105
|
|
|
@@ -270,26 +138,31 @@ exports[`ts#rdb generator > should add mysql prisma dependencies when engine is
|
|
|
270
138
|
"import { PrismaMariaDb } from '@prisma/adapter-mariadb';
|
|
271
139
|
import { Signer } from '@aws-sdk/rds-signer';
|
|
272
140
|
import { Prisma, PrismaClient } from '../generated/prisma/client.js';
|
|
273
|
-
import {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
LOCAL_DB_NAME,
|
|
277
|
-
LOCAL_DB_PASSWORD,
|
|
278
|
-
LOCAL_DB_PORT,
|
|
279
|
-
LOCAL_DB_USER,
|
|
280
|
-
} from './constants.js';
|
|
141
|
+
import { readFileSync } from 'fs';
|
|
142
|
+
import { join, dirname } from 'path';
|
|
143
|
+
import { fileURLToPath } from 'url';
|
|
281
144
|
import { getDatabaseConfig } from './utils.js';
|
|
282
145
|
|
|
146
|
+
// Generated: must match runtimeConfigKey in config.json
|
|
147
|
+
const runtimeConfigKey = 'Db';
|
|
148
|
+
|
|
149
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
150
|
+
// config.json is only present in local dev (not included in the deployed bundle); guard with SERVE_LOCAL check
|
|
151
|
+
const serveLocal = () =>
|
|
152
|
+
JSON.parse(readFileSync(join(__dirname, '../config.json'), 'utf-8'))
|
|
153
|
+
.serveLocal;
|
|
154
|
+
|
|
283
155
|
export const getPrisma = async <LogOpts extends Prisma.LogLevel>(
|
|
284
156
|
log: LogOpts[] = ['warn', 'error'] as LogOpts[],
|
|
285
157
|
): Promise<PrismaClient<LogOpts>> => {
|
|
286
158
|
if (process.env.SERVE_LOCAL === 'true') {
|
|
159
|
+
const { host, port, dbName, dbUser, dbPassword } = serveLocal();
|
|
287
160
|
const adapter = new PrismaMariaDb({
|
|
288
|
-
host
|
|
289
|
-
port
|
|
290
|
-
database:
|
|
291
|
-
user:
|
|
292
|
-
password:
|
|
161
|
+
host,
|
|
162
|
+
port,
|
|
163
|
+
database: dbName,
|
|
164
|
+
user: dbUser,
|
|
165
|
+
password: dbPassword,
|
|
293
166
|
allowPublicKeyRetrieval: true,
|
|
294
167
|
});
|
|
295
168
|
return new PrismaClient({
|
|
@@ -299,7 +172,7 @@ export const getPrisma = async <LogOpts extends Prisma.LogLevel>(
|
|
|
299
172
|
}
|
|
300
173
|
|
|
301
174
|
const { hostname, port, database, dbUser, region } =
|
|
302
|
-
await getDatabaseConfig(
|
|
175
|
+
await getDatabaseConfig(runtimeConfigKey);
|
|
303
176
|
const iamAuthToken = await new Signer({
|
|
304
177
|
hostname,
|
|
305
178
|
port,
|
|
@@ -896,17 +769,14 @@ export abstract class AuroraDatabase extends Construct {
|
|
|
896
769
|
|
|
897
770
|
exports[`ts#rdb generator > should add mysql prisma dependencies when engine is MySQL 2`] = `
|
|
898
771
|
"import { defineConfig } from 'prisma/config';
|
|
772
|
+
import { readFileSync } from 'fs';
|
|
899
773
|
|
|
900
774
|
const getDatabaseUrl = async () => {
|
|
901
775
|
if (process.env.SERVE_LOCAL === 'true') {
|
|
902
|
-
const {
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
LOCAL_DB_PORT,
|
|
907
|
-
LOCAL_DB_USER,
|
|
908
|
-
} = await import('./src/constants.js');
|
|
909
|
-
return \`mysql://\${LOCAL_DB_USER}:\${LOCAL_DB_PASSWORD}@\${LOCAL_DB_HOST}:\${LOCAL_DB_PORT}/\${LOCAL_DB_NAME}\`;
|
|
776
|
+
const { host, port, dbName, dbUser, dbPassword } = JSON.parse(
|
|
777
|
+
readFileSync('config.json', 'utf-8'),
|
|
778
|
+
).serveLocal;
|
|
779
|
+
return \`mysql://\${dbUser}:\${dbPassword}@\${host}:\${port}/\${dbName}\`;
|
|
910
780
|
}
|
|
911
781
|
return process.env.DATABASE_URL;
|
|
912
782
|
};
|
|
@@ -1822,10 +1692,12 @@ resource "random_string" "suffix" {
|
|
|
1822
1692
|
}
|
|
1823
1693
|
|
|
1824
1694
|
locals {
|
|
1825
|
-
|
|
1826
|
-
|
|
1695
|
+
config = jsondecode(file("\${path.module}/../../../../../../../packages/db/config.json"))
|
|
1696
|
+
runtime_config_key = local.config.runtimeConfigKey
|
|
1697
|
+
create_db_user_bundle_path = "\${path.module}/../../../../../../../dist/packages/db/bundle/create-db-user"
|
|
1698
|
+
migration_function_name = "db-migration-\${random_string.suffix.result}"
|
|
1827
1699
|
create_db_user_function_name = "db-create-db-user-\${random_string.suffix.result}"
|
|
1828
|
-
database_runtime_user
|
|
1700
|
+
database_runtime_user = "db_\${random_string.suffix.result}"
|
|
1829
1701
|
}
|
|
1830
1702
|
|
|
1831
1703
|
module "aurora" {
|
|
@@ -1891,7 +1763,7 @@ module "add_rdb_to_runtime_config" {
|
|
|
1891
1763
|
source = "../../../core/runtime-config/entry"
|
|
1892
1764
|
|
|
1893
1765
|
namespace = "database"
|
|
1894
|
-
key =
|
|
1766
|
+
key = local.runtime_config_key
|
|
1895
1767
|
value = {
|
|
1896
1768
|
hostname = module.aurora.cluster_endpoint
|
|
1897
1769
|
port = module.aurora.cluster_port
|
|
@@ -3281,10 +3153,12 @@ resource "random_string" "suffix" {
|
|
|
3281
3153
|
}
|
|
3282
3154
|
|
|
3283
3155
|
locals {
|
|
3284
|
-
|
|
3285
|
-
|
|
3156
|
+
config = jsondecode(file("\${path.module}/../../../../../../../packages/db/config.json"))
|
|
3157
|
+
runtime_config_key = local.config.runtimeConfigKey
|
|
3158
|
+
create_db_user_bundle_path = "\${path.module}/../../../../../../../dist/packages/db/bundle/create-db-user"
|
|
3159
|
+
migration_function_name = "db-migration-\${random_string.suffix.result}"
|
|
3286
3160
|
create_db_user_function_name = "db-create-db-user-\${random_string.suffix.result}"
|
|
3287
|
-
database_runtime_user
|
|
3161
|
+
database_runtime_user = "db_\${random_string.suffix.result}"
|
|
3288
3162
|
}
|
|
3289
3163
|
|
|
3290
3164
|
module "aurora" {
|
|
@@ -3350,7 +3224,7 @@ module "add_rdb_to_runtime_config" {
|
|
|
3350
3224
|
source = "../../../core/runtime-config/entry"
|
|
3351
3225
|
|
|
3352
3226
|
namespace = "database"
|
|
3353
|
-
key =
|
|
3227
|
+
key = local.runtime_config_key
|
|
3354
3228
|
value = {
|
|
3355
3229
|
hostname = module.aurora.cluster_endpoint
|
|
3356
3230
|
port = module.aurora.cluster_port
|
|
@@ -3864,139 +3738,6 @@ datasource db {
|
|
|
3864
3738
|
"
|
|
3865
3739
|
`;
|
|
3866
3740
|
|
|
3867
|
-
exports[`ts#rdb generator > should generate the aurora shared construct > packages/db/scripts/pull-image.ts 1`] = `
|
|
3868
|
-
"import { spawnSync } from 'child_process';
|
|
3869
|
-
|
|
3870
|
-
const ENGINE = 'docker';
|
|
3871
|
-
const image = process.argv[2];
|
|
3872
|
-
|
|
3873
|
-
const inspect = spawnSync(ENGINE, ['image', 'inspect', image], {
|
|
3874
|
-
stdio: 'ignore',
|
|
3875
|
-
});
|
|
3876
|
-
|
|
3877
|
-
if (inspect.status !== 0) {
|
|
3878
|
-
const pull = spawnSync(ENGINE, ['pull', image], { stdio: 'inherit' });
|
|
3879
|
-
if (pull.status !== 0) {
|
|
3880
|
-
process.exit(pull.status ?? 1);
|
|
3881
|
-
}
|
|
3882
|
-
}
|
|
3883
|
-
"
|
|
3884
|
-
`;
|
|
3885
|
-
|
|
3886
|
-
exports[`ts#rdb generator > should generate the aurora shared construct > packages/db/scripts/start-container.ts 1`] = `
|
|
3887
|
-
"import { spawn, spawnSync } from 'child_process';
|
|
3888
|
-
|
|
3889
|
-
const ENGINE = 'docker';
|
|
3890
|
-
|
|
3891
|
-
const [containerName, image, hostPort, dbName, dbUser, dbPassword] =
|
|
3892
|
-
process.argv.slice(2);
|
|
3893
|
-
|
|
3894
|
-
const containerExists = (): boolean =>
|
|
3895
|
-
spawnSync(ENGINE, ['container', 'inspect', containerName], {
|
|
3896
|
-
stdio: 'ignore',
|
|
3897
|
-
}).status === 0;
|
|
3898
|
-
|
|
3899
|
-
const isRunning = (): boolean => {
|
|
3900
|
-
const result = spawnSync(
|
|
3901
|
-
ENGINE,
|
|
3902
|
-
['container', 'inspect', '-f', '{{.State.Running}}', containerName],
|
|
3903
|
-
{ encoding: 'utf-8' },
|
|
3904
|
-
);
|
|
3905
|
-
return result.status === 0 && result.stdout.trim() === 'true';
|
|
3906
|
-
};
|
|
3907
|
-
|
|
3908
|
-
if (containerExists()) {
|
|
3909
|
-
if (!isRunning()) {
|
|
3910
|
-
const start = spawnSync(ENGINE, ['start', containerName], {
|
|
3911
|
-
stdio: 'inherit',
|
|
3912
|
-
});
|
|
3913
|
-
if (start.status !== 0) process.exit(start.status ?? 1);
|
|
3914
|
-
}
|
|
3915
|
-
} else {
|
|
3916
|
-
const runArgs = (
|
|
3917
|
-
\`run --rm --name \${containerName}\` +
|
|
3918
|
-
\` -e POSTGRES_DB=\${dbName}\` +
|
|
3919
|
-
\` -e POSTGRES_USER=\${dbUser}\` +
|
|
3920
|
-
\` -e POSTGRES_PASSWORD=\${dbPassword}\` +
|
|
3921
|
-
\` -e PGDATA=/var/lib/postgresql/17/docker\` +
|
|
3922
|
-
\` -p \${hostPort}:5432\` +
|
|
3923
|
-
\` -v \${containerName}-data:/var/lib/postgresql\` +
|
|
3924
|
-
\` -d \${image}\`
|
|
3925
|
-
).split(' ');
|
|
3926
|
-
const create = spawnSync(ENGINE, runArgs, { stdio: 'inherit' });
|
|
3927
|
-
if (create.status !== 0) process.exit(create.status ?? 1);
|
|
3928
|
-
}
|
|
3929
|
-
|
|
3930
|
-
const logs = spawn(ENGINE, ['logs', '-f', containerName], {
|
|
3931
|
-
stdio: ['ignore', 'inherit', 'inherit'],
|
|
3932
|
-
});
|
|
3933
|
-
|
|
3934
|
-
let exiting = false;
|
|
3935
|
-
|
|
3936
|
-
const cleanup = () => {
|
|
3937
|
-
if (exiting) return;
|
|
3938
|
-
exiting = true;
|
|
3939
|
-
spawnSync(ENGINE, ['stop', containerName], { stdio: 'ignore' });
|
|
3940
|
-
logs.kill();
|
|
3941
|
-
process.exit(0);
|
|
3942
|
-
};
|
|
3943
|
-
|
|
3944
|
-
process.on('SIGTERM', cleanup);
|
|
3945
|
-
process.on('SIGINT', cleanup);
|
|
3946
|
-
process.on('SIGHUP', cleanup);
|
|
3947
|
-
|
|
3948
|
-
logs.on('exit', (code) => {
|
|
3949
|
-
if (!exiting) process.exit(code ?? 0);
|
|
3950
|
-
});
|
|
3951
|
-
"
|
|
3952
|
-
`;
|
|
3953
|
-
|
|
3954
|
-
exports[`ts#rdb generator > should generate the aurora shared construct > packages/db/scripts/wait-for-db.ts 1`] = `
|
|
3955
|
-
"import { Client } from 'pg';
|
|
3956
|
-
|
|
3957
|
-
const noop = () => undefined;
|
|
3958
|
-
|
|
3959
|
-
const [portArg, dbArg, userArg, passwordArg] = process.argv.slice(2);
|
|
3960
|
-
const timeoutAt = Date.now() + 60000;
|
|
3961
|
-
|
|
3962
|
-
while (Date.now() < timeoutAt) {
|
|
3963
|
-
const client = new Client({
|
|
3964
|
-
host: 'localhost',
|
|
3965
|
-
port: parseInt(portArg),
|
|
3966
|
-
user: userArg,
|
|
3967
|
-
password: passwordArg,
|
|
3968
|
-
database: dbArg,
|
|
3969
|
-
connectionTimeoutMillis: 500,
|
|
3970
|
-
});
|
|
3971
|
-
client.on('error', noop);
|
|
3972
|
-
try {
|
|
3973
|
-
await client.connect();
|
|
3974
|
-
await client.end();
|
|
3975
|
-
console.log('Database is ready.');
|
|
3976
|
-
process.exit(0);
|
|
3977
|
-
} catch {
|
|
3978
|
-
console.log('Database is not ready.');
|
|
3979
|
-
await client.end().catch(noop);
|
|
3980
|
-
}
|
|
3981
|
-
await new Promise((r) => setTimeout(r, 200));
|
|
3982
|
-
}
|
|
3983
|
-
|
|
3984
|
-
throw new Error(\`Timed out waiting for postgres on port \${portArg}\`);
|
|
3985
|
-
"
|
|
3986
|
-
`;
|
|
3987
|
-
|
|
3988
|
-
exports[`ts#rdb generator > should generate the aurora shared construct > packages/db/src/constants.ts 1`] = `
|
|
3989
|
-
"export const DB_PACKAGE_NAME = 'Db';
|
|
3990
|
-
|
|
3991
|
-
// Local development connection details (used when SERVE_LOCAL=true, see serve-local Nx target)
|
|
3992
|
-
export const LOCAL_DB_PORT = 5432;
|
|
3993
|
-
export const LOCAL_DB_HOST = 'localhost';
|
|
3994
|
-
export const LOCAL_DB_NAME = 'database_name';
|
|
3995
|
-
export const LOCAL_DB_USER = 'dbadmin';
|
|
3996
|
-
export const LOCAL_DB_PASSWORD = 'password';
|
|
3997
|
-
"
|
|
3998
|
-
`;
|
|
3999
|
-
|
|
4000
3741
|
exports[`ts#rdb generator > should generate the aurora shared construct > packages/db/src/create-db-user-handler.ts 1`] = `
|
|
4001
3742
|
"import type { CloudFormationCustomResourceEvent } from 'aws-lambda';
|
|
4002
3743
|
import { randomBytes } from 'node:crypto';
|
|
@@ -4088,8 +3829,7 @@ export const handler = async (
|
|
|
4088
3829
|
`;
|
|
4089
3830
|
|
|
4090
3831
|
exports[`ts#rdb generator > should generate the aurora shared construct > packages/db/src/index.ts 1`] = `
|
|
4091
|
-
"export {
|
|
4092
|
-
export { getPrisma } from './prisma.js';
|
|
3832
|
+
"export { getPrisma } from './prisma.js';
|
|
4093
3833
|
"
|
|
4094
3834
|
`;
|
|
4095
3835
|
|
|
@@ -4141,16 +3881,20 @@ exports[`ts#rdb generator > should generate the aurora shared construct > packag
|
|
|
4141
3881
|
import { Signer } from '@aws-sdk/rds-signer';
|
|
4142
3882
|
import { Prisma, PrismaClient } from '../generated/prisma/client.js';
|
|
4143
3883
|
import { Pool } from 'pg';
|
|
4144
|
-
import {
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
LOCAL_DB_NAME,
|
|
4148
|
-
LOCAL_DB_PASSWORD,
|
|
4149
|
-
LOCAL_DB_PORT,
|
|
4150
|
-
LOCAL_DB_USER,
|
|
4151
|
-
} from './constants.js';
|
|
3884
|
+
import { readFileSync } from 'fs';
|
|
3885
|
+
import { join, dirname } from 'path';
|
|
3886
|
+
import { fileURLToPath } from 'url';
|
|
4152
3887
|
import { getDatabaseConfig } from './utils.js';
|
|
4153
3888
|
|
|
3889
|
+
// Generated: must match runtimeConfigKey in config.json
|
|
3890
|
+
const runtimeConfigKey = 'Db';
|
|
3891
|
+
|
|
3892
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
3893
|
+
// config.json is only present in local dev (not included in the deployed bundle); guard with SERVE_LOCAL check
|
|
3894
|
+
const serveLocal = () =>
|
|
3895
|
+
JSON.parse(readFileSync(join(__dirname, '../config.json'), 'utf-8'))
|
|
3896
|
+
.serveLocal;
|
|
3897
|
+
|
|
4154
3898
|
let prismaClient: PrismaClient<Prisma.LogLevel> | undefined;
|
|
4155
3899
|
|
|
4156
3900
|
export const getPrisma = async <LogOpts extends Prisma.LogLevel>(
|
|
@@ -4159,13 +3903,14 @@ export const getPrisma = async <LogOpts extends Prisma.LogLevel>(
|
|
|
4159
3903
|
if (prismaClient) return prismaClient;
|
|
4160
3904
|
|
|
4161
3905
|
if (process.env.SERVE_LOCAL === 'true') {
|
|
3906
|
+
const { host, port, dbName, dbUser, dbPassword } = serveLocal();
|
|
4162
3907
|
const adapter = new PrismaPg(
|
|
4163
3908
|
new Pool({
|
|
4164
|
-
host
|
|
4165
|
-
port
|
|
4166
|
-
database:
|
|
4167
|
-
user:
|
|
4168
|
-
password:
|
|
3909
|
+
host,
|
|
3910
|
+
port,
|
|
3911
|
+
database: dbName,
|
|
3912
|
+
user: dbUser,
|
|
3913
|
+
password: dbPassword,
|
|
4169
3914
|
allowExitOnIdle: true,
|
|
4170
3915
|
}),
|
|
4171
3916
|
);
|
|
@@ -4177,7 +3922,7 @@ export const getPrisma = async <LogOpts extends Prisma.LogLevel>(
|
|
|
4177
3922
|
}
|
|
4178
3923
|
|
|
4179
3924
|
const { hostname, port, database, dbUser, region } =
|
|
4180
|
-
await getDatabaseConfig(
|
|
3925
|
+
await getDatabaseConfig(runtimeConfigKey);
|
|
4181
3926
|
const adapter = new PrismaPg(
|
|
4182
3927
|
new Pool({
|
|
4183
3928
|
host: hostname,
|
|
@@ -4780,8 +4525,8 @@ export abstract class AuroraDatabase extends Construct {
|
|
|
4780
4525
|
exports[`ts#rdb generator > should generate the aurora shared construct 2`] = `
|
|
4781
4526
|
"import * as path from 'path';
|
|
4782
4527
|
import * as url from 'url';
|
|
4528
|
+
import { readFileSync } from 'fs';
|
|
4783
4529
|
import { Construct } from 'constructs';
|
|
4784
|
-
import { DB_PACKAGE_NAME } from ':proj/db';
|
|
4785
4530
|
import {
|
|
4786
4531
|
AuroraDatabase,
|
|
4787
4532
|
AuroraDatabaseEngines,
|
|
@@ -4789,6 +4534,16 @@ import {
|
|
|
4789
4534
|
} from '../../core/rdb/aurora.js';
|
|
4790
4535
|
import { findWorkspaceRoot } from '../../core/workspace.js';
|
|
4791
4536
|
|
|
4537
|
+
const { runtimeConfigKey } = JSON.parse(
|
|
4538
|
+
readFileSync(
|
|
4539
|
+
path.join(
|
|
4540
|
+
findWorkspaceRoot(url.fileURLToPath(new URL(import.meta.url))),
|
|
4541
|
+
'packages/db/config.json',
|
|
4542
|
+
),
|
|
4543
|
+
'utf-8',
|
|
4544
|
+
),
|
|
4545
|
+
) as { runtimeConfigKey: string };
|
|
4546
|
+
|
|
4792
4547
|
export type DbProps = Omit<
|
|
4793
4548
|
AuroraDatabaseProps,
|
|
4794
4549
|
| 'databaseName'
|
|
@@ -4808,7 +4563,7 @@ export class Db extends AuroraDatabase {
|
|
|
4808
4563
|
...props,
|
|
4809
4564
|
databaseName: 'database_name',
|
|
4810
4565
|
adminUser: 'databaseUser',
|
|
4811
|
-
runtimeConfigKey
|
|
4566
|
+
runtimeConfigKey,
|
|
4812
4567
|
migrationBundleDir: path.join(
|
|
4813
4568
|
findWorkspaceRoot(url.fileURLToPath(new URL(import.meta.url))),
|
|
4814
4569
|
'dist/packages/db/bundle/migration',
|
|
@@ -4826,17 +4581,14 @@ export class Db extends AuroraDatabase {
|
|
|
4826
4581
|
|
|
4827
4582
|
exports[`ts#rdb generator > should generate the aurora shared construct 3`] = `
|
|
4828
4583
|
"import { defineConfig } from 'prisma/config';
|
|
4584
|
+
import { readFileSync } from 'fs';
|
|
4829
4585
|
|
|
4830
4586
|
const getDatabaseUrl = async () => {
|
|
4831
4587
|
if (process.env.SERVE_LOCAL === 'true') {
|
|
4832
|
-
const {
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
LOCAL_DB_PORT,
|
|
4837
|
-
LOCAL_DB_USER,
|
|
4838
|
-
} = await import('./src/constants.js');
|
|
4839
|
-
return \`postgresql://\${LOCAL_DB_USER}:\${LOCAL_DB_PASSWORD}@\${LOCAL_DB_HOST}:\${LOCAL_DB_PORT}/\${LOCAL_DB_NAME}\`;
|
|
4588
|
+
const { host, port, dbName, dbUser, dbPassword } = JSON.parse(
|
|
4589
|
+
readFileSync('config.json', 'utf-8'),
|
|
4590
|
+
).serveLocal;
|
|
4591
|
+
return \`postgresql://\${dbUser}:\${dbPassword}@\${host}:\${port}/\${dbName}\`;
|
|
4840
4592
|
}
|
|
4841
4593
|
return process.env.DATABASE_URL;
|
|
4842
4594
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"runtimeConfigKey": "<%= runtimeConfigKey %>",
|
|
3
|
+
"serveLocal": {
|
|
4
|
+
"containerEngine": "<%= containerEngine %>",
|
|
5
|
+
"containerName": "<%= containerName %>",
|
|
6
|
+
"image": "<%= dockerImage %>",
|
|
7
|
+
"port": <%= localDbPort %>,
|
|
8
|
+
"host": "<%= localDbHost %>",
|
|
9
|
+
"dbName": "<%= localDbName %>",
|
|
10
|
+
"dbUser": "<%= localDbUser %>",
|
|
11
|
+
"dbPassword": "<%= localDbPassword %>",
|
|
12
|
+
"dbEngine": "<%= engine %>"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { defineConfig } from 'prisma/config';
|
|
2
|
+
import { readFileSync } from 'fs';
|
|
2
3
|
|
|
3
4
|
const getDatabaseUrl = async () => {
|
|
4
5
|
if (process.env.SERVE_LOCAL === 'true') {
|
|
5
|
-
const {
|
|
6
|
-
|
|
6
|
+
const { host, port, dbName, dbUser, dbPassword } =
|
|
7
|
+
JSON.parse(readFileSync('config.json', 'utf-8')).serveLocal;
|
|
7
8
|
<%_ if (engine === 'mysql') { _%>
|
|
8
|
-
return `mysql://${
|
|
9
|
+
return `mysql://${dbUser}:${dbPassword}@${host}:${port}/${dbName}`;
|
|
9
10
|
<%_ } else { _%>
|
|
10
|
-
return `postgresql://${
|
|
11
|
+
return `postgresql://${dbUser}:${dbPassword}@${host}:${port}/${dbName}`;
|
|
11
12
|
<%_ } _%>
|
|
12
13
|
}
|
|
13
14
|
return process.env.DATABASE_URL;
|
|
@@ -4,27 +4,31 @@ import { Prisma, PrismaClient } from '../generated/prisma/client.js';
|
|
|
4
4
|
<%_ if (engine === 'postgres') { _%>
|
|
5
5
|
import { Pool } from 'pg';
|
|
6
6
|
<%_ } _%>
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
LOCAL_DB_NAME,
|
|
11
|
-
LOCAL_DB_PASSWORD,
|
|
12
|
-
LOCAL_DB_PORT,
|
|
13
|
-
LOCAL_DB_USER,
|
|
14
|
-
} from './constants.js';
|
|
7
|
+
import { readFileSync } from 'fs';
|
|
8
|
+
import { join, dirname } from 'path';
|
|
9
|
+
import { fileURLToPath } from 'url';
|
|
15
10
|
import { getDatabaseConfig } from './utils.js';
|
|
16
|
-
<%_ if (engine === 'mysql') { _%>
|
|
17
11
|
|
|
12
|
+
// Generated: must match runtimeConfigKey in config.json
|
|
13
|
+
const runtimeConfigKey = '<%= runtimeConfigKey %>';
|
|
14
|
+
|
|
15
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
// config.json is only present in local dev (not included in the deployed bundle); guard with SERVE_LOCAL check
|
|
17
|
+
const serveLocal = () =>
|
|
18
|
+
JSON.parse(readFileSync(join(__dirname, '../config.json'), 'utf-8')).serveLocal;
|
|
19
|
+
|
|
20
|
+
<%_ if (engine === 'mysql') { _%>
|
|
18
21
|
export const getPrisma = async <LogOpts extends Prisma.LogLevel>(
|
|
19
22
|
log: LogOpts[] = ['warn', 'error'] as LogOpts[],
|
|
20
23
|
): Promise<PrismaClient<LogOpts>> => {
|
|
21
24
|
if (process.env.SERVE_LOCAL === 'true') {
|
|
25
|
+
const { host, port, dbName, dbUser, dbPassword } = serveLocal();
|
|
22
26
|
const adapter = new PrismaMariaDb({
|
|
23
|
-
host
|
|
24
|
-
port
|
|
25
|
-
database:
|
|
26
|
-
user:
|
|
27
|
-
password:
|
|
27
|
+
host,
|
|
28
|
+
port,
|
|
29
|
+
database: dbName,
|
|
30
|
+
user: dbUser,
|
|
31
|
+
password: dbPassword,
|
|
28
32
|
allowPublicKeyRetrieval: true,
|
|
29
33
|
});
|
|
30
34
|
return new PrismaClient({
|
|
@@ -34,7 +38,7 @@ export const getPrisma = async <LogOpts extends Prisma.LogLevel>(
|
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
const { hostname, port, database, dbUser, region } =
|
|
37
|
-
await getDatabaseConfig(
|
|
41
|
+
await getDatabaseConfig(runtimeConfigKey);
|
|
38
42
|
const iamAuthToken = await new Signer({
|
|
39
43
|
hostname,
|
|
40
44
|
port,
|
|
@@ -68,13 +72,14 @@ export const getPrisma = async <LogOpts extends Prisma.LogLevel>(
|
|
|
68
72
|
if (prismaClient) return prismaClient;
|
|
69
73
|
|
|
70
74
|
if (process.env.SERVE_LOCAL === 'true') {
|
|
75
|
+
const { host, port, dbName, dbUser, dbPassword } = serveLocal();
|
|
71
76
|
const adapter = new PrismaPg(
|
|
72
77
|
new Pool({
|
|
73
|
-
host
|
|
74
|
-
port
|
|
75
|
-
database:
|
|
76
|
-
user:
|
|
77
|
-
password:
|
|
78
|
+
host,
|
|
79
|
+
port,
|
|
80
|
+
database: dbName,
|
|
81
|
+
user: dbUser,
|
|
82
|
+
password: dbPassword,
|
|
78
83
|
allowExitOnIdle: true,
|
|
79
84
|
}),
|
|
80
85
|
);
|
|
@@ -86,7 +91,7 @@ export const getPrisma = async <LogOpts extends Prisma.LogLevel>(
|
|
|
86
91
|
}
|
|
87
92
|
|
|
88
93
|
const { hostname, port, database, dbUser, region } =
|
|
89
|
-
await getDatabaseConfig(
|
|
94
|
+
await getDatabaseConfig(runtimeConfigKey);
|
|
90
95
|
const adapter = new PrismaPg(
|
|
91
96
|
new Pool({
|
|
92
97
|
host: hostname,
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
1
|
import { type GeneratorCallback, type Tree } from '@nx/devkit';
|
|
6
2
|
import { type NxGeneratorInfo } from '../../utils/nx';
|
|
7
3
|
import type { TsRdbGeneratorSchema } from './schema';
|
package/src/ts/rdb/generator.js
CHANGED
|
@@ -6,6 +6,7 @@ const tslib_1 = require("tslib");
|
|
|
6
6
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
7
7
|
* SPDX-License-Identifier: Apache-2.0
|
|
8
8
|
*/
|
|
9
|
+
const node_path_1 = require("node:path");
|
|
9
10
|
const devkit_1 = require("@nx/devkit");
|
|
10
11
|
const bundle_1 = require("../../utils/bundle/bundle");
|
|
11
12
|
const containers_1 = require("../../utils/containers");
|
|
@@ -22,6 +23,8 @@ const pnpm_workspace_1 = require("../../utils/pnpm-workspace");
|
|
|
22
23
|
const port_1 = require("../../utils/port");
|
|
23
24
|
const rdb_constructs_1 = require("../../utils/rdb-constructs/rdb-constructs");
|
|
24
25
|
const shared_constructs_1 = require("../../utils/shared-constructs");
|
|
26
|
+
const shared_constructs_constants_1 = require("../../utils/shared-constructs-constants");
|
|
27
|
+
const shared_rdb_scripts_1 = require("../../utils/shared-rdb-scripts");
|
|
25
28
|
const versions_1 = require("../../utils/versions");
|
|
26
29
|
const generator_1 = tslib_1.__importStar(require("../lib/generator"));
|
|
27
30
|
exports.TS_RDB_GENERATOR_INFO = (0, nx_1.getGeneratorInfo)(__filename);
|
|
@@ -59,6 +62,10 @@ const tsRdbGenerator = async (tree, options) => {
|
|
|
59
62
|
const localDbHost = 'localhost';
|
|
60
63
|
const localDbUser = options.engine === 'mysql' ? 'root' : 'dbadmin';
|
|
61
64
|
const localDbPassword = 'password';
|
|
65
|
+
const containerName = `${(0, npm_scope_1.getNpmScope)(tree)}-${databaseName}`;
|
|
66
|
+
const dockerImage = options.engine === 'mysql'
|
|
67
|
+
? 'public.ecr.aws/docker/library/mysql:8.0.44'
|
|
68
|
+
: 'public.ecr.aws/docker/library/postgres:17.7';
|
|
62
69
|
const templateOptions = {
|
|
63
70
|
engine: options.engine,
|
|
64
71
|
runtimeConfigKey: nameClassName,
|
|
@@ -75,9 +82,13 @@ const tsRdbGenerator = async (tree, options) => {
|
|
|
75
82
|
localDbUser,
|
|
76
83
|
localDbPassword,
|
|
77
84
|
containerEngine,
|
|
85
|
+
containerName,
|
|
86
|
+
dockerImage,
|
|
78
87
|
};
|
|
79
88
|
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files'), dir, templateOptions);
|
|
80
89
|
(0, git_1.updateGitIgnore)(tree, dir, (patterns) => [...patterns, 'generated/prisma']);
|
|
90
|
+
await (0, shared_rdb_scripts_1.sharedRdbScriptsGenerator)(tree);
|
|
91
|
+
const scriptsDir = (0, node_path_1.relative)(dir, (0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.SHARED_SCRIPTS_DIR, 'src', 'rdb'));
|
|
81
92
|
const relativePathToRoot = (0, paths_1.getRelativePathToRootByDirectory)(projectConfig.root);
|
|
82
93
|
const fs = new fs_1.FsCommands(tree);
|
|
83
94
|
const migrationBundleDir = (0, devkit_1.joinPathFragments)('dist', projectConfig.root, 'bundle', 'migration');
|
|
@@ -120,21 +131,17 @@ const tsRdbGenerator = async (tree, options) => {
|
|
|
120
131
|
cwd: '{projectRoot}',
|
|
121
132
|
},
|
|
122
133
|
};
|
|
123
|
-
const containerName = `${(0, npm_scope_1.getNpmScope)(tree)}-${databaseName}`;
|
|
124
|
-
const dockerImage = options.engine === 'mysql'
|
|
125
|
-
? 'public.ecr.aws/docker/library/mysql:8.0.44'
|
|
126
|
-
: 'public.ecr.aws/docker/library/postgres:17.7';
|
|
127
134
|
projectConfig.targets['pull-image'] = {
|
|
128
135
|
executor: 'nx:run-commands',
|
|
129
136
|
options: {
|
|
130
|
-
command: `tsx
|
|
137
|
+
command: `tsx ${scriptsDir}/pull-image.ts`,
|
|
131
138
|
cwd: '{projectRoot}',
|
|
132
139
|
},
|
|
133
140
|
};
|
|
134
141
|
projectConfig.targets['serve-local'] = {
|
|
135
142
|
executor: 'nx:run-commands',
|
|
136
143
|
options: {
|
|
137
|
-
command: `tsx
|
|
144
|
+
command: `tsx ${scriptsDir}/start-container.ts`,
|
|
138
145
|
cwd: '{projectRoot}',
|
|
139
146
|
},
|
|
140
147
|
continuous: true,
|
|
@@ -144,7 +151,7 @@ const tsRdbGenerator = async (tree, options) => {
|
|
|
144
151
|
executor: 'nx:run-commands',
|
|
145
152
|
dependsOn: ['serve-local'],
|
|
146
153
|
options: {
|
|
147
|
-
command: `tsx
|
|
154
|
+
command: `tsx ${scriptsDir}/wait-for-db.ts`,
|
|
148
155
|
cwd: '{projectRoot}',
|
|
149
156
|
},
|
|
150
157
|
};
|
|
@@ -185,6 +192,7 @@ const tsRdbGenerator = async (tree, options) => {
|
|
|
185
192
|
await (0, rdb_constructs_1.addRdbInfra)(tree, {
|
|
186
193
|
iac,
|
|
187
194
|
projectName: fullyQualifiedName,
|
|
195
|
+
projectRoot: dir,
|
|
188
196
|
nameClassName,
|
|
189
197
|
nameKebabCase,
|
|
190
198
|
databasePackageAlias: (0, npm_scope_1.toScopeAlias)(fullyQualifiedName),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/ts/rdb/generator.ts"],"names":[],"mappings":";;;;AAAA;;;GAGG;AACH,uCAUoB;AACpB,sDAAsE;AACtE,uDAA2D;AAC3D,+CAA0D;AAC1D,uCAA4C;AAC5C,yCAAkD;AAClD,yCAA6C;AAC7C,iDAAsE;AACtE,6CAAsE;AACtE,qDAAkE;AAClE,uCAKwB;AACxB,6CAAqE;AACrE,+DAA2E;AAC3E,2CAA8C;AAC9C,8EAAwE;AACxE,qEAA0E;AAC1E,mDAAiE;AACjE,sEAAuE;AAG1D,QAAA,qBAAqB,GAChC,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;AAExB,MAAM,cAAc,GAAG,KAAK,EACjC,IAAU,EACV,OAA6B,EACD,EAAE;IAC9B,MAAM,aAAa,GAAG,IAAA,iBAAS,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,MAAM,aAAa,GAAG,IAAA,mBAAW,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,SAAS,CAAC;IACvD,MAAM,YAAY,GAAG,IAAA,iBAAS,EAAC,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACrE,MAAM,eAAe,GAAG,MAAM,IAAA,8BAAiB,EAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACjE,MAAM,EAAE,kBAAkB,EAAE,GAAG,EAAE,GAAG,IAAA,2BAAe,EAAC,IAAI,EAAE;QACxD,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,YAAY,EAAE,OAAO,CAAC,YAAY;KACnC,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AiC;QACjC,qBAAqB;QACrB,gBAAgB;QAChB,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,OAAO;YAC5B,CAAC,CAAE,CAAC,yBAAyB,EAAE,SAAS,CAAW;YACnD,CAAC,CAAE,CAAC,oBAAoB,EAAE,IAAI,CAAW,CAAC;KAC7C,CAAC,EACF,IAAA,uBAAY,EAAC;QACX,QAAQ;QACR,KAAK;QACL,mBAAmB;QACnB,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,OAAO;YAC5B,CAAC,CAAE,EAAY;YACf,CAAC,CAAE,CAAC,WAAW,CAAW,CAAC;KAC9B,CAAC,CACH,CAAC;IAEF,IAAA,8CAA6B,EAAC,IAAI,EAAE;QAClC,iBAAiB,EAAE,KAAK;QACxB,MAAM,EAAE,KAAK;KACd,CAAC,CAAC;IAEH,MAAM,IAAA,yCAA+B,EAAC,IAAI,EAAE,CAAC,6BAAqB,CAAC,CAAC,CAAC;IAErE,MAAM,IAAA,6BAAoB,EAAC,IAAI,CAAC,CAAC;IACjC,OAAO,GAAG,EAAE;QACV,IAAA,4BAAmB,EAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC,CAAC;AAlQW,QAAA,cAAc,kBAkQzB;AAEF,kBAAe,sBAAc,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { spawnSync } from 'child_process';
|
|
2
|
+
import { readFileSync } from 'fs';
|
|
3
|
+
|
|
4
|
+
const { containerEngine, image } =
|
|
5
|
+
JSON.parse(readFileSync('config.json', 'utf-8')).serveLocal;
|
|
6
|
+
|
|
7
|
+
const inspect = spawnSync(containerEngine, ['image', 'inspect', image], {
|
|
8
|
+
stdio: 'ignore',
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
if (inspect.status !== 0) {
|
|
12
|
+
const pull = spawnSync(containerEngine, ['pull', image], { stdio: 'inherit' });
|
|
13
|
+
if (pull.status !== 0) {
|
|
14
|
+
process.exit(pull.status ?? 1);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { spawn, spawnSync } from "child_process";
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
containerEngine,
|
|
6
|
+
containerName,
|
|
7
|
+
image,
|
|
8
|
+
port,
|
|
9
|
+
dbName,
|
|
10
|
+
dbUser,
|
|
11
|
+
dbPassword,
|
|
12
|
+
dbEngine,
|
|
13
|
+
} = JSON.parse(readFileSync("config.json", "utf-8")).serveLocal;
|
|
14
|
+
|
|
15
|
+
const containerExists = (): boolean =>
|
|
16
|
+
spawnSync(containerEngine, ["container", "inspect", containerName], {
|
|
17
|
+
stdio: "ignore",
|
|
18
|
+
}).status === 0;
|
|
19
|
+
|
|
20
|
+
const isRunning = (): boolean => {
|
|
21
|
+
const result = spawnSync(
|
|
22
|
+
containerEngine,
|
|
23
|
+
["container", "inspect", "-f", "{{.State.Running}}", containerName],
|
|
24
|
+
{ encoding: "utf-8" },
|
|
25
|
+
);
|
|
26
|
+
return result.status === 0 && result.stdout.trim() === "true";
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
if (containerExists()) {
|
|
30
|
+
if (!isRunning()) {
|
|
31
|
+
const start = spawnSync(containerEngine, ["start", containerName], {
|
|
32
|
+
stdio: "inherit",
|
|
33
|
+
});
|
|
34
|
+
if (start.status !== 0) process.exit(start.status ?? 1);
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
const engineArgs =
|
|
38
|
+
dbEngine === "mysql"
|
|
39
|
+
? [
|
|
40
|
+
"-v",
|
|
41
|
+
`${containerName}-data:/var/lib/mysql`,
|
|
42
|
+
"-e",
|
|
43
|
+
`MYSQL_DATABASE=${dbName}`,
|
|
44
|
+
"-e",
|
|
45
|
+
`MYSQL_ROOT_PASSWORD=${dbPassword}`,
|
|
46
|
+
"-p",
|
|
47
|
+
`${port}:3306`,
|
|
48
|
+
]
|
|
49
|
+
: [
|
|
50
|
+
"-v",
|
|
51
|
+
`${containerName}-data:/var/lib/postgresql`,
|
|
52
|
+
"-e",
|
|
53
|
+
`POSTGRES_DB=${dbName}`,
|
|
54
|
+
"-e",
|
|
55
|
+
`POSTGRES_USER=${dbUser}`,
|
|
56
|
+
"-e",
|
|
57
|
+
`POSTGRES_PASSWORD=${dbPassword}`,
|
|
58
|
+
"-e",
|
|
59
|
+
"PGDATA=/var/lib/postgresql/17/docker",
|
|
60
|
+
"-p",
|
|
61
|
+
`${port}:5432`,
|
|
62
|
+
];
|
|
63
|
+
const runArgs = [
|
|
64
|
+
"run",
|
|
65
|
+
...(containerEngine === "docker" ? ["--rm"] : []),
|
|
66
|
+
"--name",
|
|
67
|
+
containerName,
|
|
68
|
+
"-d",
|
|
69
|
+
...engineArgs,
|
|
70
|
+
image,
|
|
71
|
+
];
|
|
72
|
+
const create = spawnSync(containerEngine, runArgs, { stdio: "inherit" });
|
|
73
|
+
if (create.status !== 0) process.exit(create.status ?? 1);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const logs = spawn(containerEngine, ["logs", "-f", containerName], {
|
|
77
|
+
stdio: ["ignore", "inherit", "inherit"],
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
let exiting = false;
|
|
81
|
+
|
|
82
|
+
const cleanup = () => {
|
|
83
|
+
if (exiting) return;
|
|
84
|
+
exiting = true;
|
|
85
|
+
if (containerEngine === "docker") {
|
|
86
|
+
spawnSync(containerEngine, ["stop", containerName], { stdio: "ignore" });
|
|
87
|
+
} else {
|
|
88
|
+
spawnSync(containerEngine, ["rm", "-f", containerName], {
|
|
89
|
+
stdio: "ignore",
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
logs.kill();
|
|
93
|
+
process.exit(0);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
process.on("SIGTERM", cleanup);
|
|
97
|
+
process.on("SIGINT", cleanup);
|
|
98
|
+
process.on("SIGHUP", cleanup);
|
|
99
|
+
|
|
100
|
+
logs.on("exit", (code) => {
|
|
101
|
+
if (!exiting) process.exit(code ?? 0);
|
|
102
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
|
|
3
|
+
const { port, dbName, dbUser, dbPassword, dbEngine } =
|
|
4
|
+
JSON.parse(readFileSync('config.json', 'utf-8')).serveLocal;
|
|
5
|
+
|
|
6
|
+
const noop = () => undefined;
|
|
7
|
+
const timeoutAt = Date.now() + 60000;
|
|
8
|
+
|
|
9
|
+
if (dbEngine === 'mysql') {
|
|
10
|
+
// @ts-ignore - mariadb is only installed for mysql engine
|
|
11
|
+
const { createConnection } = await import('mariadb');
|
|
12
|
+
while (Date.now() < timeoutAt) {
|
|
13
|
+
let conn: Awaited<ReturnType<typeof createConnection>> | undefined;
|
|
14
|
+
try {
|
|
15
|
+
conn = await createConnection({
|
|
16
|
+
host: 'localhost',
|
|
17
|
+
port: parseInt(port),
|
|
18
|
+
user: dbUser,
|
|
19
|
+
password: dbPassword,
|
|
20
|
+
database: dbName,
|
|
21
|
+
connectTimeout: 500,
|
|
22
|
+
allowPublicKeyRetrieval: true,
|
|
23
|
+
});
|
|
24
|
+
await conn.end();
|
|
25
|
+
console.log('Database is ready.');
|
|
26
|
+
process.exit(0);
|
|
27
|
+
} catch {
|
|
28
|
+
console.log('Database is not ready.');
|
|
29
|
+
await conn?.end().catch(noop);
|
|
30
|
+
}
|
|
31
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
// @ts-ignore - pg is only installed for pg engine
|
|
35
|
+
const { Client } = await import('pg');
|
|
36
|
+
while (Date.now() < timeoutAt) {
|
|
37
|
+
const client = new Client({
|
|
38
|
+
host: 'localhost',
|
|
39
|
+
port: parseInt(port),
|
|
40
|
+
user: dbUser,
|
|
41
|
+
password: dbPassword,
|
|
42
|
+
database: dbName,
|
|
43
|
+
connectionTimeoutMillis: 500,
|
|
44
|
+
});
|
|
45
|
+
client.on('error', noop);
|
|
46
|
+
try {
|
|
47
|
+
await client.connect();
|
|
48
|
+
await client.end();
|
|
49
|
+
console.log('Database is ready.');
|
|
50
|
+
process.exit(0);
|
|
51
|
+
} catch {
|
|
52
|
+
console.log('Database is not ready.');
|
|
53
|
+
await client.end().catch(noop);
|
|
54
|
+
}
|
|
55
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
throw new Error(`Timed out waiting for ${dbEngine} on port ${port}`);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as path from 'path';
|
|
2
2
|
import * as url from 'url';
|
|
3
|
+
import { readFileSync } from 'fs';
|
|
3
4
|
import { Construct } from 'constructs';
|
|
4
|
-
import { DB_PACKAGE_NAME } from '<%= databasePackageAlias %>';
|
|
5
5
|
import {
|
|
6
6
|
AuroraDatabase,
|
|
7
7
|
AuroraDatabaseEngines,
|
|
@@ -9,6 +9,16 @@ import {
|
|
|
9
9
|
} from '../../core/rdb/aurora.js';
|
|
10
10
|
import { findWorkspaceRoot } from '../../core/workspace.js';
|
|
11
11
|
|
|
12
|
+
const { runtimeConfigKey } = JSON.parse(
|
|
13
|
+
readFileSync(
|
|
14
|
+
path.join(
|
|
15
|
+
findWorkspaceRoot(url.fileURLToPath(new URL(import.meta.url))),
|
|
16
|
+
'<%= projectRoot %>/config.json',
|
|
17
|
+
),
|
|
18
|
+
'utf-8',
|
|
19
|
+
),
|
|
20
|
+
) as { runtimeConfigKey: string };
|
|
21
|
+
|
|
12
22
|
export type <%= nameClassName %>Props = Omit<
|
|
13
23
|
AuroraDatabaseProps,
|
|
14
24
|
| 'databaseName'
|
|
@@ -28,7 +38,7 @@ export class <%= nameClassName %> extends AuroraDatabase {
|
|
|
28
38
|
...props,
|
|
29
39
|
databaseName: '<%= databaseName %>',
|
|
30
40
|
adminUser: '<%= adminUser %>',
|
|
31
|
-
runtimeConfigKey
|
|
41
|
+
runtimeConfigKey,
|
|
32
42
|
migrationBundleDir: path.join(
|
|
33
43
|
findWorkspaceRoot(url.fileURLToPath(new URL(import.meta.url))),
|
|
34
44
|
'<%- migrationBundleDir %>',
|
|
@@ -141,10 +141,12 @@ resource "random_string" "suffix" {
|
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
locals {
|
|
144
|
-
|
|
145
|
-
|
|
144
|
+
config = jsondecode(file("${path.module}/../../../../../../../<%= projectRoot %>/config.json"))
|
|
145
|
+
runtime_config_key = local.config.runtimeConfigKey
|
|
146
|
+
create_db_user_bundle_path = "${path.module}/../../../../../../../<%- createDbUserBundleDir %>"
|
|
147
|
+
migration_function_name = "<%= nameKebabCase %>-migration-${random_string.suffix.result}"
|
|
146
148
|
create_db_user_function_name = "<%= nameKebabCase %>-create-db-user-${random_string.suffix.result}"
|
|
147
|
-
database_runtime_user
|
|
149
|
+
database_runtime_user = "db_${random_string.suffix.result}"
|
|
148
150
|
}
|
|
149
151
|
|
|
150
152
|
module "aurora" {
|
|
@@ -210,7 +212,7 @@ module "add_rdb_to_runtime_config" {
|
|
|
210
212
|
source = "../../../core/runtime-config/entry"
|
|
211
213
|
|
|
212
214
|
namespace = "database"
|
|
213
|
-
key =
|
|
215
|
+
key = local.runtime_config_key
|
|
214
216
|
value = {
|
|
215
217
|
hostname = module.aurora.cluster_endpoint
|
|
216
218
|
port = module.aurora.cluster_port
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rdb-constructs.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/utils/rdb-constructs/rdb-constructs.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCAOoB;AACpB,gCAAuC;AAGvC,8BAA0D;AAC1D,gFAIwC;
|
|
1
|
+
{"version":3,"file":"rdb-constructs.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/utils/rdb-constructs/rdb-constructs.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCAOoB;AACp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IAAA,0BAAiB,EAAC,0CAAY,EAAE,kDAAoB,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,EAC1E,OAAO,EACP;QACE,iBAAiB,EAAE,0BAAiB,CAAC,YAAY;KAClD,CACF,CAAC;AACJ,CAAC,CAAC;AAvBW,QAAA,sBAAsB,0BAuBjC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { type Tree } from '@nx/devkit';
|
|
6
|
+
/**
|
|
7
|
+
* Ensures the shared scripts package exists and adds RDB local-dev scripts
|
|
8
|
+
* to packages/common/scripts/src/rdb/. Used by ts#rdb. Scripts read all
|
|
9
|
+
* config at runtime from config.json so a single set serves all database engines.
|
|
10
|
+
*/
|
|
11
|
+
export declare function sharedRdbScriptsGenerator(tree: Tree): Promise<void>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sharedRdbScriptsGenerator = sharedRdbScriptsGenerator;
|
|
4
|
+
/**
|
|
5
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
const devkit_1 = require("@nx/devkit");
|
|
9
|
+
const shared_constructs_constants_1 = require("./shared-constructs-constants");
|
|
10
|
+
const shared_scripts_1 = require("./shared-scripts");
|
|
11
|
+
/**
|
|
12
|
+
* Ensures the shared scripts package exists and adds RDB local-dev scripts
|
|
13
|
+
* to packages/common/scripts/src/rdb/. Used by ts#rdb. Scripts read all
|
|
14
|
+
* config at runtime from config.json so a single set serves all database engines.
|
|
15
|
+
*/
|
|
16
|
+
async function sharedRdbScriptsGenerator(tree) {
|
|
17
|
+
await (0, shared_scripts_1.ensureSharedScriptsProject)(tree);
|
|
18
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', shared_constructs_constants_1.SHARED_SCRIPTS_DIR, 'src', 'rdb'), (0, devkit_1.joinPathFragments)(shared_constructs_constants_1.PACKAGES_DIR, shared_constructs_constants_1.SHARED_SCRIPTS_DIR, 'src', 'rdb'), {}, { overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting });
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=shared-rdb-scripts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-rdb-scripts.js","sourceRoot":"","sources":["../../../../../packages/nx-plugin/src/utils/shared-rdb-scripts.ts"],"names":[],"mappings":";;AAqBA,8DAUC;AA/BD;;;GAGG;AACH,uCAKoB;AACpB,+EAGuC;AACvC,qDAA8D;AAE9D;;;;GAIG;AACI,KAAK,UAAU,yBAAyB,CAAC,IAAU;IACxD,MAAM,IAAA,2CAA0B,EAAC,IAAI,CAAC,CAAC;IAEvC,IAAA,sBAAa,EACX,IAAI,EACJ,IAAA,0BAAiB,EAAC,SAAS,EAAE,OAAO,EAAE,gDAAkB,EAAE,KAAK,EAAE,KAAK,CAAC,EACvE,IAAA,0BAAiB,EAAC,0CAAY,EAAE,gDAAkB,EAAE,KAAK,EAAE,KAAK,CAAC,EACjE,EAAE,EACF,EAAE,iBAAiB,EAAE,0BAAiB,CAAC,YAAY,EAAE,CACtD,CAAC;AACJ,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { spawnSync } from 'child_process';
|
|
2
|
-
|
|
3
|
-
const ENGINE = '<%= containerEngine %>';
|
|
4
|
-
const image = process.argv[2];
|
|
5
|
-
|
|
6
|
-
const inspect = spawnSync(ENGINE, ['image', 'inspect', image], {
|
|
7
|
-
stdio: 'ignore',
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
if (inspect.status !== 0) {
|
|
11
|
-
const pull = spawnSync(ENGINE, ['pull', image], { stdio: 'inherit' });
|
|
12
|
-
if (pull.status !== 0) {
|
|
13
|
-
process.exit(pull.status ?? 1);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { spawn, spawnSync } from 'child_process';
|
|
2
|
-
|
|
3
|
-
const ENGINE = '<%= containerEngine %>';
|
|
4
|
-
|
|
5
|
-
<%_ if (engine === 'mysql') { _%>
|
|
6
|
-
const [containerName, image, hostPort, dbName, dbPassword] =
|
|
7
|
-
process.argv.slice(2);
|
|
8
|
-
<%_ } else { _%>
|
|
9
|
-
const [containerName, image, hostPort, dbName, dbUser, dbPassword] =
|
|
10
|
-
process.argv.slice(2);
|
|
11
|
-
<%_ } _%>
|
|
12
|
-
|
|
13
|
-
const containerExists = (): boolean =>
|
|
14
|
-
spawnSync(ENGINE, ['container', 'inspect', containerName], {
|
|
15
|
-
stdio: 'ignore',
|
|
16
|
-
}).status === 0;
|
|
17
|
-
|
|
18
|
-
const isRunning = (): boolean => {
|
|
19
|
-
const result = spawnSync(
|
|
20
|
-
ENGINE,
|
|
21
|
-
['container', 'inspect', '-f', '{{.State.Running}}', containerName],
|
|
22
|
-
{ encoding: 'utf-8' },
|
|
23
|
-
);
|
|
24
|
-
return result.status === 0 && result.stdout.trim() === 'true';
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
if (containerExists()) {
|
|
28
|
-
if (!isRunning()) {
|
|
29
|
-
const start = spawnSync(ENGINE, ['start', containerName], {
|
|
30
|
-
stdio: 'inherit',
|
|
31
|
-
});
|
|
32
|
-
if (start.status !== 0) process.exit(start.status ?? 1);
|
|
33
|
-
}
|
|
34
|
-
} else {
|
|
35
|
-
<%_ if (engine === 'mysql') { _%>
|
|
36
|
-
const runArgs = (
|
|
37
|
-
`run <%- containerEngine === 'docker' ? '--rm ' : '' %>--name ${containerName}` +
|
|
38
|
-
` -e MYSQL_DATABASE=${dbName}` +
|
|
39
|
-
` -e MYSQL_ROOT_PASSWORD=${dbPassword}` +
|
|
40
|
-
` -p ${hostPort}:3306` +
|
|
41
|
-
` -v ${containerName}-data:/var/lib/mysql` +
|
|
42
|
-
` -d ${image}`
|
|
43
|
-
).split(' ');
|
|
44
|
-
<%_ } else { _%>
|
|
45
|
-
const runArgs = (
|
|
46
|
-
`run <%- containerEngine === 'docker' ? '--rm ' : '' %>--name ${containerName}` +
|
|
47
|
-
` -e POSTGRES_DB=${dbName}` +
|
|
48
|
-
` -e POSTGRES_USER=${dbUser}` +
|
|
49
|
-
` -e POSTGRES_PASSWORD=${dbPassword}` +
|
|
50
|
-
` -e PGDATA=/var/lib/postgresql/17/docker` +
|
|
51
|
-
` -p ${hostPort}:5432` +
|
|
52
|
-
` -v ${containerName}-data:/var/lib/postgresql` +
|
|
53
|
-
` -d ${image}`
|
|
54
|
-
).split(' ');
|
|
55
|
-
<%_ } _%>
|
|
56
|
-
const create = spawnSync(ENGINE, runArgs, { stdio: 'inherit' });
|
|
57
|
-
if (create.status !== 0) process.exit(create.status ?? 1);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const logs = spawn(ENGINE, ['logs', '-f', containerName], {
|
|
61
|
-
stdio: ['ignore', 'inherit', 'inherit'],
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
let exiting = false;
|
|
65
|
-
|
|
66
|
-
const cleanup = () => {
|
|
67
|
-
if (exiting) return;
|
|
68
|
-
exiting = true;
|
|
69
|
-
<%_ if (containerEngine === 'docker') { _%>
|
|
70
|
-
spawnSync(ENGINE, ['stop', containerName], { stdio: 'ignore' });
|
|
71
|
-
<%_ } else { _%>
|
|
72
|
-
spawnSync(ENGINE, ['rm', '-f', containerName], { stdio: 'ignore' });
|
|
73
|
-
<%_ } _%>
|
|
74
|
-
logs.kill();
|
|
75
|
-
process.exit(0);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
process.on('SIGTERM', cleanup);
|
|
79
|
-
process.on('SIGINT', cleanup);
|
|
80
|
-
process.on('SIGHUP', cleanup);
|
|
81
|
-
|
|
82
|
-
logs.on('exit', (code) => {
|
|
83
|
-
if (!exiting) process.exit(code ?? 0);
|
|
84
|
-
});
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
<%_ if (engine === 'mysql') { _%>
|
|
2
|
-
import { createConnection, Connection } from 'mariadb';
|
|
3
|
-
<%_ } else { _%>
|
|
4
|
-
import { Client } from 'pg';
|
|
5
|
-
<%_ } _%>
|
|
6
|
-
|
|
7
|
-
const noop = () => undefined;
|
|
8
|
-
|
|
9
|
-
const [portArg, dbArg, userArg, passwordArg] = process.argv.slice(2);
|
|
10
|
-
const timeoutAt = Date.now() + 60000;
|
|
11
|
-
|
|
12
|
-
while (Date.now() < timeoutAt) {
|
|
13
|
-
<%_ if (engine === 'mysql') { _%>
|
|
14
|
-
let conn: Connection | undefined;
|
|
15
|
-
try {
|
|
16
|
-
conn = await createConnection({
|
|
17
|
-
host: 'localhost',
|
|
18
|
-
port: parseInt(portArg),
|
|
19
|
-
user: userArg,
|
|
20
|
-
password: passwordArg,
|
|
21
|
-
database: dbArg,
|
|
22
|
-
connectTimeout: 500,
|
|
23
|
-
allowPublicKeyRetrieval: true,
|
|
24
|
-
});
|
|
25
|
-
await conn.end();
|
|
26
|
-
console.log('Database is ready.');
|
|
27
|
-
process.exit(0);
|
|
28
|
-
} catch {
|
|
29
|
-
console.log('Database is not ready.');
|
|
30
|
-
await conn?.end().catch(noop);
|
|
31
|
-
}
|
|
32
|
-
<%_ } else { _%>
|
|
33
|
-
const client = new Client({
|
|
34
|
-
host: 'localhost',
|
|
35
|
-
port: parseInt(portArg),
|
|
36
|
-
user: userArg,
|
|
37
|
-
password: passwordArg,
|
|
38
|
-
database: dbArg,
|
|
39
|
-
connectionTimeoutMillis: 500,
|
|
40
|
-
});
|
|
41
|
-
client.on('error', noop);
|
|
42
|
-
try {
|
|
43
|
-
await client.connect();
|
|
44
|
-
await client.end();
|
|
45
|
-
console.log('Database is ready.');
|
|
46
|
-
process.exit(0);
|
|
47
|
-
} catch {
|
|
48
|
-
console.log('Database is not ready.');
|
|
49
|
-
await client.end().catch(noop);
|
|
50
|
-
}
|
|
51
|
-
<%_ } _%>
|
|
52
|
-
await new Promise((r) => setTimeout(r, 200));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
throw new Error(`Timed out waiting for <%= engine === 'mysql' ? 'mysql' : 'postgres' %> on port ${portArg}`);
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export const DB_PACKAGE_NAME = '<%= runtimeConfigKey %>';
|
|
2
|
-
|
|
3
|
-
// Local development connection details (used when SERVE_LOCAL=true, see serve-local Nx target)
|
|
4
|
-
export const LOCAL_DB_PORT = <%= localDbPort %>;
|
|
5
|
-
export const LOCAL_DB_HOST = '<%= localDbHost %>';
|
|
6
|
-
export const LOCAL_DB_NAME = '<%= localDbName %>';
|
|
7
|
-
export const LOCAL_DB_USER = '<%= localDbUser %>';
|
|
8
|
-
export const LOCAL_DB_PASSWORD = '<%= localDbPassword %>';
|