@dbos-inc/dbos-sdk 0.8.43-preview → 0.8.45-preview
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/packages/dbos-cloud/cli.js +0 -12
- package/dist/packages/dbos-cloud/cli.js.map +1 -1
- package/dist/packages/dbos-cloud/userdb.d.ts +0 -2
- package/dist/packages/dbos-cloud/userdb.d.ts.map +1 -1
- package/dist/packages/dbos-cloud/userdb.js +1 -173
- package/dist/packages/dbos-cloud/userdb.js.map +1 -1
- package/dist/src/dbos-runtime/cli.d.ts.map +1 -1
- package/dist/src/dbos-runtime/cli.js +14 -0
- package/dist/src/dbos-runtime/cli.js.map +1 -1
- package/dist/src/dbos-runtime/migrate.d.ts +3 -0
- package/dist/src/dbos-runtime/migrate.d.ts.map +1 -0
- package/dist/src/dbos-runtime/migrate.js +175 -0
- package/dist/src/dbos-runtime/migrate.js.map +1 -0
- package/dist/src/system_database.d.ts +2 -0
- package/dist/src/system_database.d.ts.map +1 -1
- package/dist/src/system_database.js +26 -11
- package/dist/src/system_database.js.map +1 -1
- package/dist/src/utils.d.ts +1 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +26 -1
- package/dist/src/utils.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/migrations/20240123182943_schema.js +8 -0
- package/migrations/20240123183021_tables.js +48 -0
- package/migrations/20240123183025_indexes.js +14 -0
- package/migrations/20240123183030_triggers.js +39 -0
- package/package.json +1 -1
- package/packages/dbos-cloud/dist/packages/dbos-cloud/cli.js +0 -12
- package/packages/dbos-cloud/dist/packages/dbos-cloud/cli.js.map +1 -1
- package/packages/dbos-cloud/dist/packages/dbos-cloud/userdb.d.ts +0 -2
- package/packages/dbos-cloud/dist/packages/dbos-cloud/userdb.d.ts.map +1 -1
- package/packages/dbos-cloud/dist/packages/dbos-cloud/userdb.js +1 -173
- package/packages/dbos-cloud/dist/packages/dbos-cloud/userdb.js.map +1 -1
- package/packages/dbos-cloud/dist/src/dbos-runtime/cli.d.ts.map +1 -1
- package/packages/dbos-cloud/dist/src/dbos-runtime/cli.js +14 -0
- package/packages/dbos-cloud/dist/src/dbos-runtime/cli.js.map +1 -1
- package/packages/dbos-cloud/dist/src/dbos-runtime/migrate.d.ts +3 -0
- package/packages/dbos-cloud/dist/src/dbos-runtime/migrate.d.ts.map +1 -0
- package/packages/dbos-cloud/dist/src/dbos-runtime/migrate.js +175 -0
- package/packages/dbos-cloud/dist/src/dbos-runtime/migrate.js.map +1 -0
- package/packages/dbos-cloud/dist/src/system_database.d.ts +2 -0
- package/packages/dbos-cloud/dist/src/system_database.d.ts.map +1 -1
- package/packages/dbos-cloud/dist/src/system_database.js +26 -11
- package/packages/dbos-cloud/dist/src/system_database.js.map +1 -1
- package/packages/dbos-cloud/dist/src/utils.d.ts +1 -0
- package/packages/dbos-cloud/dist/src/utils.d.ts.map +1 -1
- package/packages/dbos-cloud/dist/src/utils.js +26 -1
- package/packages/dbos-cloud/dist/src/utils.js.map +1 -1
- package/packages/dbos-cloud/package.json +1 -1
- package/packages/dbos-openapi/package.json +1 -1
@@ -129,18 +129,6 @@ userdbCommands
|
|
129
129
|
const { host } = userdbCommands.opts();
|
130
130
|
await (0, userdb_1.deleteUserDb)(host, dbname);
|
131
131
|
}));
|
132
|
-
userdbCommands
|
133
|
-
.command('migrate')
|
134
|
-
.action((async () => {
|
135
|
-
const exitCode = await (0, userdb_1.migrate)();
|
136
|
-
process.exit(exitCode);
|
137
|
-
}));
|
138
|
-
userdbCommands
|
139
|
-
.command('rollbackmigration')
|
140
|
-
.action((() => {
|
141
|
-
const exitCode = (0, userdb_1.rollbackMigration)();
|
142
|
-
process.exit(exitCode);
|
143
|
-
}));
|
144
132
|
program.parse(process.argv);
|
145
133
|
// If no arguments provided, display help by default
|
146
134
|
if (!process.argv.slice(2).length) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../packages/dbos-cloud/cli.ts"],"names":[],"mappings":";;;AAEA,iDAOwB;AACx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AAE,EAAE;IAChC,MAAM,EAAE,IAAI,EAAE,GAAqB,cAAc,CAAC,IAAI,EAAE,CAAA;IACxD,MAAM,IAAA,kBAAS,EAAC,IAAI,EAAE,MAAM,CAAC,CAAA;AAC/B,CAAC,CAAC,CAAC,CAAA;AAEL,cAAc;KACX,OAAO,CAAC,QAAQ,CAAC;KACjB,QAAQ,CAAC,UAAU,EAAE,eAAe,CAAC;KACrC,MAAM,CAAC,CAAC,KAAK,EAAE,MAAc,EAAE,EAAE;IAChC,MAAM,EAAE,IAAI,EAAE,GAAqB,cAAc,CAAC,IAAI,EAAE,CAAA;IACxD,MAAM,IAAA,qBAAY,EAAC,IAAI,EAAE,MAAM,CAAC,CAAA;AAClC,CAAC,CAAC,CAAC,CAAA;AAEL,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5B,oDAAoD;AACpD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAClC,OAAO,CAAC,UAAU,EAAE,CAAC;AACvB,CAAC"}
|
@@ -7,7 +7,5 @@ export interface UserDBInstance {
|
|
7
7
|
export declare function createUserDb(host: string, dbName: string, adminName: string, adminPassword: string, sync: boolean): Promise<void>;
|
8
8
|
export declare function deleteUserDb(host: string, dbName: string): Promise<void>;
|
9
9
|
export declare function getUserDb(host: string, dbName: string): Promise<void>;
|
10
|
-
export declare function migrate(): Promise<number>;
|
11
|
-
export declare function rollbackMigration(): number;
|
12
10
|
export declare function getUserDBInfo(host: string, dbName: string): Promise<UserDBInstance>;
|
13
11
|
//# sourceMappingURL=userdb.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"userdb.d.ts","sourceRoot":"","sources":["../../../packages/dbos-cloud/userdb.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"userdb.d.ts","sourceRoot":"","sources":["../../../packages/dbos-cloud/userdb.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,iBAmCvH;AAED,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,iBAoB9D;AAED,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,iBAa3D;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAYzF"}
|
@@ -3,17 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.getUserDBInfo = exports.
|
6
|
+
exports.getUserDBInfo = exports.getUserDb = exports.deleteUserDb = exports.createUserDb = void 0;
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
8
8
|
const logs_1 = require("../../src/telemetry/logs");
|
9
9
|
const cloudutils_1 = require("./cloudutils");
|
10
10
|
const utils_1 = require("../../src/utils");
|
11
|
-
const config_1 = require("../../src/dbos-runtime/config");
|
12
|
-
const child_process_1 = require("child_process");
|
13
|
-
const user_database_1 = require("../../src/user_database");
|
14
|
-
const pg_1 = require("pg");
|
15
|
-
const system_db_schema_1 = require("../../schemas/system_db_schema");
|
16
|
-
const user_db_schema_1 = require("../../schemas/user_db_schema");
|
17
11
|
async function createUserDb(host, dbName, adminName, adminPassword, sync) {
|
18
12
|
const logger = new logs_1.GlobalLogger();
|
19
13
|
const userCredentials = (0, cloudutils_1.getCloudCredentials)();
|
@@ -85,118 +79,6 @@ async function getUserDb(host, dbName) {
|
|
85
79
|
}
|
86
80
|
}
|
87
81
|
exports.getUserDb = getUserDb;
|
88
|
-
async function migrate() {
|
89
|
-
const logger = new logs_1.GlobalLogger();
|
90
|
-
// Read the configuration YAML file
|
91
|
-
const configFile = (0, config_1.loadConfigFile)(config_1.dbosConfigFilePath);
|
92
|
-
if (!configFile) {
|
93
|
-
logger.error(`Failed to parse ${config_1.dbosConfigFilePath}`);
|
94
|
-
return 1;
|
95
|
-
}
|
96
|
-
const userDBName = configFile.database.user_database;
|
97
|
-
logger.info(`Creating database ${userDBName} if it does not already exist`);
|
98
|
-
const createDB = `createdb -h ${configFile.database.hostname} -p ${configFile.database.port} ${userDBName} -U ${configFile.database.username} -ew ${userDBName}`;
|
99
|
-
try {
|
100
|
-
process.env.PGPASSWORD = configFile.database.password;
|
101
|
-
const createDBOutput = (0, child_process_1.execSync)(createDB, { env: process.env }).toString();
|
102
|
-
if (createDBOutput.includes(`database "${userDBName}" already exists`)) {
|
103
|
-
logger.info(`Database ${userDBName} already exists`);
|
104
|
-
}
|
105
|
-
else {
|
106
|
-
logger.info(createDBOutput);
|
107
|
-
}
|
108
|
-
}
|
109
|
-
catch (e) {
|
110
|
-
if (e instanceof Error) {
|
111
|
-
if (e.message.includes(`database "${userDBName}" already exists`)) {
|
112
|
-
logger.info(`Database ${userDBName} already exists`);
|
113
|
-
}
|
114
|
-
else {
|
115
|
-
logger.error(`Error creating database: ${e.message}`);
|
116
|
-
return 1;
|
117
|
-
}
|
118
|
-
}
|
119
|
-
else {
|
120
|
-
logger.error(e);
|
121
|
-
return 1;
|
122
|
-
}
|
123
|
-
}
|
124
|
-
const dbType = configFile.database.user_dbclient || user_database_1.UserDatabaseName.KNEX;
|
125
|
-
const migrationScript = `node_modules/.bin/${dbType}`;
|
126
|
-
const migrationCommands = configFile.database.migrate;
|
127
|
-
try {
|
128
|
-
migrationCommands?.forEach((cmd) => {
|
129
|
-
const command = `node ${migrationScript} ${cmd}`;
|
130
|
-
logger.info(`Executing migration command: ${command}`);
|
131
|
-
const migrateCommandOutput = (0, child_process_1.execSync)(command).toString();
|
132
|
-
logger.info(migrateCommandOutput);
|
133
|
-
});
|
134
|
-
}
|
135
|
-
catch (e) {
|
136
|
-
logger.error("Error running migration");
|
137
|
-
if (e instanceof Error) {
|
138
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
|
139
|
-
const stderr = e.stderr;
|
140
|
-
if (stderr && Buffer.isBuffer(stderr) && stderr.length > 0) {
|
141
|
-
logger.error(`Standard Error: ${stderr.toString().trim()}`);
|
142
|
-
}
|
143
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
|
144
|
-
const stdout = e.stdout;
|
145
|
-
if (stdout && Buffer.isBuffer(stdout) && stdout.length > 0) {
|
146
|
-
logger.error(`Standard Output: ${stdout.toString().trim()}`);
|
147
|
-
}
|
148
|
-
if (e.message) {
|
149
|
-
logger.error(e.message);
|
150
|
-
}
|
151
|
-
}
|
152
|
-
else {
|
153
|
-
logger.error(e);
|
154
|
-
}
|
155
|
-
return 1;
|
156
|
-
}
|
157
|
-
logger.info("Creating DBOS tables and system database.");
|
158
|
-
try {
|
159
|
-
await createDBOSTables(configFile);
|
160
|
-
}
|
161
|
-
catch (e) {
|
162
|
-
if (e instanceof Error) {
|
163
|
-
logger.error(`Error creating DBOS system database: ${e.message}`);
|
164
|
-
}
|
165
|
-
else {
|
166
|
-
logger.error(e);
|
167
|
-
}
|
168
|
-
return 1;
|
169
|
-
}
|
170
|
-
return 0;
|
171
|
-
}
|
172
|
-
exports.migrate = migrate;
|
173
|
-
function rollbackMigration() {
|
174
|
-
const logger = new logs_1.GlobalLogger();
|
175
|
-
// read the yaml file
|
176
|
-
const configFile = (0, config_1.loadConfigFile)(config_1.dbosConfigFilePath);
|
177
|
-
if (!configFile) {
|
178
|
-
logger.error(`failed to parse ${config_1.dbosConfigFilePath}`);
|
179
|
-
return 1;
|
180
|
-
}
|
181
|
-
let dbType = configFile.database.user_dbclient;
|
182
|
-
if (dbType == undefined) {
|
183
|
-
dbType = "knex";
|
184
|
-
}
|
185
|
-
const rollbackcommands = configFile.database.rollback;
|
186
|
-
try {
|
187
|
-
rollbackcommands?.forEach((cmd) => {
|
188
|
-
const command = "npx " + dbType + " " + cmd;
|
189
|
-
logger.info("Executing " + command);
|
190
|
-
(0, child_process_1.execSync)(command);
|
191
|
-
});
|
192
|
-
}
|
193
|
-
catch (e) {
|
194
|
-
logger.error("Error rolling back migration. ");
|
195
|
-
return 1;
|
196
|
-
}
|
197
|
-
return 0;
|
198
|
-
}
|
199
|
-
exports.rollbackMigration = rollbackMigration;
|
200
82
|
async function getUserDBInfo(host, dbName) {
|
201
83
|
const userCredentials = (0, cloudutils_1.getCloudCredentials)();
|
202
84
|
const bearerToken = "Bearer " + userCredentials.token;
|
@@ -209,58 +91,4 @@ async function getUserDBInfo(host, dbName) {
|
|
209
91
|
return res.data;
|
210
92
|
}
|
211
93
|
exports.getUserDBInfo = getUserDBInfo;
|
212
|
-
// Create DBOS system DB and tables.
|
213
|
-
// TODO: replace this with knex to manage schema.
|
214
|
-
async function createDBOSTables(configFile) {
|
215
|
-
const logger = new logs_1.GlobalLogger();
|
216
|
-
const userPoolConfig = {
|
217
|
-
host: configFile.database.hostname,
|
218
|
-
port: configFile.database.port,
|
219
|
-
user: configFile.database.username,
|
220
|
-
password: configFile.database.password,
|
221
|
-
connectionTimeoutMillis: configFile.database.connectionTimeoutMillis || 3000,
|
222
|
-
database: configFile.database.user_database,
|
223
|
-
};
|
224
|
-
if (configFile.database.ssl_ca) {
|
225
|
-
userPoolConfig.ssl = { ca: [(0, utils_1.readFileSync)(configFile.database.ssl_ca)], rejectUnauthorized: true };
|
226
|
-
}
|
227
|
-
const systemPoolConfig = { ...userPoolConfig };
|
228
|
-
systemPoolConfig.database = `${userPoolConfig.database}_dbos_sys`;
|
229
|
-
const pgUserClient = new pg_1.Client(userPoolConfig);
|
230
|
-
await pgUserClient.connect();
|
231
|
-
// Create DBOS table/schema in user DB.
|
232
|
-
const schemaExists = await pgUserClient.query(`SELECT EXISTS (SELECT FROM information_schema.schemata WHERE schema_name = 'dbos')`);
|
233
|
-
if (!schemaExists.rows[0].exists) {
|
234
|
-
await pgUserClient.query(user_db_schema_1.createUserDBSchema);
|
235
|
-
await pgUserClient.query(user_db_schema_1.userDBSchema);
|
236
|
-
}
|
237
|
-
// Create the DBOS system database.
|
238
|
-
const dbExists = await pgUserClient.query(`SELECT EXISTS (SELECT FROM pg_database WHERE datname = '${systemPoolConfig.database}')`);
|
239
|
-
if (!dbExists.rows[0].exists) {
|
240
|
-
await pgUserClient.query(`CREATE DATABASE ${systemPoolConfig.database}`);
|
241
|
-
}
|
242
|
-
// Load the DBOS system schema.
|
243
|
-
const pgSystemClient = new pg_1.Client(systemPoolConfig);
|
244
|
-
await pgSystemClient.connect();
|
245
|
-
try {
|
246
|
-
const tableExists = await pgSystemClient.query(`SELECT EXISTS (SELECT FROM information_schema.schemata WHERE schema_name = 'dbos')`);
|
247
|
-
if (!tableExists.rows[0].exists) {
|
248
|
-
await pgSystemClient.query(system_db_schema_1.systemDBSchema);
|
249
|
-
}
|
250
|
-
}
|
251
|
-
catch (e) {
|
252
|
-
const tableExists = await pgSystemClient.query(`SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema = 'dbos' AND table_name = 'operation_outputs')`);
|
253
|
-
if (tableExists.rows[0].exists) {
|
254
|
-
// If the table has been created by someone else. Ignore the error.
|
255
|
-
logger.warn(`System tables creation failed, may conflict with concurrent tasks: ${e.message}`);
|
256
|
-
}
|
257
|
-
else {
|
258
|
-
throw e;
|
259
|
-
}
|
260
|
-
}
|
261
|
-
finally {
|
262
|
-
await pgSystemClient.end();
|
263
|
-
await pgUserClient.end();
|
264
|
-
}
|
265
|
-
}
|
266
94
|
//# sourceMappingURL=userdb.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"userdb.js","sourceRoot":"","sources":["../../../packages/dbos-cloud/userdb.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,mDAAwD;AACxD,6CAAmD;AACnD,
|
1
|
+
{"version":3,"file":"userdb.js","sourceRoot":"","sources":["../../../packages/dbos-cloud/userdb.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,mDAAwD;AACxD,6CAAmD;AACnD,2CAAwC;AAUjC,KAAK,UAAU,YAAY,CAAC,IAAY,EAAE,MAAc,EAAE,SAAiB,EAAE,aAAqB,EAAE,IAAa;IACtH,MAAM,MAAM,GAAG,IAAI,mBAAY,EAAE,CAAC;IAClC,MAAM,eAAe,GAAG,IAAA,gCAAmB,GAAE,CAAC;IAC9C,MAAM,WAAW,GAAG,SAAS,GAAG,eAAe,CAAC,KAAK,CAAC;IAEtD,IAAI,CAAC;QACH,MAAM,eAAK,CAAC,IAAI,CACd,WAAW,IAAI,IAAI,eAAe,CAAC,QAAQ,mBAAmB,EAC9D,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,EACpE;YACE,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,aAAa,EAAE,WAAW;aAC3B;SACF,CACF,CAAC;QAEF,MAAM,CAAC,IAAI,CAAC,2CAA2C,MAAM,EAAE,CAAC,CAAC;QAEjE,IAAI,IAAI,EAAE,CAAC;YACT,IAAI,MAAM,GAAG,EAAE,CAAC;YAChB,OAAO,MAAM,IAAI,WAAW,EAAE,CAAC;gBAC7B,MAAM,IAAA,aAAK,EAAC,KAAK,CAAC,CAAC;gBACnB,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,MAAM,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1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../../src/dbos-runtime/cli.ts"],"names":[],"mappings":";
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../../src/dbos-runtime/cli.ts"],"names":[],"mappings":";AAiBA,MAAM,WAAW,mBAAmB;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
|
@@ -6,6 +6,7 @@ const runtime_1 = require("./runtime");
|
|
6
6
|
const commander_1 = require("commander");
|
7
7
|
const init_1 = require("./init");
|
8
8
|
const debug_1 = require("./debug");
|
9
|
+
const migrate_1 = require("./migrate");
|
9
10
|
const program = new commander_1.Command();
|
10
11
|
program
|
11
12
|
.command('start')
|
@@ -39,6 +40,19 @@ program
|
|
39
40
|
.action(async (options) => {
|
40
41
|
await (0, init_1.init)(options.appName);
|
41
42
|
});
|
43
|
+
program
|
44
|
+
.command('migrate')
|
45
|
+
.description("Perform a database migration")
|
46
|
+
.action((async () => {
|
47
|
+
const exitCode = await (0, migrate_1.migrate)();
|
48
|
+
process.exit(exitCode);
|
49
|
+
}));
|
50
|
+
program
|
51
|
+
.command('rollback')
|
52
|
+
.action((() => {
|
53
|
+
const exitCode = (0, migrate_1.rollbackMigration)();
|
54
|
+
process.exit(exitCode);
|
55
|
+
}));
|
42
56
|
program.parse(process.argv);
|
43
57
|
// If no arguments provided, display help by default
|
44
58
|
if (!process.argv.slice(2).length) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/dbos-runtime/cli.ts"],"names":[],"mappings":";;;AAEA,qCAA+D;AAC/D,uCAA2D;AAE3D,yCAAoC;AAEpC,iCAA8B;AAC9B,mCAAwC;
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/dbos-runtime/c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AC,CAiF/C;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CA4B1C"}
|
@@ -0,0 +1,175 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.rollbackMigration = exports.migrate = void 0;
|
4
|
+
const child_process_1 = require("child_process");
|
5
|
+
const logs_1 = require("../telemetry/logs");
|
6
|
+
const user_database_1 = require("../user_database");
|
7
|
+
const config_1 = require("./config");
|
8
|
+
const utils_1 = require("../utils");
|
9
|
+
const pg_1 = require("pg");
|
10
|
+
const user_db_schema_1 = require("../../schemas/user_db_schema");
|
11
|
+
const system_database_1 = require("../system_database");
|
12
|
+
async function migrate() {
|
13
|
+
const logger = new logs_1.GlobalLogger();
|
14
|
+
// Read the configuration YAML file
|
15
|
+
const configFile = (0, config_1.loadConfigFile)(config_1.dbosConfigFilePath);
|
16
|
+
if (!configFile) {
|
17
|
+
logger.error(`Failed to parse ${config_1.dbosConfigFilePath}`);
|
18
|
+
return 1;
|
19
|
+
}
|
20
|
+
const userDBName = configFile.database.user_database;
|
21
|
+
logger.info(`Creating database ${userDBName} if it does not already exist`);
|
22
|
+
const createDB = `createdb -h ${configFile.database.hostname} -p ${configFile.database.port} ${userDBName} -U ${configFile.database.username} -ew ${userDBName}`;
|
23
|
+
try {
|
24
|
+
process.env.PGPASSWORD = configFile.database.password;
|
25
|
+
const createDBOutput = (0, child_process_1.execSync)(createDB, { env: process.env }).toString();
|
26
|
+
if (createDBOutput.includes(`database "${userDBName}" already exists`)) {
|
27
|
+
logger.info(`Database ${userDBName} already exists`);
|
28
|
+
}
|
29
|
+
else {
|
30
|
+
logger.info(createDBOutput);
|
31
|
+
}
|
32
|
+
}
|
33
|
+
catch (e) {
|
34
|
+
if (e instanceof Error) {
|
35
|
+
if (e.message.includes(`database "${userDBName}" already exists`)) {
|
36
|
+
logger.info(`Database ${userDBName} already exists`);
|
37
|
+
}
|
38
|
+
else {
|
39
|
+
logger.error(`Error creating database: ${e.message}`);
|
40
|
+
return 1;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
else {
|
44
|
+
logger.error(e);
|
45
|
+
return 1;
|
46
|
+
}
|
47
|
+
}
|
48
|
+
const dbType = configFile.database.user_dbclient || user_database_1.UserDatabaseName.KNEX;
|
49
|
+
const migrationScript = `node_modules/.bin/${dbType}`;
|
50
|
+
const migrationCommands = configFile.database.migrate;
|
51
|
+
try {
|
52
|
+
migrationCommands?.forEach((cmd) => {
|
53
|
+
const command = `node ${migrationScript} ${cmd}`;
|
54
|
+
logger.info(`Executing migration command: ${command}`);
|
55
|
+
const migrateCommandOutput = (0, child_process_1.execSync)(command).toString();
|
56
|
+
logger.info(migrateCommandOutput);
|
57
|
+
});
|
58
|
+
}
|
59
|
+
catch (e) {
|
60
|
+
logger.error("Error running migration");
|
61
|
+
if (e instanceof Error) {
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
|
63
|
+
const stderr = e.stderr;
|
64
|
+
if (stderr && Buffer.isBuffer(stderr) && stderr.length > 0) {
|
65
|
+
logger.error(`Standard Error: ${stderr.toString().trim()}`);
|
66
|
+
}
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
|
68
|
+
const stdout = e.stdout;
|
69
|
+
if (stdout && Buffer.isBuffer(stdout) && stdout.length > 0) {
|
70
|
+
logger.error(`Standard Output: ${stdout.toString().trim()}`);
|
71
|
+
}
|
72
|
+
if (e.message) {
|
73
|
+
logger.error(e.message);
|
74
|
+
}
|
75
|
+
}
|
76
|
+
else {
|
77
|
+
logger.error(e);
|
78
|
+
}
|
79
|
+
return 1;
|
80
|
+
}
|
81
|
+
logger.info("Creating DBOS tables and system database.");
|
82
|
+
try {
|
83
|
+
await createDBOSTables(configFile);
|
84
|
+
}
|
85
|
+
catch (e) {
|
86
|
+
if (e instanceof Error) {
|
87
|
+
logger.error(`Error creating DBOS system database: ${e.message}`);
|
88
|
+
}
|
89
|
+
else {
|
90
|
+
logger.error(e);
|
91
|
+
}
|
92
|
+
return 1;
|
93
|
+
}
|
94
|
+
return 0;
|
95
|
+
}
|
96
|
+
exports.migrate = migrate;
|
97
|
+
function rollbackMigration() {
|
98
|
+
const logger = new logs_1.GlobalLogger();
|
99
|
+
// read the yaml file
|
100
|
+
const configFile = (0, config_1.loadConfigFile)(config_1.dbosConfigFilePath);
|
101
|
+
if (!configFile) {
|
102
|
+
logger.error(`failed to parse ${config_1.dbosConfigFilePath}`);
|
103
|
+
return 1;
|
104
|
+
}
|
105
|
+
let dbType = configFile.database.user_dbclient;
|
106
|
+
if (dbType == undefined) {
|
107
|
+
dbType = "knex";
|
108
|
+
}
|
109
|
+
const rollbackcommands = configFile.database.rollback;
|
110
|
+
try {
|
111
|
+
rollbackcommands?.forEach((cmd) => {
|
112
|
+
const command = "npx " + dbType + " " + cmd;
|
113
|
+
logger.info("Executing " + command);
|
114
|
+
(0, child_process_1.execSync)(command);
|
115
|
+
});
|
116
|
+
}
|
117
|
+
catch (e) {
|
118
|
+
logger.error("Error rolling back migration. ");
|
119
|
+
return 1;
|
120
|
+
}
|
121
|
+
return 0;
|
122
|
+
}
|
123
|
+
exports.rollbackMigration = rollbackMigration;
|
124
|
+
// Create DBOS system DB and tables.
|
125
|
+
// TODO: replace this with knex to manage schema.
|
126
|
+
async function createDBOSTables(configFile) {
|
127
|
+
const logger = new logs_1.GlobalLogger();
|
128
|
+
const userPoolConfig = {
|
129
|
+
host: configFile.database.hostname,
|
130
|
+
port: configFile.database.port,
|
131
|
+
user: configFile.database.username,
|
132
|
+
password: configFile.database.password,
|
133
|
+
connectionTimeoutMillis: configFile.database.connectionTimeoutMillis || 3000,
|
134
|
+
database: configFile.database.user_database,
|
135
|
+
};
|
136
|
+
if (configFile.database.ssl_ca) {
|
137
|
+
userPoolConfig.ssl = { ca: [(0, utils_1.readFileSync)(configFile.database.ssl_ca)], rejectUnauthorized: true };
|
138
|
+
}
|
139
|
+
const systemPoolConfig = { ...userPoolConfig };
|
140
|
+
systemPoolConfig.database = `${userPoolConfig.database}_dbos_sys`;
|
141
|
+
const pgUserClient = new pg_1.Client(userPoolConfig);
|
142
|
+
await pgUserClient.connect();
|
143
|
+
// Create DBOS table/schema in user DB.
|
144
|
+
const schemaExists = await pgUserClient.query(`SELECT EXISTS (SELECT FROM information_schema.schemata WHERE schema_name = 'dbos')`);
|
145
|
+
if (!schemaExists.rows[0].exists) {
|
146
|
+
await pgUserClient.query(user_db_schema_1.createUserDBSchema);
|
147
|
+
await pgUserClient.query(user_db_schema_1.userDBSchema);
|
148
|
+
}
|
149
|
+
// Create the DBOS system database.
|
150
|
+
const dbExists = await pgUserClient.query(`SELECT EXISTS (SELECT FROM pg_database WHERE datname = '${systemPoolConfig.database}')`);
|
151
|
+
if (!dbExists.rows[0].exists) {
|
152
|
+
await pgUserClient.query(`CREATE DATABASE ${systemPoolConfig.database}`);
|
153
|
+
}
|
154
|
+
// Load the DBOS system schema.
|
155
|
+
const pgSystemClient = new pg_1.Client(systemPoolConfig);
|
156
|
+
await pgSystemClient.connect();
|
157
|
+
try {
|
158
|
+
await (0, system_database_1.migrateSystemDatabase)(systemPoolConfig);
|
159
|
+
}
|
160
|
+
catch (e) {
|
161
|
+
const tableExists = await pgSystemClient.query(`SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema = 'dbos' AND table_name = 'operation_outputs')`);
|
162
|
+
if (tableExists.rows[0].exists) {
|
163
|
+
// If the table has been created by someone else. Ignore the error.
|
164
|
+
logger.warn(`System tables creation failed, may conflict with concurrent tasks: ${e.message}`);
|
165
|
+
}
|
166
|
+
else {
|
167
|
+
throw e;
|
168
|
+
}
|
169
|
+
}
|
170
|
+
finally {
|
171
|
+
await pgSystemClient.end();
|
172
|
+
await pgUserClient.end();
|
173
|
+
}
|
174
|
+
}
|
175
|
+
//# sourceMappingURL=migrate.js.map
|
@@ -0,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BAA+B;IAC/B,MAAM,cAAc,GAAG,IAAI,WAAM,CAAC,gBAAgB,CAAC,CAAC;IACpD,MAAM,cAAc,CAAC,OAAO,EAAE,CAAC;IAE/B,IAAI,CAAC;QACH,MAAM,IAAA,uCAAqB,EAAC,gBAAgB,CAAC,CAAA;IAC/C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,WAAW,GAAG,MAAM,cAAc,CAAC,KAAK,CAAiB,wHAAwH,CAAC,CAAC;QACzL,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;YAC/B,mEAAmE;YACnE,MAAM,CAAC,IAAI,CAAC,sEAAuE,CAAW,CAAC,OAAO,EAAE,CAAC,CAAC;QAC5G,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,cAAc,CAAC,GAAG,EAAE,CAAC;QAC3B,MAAM,YAAY,CAAC,GAAG,EAAE,CAAC;IAC3B,CAAC;AACH,CAAC"}
|
@@ -40,11 +40,13 @@ export interface WorkflowStatusInternal {
|
|
40
40
|
export interface ExistenceCheck {
|
41
41
|
exists: boolean;
|
42
42
|
}
|
43
|
+
export declare function migrateSystemDatabase(systemPoolConfig: PoolConfig): Promise<void>;
|
43
44
|
export declare class PostgresSystemDatabase implements SystemDatabase {
|
44
45
|
readonly pgPoolConfig: PoolConfig;
|
45
46
|
readonly systemDatabaseName: string;
|
46
47
|
readonly logger: Logger;
|
47
48
|
readonly pool: Pool;
|
49
|
+
readonly systemPoolConfig: PoolConfig;
|
48
50
|
notificationsClient: PoolClient | null;
|
49
51
|
readonly notificationsMap: Record<string, () => void>;
|
50
52
|
readonly workflowEventsMap: Record<string, () => void>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"system_database.d.ts","sourceRoot":"","sources":["../../src/system_database.ts"],"names":[],"mappings":"AAGA,OAAO,EAA0B,QAAQ,EAAE,MAAM,iB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AAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBtH,QAAQ,CAAC,CAAC,SAAS,WAAW,CAAC,GAAG,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAiD5J,iBAAiB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IA6BjH,iBAAiB,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAkB5D;;;OAGG;IACG,sBAAsB;CAiB7B"}
|
@@ -1,19 +1,39 @@
|
|
1
1
|
"use strict";
|
2
2
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
5
|
+
};
|
3
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
exports.PostgresSystemDatabase = void 0;
|
7
|
+
exports.PostgresSystemDatabase = exports.migrateSystemDatabase = void 0;
|
5
8
|
const serialize_error_1 = require("serialize-error");
|
6
9
|
const dbos_executor_1 = require("./dbos-executor");
|
7
10
|
const pg_1 = require("pg");
|
8
11
|
const error_1 = require("./error");
|
9
12
|
const workflow_1 = require("./workflow");
|
10
|
-
const system_db_schema_1 = require("../schemas/system_db_schema");
|
11
13
|
const utils_1 = require("./utils");
|
14
|
+
const knex_1 = __importDefault(require("knex"));
|
15
|
+
const path_1 = __importDefault(require("path"));
|
16
|
+
async function migrateSystemDatabase(systemPoolConfig) {
|
17
|
+
const migrationsDirectory = path_1.default.join((0, utils_1.findPackageRoot)(__dirname), 'migrations');
|
18
|
+
const knexConfig = {
|
19
|
+
client: 'pg',
|
20
|
+
connection: systemPoolConfig,
|
21
|
+
migrations: {
|
22
|
+
directory: migrationsDirectory,
|
23
|
+
tableName: 'knex_migrations'
|
24
|
+
}
|
25
|
+
};
|
26
|
+
const knexDB = (0, knex_1.default)(knexConfig);
|
27
|
+
await knexDB.migrate.latest();
|
28
|
+
await knexDB.destroy();
|
29
|
+
}
|
30
|
+
exports.migrateSystemDatabase = migrateSystemDatabase;
|
12
31
|
class PostgresSystemDatabase {
|
13
32
|
pgPoolConfig;
|
14
33
|
systemDatabaseName;
|
15
34
|
logger;
|
16
35
|
pool;
|
36
|
+
systemPoolConfig;
|
17
37
|
notificationsClient = null;
|
18
38
|
notificationsMap = {};
|
19
39
|
workflowEventsMap = {};
|
@@ -24,9 +44,9 @@ class PostgresSystemDatabase {
|
|
24
44
|
this.pgPoolConfig = pgPoolConfig;
|
25
45
|
this.systemDatabaseName = systemDatabaseName;
|
26
46
|
this.logger = logger;
|
27
|
-
|
28
|
-
|
29
|
-
this.pool = new pg_1.Pool(
|
47
|
+
this.systemPoolConfig = { ...pgPoolConfig };
|
48
|
+
this.systemPoolConfig.database = systemDatabaseName;
|
49
|
+
this.pool = new pg_1.Pool(this.systemPoolConfig);
|
30
50
|
}
|
31
51
|
async init() {
|
32
52
|
const pgSystemClient = new pg_1.Client(this.pgPoolConfig);
|
@@ -37,12 +57,7 @@ class PostgresSystemDatabase {
|
|
37
57
|
// Create the DBOS system database.
|
38
58
|
await pgSystemClient.query(`CREATE DATABASE "${this.systemDatabaseName}"`);
|
39
59
|
}
|
40
|
-
|
41
|
-
const schemaExists = await this.pool.query(`SELECT EXISTS (SELECT FROM information_schema.schemata WHERE schema_name = '${dbos_executor_1.DBOSExecutor.systemDBSchemaName}')`);
|
42
|
-
if (!schemaExists.rows[0].exists) {
|
43
|
-
// Load the DBOS system schemas.
|
44
|
-
await this.pool.query(system_db_schema_1.systemDBSchema);
|
45
|
-
}
|
60
|
+
await migrateSystemDatabase(this.systemPoolConfig);
|
46
61
|
await this.listenForNotifications();
|
47
62
|
await pgSystemClient.end();
|
48
63
|
}
|