@reyemtech/nimbus 2.12.6 → 3.0.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.
Files changed (262) hide show
  1. package/README.md +2 -0
  2. package/dist/cjs/cli/migrate-cnpg-ownership.d.ts +43 -0
  3. package/dist/cjs/cli/migrate-cnpg-ownership.d.ts.map +1 -0
  4. package/dist/cjs/cli/migrate-cnpg-ownership.js +67 -0
  5. package/dist/cjs/cli/migrate-cnpg-ownership.js.map +1 -0
  6. package/dist/cjs/cli/migrate-cnpg-roles.d.ts +92 -0
  7. package/dist/cjs/cli/migrate-cnpg-roles.d.ts.map +1 -0
  8. package/dist/cjs/cli/migrate-cnpg-roles.js +337 -0
  9. package/dist/cjs/cli/migrate-cnpg-roles.js.map +1 -0
  10. package/dist/cjs/cli/migrate-cnpg.d.ts +38 -0
  11. package/dist/cjs/cli/migrate-cnpg.d.ts.map +1 -0
  12. package/dist/cjs/cli/migrate-cnpg.js +258 -0
  13. package/dist/cjs/cli/migrate-cnpg.js.map +1 -0
  14. package/dist/cjs/cli/migrate-exec.d.ts +45 -0
  15. package/dist/cjs/cli/migrate-exec.d.ts.map +1 -0
  16. package/dist/cjs/cli/migrate-exec.js +104 -0
  17. package/dist/cjs/cli/migrate-exec.js.map +1 -0
  18. package/dist/cjs/cli/migrate-psql.d.ts +125 -0
  19. package/dist/cjs/cli/migrate-psql.d.ts.map +1 -0
  20. package/dist/cjs/cli/migrate-psql.js +213 -0
  21. package/dist/cjs/cli/migrate-psql.js.map +1 -0
  22. package/dist/cjs/cli/migrate-report.d.ts +27 -0
  23. package/dist/cjs/cli/migrate-report.d.ts.map +1 -0
  24. package/dist/cjs/cli/migrate-report.js +29 -0
  25. package/dist/cjs/cli/migrate-report.js.map +1 -0
  26. package/dist/cjs/cli/migrate-superuser.d.ts +22 -0
  27. package/dist/cjs/cli/migrate-superuser.d.ts.map +1 -0
  28. package/dist/cjs/cli/migrate-superuser.js +73 -0
  29. package/dist/cjs/cli/migrate-superuser.js.map +1 -0
  30. package/dist/cjs/cli/migrate.d.ts +37 -0
  31. package/dist/cjs/cli/migrate.d.ts.map +1 -0
  32. package/dist/cjs/cli/migrate.js +67 -0
  33. package/dist/cjs/cli/migrate.js.map +1 -0
  34. package/dist/cjs/cli.d.ts +1 -0
  35. package/dist/cjs/cli.d.ts.map +1 -1
  36. package/dist/cjs/cli.js +6 -0
  37. package/dist/cjs/cli.js.map +1 -1
  38. package/dist/cjs/index.d.ts +1 -1
  39. package/dist/cjs/index.d.ts.map +1 -1
  40. package/dist/cjs/index.js.map +1 -1
  41. package/dist/cjs/operator/cnpg-common.d.ts +56 -0
  42. package/dist/cjs/operator/cnpg-common.d.ts.map +1 -0
  43. package/dist/cjs/operator/cnpg-common.js +82 -0
  44. package/dist/cjs/operator/cnpg-common.js.map +1 -0
  45. package/dist/cjs/operator/cnpg-database.d.ts +66 -0
  46. package/dist/cjs/operator/cnpg-database.d.ts.map +1 -0
  47. package/dist/cjs/operator/cnpg-database.js +296 -0
  48. package/dist/cjs/operator/cnpg-database.js.map +1 -0
  49. package/dist/cjs/operator/cnpg-roles.d.ts +173 -0
  50. package/dist/cjs/operator/cnpg-roles.d.ts.map +1 -0
  51. package/dist/cjs/operator/cnpg-roles.js +225 -0
  52. package/dist/cjs/operator/cnpg-roles.js.map +1 -0
  53. package/dist/cjs/operator/cnpg.d.ts.map +1 -1
  54. package/dist/cjs/operator/cnpg.js +50 -162
  55. package/dist/cjs/operator/cnpg.js.map +1 -1
  56. package/dist/cjs/operator/connection-uri.d.ts +44 -0
  57. package/dist/cjs/operator/connection-uri.d.ts.map +1 -0
  58. package/dist/cjs/operator/connection-uri.js +49 -0
  59. package/dist/cjs/operator/connection-uri.js.map +1 -0
  60. package/dist/cjs/operator/credentials.d.ts +76 -0
  61. package/dist/cjs/operator/credentials.d.ts.map +1 -0
  62. package/dist/cjs/operator/credentials.js +106 -0
  63. package/dist/cjs/operator/credentials.js.map +1 -0
  64. package/dist/cjs/operator/database-options.d.ts +121 -0
  65. package/dist/cjs/operator/database-options.d.ts.map +1 -0
  66. package/dist/cjs/operator/database-options.js +131 -0
  67. package/dist/cjs/operator/database-options.js.map +1 -0
  68. package/dist/cjs/operator/grants/postgres-job.d.ts +109 -0
  69. package/dist/cjs/operator/grants/postgres-job.d.ts.map +1 -0
  70. package/dist/cjs/operator/grants/postgres-job.js +232 -0
  71. package/dist/cjs/operator/grants/postgres-job.js.map +1 -0
  72. package/dist/cjs/operator/grants/postgres-sql.d.ts +130 -0
  73. package/dist/cjs/operator/grants/postgres-sql.d.ts.map +1 -0
  74. package/dist/cjs/operator/grants/postgres-sql.js +305 -0
  75. package/dist/cjs/operator/grants/postgres-sql.js.map +1 -0
  76. package/dist/cjs/operator/grants/privileges.d.ts +24 -0
  77. package/dist/cjs/operator/grants/privileges.d.ts.map +1 -0
  78. package/dist/cjs/operator/grants/privileges.js +35 -0
  79. package/dist/cjs/operator/grants/privileges.js.map +1 -0
  80. package/dist/cjs/operator/grants/role-config.d.ts +80 -0
  81. package/dist/cjs/operator/grants/role-config.d.ts.map +1 -0
  82. package/dist/cjs/operator/grants/role-config.js +134 -0
  83. package/dist/cjs/operator/grants/role-config.js.map +1 -0
  84. package/dist/cjs/operator/index.d.ts +1 -1
  85. package/dist/cjs/operator/index.d.ts.map +1 -1
  86. package/dist/cjs/operator/index.js.map +1 -1
  87. package/dist/cjs/operator/interfaces.d.ts +223 -1
  88. package/dist/cjs/operator/interfaces.d.ts.map +1 -1
  89. package/dist/cjs/operator/interfaces.js.map +1 -1
  90. package/dist/cjs/operator/mariadb-common.d.ts +99 -0
  91. package/dist/cjs/operator/mariadb-common.d.ts.map +1 -0
  92. package/dist/cjs/operator/mariadb-common.js +141 -0
  93. package/dist/cjs/operator/mariadb-common.js.map +1 -0
  94. package/dist/cjs/operator/mariadb-database.d.ts +65 -0
  95. package/dist/cjs/operator/mariadb-database.d.ts.map +1 -0
  96. package/dist/cjs/operator/mariadb-database.js +285 -0
  97. package/dist/cjs/operator/mariadb-database.js.map +1 -0
  98. package/dist/cjs/operator/mariadb-roles.d.ts +264 -0
  99. package/dist/cjs/operator/mariadb-roles.d.ts.map +1 -0
  100. package/dist/cjs/operator/mariadb-roles.js +366 -0
  101. package/dist/cjs/operator/mariadb-roles.js.map +1 -0
  102. package/dist/cjs/operator/mariadb.d.ts.map +1 -1
  103. package/dist/cjs/operator/mariadb.js +35 -147
  104. package/dist/cjs/operator/mariadb.js.map +1 -1
  105. package/dist/cjs/operator/neo4j-common.d.ts +62 -0
  106. package/dist/cjs/operator/neo4j-common.d.ts.map +1 -0
  107. package/dist/cjs/operator/neo4j-common.js +89 -0
  108. package/dist/cjs/operator/neo4j-common.js.map +1 -0
  109. package/dist/cjs/operator/neo4j-database.d.ts +88 -0
  110. package/dist/cjs/operator/neo4j-database.d.ts.map +1 -0
  111. package/dist/cjs/operator/neo4j-database.js +274 -0
  112. package/dist/cjs/operator/neo4j-database.js.map +1 -0
  113. package/dist/cjs/operator/neo4j-roles.d.ts +203 -0
  114. package/dist/cjs/operator/neo4j-roles.d.ts.map +1 -0
  115. package/dist/cjs/operator/neo4j-roles.js +298 -0
  116. package/dist/cjs/operator/neo4j-roles.js.map +1 -0
  117. package/dist/cjs/operator/neo4j.d.ts.map +1 -1
  118. package/dist/cjs/operator/neo4j.js +32 -132
  119. package/dist/cjs/operator/neo4j.js.map +1 -1
  120. package/dist/cjs/operator/resource-identity.d.ts +170 -0
  121. package/dist/cjs/operator/resource-identity.d.ts.map +1 -0
  122. package/dist/cjs/operator/resource-identity.js +231 -0
  123. package/dist/cjs/operator/resource-identity.js.map +1 -0
  124. package/dist/cjs/operator/role-registry.d.ts +85 -0
  125. package/dist/cjs/operator/role-registry.d.ts.map +1 -0
  126. package/dist/cjs/operator/role-registry.js +72 -0
  127. package/dist/cjs/operator/role-registry.js.map +1 -0
  128. package/dist/cjs/types/errors.d.ts +3 -0
  129. package/dist/cjs/types/errors.d.ts.map +1 -1
  130. package/dist/cjs/types/errors.js +3 -0
  131. package/dist/cjs/types/errors.js.map +1 -1
  132. package/dist/esm/cli/migrate-cnpg-ownership.d.ts +43 -0
  133. package/dist/esm/cli/migrate-cnpg-ownership.d.ts.map +1 -0
  134. package/dist/esm/cli/migrate-cnpg-ownership.js +67 -0
  135. package/dist/esm/cli/migrate-cnpg-ownership.js.map +1 -0
  136. package/dist/esm/cli/migrate-cnpg-roles.d.ts +92 -0
  137. package/dist/esm/cli/migrate-cnpg-roles.d.ts.map +1 -0
  138. package/dist/esm/cli/migrate-cnpg-roles.js +337 -0
  139. package/dist/esm/cli/migrate-cnpg-roles.js.map +1 -0
  140. package/dist/esm/cli/migrate-cnpg.d.ts +38 -0
  141. package/dist/esm/cli/migrate-cnpg.d.ts.map +1 -0
  142. package/dist/esm/cli/migrate-cnpg.js +258 -0
  143. package/dist/esm/cli/migrate-cnpg.js.map +1 -0
  144. package/dist/esm/cli/migrate-exec.d.ts +45 -0
  145. package/dist/esm/cli/migrate-exec.d.ts.map +1 -0
  146. package/dist/esm/cli/migrate-exec.js +104 -0
  147. package/dist/esm/cli/migrate-exec.js.map +1 -0
  148. package/dist/esm/cli/migrate-psql.d.ts +125 -0
  149. package/dist/esm/cli/migrate-psql.d.ts.map +1 -0
  150. package/dist/esm/cli/migrate-psql.js +213 -0
  151. package/dist/esm/cli/migrate-psql.js.map +1 -0
  152. package/dist/esm/cli/migrate-report.d.ts +27 -0
  153. package/dist/esm/cli/migrate-report.d.ts.map +1 -0
  154. package/dist/esm/cli/migrate-report.js +29 -0
  155. package/dist/esm/cli/migrate-report.js.map +1 -0
  156. package/dist/esm/cli/migrate-superuser.d.ts +22 -0
  157. package/dist/esm/cli/migrate-superuser.d.ts.map +1 -0
  158. package/dist/esm/cli/migrate-superuser.js +73 -0
  159. package/dist/esm/cli/migrate-superuser.js.map +1 -0
  160. package/dist/esm/cli/migrate.d.ts +37 -0
  161. package/dist/esm/cli/migrate.d.ts.map +1 -0
  162. package/dist/esm/cli/migrate.js +67 -0
  163. package/dist/esm/cli/migrate.js.map +1 -0
  164. package/dist/esm/cli.d.ts +1 -0
  165. package/dist/esm/cli.d.ts.map +1 -1
  166. package/dist/esm/cli.js +6 -0
  167. package/dist/esm/cli.js.map +1 -1
  168. package/dist/esm/index.d.ts +1 -1
  169. package/dist/esm/index.d.ts.map +1 -1
  170. package/dist/esm/index.js.map +1 -1
  171. package/dist/esm/operator/cnpg-common.d.ts +56 -0
  172. package/dist/esm/operator/cnpg-common.d.ts.map +1 -0
  173. package/dist/esm/operator/cnpg-common.js +82 -0
  174. package/dist/esm/operator/cnpg-common.js.map +1 -0
  175. package/dist/esm/operator/cnpg-database.d.ts +66 -0
  176. package/dist/esm/operator/cnpg-database.d.ts.map +1 -0
  177. package/dist/esm/operator/cnpg-database.js +296 -0
  178. package/dist/esm/operator/cnpg-database.js.map +1 -0
  179. package/dist/esm/operator/cnpg-roles.d.ts +173 -0
  180. package/dist/esm/operator/cnpg-roles.d.ts.map +1 -0
  181. package/dist/esm/operator/cnpg-roles.js +225 -0
  182. package/dist/esm/operator/cnpg-roles.js.map +1 -0
  183. package/dist/esm/operator/cnpg.d.ts.map +1 -1
  184. package/dist/esm/operator/cnpg.js +50 -162
  185. package/dist/esm/operator/cnpg.js.map +1 -1
  186. package/dist/esm/operator/connection-uri.d.ts +44 -0
  187. package/dist/esm/operator/connection-uri.d.ts.map +1 -0
  188. package/dist/esm/operator/connection-uri.js +49 -0
  189. package/dist/esm/operator/connection-uri.js.map +1 -0
  190. package/dist/esm/operator/credentials.d.ts +76 -0
  191. package/dist/esm/operator/credentials.d.ts.map +1 -0
  192. package/dist/esm/operator/credentials.js +106 -0
  193. package/dist/esm/operator/credentials.js.map +1 -0
  194. package/dist/esm/operator/database-options.d.ts +121 -0
  195. package/dist/esm/operator/database-options.d.ts.map +1 -0
  196. package/dist/esm/operator/database-options.js +131 -0
  197. package/dist/esm/operator/database-options.js.map +1 -0
  198. package/dist/esm/operator/grants/postgres-job.d.ts +109 -0
  199. package/dist/esm/operator/grants/postgres-job.d.ts.map +1 -0
  200. package/dist/esm/operator/grants/postgres-job.js +232 -0
  201. package/dist/esm/operator/grants/postgres-job.js.map +1 -0
  202. package/dist/esm/operator/grants/postgres-sql.d.ts +130 -0
  203. package/dist/esm/operator/grants/postgres-sql.d.ts.map +1 -0
  204. package/dist/esm/operator/grants/postgres-sql.js +305 -0
  205. package/dist/esm/operator/grants/postgres-sql.js.map +1 -0
  206. package/dist/esm/operator/grants/privileges.d.ts +24 -0
  207. package/dist/esm/operator/grants/privileges.d.ts.map +1 -0
  208. package/dist/esm/operator/grants/privileges.js +35 -0
  209. package/dist/esm/operator/grants/privileges.js.map +1 -0
  210. package/dist/esm/operator/grants/role-config.d.ts +80 -0
  211. package/dist/esm/operator/grants/role-config.d.ts.map +1 -0
  212. package/dist/esm/operator/grants/role-config.js +134 -0
  213. package/dist/esm/operator/grants/role-config.js.map +1 -0
  214. package/dist/esm/operator/index.d.ts +1 -1
  215. package/dist/esm/operator/index.d.ts.map +1 -1
  216. package/dist/esm/operator/index.js.map +1 -1
  217. package/dist/esm/operator/interfaces.d.ts +223 -1
  218. package/dist/esm/operator/interfaces.d.ts.map +1 -1
  219. package/dist/esm/operator/interfaces.js.map +1 -1
  220. package/dist/esm/operator/mariadb-common.d.ts +99 -0
  221. package/dist/esm/operator/mariadb-common.d.ts.map +1 -0
  222. package/dist/esm/operator/mariadb-common.js +141 -0
  223. package/dist/esm/operator/mariadb-common.js.map +1 -0
  224. package/dist/esm/operator/mariadb-database.d.ts +65 -0
  225. package/dist/esm/operator/mariadb-database.d.ts.map +1 -0
  226. package/dist/esm/operator/mariadb-database.js +285 -0
  227. package/dist/esm/operator/mariadb-database.js.map +1 -0
  228. package/dist/esm/operator/mariadb-roles.d.ts +264 -0
  229. package/dist/esm/operator/mariadb-roles.d.ts.map +1 -0
  230. package/dist/esm/operator/mariadb-roles.js +366 -0
  231. package/dist/esm/operator/mariadb-roles.js.map +1 -0
  232. package/dist/esm/operator/mariadb.d.ts.map +1 -1
  233. package/dist/esm/operator/mariadb.js +35 -147
  234. package/dist/esm/operator/mariadb.js.map +1 -1
  235. package/dist/esm/operator/neo4j-common.d.ts +62 -0
  236. package/dist/esm/operator/neo4j-common.d.ts.map +1 -0
  237. package/dist/esm/operator/neo4j-common.js +89 -0
  238. package/dist/esm/operator/neo4j-common.js.map +1 -0
  239. package/dist/esm/operator/neo4j-database.d.ts +88 -0
  240. package/dist/esm/operator/neo4j-database.d.ts.map +1 -0
  241. package/dist/esm/operator/neo4j-database.js +274 -0
  242. package/dist/esm/operator/neo4j-database.js.map +1 -0
  243. package/dist/esm/operator/neo4j-roles.d.ts +203 -0
  244. package/dist/esm/operator/neo4j-roles.d.ts.map +1 -0
  245. package/dist/esm/operator/neo4j-roles.js +298 -0
  246. package/dist/esm/operator/neo4j-roles.js.map +1 -0
  247. package/dist/esm/operator/neo4j.d.ts.map +1 -1
  248. package/dist/esm/operator/neo4j.js +32 -132
  249. package/dist/esm/operator/neo4j.js.map +1 -1
  250. package/dist/esm/operator/resource-identity.d.ts +170 -0
  251. package/dist/esm/operator/resource-identity.d.ts.map +1 -0
  252. package/dist/esm/operator/resource-identity.js +231 -0
  253. package/dist/esm/operator/resource-identity.js.map +1 -0
  254. package/dist/esm/operator/role-registry.d.ts +85 -0
  255. package/dist/esm/operator/role-registry.d.ts.map +1 -0
  256. package/dist/esm/operator/role-registry.js +72 -0
  257. package/dist/esm/operator/role-registry.js.map +1 -0
  258. package/dist/esm/types/errors.d.ts +3 -0
  259. package/dist/esm/types/errors.d.ts.map +1 -1
  260. package/dist/esm/types/errors.js +3 -0
  261. package/dist/esm/types/errors.js.map +1 -1
  262. package/package.json +1 -1
