@take-out/postgres 0.0.28

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 (186) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +242 -0
  3. package/cli.cjs +3 -0
  4. package/dist/cjs/build.cjs +26 -0
  5. package/dist/cjs/build.js +21 -0
  6. package/dist/cjs/build.js.map +6 -0
  7. package/dist/cjs/build.native.js +29 -0
  8. package/dist/cjs/build.native.js.map +1 -0
  9. package/dist/cjs/cli.cjs +156 -0
  10. package/dist/cjs/cli.js +128 -0
  11. package/dist/cjs/cli.js.map +6 -0
  12. package/dist/cjs/cli.native.js +164 -0
  13. package/dist/cjs/cli.native.js.map +1 -0
  14. package/dist/cjs/createServerHelpers.cjs +37 -0
  15. package/dist/cjs/createServerHelpers.js +28 -0
  16. package/dist/cjs/createServerHelpers.js.map +6 -0
  17. package/dist/cjs/createServerHelpers.native.js +43 -0
  18. package/dist/cjs/createServerHelpers.native.js.map +1 -0
  19. package/dist/cjs/helpers/chunkedQuery.cjs +60 -0
  20. package/dist/cjs/helpers/chunkedQuery.js +51 -0
  21. package/dist/cjs/helpers/chunkedQuery.js.map +6 -0
  22. package/dist/cjs/helpers/chunkedQuery.native.js +73 -0
  23. package/dist/cjs/helpers/chunkedQuery.native.js.map +1 -0
  24. package/dist/cjs/helpers/getDBClient.cjs +172 -0
  25. package/dist/cjs/helpers/getDBClient.js +179 -0
  26. package/dist/cjs/helpers/getDBClient.js.map +6 -0
  27. package/dist/cjs/helpers/getDBClient.native.js +189 -0
  28. package/dist/cjs/helpers/getDBClient.native.js.map +1 -0
  29. package/dist/cjs/index.cjs +59 -0
  30. package/dist/cjs/index.js +45 -0
  31. package/dist/cjs/index.js.map +6 -0
  32. package/dist/cjs/index.native.js +64 -0
  33. package/dist/cjs/index.native.js.map +1 -0
  34. package/dist/cjs/migrate.cjs +117 -0
  35. package/dist/cjs/migrate.js +106 -0
  36. package/dist/cjs/migrate.js.map +6 -0
  37. package/dist/cjs/migrate.native.js +185 -0
  38. package/dist/cjs/migrate.native.js.map +1 -0
  39. package/dist/cjs/scripts/build-migrations.cjs +81 -0
  40. package/dist/cjs/scripts/build-migrations.js +69 -0
  41. package/dist/cjs/scripts/build-migrations.js.map +6 -0
  42. package/dist/cjs/scripts/build-migrations.native.js +86 -0
  43. package/dist/cjs/scripts/build-migrations.native.js.map +1 -0
  44. package/dist/cjs/scripts/drizzle-migrations-sync.cjs +111 -0
  45. package/dist/cjs/scripts/drizzle-migrations-sync.js +101 -0
  46. package/dist/cjs/scripts/drizzle-migrations-sync.js.map +6 -0
  47. package/dist/cjs/scripts/drizzle-migrations-sync.native.js +209 -0
  48. package/dist/cjs/scripts/drizzle-migrations-sync.native.js.map +1 -0
  49. package/dist/cjs/scripts/migration-add.cjs +53 -0
  50. package/dist/cjs/scripts/migration-add.js +40 -0
  51. package/dist/cjs/scripts/migration-add.js.map +6 -0
  52. package/dist/cjs/scripts/migration-add.native.js +72 -0
  53. package/dist/cjs/scripts/migration-add.native.js.map +1 -0
  54. package/dist/cjs/scripts/pg_dump.cjs +49 -0
  55. package/dist/cjs/scripts/pg_dump.js +36 -0
  56. package/dist/cjs/scripts/pg_dump.js.map +6 -0
  57. package/dist/cjs/scripts/pg_dump.native.js +55 -0
  58. package/dist/cjs/scripts/pg_dump.native.js.map +1 -0
  59. package/dist/cjs/scripts/psql.cjs +50 -0
  60. package/dist/cjs/scripts/psql.js +37 -0
  61. package/dist/cjs/scripts/psql.js.map +6 -0
  62. package/dist/cjs/scripts/psql.native.js +56 -0
  63. package/dist/cjs/scripts/psql.native.js.map +1 -0
  64. package/dist/cjs/sql.cjs +40 -0
  65. package/dist/cjs/sql.js +35 -0
  66. package/dist/cjs/sql.js.map +6 -0
  67. package/dist/cjs/sql.native.js +49 -0
  68. package/dist/cjs/sql.native.js.map +1 -0
  69. package/dist/esm/build.js +5 -0
  70. package/dist/esm/build.js.map +6 -0
  71. package/dist/esm/build.mjs +3 -0
  72. package/dist/esm/build.mjs.map +1 -0
  73. package/dist/esm/build.native.js +3 -0
  74. package/dist/esm/build.native.js.map +1 -0
  75. package/dist/esm/cli.js +134 -0
  76. package/dist/esm/cli.js.map +6 -0
  77. package/dist/esm/cli.mjs +157 -0
  78. package/dist/esm/cli.mjs.map +1 -0
  79. package/dist/esm/cli.native.js +162 -0
  80. package/dist/esm/cli.native.js.map +1 -0
  81. package/dist/esm/createServerHelpers.js +13 -0
  82. package/dist/esm/createServerHelpers.js.map +6 -0
  83. package/dist/esm/createServerHelpers.mjs +14 -0
  84. package/dist/esm/createServerHelpers.mjs.map +1 -0
  85. package/dist/esm/createServerHelpers.native.js +17 -0
  86. package/dist/esm/createServerHelpers.native.js.map +1 -0
  87. package/dist/esm/helpers/chunkedQuery.js +35 -0
  88. package/dist/esm/helpers/chunkedQuery.js.map +6 -0
  89. package/dist/esm/helpers/chunkedQuery.mjs +36 -0
  90. package/dist/esm/helpers/chunkedQuery.mjs.map +1 -0
  91. package/dist/esm/helpers/chunkedQuery.native.js +46 -0
  92. package/dist/esm/helpers/chunkedQuery.native.js.map +1 -0
  93. package/dist/esm/helpers/getDBClient.js +155 -0
  94. package/dist/esm/helpers/getDBClient.js.map +6 -0
  95. package/dist/esm/helpers/getDBClient.mjs +136 -0
  96. package/dist/esm/helpers/getDBClient.mjs.map +1 -0
  97. package/dist/esm/helpers/getDBClient.native.js +150 -0
  98. package/dist/esm/helpers/getDBClient.native.js.map +1 -0
  99. package/dist/esm/index.js +29 -0
  100. package/dist/esm/index.js.map +6 -0
  101. package/dist/esm/index.mjs +18 -0
  102. package/dist/esm/index.mjs.map +1 -0
  103. package/dist/esm/index.native.js +20 -0
  104. package/dist/esm/index.native.js.map +1 -0
  105. package/dist/esm/migrate.js +91 -0
  106. package/dist/esm/migrate.js.map +6 -0
  107. package/dist/esm/migrate.mjs +94 -0
  108. package/dist/esm/migrate.mjs.map +1 -0
  109. package/dist/esm/migrate.native.js +159 -0
  110. package/dist/esm/migrate.native.js.map +1 -0
  111. package/dist/esm/scripts/build-migrations.js +46 -0
  112. package/dist/esm/scripts/build-migrations.js.map +6 -0
  113. package/dist/esm/scripts/build-migrations.mjs +47 -0
  114. package/dist/esm/scripts/build-migrations.mjs.map +1 -0
  115. package/dist/esm/scripts/build-migrations.native.js +49 -0
  116. package/dist/esm/scripts/build-migrations.native.js.map +1 -0
  117. package/dist/esm/scripts/drizzle-migrations-sync.js +87 -0
  118. package/dist/esm/scripts/drizzle-migrations-sync.js.map +6 -0
  119. package/dist/esm/scripts/drizzle-migrations-sync.mjs +88 -0
  120. package/dist/esm/scripts/drizzle-migrations-sync.mjs.map +1 -0
  121. package/dist/esm/scripts/drizzle-migrations-sync.native.js +183 -0
  122. package/dist/esm/scripts/drizzle-migrations-sync.native.js.map +1 -0
  123. package/dist/esm/scripts/migration-add.js +25 -0
  124. package/dist/esm/scripts/migration-add.js.map +6 -0
  125. package/dist/esm/scripts/migration-add.mjs +30 -0
  126. package/dist/esm/scripts/migration-add.mjs.map +1 -0
  127. package/dist/esm/scripts/migration-add.native.js +46 -0
  128. package/dist/esm/scripts/migration-add.native.js.map +1 -0
  129. package/dist/esm/scripts/pg_dump.js +20 -0
  130. package/dist/esm/scripts/pg_dump.js.map +6 -0
  131. package/dist/esm/scripts/pg_dump.mjs +26 -0
  132. package/dist/esm/scripts/pg_dump.mjs.map +1 -0
  133. package/dist/esm/scripts/pg_dump.native.js +29 -0
  134. package/dist/esm/scripts/pg_dump.native.js.map +1 -0
  135. package/dist/esm/scripts/psql.js +21 -0
  136. package/dist/esm/scripts/psql.js.map +6 -0
  137. package/dist/esm/scripts/psql.mjs +27 -0
  138. package/dist/esm/scripts/psql.mjs.map +1 -0
  139. package/dist/esm/scripts/psql.native.js +30 -0
  140. package/dist/esm/scripts/psql.native.js.map +1 -0
  141. package/dist/esm/sql.js +19 -0
  142. package/dist/esm/sql.js.map +6 -0
  143. package/dist/esm/sql.mjs +15 -0
  144. package/dist/esm/sql.mjs.map +1 -0
  145. package/dist/esm/sql.native.js +21 -0
  146. package/dist/esm/sql.native.js.map +1 -0
  147. package/package.json +67 -0
  148. package/src/build.ts +2 -0
  149. package/src/cli.ts +153 -0
  150. package/src/createServerHelpers.ts +20 -0
  151. package/src/helpers/chunkedQuery.ts +91 -0
  152. package/src/helpers/getDBClient.ts +264 -0
  153. package/src/index.ts +36 -0
  154. package/src/migrate.ts +192 -0
  155. package/src/scripts/build-migrations.ts +66 -0
  156. package/src/scripts/drizzle-migrations-sync.ts +179 -0
  157. package/src/scripts/migration-add.ts +54 -0
  158. package/src/scripts/pg_dump.ts +46 -0
  159. package/src/scripts/psql.ts +51 -0
  160. package/src/sql.ts +36 -0
  161. package/types/build.d.ts +2 -0
  162. package/types/build.d.ts.map +1 -0
  163. package/types/cli.d.ts +3 -0
  164. package/types/cli.d.ts.map +1 -0
  165. package/types/createServerHelpers.d.ts +9 -0
  166. package/types/createServerHelpers.d.ts.map +1 -0
  167. package/types/helpers/chunkedQuery.d.ts +17 -0
  168. package/types/helpers/chunkedQuery.d.ts.map +1 -0
  169. package/types/helpers/getDBClient.d.ts +11 -0
  170. package/types/helpers/getDBClient.d.ts.map +1 -0
  171. package/types/index.d.ts +10 -0
  172. package/types/index.d.ts.map +1 -0
  173. package/types/migrate.d.ts +25 -0
  174. package/types/migrate.d.ts.map +1 -0
  175. package/types/scripts/build-migrations.d.ts +8 -0
  176. package/types/scripts/build-migrations.d.ts.map +1 -0
  177. package/types/scripts/drizzle-migrations-sync.d.ts +11 -0
  178. package/types/scripts/drizzle-migrations-sync.d.ts.map +1 -0
  179. package/types/scripts/migration-add.d.ts +6 -0
  180. package/types/scripts/migration-add.d.ts.map +1 -0
  181. package/types/scripts/pg_dump.d.ts +11 -0
  182. package/types/scripts/pg_dump.d.ts.map +1 -0
  183. package/types/scripts/psql.d.ts +11 -0
  184. package/types/scripts/psql.d.ts.map +1 -0
  185. package/types/sql.d.ts +9 -0
  186. package/types/sql.d.ts.map +1 -0
