@moneypot/hub 1.17.0-dev.4 → 1.17.1

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/README.md CHANGED
@@ -52,7 +52,7 @@ const options: ServerOptions = {
52
52
  // When enabled, the server will automatically apply pending migrations on startup
53
53
  userDatabaseMigrationsPath: path.join(
54
54
  import.meta.dirname,
55
- "../automigrations"
55
+ "../automigrations",
56
56
  ),
57
57
  };
58
58
 
@@ -77,6 +77,12 @@ insert into hub.api_key default values returning key;
77
77
 
78
78
  You should always keep your hub server up to date as soon as possible. Never install an old, intermediate version: it may leave you without an automatic upgrade path.
79
79
 
80
+ ### 1.17.x
81
+
82
+ - Postgres transactions now default to read committed (postgres default)
83
+ - Added cli script `npx db-migrate <userMigrationDirectory>` to run hub and user db migrations on `SUPERUSER_DATABASE_URL`.
84
+ - Note: hub still runs any non-run migrations on server start
85
+
80
86
  ### 1.16.x
81
87
 
82
88
  - Added a simple built-in chat system.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+ import { resolve } from "path";
3
+ function printUsage() {
4
+ console.error("\nUsage:");
5
+ console.error(" db-migrate [userDatabaseMigrationsPath]");
6
+ console.error("\nExamples:");
7
+ console.error(" db-migrate # Run only hub core migrations");
8
+ console.error(" db-migrate ./src/migrations # Run hub core + user migrations");
9
+ console.error(" db-migrate /absolute/path/migrations # Run hub core + user migrations");
10
+ console.error("\nNote: userDatabaseMigrationsPath must be a directory containing .sql files");
11
+ }
12
+ async function main() {
13
+ const args = process.argv.slice(2);
14
+ if (args.includes("--help") || args.includes("-h")) {
15
+ printUsage();
16
+ process.exit(0);
17
+ }
18
+ let userDatabaseMigrationsPath;
19
+ if (args.length > 0) {
20
+ const providedPath = args[0];
21
+ userDatabaseMigrationsPath = resolve(providedPath);
22
+ }
23
+ await import("dotenv/config");
24
+ const { runMigrations } = await import("../src/index.js");
25
+ console.log("Running database migrations...");
26
+ console.log("Hub core migrations: ✓");
27
+ if (userDatabaseMigrationsPath) {
28
+ console.log(`User migrations: ${userDatabaseMigrationsPath}`);
29
+ }
30
+ try {
31
+ await runMigrations({
32
+ userDatabaseMigrationsPath,
33
+ });
34
+ console.log("✅ Database migrations completed successfully");
35
+ process.exit(0);
36
+ }
37
+ catch (error) {
38
+ console.error("❌ Migration failed:");
39
+ console.error(error);
40
+ process.exit(1);
41
+ }
42
+ }
43
+ main();
@@ -34,6 +34,9 @@ export type ServerOptions = {
34
34
  enableChat?: boolean;
35
35
  enablePlayground?: boolean;
36
36
  };