@@ -0,0 +1,258 @@
1
+ "use strict";
2
+ /**
3
+ * CNPG-specific checks for `nimbus migrate`: CRD presence, role attributes,
4
+ * and database ownership.
5
+ *
6
+ * @module cli/migrate-cnpg
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.CNPG_DATABASE_ROLE_CRD_NAME = exports.CNPG_DATABASE_CRD_NAME = void 0;
10
+ exports.checkCnpgCrds = checkCnpgCrds;
11
+ exports.checkClusterState = checkClusterState;
12
+ const cnpg_common_js_1 = require("../operator/cnpg-common.js");
13
+ const migrate_exec_js_1 = require("./migrate-exec.js");
14
+ const migrate_report_js_1 = require("./migrate-report.js");
15
+ const migrate_cnpg_roles_js_1 = require("./migrate-cnpg-roles.js");
16
+ const migrate_cnpg_ownership_js_1 = require("./migrate-cnpg-ownership.js");
17
+ /** CRD name backing the `Database` custom resource. */
18
+ exports.CNPG_DATABASE_CRD_NAME = "databases.postgresql.cnpg.io";
19
+ /** CRD name backing the `DatabaseRole` custom resource. */
20
+ exports.CNPG_DATABASE_ROLE_CRD_NAME = "databaseroles.postgresql.cnpg.io";
21
+ /**
22
+ * Check that both CNPG CRDs required by the declarative path exist.
23
+ *
24
+ * @returns The section result plus whether the cluster was reachable, so
25
+ * downstream checks know whether to attempt a `kubectl exec`
26
+ */
27
+ function checkCnpgCrds() {
28
+ const result = (0, migrate_exec_js_1.runCommand)("kubectl", [
29
+ "get",
30
+ "crd",
31
+ exports.CNPG_DATABASE_CRD_NAME,
32
+ exports.CNPG_DATABASE_ROLE_CRD_NAME,
33
+ "-o",
34
+ "name",
35
+ ]);
36
+ if (result.ok) {
37
+ return {
38
+ section: {
39
+ status: migrate_report_js_1.CHECK_STATUS.PASS,
40
+ lines: [`Found ${exports.CNPG_DATABASE_CRD_NAME} and ${exports.CNPG_DATABASE_ROLE_CRD_NAME}.`],
41
+ },
42
+ clusterReachable: true,
43
+ };
44
+ }
45
+ if (result.reason === "not-found") {
46
+ return {
47
+ section: {
48
+ status: migrate_report_js_1.CHECK_STATUS.WARN,
49
+ lines: [
50
+ `"kubectl" was not found on PATH. Install kubectl and re-run this check.`,
51
+ "Role attribute and database ownership checks below are skipped as a result.",
52
+ ],
53
+ },
54
+ clusterReachable: false,
55
+ };
56
+ }
57
+ if (/notfound/i.test(result.message)) {
58
+ return {
59
+ section: {
60
+ status: migrate_report_js_1.CHECK_STATUS.FAIL,
61
+ lines: [
62
+ `Missing one or both CRDs: ${exports.CNPG_DATABASE_CRD_NAME}, ${exports.CNPG_DATABASE_ROLE_CRD_NAME}.`,
63
+ "The declarative Database/DatabaseRole path requires CloudNativePG 1.30 or newer.",
64
+ "Upgrade the CNPG operator before adopting this release.",
65
+ result.message,
66
+ ],
67
+ },
68
+ clusterReachable: false,
69
+ };
70
+ }
71
+ return {
72
+ section: {
73
+ status: migrate_report_js_1.CHECK_STATUS.WARN,
74
+ lines: [
75
+ `Could not reach the cluster to verify CRDs: ${result.message}`,
76
+ "Role attribute and database ownership checks below are skipped as a result.",
77
+ ],
78
+ },
79
+ clusterReachable: false,
80
+ };
81
+ }
82
+ /**
83
+ * List CNPG cluster names in the namespace nimbus always deploys to.
84
+ *
85
+ * @returns Cluster names on success, or a failure with an explanatory message
86
+ */
87
+ function listCnpgClusters() {
88
+ const result = (0, migrate_exec_js_1.runCommand)("kubectl", [
89
+ "get",
90
+ "clusters.postgresql.cnpg.io",
91
+ "-n",
92
+ cnpg_common_js_1.DATA_NAMESPACE,
93
+ "-o",
94
+ "jsonpath={.items[*].metadata.name}",
95
+ ]);
96
+ if (!result.ok) {
97
+ return result;
98
+ }
99
+ const names = result.stdout
100
+ .trim()
101
+ .split(/\s+/)
102
+ .filter((name) => name.length > 0);
103
+ return { ok: true, names };
104
+ }
105
+ /**
106
+ * Resolve the primary instance's pod name for a CNPG cluster, so queries run
107
+ * against a writable connection. Falls back to the conventional `<cluster>-1`
108
+ * pod name (used by every nimbus-provisioned cluster's first instance) when
109
+ * the cluster's status has not reported a primary yet.
110
+ *
111
+ * @param clusterName - CNPG `Cluster` object name
112
+ * @returns The pod name to `kubectl exec` into
113
+ */
114
+ function resolvePrimaryPod(clusterName) {
115
+ const result = (0, migrate_exec_js_1.runCommand)("kubectl", [
116
+ "get",
117
+ "cluster.postgresql.cnpg.io",
118
+ clusterName,
119
+ "-n",
120
+ cnpg_common_js_1.DATA_NAMESPACE,
121
+ "-o",
122
+ "jsonpath={.status.currentPrimary}",
123
+ ]);
124
+ const primary = result.ok ? result.stdout.trim() : "";
125
+ return primary.length > 0 ? primary : `${clusterName}-1`;
126
+ }
127
+ /**
128
+ * Run a read-only `psql -tAc` query inside a cluster's primary pod via `kubectl exec`.
129
+ *
130
+ * @param pod - Pod name to exec into
131
+ * @param query - SQL query text (never built from unsanitised input)
132
+ * @returns The query's unaligned, tuples-only output on success
133
+ */
134
+ function runPsqlQuery(pod, query) {
135
+ return (0, migrate_exec_js_1.runCommand)("kubectl", ["exec", "-n", cnpg_common_js_1.DATA_NAMESPACE, pod, "--", "psql", "-tAc", query]);
136
+ }
137
+ /**
138
+ * Build a matching WARN result for both cluster-dependent sections, used when
139
+ * they must be skipped for the same reason (kubectl missing, cluster
140
+ * unreachable, or no clusters found).
141
+ *
142
+ * @param reason - Human-readable explanation shown in both sections
143
+ * @returns Identical WARN results for the role and ownership sections
144
+ */
145
+ function skippedClusterSections(reason) {
146
+ const lines = [reason];
147
+ return {
148
+ roleSection: { status: migrate_report_js_1.CHECK_STATUS.WARN, lines },
149
+ ownershipSection: { status: migrate_report_js_1.CHECK_STATUS.WARN, lines },
150
+ };
151
+ }
152
+ /**
153
+ * Check every nimbus-managed CNPG cluster's role attributes and database
154
+ * ownership against the baseline that makes `Database`/`DatabaseRole`
155
+ * adoption a no-op.
156
+ *
157
+ * @param clusterReachable - Whether {@link checkCnpgCrds} could reach the cluster
158
+ * @returns Section results for role attributes and database ownership
159
+ */
160
+ function checkClusterState(clusterReachable) {
161
+ if (!clusterReachable) {
162
+ return skippedClusterSections("Skipped: could not reach the cluster to verify CRDs (see check 1 above).");
163
+ }
164
+ const discovery = listCnpgClusters();
165
+ if (!discovery.ok) {
166
+ return skippedClusterSections(`Skipped: could not list CloudNativePG clusters in namespace "${cnpg_common_js_1.DATA_NAMESPACE}": ${discovery.message}`);
167
+ }
168
+ const clusterNames = discovery.names;
169
+ if (clusterNames.length === 0) {
170
+ return skippedClusterSections(`No CloudNativePG clusters found in namespace "${cnpg_common_js_1.DATA_NAMESPACE}". ` +
171
+ "If you expected clusters here, verify your kubectl context.");
172
+ }
173
+ const roleLines = [];
174
+ const ownershipLines = [];
175
+ let roleDeviationCount = 0;
176
+ let ownershipMismatchCount = 0;
177
+ let rolesChecked = 0;
178
+ let databasesChecked = 0;
179
+ let roleCheckIncomplete = false;
180
+ let ownershipCheckIncomplete = false;
181
+ for (const clusterName of clusterNames) {
182
+ const pod = resolvePrimaryPod(clusterName);
183
+ const roleResult = runPsqlQuery(pod, migrate_cnpg_roles_js_1.ROLE_ATTRIBUTES_JSON_QUERY);
184
+ if (!roleResult.ok) {
185
+ roleCheckIncomplete = true;
186
+ roleLines.push(`cluster "${clusterName}": could not query pg_roles on pod "${pod}": ${roleResult.message}`);
187
+ }
188
+ else {
189
+ const parsed = (0, migrate_cnpg_roles_js_1.parseRoleRows)(roleResult.stdout);
190
+ // A row that could not be parsed is a role this check did NOT inspect, so
191
+ // it downgrades the section rather than shrinking the set it claims to
192
+ // have covered. Reporting "all roles match" while having skipped one is
193
+ // the failure mode this whole command exists to prevent.
194
+ for (const warning of parsed.warnings) {
195
+ roleCheckIncomplete = true;
196
+ roleLines.push(`cluster "${clusterName}": ${warning}`);
197
+ }
198
+ const roles = parsed.roles.filter((role) => !migrate_cnpg_roles_js_1.BUILTIN_ROLE_NAMES.includes(role.name));
199
+ rolesChecked += roles.length;
200
+ for (const role of roles) {
201
+ if (!(0, migrate_cnpg_roles_js_1.roleMatchesBaseline)(role)) {
202
+ roleDeviationCount += 1;
203
+ roleLines.push(`cluster "${clusterName}": ${(0, migrate_cnpg_roles_js_1.describeRoleDeviation)(role)}`);
204
+ }
205
+ }
206
+ }
207
+ const ownershipResult = runPsqlQuery(pod, migrate_cnpg_ownership_js_1.DATABASE_OWNERSHIP_JSON_QUERY);
208
+ if (!ownershipResult.ok) {
209
+ ownershipCheckIncomplete = true;
210
+ ownershipLines.push(`cluster "${clusterName}": could not query pg_database on pod "${pod}": ${ownershipResult.message}`);
211
+ }
212
+ else {
213
+ const parsed = (0, migrate_cnpg_ownership_js_1.parseDatabaseRows)(ownershipResult.stdout);
214
+ for (const warning of parsed.warnings) {
215
+ ownershipCheckIncomplete = true;
216
+ ownershipLines.push(`cluster "${clusterName}": ${warning}`);
217
+ }
218
+ const databases = parsed.databases.filter((database) => !migrate_cnpg_ownership_js_1.SYSTEM_DATABASE_NAMES.includes(database.name));
219
+ databasesChecked += databases.length;
220
+ for (const database of databases) {
221
+ if (database.owner !== database.name) {
222
+ ownershipMismatchCount += 1;
223
+ ownershipLines.push(`cluster "${clusterName}": database "${database.name}" is owned by role "${database.owner}" ` +
224
+ `— confirm this matches the "owner" set for this database in your Pulumi config.`);
225
+ }
226
+ }
227
+ }
228
+ }
229
+ if (roleDeviationCount === 0 && !roleCheckIncomplete) {
230
+ roleLines.unshift(`Checked ${rolesChecked} role(s) across ${clusterNames.length} cluster(s); all match the nimbus baseline.`);
231
+ }
232
+ else if (roleDeviationCount > 0) {
233
+ roleLines.unshift(`${roleDeviationCount} role(s) deviate from the nimbus baseline. DatabaseRole adoption ` +
234
+ "forces attributes the manifest omits back to this baseline, so any hand-granted " +
235
+ "privilege or membership listed below would be silently revoked.");
236
+ }
237
+ if (ownershipMismatchCount === 0 && !ownershipCheckIncomplete) {
238
+ ownershipLines.unshift(`Checked ${databasesChecked} database(s) across ${clusterNames.length} cluster(s); ` +
239
+ "ownership matches the nimbus naming convention.");
240
+ }
241
+ else if (ownershipMismatchCount > 0) {
242
+ ownershipLines.unshift(`${ownershipMismatchCount} database(s) have an owner that does not match the nimbus default ` +
243
+ "naming convention (owner name equal to database name).");
244
+ }
245
+ return {
246
+ roleSection: {
247
+ status: roleDeviationCount > 0 || roleCheckIncomplete ? migrate_report_js_1.CHECK_STATUS.WARN : migrate_report_js_1.CHECK_STATUS.PASS,
248
+ lines: roleLines,
249
+ },
250
+ ownershipSection: {
251
+ status: ownershipMismatchCount > 0 || ownershipCheckIncomplete
252
+ ? migrate_report_js_1.CHECK_STATUS.WARN
253
+ : migrate_report_js_1.CHECK_STATUS.PASS,
254
+ lines: ownershipLines,
255
+ },
256
+ };
257
+ }
258
+ //# sourceMappingURL=migrate-cnpg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate-cnpg.js","sourceRoot":"","sources":["../../../src/cli/migrate-cnpg.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAqCH,sCA0DC;AA0FD,8CA6HC;AApTD,+DAA4D;AAE5D,uDAA+C;AAC/C,2DAAmD;AAEnD,mEAMiC;AACjC,2EAIqC;AAErC,uDAAuD;AAC1C,QAAA,sBAAsB,GAAG,8BAA8B,CAAC;AACrE,2DAA2D;AAC9C,QAAA,2BAA2B,GAAG,kCAAkC,CAAC;AAQ9E;;;;;GAKG;AACH,SAAgB,aAAa;IAC3B,MAAM,MAAM,GAAG,IAAA,4BAAU,EAAC,SAAS,EAAE;QACnC,KAAK;QACL,KAAK;QACL,8BAAsB;QACtB,mCAA2B;QAC3B,IAAI;QACJ,MAAM;KACP,CAAC,CAAC;IAEH,IAAI,MAAM,CAAC,EAAE,EAAE,CAAC;QACd,OAAO;YACL,OAAO,EAAE;gBACP,MAAM,EAAE,gCAAY,CAAC,IAAI;gBACzB,KAAK,EAAE,CAAC,SAAS,8BAAsB,QAAQ,mCAA2B,GAAG,CAAC;aAC/E;YACD,gBAAgB,EAAE,IAAI;SACvB,CAAC;IACJ,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO;YACL,OAAO,EAAE;gBACP,MAAM,EAAE,gCAAY,CAAC,IAAI;gBACzB,KAAK,EAAE;oBACL,yEAAyE;oBACzE,6EAA6E;iBAC9E;aACF;YACD,gBAAgB,EAAE,KAAK;SACxB,CAAC;IACJ,CAAC;IAED,IAAI,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,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,uBAAuB,QAAQ,CAAC,KAAK,IAAI;wBAC3F,iFAAiF,CACpF,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,kBAAkB,KAAK,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACrD,SAAS,CAAC,OAAO,CACf,WAAW,YAAY,mBAAmB,YAAY,CAAC,MAAM,6CAA6C,CAC3G,CAAC;IACJ,CAAC;SAAM,IAAI,kBAAkB,GAAG,CAAC,EAAE,CAAC;QAClC,SAAS,CAAC,OAAO,CACf,GAAG,kBAAkB,mEAAmE;YACtF,kFAAkF;YAClF,iEAAiE,CACpE,CAAC;IACJ,CAAC;IAED,IAAI,sBAAsB,KAAK,CAAC,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAC9D,cAAc,CAAC,OAAO,CACpB,WAAW,gBAAgB,uBAAuB,YAAY,CAAC,MAAM,eAAe;YAClF,iDAAiD,CACpD,CAAC;IACJ,CAAC;SAAM,IAAI,sBAAsB,GAAG,CAAC,EAAE,CAAC;QACtC,cAAc,CAAC,OAAO,CACpB,GAAG,sBAAsB,oEAAoE;YAC3F,wDAAwD,CAC3D,CAAC;IACJ,CAAC;IAED,OAAO;QACL,WAAW,EAAE;YACX,MAAM,EAAE,kBAAkB,GAAG,CAAC,IAAI,mBAAmB,CAAC,CAAC,CAAC,gCAAY,CAAC,IAAI,CAAC,CAAC,CAAC,gCAAY,CAAC,IAAI;YAC7F,KAAK,EAAE,SAAS;SACjB;QACD,gBAAgB,EAAE;YAChB,MAAM,EACJ,sBAAsB,GAAG,CAAC,IAAI,wBAAwB;gBACpD,CAAC,CAAC,gCAAY,CAAC,IAAI;gBACnB,CAAC,CAAC,gCAAY,CAAC,IAAI;YACvB,KAAK,EAAE,cAAc;SACtB;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Command execution primitives for `nimbus migrate`.
3
+ *
4
+ * Every external call the migrate command makes goes through {@link runCommand},
5
+ * which always uses `execFileSync` with an argument array — never a
6
+ * shell-interpolated string — and never throws. Callers get back a discriminated
7
+ * result instead, so a missing tool, an unreachable cluster, or a non-zero exit
8
+ * code can be turned into a clear WARN/FAIL instead of an unhandled exception.
9
+ *
10
+ * @module cli/migrate-exec
11
+ */
12
+ /** Successful command execution. */
13
+ export interface ICommandSuccess {
14
+ readonly ok: true;
15
+ readonly stdout: string;
16
+ }
17
+ /** Failed command execution, with enough detail to explain why to the operator. */
18
+ export interface ICommandFailure {
19
+ readonly ok: false;
20
+ readonly reason: "not-found" | "error";
21
+ readonly message: string;
22
+ readonly exitCode?: number;
23
+ }
24
+ /** Outcome of {@link runCommand}: either captured stdout, or a structured failure. */
25
+ export type CommandResult = ICommandSuccess | ICommandFailure;
26
+ /**
27
+ * Run a command and capture its outcome without ever throwing.
28
+ *
29
+ * Uses `execFileSync` with an argument array (never a shell-interpolated
30
+ * string) so nothing in cluster or filesystem output can be interpreted as a
31
+ * shell command.
32
+ *
33
+ * @param cmd - Executable to run
34
+ * @param args - Arguments, passed verbatim (no shell involved)
35
+ * @returns The command's stdout on success, or a structured failure reason
36
+ */
37
+ export declare function runCommand(cmd: string, args: readonly string[]): CommandResult;
38
+ /**
39
+ * Split raw command stdout into trimmed, non-empty lines.
40
+ *
41
+ * @param stdout - Raw command output
42
+ * @returns Trimmed, non-empty lines
43
+ */
44
+ export declare function splitNonEmptyLines(stdout: string): string[];
45
+ //# sourceMappingURL=migrate-exec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate-exec.d.ts","sourceRoot":"","sources":["../../../src/cli/migrate-exec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,oCAAoC;AACpC,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAClB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,mFAAmF;AACnF,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC;IACvC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,sFAAsF;AACtF,MAAM,MAAM,aAAa,GAAG,eAAe,GAAG,eAAe,CAAC;AAiD9D;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,aAAa,CAkB9E;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAK3D"}
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ /**
3
+ * Command execution primitives for `nimbus migrate`.
4
+ *
5
+ * Every external call the migrate command makes goes through {@link runCommand},
6
+ * which always uses `execFileSync` with an argument array — never a
7
+ * shell-interpolated string — and never throws. Callers get back a discriminated
8
+ * result instead, so a missing tool, an unreachable cluster, or a non-zero exit
9
+ * code can be turned into a clear WARN/FAIL instead of an unhandled exception.
10
+ *
11
+ * @module cli/migrate-exec
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.runCommand = runCommand;
15
+ exports.splitNonEmptyLines = splitNonEmptyLines;
16
+ const child_process_1 = require("child_process");
17
+ /**
18
+ * Narrow an unknown thrown value to a Node.js errno exception.
19
+ *
20
+ * @param error - Value caught from a try/catch block
21
+ * @returns True when the value looks like a Node.js system error
22
+ */
23
+ function isErrnoException(error) {
24
+ return error instanceof Error;
25
+ }
26
+ /**
27
+ * Extract the numeric exit code from an `execFileSync` failure, if present.
28
+ *
29
+ * @param error - Value caught from a try/catch block
30
+ * @returns The process exit code, or undefined when unavailable
31
+ */
32
+ function extractExitCode(error) {
33
+ if (error && typeof error === "object" && "status" in error) {
34
+ const status = error.status;
35
+ return typeof status === "number" ? status : undefined;
36
+ }
37
+ return undefined;
38
+ }
39
+ /**
40
+ * Extract a human-readable message from an `execFileSync` failure, preferring
41
+ * captured stderr over the generic Error message.
42
+ *
43
+ * @param error - Value caught from a try/catch block
44
+ * @returns A trimmed, human-readable error message
45
+ */
46
+ function extractErrorMessage(error) {
47
+ if (error && typeof error === "object") {
48
+ const withStreams = error;
49
+ if (typeof withStreams.stderr === "string" && withStreams.stderr.trim().length > 0) {
50
+ return withStreams.stderr.trim();
51
+ }
52
+ if (Buffer.isBuffer(withStreams.stderr) && withStreams.stderr.length > 0) {
53
+ return withStreams.stderr.toString("utf8").trim();
54
+ }
55
+ if (typeof withStreams.message === "string") {
56
+ return withStreams.message;
57
+ }
58
+ }
59
+ return String(error);
60
+ }
61
+ /**
62
+ * Run a command and capture its outcome without ever throwing.
63
+ *
64
+ * Uses `execFileSync` with an argument array (never a shell-interpolated
65
+ * string) so nothing in cluster or filesystem output can be interpreted as a
66
+ * shell command.
67
+ *
68
+ * @param cmd - Executable to run
69
+ * @param args - Arguments, passed verbatim (no shell involved)
70
+ * @returns The command's stdout on success, or a structured failure reason
71
+ */
72
+ function runCommand(cmd, args) {
73
+ try {
74
+ const stdout = (0, child_process_1.execFileSync)(cmd, [...args], {
75
+ encoding: "utf8",
76
+ stdio: ["ignore", "pipe", "pipe"],
77
+ });
78
+ return { ok: true, stdout };
79
+ }
80
+ catch (error) {
81
+ if (isErrnoException(error) && error.code === "ENOENT") {
82
+ return { ok: false, reason: "not-found", message: `"${cmd}" was not found on PATH.` };
83
+ }
84
+ return {
85
+ ok: false,
86
+ reason: "error",
87
+ message: extractErrorMessage(error),
88
+ exitCode: extractExitCode(error),
89
+ };
90
+ }
91
+ }
92
+ /**
93
+ * Split raw command stdout into trimmed, non-empty lines.
94
+ *
95
+ * @param stdout - Raw command output
96
+ * @returns Trimmed, non-empty lines
97
+ */
98
+ function splitNonEmptyLines(stdout) {
99
+ return stdout
100
+ .split("\n")
101
+ .map((line) => line.trim())
102
+ .filter((line) => line.length > 0);
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3
+ *
4
+ * `psql -tAc` prints columns separated by `|` and escapes nothing, so a value
5
+ * containing that character is indistinguishable from a column boundary. A role
6
+ * called `read|er` — legal in PostgreSQL, which quotes identifiers — produced a
7
+ * line with ten fields where the parser expected nine, and the row was dropped.
8
+ * The check could then report that every role matches the adoption baseline
9
+ * while having skipped precisely the role whose attributes `DatabaseRole`
10
+ * adoption would reset: a false all-clear from the tool whose entire purpose is
11
+ * catching that.
12
+ *
13
+ * {@link toJsonRowsQuery} wraps a row-returning query so PostgreSQL renders the
14
+ * whole result as one JSON document, which escapes delimiters, quotes and
15
+ * newlines for us. The documented query itself is kept verbatim as the wrapped
16
+ * subquery, so this check and the manual procedure in
17
+ * `docs/cnpg-declarative-databases.md` still cannot drift apart.
18
+ *
19
+ * Nothing here drops a row it cannot read. {@link parseJsonRows} returns the
20
+ * rows it understood **and** a warning for everything else, which the caller
21
+ * surfaces as a WARN naming the row rather than silently omitting it.
22
+ *
23
+ * @module cli/migrate-psql
24
+ */
25
+ /**
26
+ * Wrap a row-returning query so `psql -tAc` emits a single JSON array.
27
+ *
28
+ * `json_agg` over `row_to_json` renders every column with its own name and
29
+ * escapes anything a value might contain, so no `|`, newline or quote in a role
30
+ * or database name can shift a field boundary. `coalesce` keeps the output a
31
+ * valid document (`[]`) when the query matches nothing, rather than the empty
32
+ * string `json_agg` returns for no rows.
33
+ *
34
+ * The query is embedded verbatim, so the constant a check runs stays byte-equal
35
+ * to the one the migration guide tells an operator to run by hand.
36
+ *
37
+ * @param query - A row-returning `SELECT`, without a trailing semicolon
38
+ * @returns A query returning one row with one JSON-array column
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * toJsonRowsQuery("SELECT datname FROM pg_database");
43
+ * // SELECT coalesce(json_agg(row_to_json(nimbus_row)), '[]'::json)
44
+ * // FROM (SELECT datname FROM pg_database) AS nimbus_row
45
+ * ```
46
+ */
47
+ export declare function toJsonRowsQuery(query: string): string;
48
+ /** Rows parsed out of one JSON document, plus what could not be parsed. */
49
+ export interface IJsonRowsResult {
50
+ /** Every element that was a JSON object, in the order returned. */
51
+ readonly rows: ReadonlyArray<Record<string, unknown>>;
52
+ /** One line per unreadable element, or per wholly unusable output. */
53
+ readonly warnings: ReadonlyArray<string>;
54
+ }
55
+ /**
56
+ * Parse the output of a {@link toJsonRowsQuery} query into row objects.
57
+ *
58
+ * A row that cannot be used is reported, never dropped: the caller turns each
59
+ * warning into a WARN line, so an unreadable row downgrades the check instead of
60
+ * quietly shrinking the set it claims to have inspected.
61
+ *
62
+ * @param stdout - Raw `psql -tAc` output
63
+ * @param subject - What the query was reading, named in warnings (e.g. "pg_roles")
64
+ * @returns The object rows, and a warning for anything unusable
65
+ */
66
+ export declare function parseJsonRows(stdout: string, subject: string): IJsonRowsResult;
67
+ /**
68
+ * Read a column that must hold a non-empty string.
69
+ *
70
+ * @param row - Parsed row
71
+ * @param column - Column name
72
+ * @returns The value, or undefined when absent, empty, or another type
73
+ */
74
+ export declare function readString(row: Record<string, unknown>, column: string): string | undefined;
75
+ /**
76
+ * Read a column that may legitimately hold SQL `NULL`.
77
+ *
78
+ * A nullable column has three states this parser must keep apart: a value, an
79
+ * explicit `NULL` — which is data, not a failure (`rolvaliduntil` NULL is how
80
+ * PostgreSQL spells "this password never expires") — and a column that is absent
81
+ * or of the wrong type, which is unreadable. Only the last may warn, so `null`
82
+ * is returned as itself rather than collapsed into the `undefined` that
83
+ * {@link readString} uses for "could not read this".
84
+ *
85
+ * An empty string is a value here, unlike in {@link readString}: `COMMENT ON
86
+ * ROLE … IS ''` is a real, if pointless, state and must not read as unreadable.
87
+ *
88
+ * @param row - Parsed row
89
+ * @param column - Column name
90
+ * @returns The value, `null` for a SQL `NULL`, or undefined when the column is
91
+ * absent or of another type
92
+ */
93
+ export declare function readNullableString(row: Record<string, unknown>, column: string): string | null | undefined;
94
+ /**
95
+ * Read a column that must hold a JSON boolean.
96
+ *
97
+ * PostgreSQL's `boolean` renders as a JSON boolean, not as psql's `t`/`f`, so a
98
+ * `"t"` here means the query was not the wrapped JSON one.
99
+ *
100
+ * @param row - Parsed row
101
+ * @param column - Column name
102
+ * @returns The value, or undefined when absent or another type
103
+ */
104
+ export declare function readBoolean(row: Record<string, unknown>, column: string): boolean | undefined;
105
+ /**
106
+ * Read a column that must hold a finite JSON number.
107
+ *
108
+ * @param row - Parsed row
109
+ * @param column - Column name
110
+ * @returns The value, or undefined when absent, not finite, or another type
111
+ */
112
+ export declare function readNumber(row: Record<string, unknown>, column: string): number | undefined;
113
+ /**
114
+ * Read a column that must hold an array of strings.
115
+ *
116
+ * A PostgreSQL `text[]` renders as a JSON array, so role memberships arrive
117
+ * already separated — a membership containing a comma or a `|` can no longer
118
+ * blur into its neighbour the way it could in psql's `{a,b}` array text.
119
+ *
120
+ * @param row - Parsed row
121
+ * @param column - Column name
122
+ * @returns The values, or undefined when absent or not an array of strings
123
+ */
124
+ export declare function readStringArray(row: Record<string, unknown>, column: string): ReadonlyArray<string> | undefined;
125
+ //# sourceMappingURL=migrate-psql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate-psql.d.ts","sourceRoot":"","sources":["../../../src/cli/migrate-psql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAQH;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKrD;AAED,2EAA2E;AAC3E,MAAM,WAAW,eAAe;IAC9B,mEAAmE;IACnE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACtD,sEAAsE;IACtE,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CAC1C;AAiBD;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,eAAe,CA4C9E;AAED;;;;;;GAMG;A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