@@ -0,0 +1,117 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: !0
9
+ });
10
+ },
11
+ __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ return to;
17
+ };
18
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
+ value: !0
20
+ }), mod);
21
+ var migrate_exports = {};
22
+ __export(migrate_exports, {
23
+ migrate: () => migrate
24
+ });
25
+ module.exports = __toCommonJS(migrate_exports);
26
+ var import_node_path = require("node:path"),
27
+ import_getDBClient = require("./helpers/getDBClient.cjs");
28
+ const isServerless = !!(process.env.AWS_LAMBDA_FUNCTION_NAME || process.env.AWS_LAMBDA_RUNTIME_API || process.env.LAMBDA_RUNTIME_DIR || process.env.IS_SERVERLESS);
29
+ async function migrate(options) {
30
+ const {
31
+ connectionString,
32
+ migrationsGlob,
33
+ createDatabases = [],
34
+ onMigrationComplete,
35
+ gitSha,
36
+ cvrDb,
37
+ changeDb
38
+ } = options;
39
+ console.info(`Running migrations${gitSha ? ` for git version: ${gitSha}` : ""}`);
40
+ const client = await (0, import_getDBClient.getDBClient)({
41
+ connectionString
42
+ }),
43
+ hasDB = async name => {
44
+ const result = !!(await client.query(`
45
+ SELECT 1 FROM pg_database WHERE datname = '${name}'
46
+ `)).rows.length;
47
+ return console.info(result ? `${name} db exists` : `creating ${name} db`), result;
48
+ };
49
+ if (cvrDb || changeDb) {
50
+ if (!cvrDb) throw new Error("Missing cvrDb");
51
+ const zeroDBNames = [(0, import_node_path.basename)(cvrDb || ""), (0, import_node_path.basename)(changeDb || "")].filter(Boolean);
52
+ for (const name of zeroDBNames) (await hasDB(name)) || (await client.query(`CREATE DATABASE ${name};`));
53
+ }
54
+ for (const dbUrl of createDatabases) {
55
+ const name = (0, import_node_path.basename)(dbUrl);
56
+ (await hasDB(name)) || (await client.query(`CREATE DATABASE ${name};`));
57
+ }
58
+ try {
59
+ await client.query("BEGIN"), await client.query(`
60
+ CREATE TABLE IF NOT EXISTS migrations (
61
+ id SERIAL PRIMARY KEY,
62
+ name VARCHAR(255) NOT NULL,
63
+ run_on TIMESTAMP NOT NULL DEFAULT NOW()
64
+ )
65
+ `);
66
+ const appliedMigrations = await client.query("SELECT name FROM migrations"),
67
+ appliedMigrationNames = new Set(appliedMigrations.rows.map(row => row.name)),
68
+ tsMigrationsSorted = Object.entries(migrationsGlob).sort(([a], [b]) => a.localeCompare(b)).map(([file, run]) => ({
69
+ name: (0, import_node_path.basename)(file).replace(".ts", ""),
70
+ run
71
+ })).filter(({
72
+ name
73
+ }) => /^[\d]+/.test(name));
74
+ console.info(`Found ${tsMigrationsSorted.length} TypeScript migrations`);
75
+ const migrations = [...(await Promise.all(tsMigrationsSorted.map(async ({
76
+ name,
77
+ run
78
+ }) => {
79
+ if (appliedMigrationNames.has(name)) return console.info(`TypeScript migration applied already: ${name}`), null;
80
+ try {
81
+ return {
82
+ ...(await run()),
83
+ name
84
+ };
85
+ } catch (error) {
86
+ throw console.error(`Failed to load TypeScript migration ${name}:`, error), error;
87
+ }
88
+ })).then(migrations2 => migrations2.filter(Boolean)))].sort((a, b) => a.name.localeCompare(b.name));
89
+ if (!migrations.length) console.info("No migrations to apply!"), await client.query("COMMIT");else {
90
+ for (const migration of migrations) console.info(`Migrating: ${migration.name}`), migration.up && (console.info(`Applying migration: ${migration.name}`), await migration.up(client)), await client.query("INSERT INTO migrations (name) VALUES ($1)", [migration.name]), console.info(`Successfully applied migration: ${migration.name}`);
91
+ await client.query("COMMIT"), console.info("Successfully committed all migrations");
92
+ }
93
+ } catch (e) {
94
+ console.error("Migration failed, rolling back:", e), await client.query("ROLLBACK"), console.info("Releasing client connection...");
95
+ try {
96
+ client.release(!1);
97
+ } catch (releaseErr) {
98
+ console.error("Error releasing connection after rollback:", releaseErr);
99
+ }
100
+ throw e;
101
+ }
102
+ onMigrationComplete && (await onMigrationComplete()), console.info("Releasing client connection...");
103
+ try {
104
+ client.release(!1);
105
+ } catch (err) {
106
+ console.error("Error releasing connection gracefully, trying to destroy:", err);
107
+ try {
108
+ client.release(!0);
109
+ } catch (destroyErr) {
110
+ console.error("Error destroying connection:", destroyErr);
111
+ }
112
+ }
113
+ console.info("\u{1F64C} Done migrating"), exitProcess();
114
+ }
115
+ function exitProcess() {
116
+ typeof process > "u" || isServerless || process.exit(0);
117
+ }
@@ -0,0 +1,106 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: !0 });
8
+ }, __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from == "object" || typeof from == "function")
10
+ for (let key of __getOwnPropNames(from))
11
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
+ var migrate_exports = {};
16
+ __export(migrate_exports, {
17
+ migrate: () => migrate
18
+ });
19
+ module.exports = __toCommonJS(migrate_exports);
20
+ var import_node_path = require("node:path"), import_getDBClient = require("./helpers/getDBClient");
21
+ const isServerless = !!(process.env.AWS_LAMBDA_FUNCTION_NAME || process.env.AWS_LAMBDA_RUNTIME_API || process.env.LAMBDA_RUNTIME_DIR || process.env.IS_SERVERLESS);
22
+ async function migrate(options) {
23
+ const {
24
+ connectionString,
25
+ migrationsGlob,
26
+ createDatabases = [],
27
+ onMigrationComplete,
28
+ gitSha,
29
+ cvrDb,
30
+ changeDb
31
+ } = options;
32
+ console.info(`Running migrations${gitSha ? ` for git version: ${gitSha}` : ""}`);
33
+ const client = await (0, import_getDBClient.getDBClient)({ connectionString }), hasDB = async (name) => {
34
+ const result = !!(await client.query(`
35
+ SELECT 1 FROM pg_database WHERE datname = '${name}'
36
+ `)).rows.length;
37
+ return console.info(result ? `${name} db exists` : `creating ${name} db`), result;
38
+ };
39
+ if (cvrDb || changeDb) {
40
+ if (!cvrDb)
41
+ throw new Error("Missing cvrDb");
42
+ const zeroDBNames = [(0, import_node_path.basename)(cvrDb || ""), (0, import_node_path.basename)(changeDb || "")].filter(Boolean);
43
+ for (const name of zeroDBNames)
44
+ await hasDB(name) || await client.query(`CREATE DATABASE ${name};`);
45
+ }
46
+ for (const dbUrl of createDatabases) {
47
+ const name = (0, import_node_path.basename)(dbUrl);
48
+ await hasDB(name) || await client.query(`CREATE DATABASE ${name};`);
49
+ }
50
+ try {
51
+ await client.query("BEGIN"), await client.query(`
52
+ CREATE TABLE IF NOT EXISTS migrations (
53
+ id SERIAL PRIMARY KEY,
54
+ name VARCHAR(255) NOT NULL,
55
+ run_on TIMESTAMP NOT NULL DEFAULT NOW()
56
+ )
57
+ `);
58
+ const appliedMigrations = await client.query("SELECT name FROM migrations"), appliedMigrationNames = new Set(appliedMigrations.rows.map((row) => row.name)), tsMigrationsSorted = Object.entries(migrationsGlob).sort(([a], [b]) => a.localeCompare(b)).map(([file, run]) => ({
59
+ name: (0, import_node_path.basename)(file).replace(".ts", ""),
60
+ run
61
+ })).filter(({ name }) => /^[\d]+/.test(name));
62
+ console.info(`Found ${tsMigrationsSorted.length} TypeScript migrations`);
63
+ const migrations = [...await Promise.all(
64
+ tsMigrationsSorted.map(async ({ name, run }) => {
65
+ if (appliedMigrationNames.has(name))
66
+ return console.info(`TypeScript migration applied already: ${name}`), null;
67
+ try {
68
+ return { ...await run(), name };
69
+ } catch (error) {
70
+ throw console.error(`Failed to load TypeScript migration ${name}:`, error), error;
71
+ }
72
+ })
73
+ ).then((migrations2) => migrations2.filter(Boolean))].sort((a, b) => a.name.localeCompare(b.name));
74
+ if (!migrations.length)
75
+ console.info("No migrations to apply!"), await client.query("COMMIT");
76
+ else {
77
+ for (const migration of migrations)
78
+ console.info(`Migrating: ${migration.name}`), migration.up && (console.info(`Applying migration: ${migration.name}`), await migration.up(client)), await client.query("INSERT INTO migrations (name) VALUES ($1)", [migration.name]), console.info(`Successfully applied migration: ${migration.name}`);
79
+ await client.query("COMMIT"), console.info("Successfully committed all migrations");
80
+ }
81
+ } catch (e) {
82
+ console.error("Migration failed, rolling back:", e), await client.query("ROLLBACK"), console.info("Releasing client connection...");
83
+ try {
84
+ client.release(!1);
85
+ } catch (releaseErr) {
86
+ console.error("Error releasing connection after rollback:", releaseErr);
87
+ }
88
+ throw e;
89
+ }
90
+ onMigrationComplete && await onMigrationComplete(), console.info("Releasing client connection...");
91
+ try {
92
+ client.release(!1);
93
+ } catch (err) {
94
+ console.error("Error releasing connection gracefully, trying to destroy:", err);
95
+ try {
96
+ client.release(!0);
97
+ } catch (destroyErr) {
98
+ console.error("Error destroying connection:", destroyErr);
99
+ }
100
+ }
101
+ console.info("\u{1F64C} Done migrating"), exitProcess();
102
+ }
103
+ function exitProcess() {
104
+ typeof process > "u" || isServerless || process.exit(0);
105
+ }
106
+ //# sourceMappingURL=migrate.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/migrate.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,uBAAyB,sBAEzB,qBAA4B;AAkB5B,MAAM,eAAe,CAAC,EACpB,QAAQ,IAAI,4BACZ,QAAQ,IAAI,0BACZ,QAAQ,IAAI,sBACZ,QAAQ,IAAI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AU,GAC7B,QAAQ,KAAK,gCAAgC;AAC7C,QAAI;AACF,aAAO,QAAQ,EAAK;AAAA,IACtB,SAAS,YAAY;AACnB,cAAQ,MAAM,8CAA8C,UAAU;AAAA,IACxE;AACA,UAAM;AAAA,EACR;AAEA,EAAI,uBACF,MAAM,oBAAoB,GAG5B,QAAQ,KAAK,gCAAgC;AAC7C,MAAI;AAEF,WAAO,QAAQ,EAAK;AAAA,EACtB,SAAS,KAAK;AACZ,YAAQ,MAAM,6DAA6D,GAAG;AAC9E,QAAI;AACF,aAAO,QAAQ,EAAI;AAAA,IACrB,SAAS,YAAY;AACnB,cAAQ,MAAM,gCAAgC,UAAU;AAAA,IAC1D;AAAA,EACF;AAEA,UAAQ,KAAK,0BAAmB,GAEhC,YAAY;AACd;AAEA,SAAS,cAAc;AACrB,EAAI,OAAO,UAAY,OAEnB,gBACJ,QAAQ,KAAK,CAAC;AAChB;",
5
+ "names": ["migrations"]
6
+ }
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: !0
11
+ });
12
+ },
13
+ __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: !0
22
+ }), mod);
23
+ var migrate_exports = {};
24
+ __export(migrate_exports, {
25
+ migrate: () => migrate
26
+ });
27
+ module.exports = __toCommonJS(migrate_exports);
28
+ var import_path = require("path"),
29
+ import_getDBClient = require("./helpers/getDBClient.native.js"),
30
+ isServerless = !!(process.env.AWS_LAMBDA_FUNCTION_NAME || process.env.AWS_LAMBDA_RUNTIME_API || process.env.LAMBDA_RUNTIME_DIR || process.env.IS_SERVERLESS);
31
+ async function migrate(options) {
32
+ var {
33
+ connectionString,
34
+ migrationsGlob,
35
+ createDatabases = [],
36
+ onMigrationComplete,
37
+ gitSha,
38
+ cvrDb,
39
+ changeDb
40
+ } = options;
41
+ console.info(`Running migrations${gitSha ? ` for git version: ${gitSha}` : ""}`);
42
+ var client = await (0, import_getDBClient.getDBClient)({
43
+ connectionString
44
+ }),
45
+ hasDB = async function (name2) {
46
+ var result = !!(await client.query(`
47
+ SELECT 1 FROM pg_database WHERE datname = '${name2}'
48
+ `)).rows.length;
49
+ return console.info(result ? `${name2} db exists` : `creating ${name2} db`), result;
50
+ };
51
+ if (cvrDb || changeDb) {
52
+ if (!cvrDb) throw new Error("Missing cvrDb");
53
+ var zeroDBNames = [(0, import_path.basename)(cvrDb || ""), (0, import_path.basename)(changeDb || "")].filter(Boolean),
54
+ _iteratorNormalCompletion = !0,
55
+ _didIteratorError = !1,
56
+ _iteratorError = void 0;
57
+ try {
58
+ for (var _iterator = zeroDBNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
59
+ var name = _step.value;
60
+ (await hasDB(name)) || (await client.query(`CREATE DATABASE ${name};`));
61
+ }
62
+ } catch (err) {
63
+ _didIteratorError = !0, _iteratorError = err;
64
+ } finally {
65
+ try {
66
+ !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
67
+ } finally {
68
+ if (_didIteratorError) throw _iteratorError;
69
+ }
70
+ }
71
+ }
72
+ var _iteratorNormalCompletion1 = !0,
73
+ _didIteratorError1 = !1,
74
+ _iteratorError1 = void 0;
75
+ try {
76
+ for (var _iterator1 = createDatabases[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = !0) {
77
+ var dbUrl = _step1.value,
78
+ name1 = (0, import_path.basename)(dbUrl);
79
+ (await hasDB(name1)) || (await client.query(`CREATE DATABASE ${name1};`));
80
+ }
81
+ } catch (err) {
82
+ _didIteratorError1 = !0, _iteratorError1 = err;
83
+ } finally {
84
+ try {
85
+ !_iteratorNormalCompletion1 && _iterator1.return != null && _iterator1.return();
86
+ } finally {
87
+ if (_didIteratorError1) throw _iteratorError1;
88
+ }
89
+ }
90
+ try {
91
+ await client.query("BEGIN"), await client.query(`
92
+ CREATE TABLE IF NOT EXISTS migrations (
93
+ id SERIAL PRIMARY KEY,
94
+ name VARCHAR(255) NOT NULL,
95
+ run_on TIMESTAMP NOT NULL DEFAULT NOW()
96
+ )
97
+ `);
98
+ var appliedMigrations = await client.query("SELECT name FROM migrations"),
99
+ appliedMigrationNames = new Set(appliedMigrations.rows.map(function (row) {
100
+ return row.name;
101
+ })),
102
+ tsMigrationsSorted = Object.entries(migrationsGlob).sort(function (param, param1) {
103
+ var [a] = param,
104
+ [b] = param1;
105
+ return a.localeCompare(b);
106
+ }).map(function (param) {
107
+ var [file, run] = param;
108
+ return {
109
+ name: (0, import_path.basename)(file).replace(".ts", ""),
110
+ run
111
+ };
112
+ }).filter(function (param) {
113
+ var {
114
+ name: name2
115
+ } = param;
116
+ return /^[\d]+/.test(name2);
117
+ });
118
+ console.info(`Found ${tsMigrationsSorted.length} TypeScript migrations`);
119
+ var tsMigrations = await Promise.all(tsMigrationsSorted.map(async function (param) {
120
+ var {
121
+ name: name2,
122
+ run
123
+ } = param;
124
+ if (appliedMigrationNames.has(name2)) return console.info(`TypeScript migration applied already: ${name2}`), null;
125
+ try {
126
+ var migration2 = await run();
127
+ return {
128
+ ...migration2,
129
+ name: name2
130
+ };
131
+ } catch (error) {
132
+ throw console.error(`Failed to load TypeScript migration ${name2}:`, error), error;
133
+ }
134
+ })).then(function (migrations2) {
135
+ return migrations2.filter(Boolean);
136
+ }),
137
+ migrations = [...tsMigrations].sort(function (a, b) {
138
+ return a.name.localeCompare(b.name);
139
+ });
140
+ if (!migrations.length) console.info("No migrations to apply!"), await client.query("COMMIT");else {
141
+ var _iteratorNormalCompletion2 = !0,
142
+ _didIteratorError2 = !1,
143
+ _iteratorError2 = void 0;
144
+ try {
145
+ for (var _iterator2 = migrations[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = !0) {
146
+ var migration = _step2.value;
147
+ console.info(`Migrating: ${migration.name}`), migration.up && (console.info(`Applying migration: ${migration.name}`), await migration.up(client)), await client.query("INSERT INTO migrations (name) VALUES ($1)", [migration.name]), console.info(`Successfully applied migration: ${migration.name}`);
148
+ }
149
+ } catch (err) {
150
+ _didIteratorError2 = !0, _iteratorError2 = err;
151
+ } finally {
152
+ try {
153
+ !_iteratorNormalCompletion2 && _iterator2.return != null && _iterator2.return();
154
+ } finally {
155
+ if (_didIteratorError2) throw _iteratorError2;
156
+ }
157
+ }
158
+ await client.query("COMMIT"), console.info("Successfully committed all migrations");
159
+ }
160
+ } catch (e) {
161
+ console.error("Migration failed, rolling back:", e), await client.query("ROLLBACK"), console.info("Releasing client connection...");
162
+ try {
163
+ client.release(!1);
164
+ } catch (releaseErr) {
165
+ console.error("Error releasing connection after rollback:", releaseErr);
166
+ }
167
+ throw e;
168
+ }
169
+ onMigrationComplete && (await onMigrationComplete()), console.info("Releasing client connection...");
170
+ try {
171
+ client.release(!1);
172
+ } catch (err) {
173
+ console.error("Error releasing connection gracefully, trying to destroy:", err);
174
+ try {
175
+ client.release(!0);
176
+ } catch (destroyErr) {
177
+ console.error("Error destroying connection:", destroyErr);
178
+ }
179
+ }
180
+ console.info("\u{1F64C} Done migrating"), exitProcess();
181
+ }
182
+ function exitProcess() {
183
+ typeof process > "u" || isServerless || process.exit(0);
184
+ }
185
+ //# sourceMappingURL=migrate.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","migrate_exports","__export","migrate","module","exports","import_path","require","import_getDBClient","isServerless","process","env","AWS_LAMBDA_FUNCTION_NAME","AWS_LAMBDA_RUNTIME_API","LAMBDA_RUNTIME_DIR","IS_SERVERLESS","options","connectionString","migrationsGlob","createDatabases","onMigrationComplete","gitSha","cvrDb","changeDb","console","info","client","getDBClient","hasDB","name2","result","query","rows","length","Error","zeroDBNames","basename","filter","Boolean","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","Symbol","iterator","_step","next","done","name","err","return","_iteratorNormalCompletion1","_didIteratorError1","_iteratorError1","_iterator1","_step1","dbUrl","name1","appliedMigrations","appliedMigrationNames","Set","map","row","tsMigrationsSorted","Object","entries","sort","param","param1","a","b","localeCompare","file","run","replace","test","tsMigrations","Promise","all","has","migration2"],"sources":["../../src/migrate.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,eAAA;AAAAC,QAAA,CAAAD,eAAA;EAAAE,OAAA,EAAAA,CAAA,KAAAA;AAAA;AAUAC,MAAA,CAAAC,OAAA,GAAAT,YAAyB,CAAAK,eAEzB;AAkBA,IAAAK,WAAM,GAAAC,OACJ,OAAQ;EAAAC,kBAAI,GAAAD,OAAA,CACZ,iCAAY;EAAAE,YACZ,MAAAC,OAAY,CAAAC,GAAA,CAAAC,wBACJ,IAAIF,OAAA,CAAAC,GAAA,CAAAE,sBAAA,IAAAH,OAAA,CAAAC,GAAA,CAAAG,kBAAA,IAAAJ,OAAA,CAAAC,GAAA,CAAAI,aAAA;AAGd,eAAsBZ,QAAQa,OAAA,EAAyB;EACrD;IAAMC,gBAAA;IAAAC,cAAA;IAAAC,eAAA;IAAAC,mBAAA;IAAAC,MAAA;IAAAC,KAAA;IAAAC;EAAA,IAAAP,OAAA;EAAAQ,OACJ,CAAA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B,KAAA;QAEF;UAAOnB,IAAA,EAAAnB;QAAa,IAAAsC,KAAA;QACtB,OAAS,QAAK,CAAAQ,IAAA,CAAA9C,KAAA;MACZ;IACAL,OAAI,CAAAC,IAAA,UAAAsC,kBAAA,CAAA9B,MAAA;IACF,IAAA2C,YAAO,GAAY,MAAAC,OAAA,CAAAC,GAAA,CAAAf,kBAAA,CAAAF,GAAA,iBAAAM,KAAA;QACrB;UAAAnB,IAAS,EAAAnB,KAAA;UAAY4C;QAAA,IAAAN,KAAA;QACnB,IAAAR,qBAAc,CAAAoB,GAAA,CAAAlD,KAAA,GAChB,OAAAL,OAAA,CAAAC,IAAA,0CAAAI,KAAA;QACF;UAEA,IAAQmD,UAAK,SAAAP,GAAA;UAGf;YAES,GAAAO,UAAc;YACVhC,IAAA,EAAAnB;UAIb","ignoreList":[]}
@@ -0,0 +1,81 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf,
6
+ __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: !0
11
+ });
12
+ },
13
+ __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: !0
28
+ }) : target, mod)),
29
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
+ value: !0
31
+ }), mod);
32
+ var build_migrations_exports = {};
33
+ __export(build_migrations_exports, {
34
+ buildMigrations: () => buildMigrations
35
+ });
36
+ module.exports = __toCommonJS(build_migrations_exports);
37
+ var import_node_child_process = require("node:child_process"),
38
+ import_node_path = __toESM(require("node:path"), 1);
39
+ async function buildMigrations(options) {
40
+ const {
41
+ migrationsDir,
42
+ outFile = "migrate-dist.js",
43
+ target = "node22",
44
+ aliases = {}
45
+ } = options,
46
+ {
47
+ build
48
+ } = await import("vite"),
49
+ migrateFile = import_node_path.default.join(migrationsDir, "..", "migrate.ts"),
50
+ result = await build({
51
+ configFile: !1,
52
+ resolve: {
53
+ alias: aliases
54
+ },
55
+ define: {
56
+ "process.env.GIT_SHA": JSON.stringify((0, import_node_child_process.execSync)("git rev-parse HEAD").toString().trim())
57
+ },
58
+ build: {
59
+ outDir: import_node_path.default.dirname(migrateFile),
60
+ target,
61
+ minify: !1,
62
+ emptyOutDir: !1,
63
+ copyPublicDir: !1,
64
+ lib: {
65
+ name: "migrate",
66
+ formats: ["es"],
67
+ entry: migrateFile
68
+ },
69
+ rollupOptions: {
70
+ external: id => id.startsWith("node:") || id === "pg" ? !0 : id.startsWith("/") ? !1 : !id.startsWith(".") && !id.startsWith("/"),
71
+ output: {
72
+ format: "es",
73
+ inlineDynamicImports: !0,
74
+ exports: "named",
75
+ entryFileNames: outFile
76
+ }
77
+ }
78
+ }
79
+ });
80
+ return console.info(`\u2713 Built migration bundle: ${outFile}`), result;
81
+ }
@@ -0,0 +1,69 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: !0 });
9
+ }, __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from == "object" || typeof from == "function")
11
+ for (let key of __getOwnPropNames(from))
12
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ return to;
14
+ };
15
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
+ // If the importer is in node compatibility mode or this is not an ESM
17
+ // file that has been converted to a CommonJS file using a Babel-
18
+ // compatible transform (i.e. "__esModule" has not been set), then set
19
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
+ mod
22
+ )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
23
+ var build_migrations_exports = {};
24
+ __export(build_migrations_exports, {
25
+ buildMigrations: () => buildMigrations
26
+ });
27
+ module.exports = __toCommonJS(build_migrations_exports);
28
+ var import_node_child_process = require("node:child_process"), import_node_path = __toESM(require("node:path"), 1);
29
+ async function buildMigrations(options) {
30
+ const {
31
+ migrationsDir,
32
+ outFile = "migrate-dist.js",
33
+ target = "node22",
34
+ aliases = {}
35
+ } = options, { build } = await import("vite"), migrateFile = import_node_path.default.join(migrationsDir, "..", "migrate.ts"), result = await build({
36
+ configFile: !1,
37
+ resolve: {
38
+ alias: aliases
39
+ },
40
+ define: {
41
+ "process.env.GIT_SHA": JSON.stringify(
42
+ (0, import_node_child_process.execSync)("git rev-parse HEAD").toString().trim()
43
+ )
44
+ },
45
+ build: {
46
+ outDir: import_node_path.default.dirname(migrateFile),
47
+ target,
48
+ minify: !1,
49
+ emptyOutDir: !1,
50
+ copyPublicDir: !1,
51
+ lib: {
52
+ name: "migrate",
53
+ formats: ["es"],
54
+ entry: migrateFile
55
+ },
56
+ rollupOptions: {
57
+ external: (id) => id.startsWith("node:") || id === "pg" ? !0 : id.startsWith("/") ? !1 : !id.startsWith(".") && !id.startsWith("/"),
58
+ output: {
59
+ format: "es",
60
+ inlineDynamicImports: !0,
61
+ exports: "named",
62
+ entryFileNames: outFile
63
+ }
64
+ }
65
+ }
66
+ });
67
+ return console.info(`\u2713 Built migration bundle: ${outFile}`), result;
68
+ }
69
+ //# sourceMappingURL=build-migrations.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/scripts/build-migrations.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gCAAyB,+BACzB,mBAAiB;AASjB,eAAsB,gBAAgB,SAAiC;AACrE,QAAM;AAAA,IACJ;AAAA,IACA,UAAU;AAAA,IACV,SAAS;AAAA,IACT,UAAU,CAAC;AAAA,EACb,IAAI,SAEE,EAAE,MAAM,IAAI,MAAM,OAAO,MAAM,GAE/B,cAAc,iBAAAA,QAAK,KAAK,eAAe,MAAM,YAAY,GAEzD,SAAS,MAAM,MAAM;AAAA,IACzB,YAAY;AAAA,IACZ,SAAS;AAAA,MACP,OAAO;AAAA,IACT;AAAA,IACA,QAAQ;AAAA,MACN,uBAAuB,KAAK;AAAA,YAC1B,oCAAS,oBAAoB,EAAE,SAAS,EAAE,KAAK;AAAA,MACjD;AAAA,IACF;AAAA,IACA,OAAO;AAAA,MACL,QAAQ,iBAAAA,QAAK,QAAQ,WAAW;AAAA,MAChC;AAAA,MACA,QAAQ;AAAA,MACR,aAAa;AAAA,MACb,eAAe;AAAA,MACf,KAAK;AAAA,QACH,MAAM;AAAA,QACN,SAAS,CAAC,IAAI;AAAA,QACd,OAAO;AAAA,MACT;AAAA,MACA,eAAe;AAAA,QACb,UAAU,CAAC,OAEL,GAAG,WAAW,OAAO,KAAK,OAAO,OAAa,KAE9C,GAAG,WAAW,GAAG,IAAU,KAE3B,CAAC,GAAG,WAAW,GAAG,KAAK,CAAC,GAAG,WAAW,GAAG;AAAA,QAG/C,QAAQ;AAAA,UACN,QAAQ;AAAA,UACR,sBAAsB;AAAA,UACtB,SAAS;AAAA,UACT,gBAAgB;AAAA,QAClB;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AAED,iBAAQ,KAAK,kCAA6B,OAAO,EAAE,GAC5C;AACT;",
5
+ "names": ["path"]
6
+ }
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf,
8
+ __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: !0
13
+ });
14
+ },
15
+ __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
17
+ get: () => from[key],
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
+ value: mod,
29
+ enumerable: !0
30
+ }) : target, mod)),
31
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
+ value: !0
33
+ }), mod);
34
+ var build_migrations_exports = {};
35
+ __export(build_migrations_exports, {
36
+ buildMigrations: () => buildMigrations
37
+ });
38
+ module.exports = __toCommonJS(build_migrations_exports);
39
+ var import_child_process = require("child_process"),
40
+ import_path = __toESM(require("path"), 1);
41
+ async function buildMigrations(options) {
42
+ var {
43
+ migrationsDir,
44
+ outFile = "migrate-dist.js",
45
+ target = "node22",
46
+ aliases = {}
47
+ } = options,
48
+ {
49
+ build
50
+ } = await import("vite"),
51
+ migrateFile = import_path.default.join(migrationsDir, "..", "migrate.ts"),
52
+ result = await build({
53
+ configFile: !1,
54
+ resolve: {
55
+ alias: aliases
56
+ },
57
+ define: {
58
+ "process.env.GIT_SHA": JSON.stringify((0, import_child_process.execSync)("git rev-parse HEAD").toString().trim())
59
+ },
60
+ build: {
61
+ outDir: import_path.default.dirname(migrateFile),
62
+ target,
63
+ minify: !1,
64
+ emptyOutDir: !1,
65
+ copyPublicDir: !1,
66
+ lib: {
67
+ name: "migrate",
68
+ formats: ["es"],
69
+ entry: migrateFile
70
+ },
71
+ rollupOptions: {
72
+ external: function (id) {
73
+ return id.startsWith("node:") || id === "pg" ? !0 : id.startsWith("/") ? !1 : !id.startsWith(".") && !id.startsWith("/");
74
+ },
75
+ output: {
76
+ format: "es",
77
+ inlineDynamicImports: !0,
78
+ exports: "named",
79
+ entryFileNames: outFile
80
+ }
81
+ }
82
+ }
83
+ });
84
+ return console.info(`\u2713 Built migration bundle: ${outFile}`), result;
85
+ }
86
+ //# sourceMappingURL=build-migrations.native.js.map