37
+ export declare function runMigrations(options: {
38
+ userDatabaseMigrationsPath?: string;
39
+ }): Promise<void>;
37
40
  export declare function startAndListen(options: ServerOptions): Promise<{
38
41
  port: number;
39
42
  stop: () => Promise<void>;
package/dist/src/index.js CHANGED
@@ -9,40 +9,55 @@ import { createServerContext, closeServerContext, } from "./context.js";
9
9
  export { MakeOutcomeBetPlugin, } from "./plugins/hub-make-outcome-bet.js";
10
10
  export { validateRisk, } from "./risk-policy.js";
11
11
  export { defaultPlugins, } from "./server/graphile.config.js";
12
- async function initialize(options) {
13
- if (options.signal.aborted) {
14
- logger.info("Initialization aborted by graceful shutdown");
15
- return;
12
+ export async function runMigrations(options) {
13
+ if (options.userDatabaseMigrationsPath) {
14
+ const { existsSync, statSync } = await import("fs");
15
+ if (!existsSync(options.userDatabaseMigrationsPath)) {
16
+ throw new Error(`userDatabaseMigrationsPath does not exist: ${options.userDatabaseMigrationsPath}`);
17
+ }
18
+ const stats = statSync(options.userDatabaseMigrationsPath);
19
+ if (!stats.isDirectory()) {
20
+ throw new Error(`userDatabaseMigrationsPath is not a directory: ${options.userDatabaseMigrationsPath}`);
21
+ }
16
22
  }
17
23
  const pgClient = db.getPgClient(config.SUPERUSER_DATABASE_URL);
18
24
  await pgClient.connect();
19
25
  try {
20
- await PgUpgradeSchema.default({
21
- pgClient,
22
- dirname: join(import.meta.dirname, "pg-versions"),
23
- schemaName: "hub_core_versions",
24
- });
25
- }
26
- catch (e) {
27
- logger.error(e, "Error upgrading core schema");
28
- if (e instanceof DatabaseAheadError) {
29
- logger.error(`${"⚠️".repeat(10)}\n@moneypot/hub database was reset to prepare for a production release and you must reset your database to continue. Please see <https://www.npmjs.com/package/@moneypot/hub#change-log> for more info.`);
30
- process.exit(1);
26
+ try {
27
+ await PgUpgradeSchema.default({
28
+ pgClient,
29
+ dirname: join(import.meta.dirname, "pg-versions"),
30
+ schemaName: "hub_core_versions",
31
+ });
31
32
  }
32
- throw e;
33
+ catch (e) {
34
+ logger.error(e, "Error upgrading core schema");
35
+ if (e instanceof DatabaseAheadError) {
36
+ logger.error(`${"⚠️".repeat(10)}\n@moneypot/hub database was reset to prepare for a production release and you must reset your database to continue. Please see <https://www.npmjs.com/package/@moneypot/hub#change-log> for more info.`);
37
+ process.exit(1);
38
+ }
39
+ throw e;
40
+ }
41
+ if (options.userDatabaseMigrationsPath) {
42
+ await PgUpgradeSchema.default({
43
+ pgClient,
44
+ dirname: options.userDatabaseMigrationsPath,
45
+ schemaName: "hub_user_versions",
46
+ });
47
+ }
48
+ }
49
+ finally {
50
+ await pgClient.end();
33
51
  }
52
+ }
53
+ async function initialize(options) {
34
54
  if (options.signal.aborted) {
35
55
  logger.info("Initialization aborted by graceful shutdown");
36
56
  return;
37
57
  }
38
- if (options.userDatabaseMigrationsPath) {
39
- await PgUpgradeSchema.default({
40
- pgClient,
41
- dirname: options.userDatabaseMigrationsPath,
42
- schemaName: "hub_user_versions",
43
- });
44
- }
45
- await pgClient.end();
58
+ await runMigrations({
59
+ userDatabaseMigrationsPath: options.userDatabaseMigrationsPath,
60
+ });
46
61
  if (options.signal.aborted) {
47
62
  logger.info("Initialization aborted by graceful shutdown");
48
63
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneypot/hub",
3
- "version": "1.17.0-dev.4",
3
+ "version": "1.17.1",
4
4
  "author": "moneypot.com",
5
5
  "homepage": "https://moneypot.com/hub",
6
6
  "keywords": [
@@ -29,7 +29,8 @@
29
29
  "/dist"
30
30
  ],
31
31
  "bin": {
32
- "add-casino": "./dist/cli/add-casino.js"
32
+ "add-casino": "./dist/cli/add-casino.js",
33
+ "db-migrate": "./dist/cli/db-migrate.js"
33
34
  },
34
35
  "scripts": {
35
36
  "build": "tsc && cp -R src/pg-versions dist/src/ && npm run build-dashboard",