@catladder/cli 1.73.0 → 1.75.0
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/dist/apps/cli/commands/cloudSQL/commandRestoreDb.js +59 -33
- package/dist/apps/cli/commands/cloudSQL/commandRestoreDb.js.map +1 -1
- package/dist/bundles/catenv/index.js +1 -1
- package/dist/bundles/cli/index.js +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/apps/cli/commands/cloudSQL/commandRestoreDb.ts +38 -16
|
@@ -62,85 +62,111 @@ exports["default"] = (function (vorpal) { return __awaiter(void 0, void 0, void
|
|
|
62
62
|
.command("cloud-sql-restore-db", "restore a db from one source to another target")
|
|
63
63
|
.action(function restoreDb() {
|
|
64
64
|
return __awaiter(this, void 0, void 0, function () {
|
|
65
|
-
var sourceInstance,
|
|
65
|
+
var sourceInstance, sourceProxy, targetProxy, sourcePort, targetPort, sourceLocalPort, sourcePassword, sourceDbName, targetInstance, targetLocalPort, targetPassword, targetDbName, shouldContinue, targetPSQL, copyDBScript;
|
|
66
66
|
return __generator(this, function (_a) {
|
|
67
67
|
switch (_a.label) {
|
|
68
68
|
case 0: return [4 /*yield*/, this.prompt({
|
|
69
69
|
type: "input",
|
|
70
70
|
name: "sourceInstance",
|
|
71
|
-
message: "Source instance (connection string)? 🤔 "
|
|
71
|
+
message: "Source instance (connection string or 'local')? 🤔 "
|
|
72
72
|
})];
|
|
73
73
|
case 1:
|
|
74
74
|
sourceInstance = (_a.sent()).sourceInstance;
|
|
75
|
-
|
|
76
|
-
TARGET_INSTANCE_PORT = 54499;
|
|
77
|
-
return [4 /*yield*/, createProxy(sourceInstance, SOURCE_INSTANCE_PORT)];
|
|
78
|
-
case 2:
|
|
79
|
-
sourceProxy = _a.sent();
|
|
75
|
+
if (!(sourceInstance === "local")) return [3 /*break*/, 3];
|
|
80
76
|
return [4 /*yield*/, this.prompt({
|
|
81
|
-
type: "
|
|
82
|
-
name: "
|
|
83
|
-
|
|
77
|
+
type: "number",
|
|
78
|
+
name: "sourceLocalPort",
|
|
79
|
+
"default": 5432,
|
|
80
|
+
message: "Local Port for source? 🤔 "
|
|
84
81
|
})];
|
|
82
|
+
case 2:
|
|
83
|
+
sourceLocalPort = (_a.sent()).sourceLocalPort;
|
|
84
|
+
sourcePort = sourceLocalPort;
|
|
85
|
+
return [3 /*break*/, 5];
|
|
85
86
|
case 3:
|
|
87
|
+
sourcePort = 54399;
|
|
88
|
+
return [4 /*yield*/, createProxy(sourceInstance, sourcePort)];
|
|
89
|
+
case 4:
|
|
90
|
+
sourceProxy = _a.sent();
|
|
91
|
+
_a.label = 5;
|
|
92
|
+
case 5: return [4 /*yield*/, this.prompt({
|
|
93
|
+
type: "input",
|
|
94
|
+
name: "sourcePassword",
|
|
95
|
+
message: "Source Password? 🤔 "
|
|
96
|
+
})];
|
|
97
|
+
case 6:
|
|
86
98
|
sourcePassword = (_a.sent()).sourcePassword;
|
|
87
99
|
return [4 /*yield*/, this.prompt({
|
|
88
100
|
type: "input",
|
|
89
101
|
name: "sourceDbName",
|
|
90
102
|
message: "Source DB name? 🤔 "
|
|
91
103
|
})];
|
|
92
|
-
case
|
|
104
|
+
case 7:
|
|
93
105
|
sourceDbName = (_a.sent()).sourceDbName;
|
|
94
106
|
return [4 /*yield*/, this.prompt({
|
|
95
107
|
type: "input",
|
|
96
108
|
name: "targetInstance",
|
|
97
|
-
message: "Targe INSTANCE (connection string)? 🤔 "
|
|
109
|
+
message: "Targe INSTANCE (connection string or 'local')? 🤔 "
|
|
98
110
|
})];
|
|
99
|
-
case
|
|
111
|
+
case 8:
|
|
100
112
|
targetInstance = (_a.sent()).targetInstance;
|
|
101
|
-
return [
|
|
102
|
-
case 6:
|
|
103
|
-
targetProxy = _a.sent();
|
|
113
|
+
if (!(targetInstance === "local")) return [3 /*break*/, 10];
|
|
104
114
|
return [4 /*yield*/, this.prompt({
|
|
105
|
-
type: "
|
|
106
|
-
name: "
|
|
107
|
-
|
|
115
|
+
type: "number",
|
|
116
|
+
name: "targetLocalPort",
|
|
117
|
+
"default": 5432,
|
|
118
|
+
message: "Local Port for target? 🤔 "
|
|
108
119
|
})];
|
|
109
|
-
case
|
|
120
|
+
case 9:
|
|
121
|
+
targetLocalPort = (_a.sent()).targetLocalPort;
|
|
122
|
+
targetPort = targetLocalPort;
|
|
123
|
+
return [3 /*break*/, 12];
|
|
124
|
+
case 10:
|
|
125
|
+
targetPort = 54499;
|
|
126
|
+
return [4 /*yield*/, createProxy(targetInstance, targetPort)];
|
|
127
|
+
case 11:
|
|
128
|
+
targetProxy = _a.sent();
|
|
129
|
+
_a.label = 12;
|
|
130
|
+
case 12: return [4 /*yield*/, this.prompt({
|
|
131
|
+
type: "input",
|
|
132
|
+
name: "targetPassword",
|
|
133
|
+
message: "Target Password? 🤔 "
|
|
134
|
+
})];
|
|
135
|
+
case 13:
|
|
110
136
|
targetPassword = (_a.sent()).targetPassword;
|
|
111
137
|
return [4 /*yield*/, this.prompt({
|
|
112
138
|
type: "input",
|
|
113
139
|
name: "targetDbName",
|
|
114
140
|
message: "Target DB name? 🤔 "
|
|
115
141
|
})];
|
|
116
|
-
case
|
|
142
|
+
case 14:
|
|
117
143
|
targetDbName = (_a.sent()).targetDbName;
|
|
118
144
|
return [4 /*yield*/, this.prompt({
|
|
119
145
|
type: "confirm",
|
|
120
146
|
name: "shouldContinue",
|
|
121
147
|
message: "This will drop ".concat(targetInstance, "/").concat(targetDbName, " and replace it with ").concat(sourceInstance, "/").concat(sourceDbName, ". Continue? \uD83E\uDD14 ")
|
|
122
148
|
})];
|
|
123
|
-
case
|
|
149
|
+
case 15:
|
|
124
150
|
shouldContinue = (_a.sent()).shouldContinue;
|
|
125
151
|
if (!shouldContinue) {
|
|
126
152
|
return [2 /*return*/];
|
|
127
153
|
}
|
|
128
154
|
targetPSQL = function (command) {
|
|
129
|
-
return "PGPASSWORD=".concat(targetPassword, " psql -p ").concat(
|
|
155
|
+
return "PGPASSWORD=".concat(targetPassword, " psql -p ").concat(targetPort, " --host=localhost --user=postgres -q ").concat(command);
|
|
130
156
|
};
|
|
131
|
-
copyDBScript = "\n set -e\n \n \n\n dumptmp=$(mktemp /tmp/dump.XXXXXX)\n\n echo \"Dumping file to $dumptmp\"\n pg_dump --dbname=postgres://postgres:".concat(sourcePassword, "@localhost:").concat(
|
|
132
|
-
_a.label =
|
|
133
|
-
case
|
|
134
|
-
_a.trys.push([
|
|
157
|
+
copyDBScript = "\n set -e\n \n \n\n dumptmp=$(mktemp /tmp/dump.XXXXXX)\n\n echo \"Dumping file to $dumptmp\"\n pg_dump --dbname=postgres://postgres:".concat(sourcePassword, "@localhost:").concat(sourcePort, "/").concat(sourceDbName, " --no-owner --no-privileges > $dumptmp\n echo \"dump done\"\n ").concat(targetPSQL("-c 'drop database \"".concat(targetDbName, "\" WITH (FORCE)' 1> /dev/null || true")), "\n ").concat(targetPSQL("-c 'create database \"".concat(targetDbName, "\"' 1> /dev/null")), "\n echo \"Restoring dump...\"\n ").concat(targetPSQL("\"".concat(targetDbName, "\" < $dumptmp 1> /dev/null")), "\n \n\n echo \"Clean up...\"\n set +e\n rm $dumptmp\n echo \"\n\uD83D\uDC31 Done!\"\n ");
|
|
158
|
+
_a.label = 16;
|
|
159
|
+
case 16:
|
|
160
|
+
_a.trys.push([16, , 18, 19]);
|
|
135
161
|
return [4 /*yield*/, (0, child_process_promise_1.spawn)(copyDBScript, [], { shell: "bash", stdio: "inherit" })];
|
|
136
|
-
case
|
|
162
|
+
case 17:
|
|
137
163
|
_a.sent();
|
|
138
|
-
return [3 /*break*/,
|
|
139
|
-
case
|
|
140
|
-
sourceProxy.stop();
|
|
141
|
-
targetProxy.stop();
|
|
164
|
+
return [3 /*break*/, 19];
|
|
165
|
+
case 18:
|
|
166
|
+
sourceProxy === null || sourceProxy === void 0 ? void 0 : sourceProxy.stop();
|
|
167
|
+
targetProxy === null || targetProxy === void 0 ? void 0 : targetProxy.stop();
|
|
142
168
|
return [7 /*endfinally*/];
|
|
143
|
-
case
|
|
169
|
+
case 19: return [2 /*return*/];
|
|
144
170
|
}
|
|
145
171
|
});
|
|
146
172
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandRestoreDb.js","sourceRoot":"","sources":["../../../../../src/apps/cli/commands/cloudSQL/commandRestoreDb.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+DAA8C;AAG9C,IAAM,WAAW,GAAG,UAAO,QAAgB,EAAE,IAAY;;;;;gBACjD,KAAK,GAAG,IAAA,6BAAK,EACjB,qCAA8B,QAAQ,kBAAQ,IAAI,CAAE,EACpD,EAAE,EACF,EAAE,KAAK,EAAE,MAAM,EAAE,CAClB,CAAC;gBACF,uBAAuB;gBACvB,qBAAM,IAAA,6BAAK,EACT,+EACoC,IAAI,2EAGrB,EACnB,EAAE,EACF,EAAE,KAAK,EAAE,MAAM,EAAE,CAClB,EAAA;;gBATD,uBAAuB;gBACvB,SAQC,CAAC;gBACI,IAAI,GAAG,cAAM,OAAA,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,EAAzB,CAAyB,CAAC;gBAC7C,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;gBAE/B,sBAAO;wBACL,IAAI,MAAA;qBACL,EAAC;;;KACH,CAAC;AAEF,sBAAe,UAAO,MAAc;;QAClC,sBAAA,MAAM;iBACH,OAAO,CACN,sBAAsB,EACtB,gDAAgD,CACjD;iBACA,MAAM,CAAC,SAAe,SAAS;;;;;oCACH,qBAAM,IAAI,CAAC,MAAM,CAAC;oCAC3C,IAAI,EAAE,OAAO;oCACb,IAAI,EAAE,gBAAgB;oCAEtB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"commandRestoreDb.js","sourceRoot":"","sources":["../../../../../src/apps/cli/commands/cloudSQL/commandRestoreDb.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;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