Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running migrations separately #9022

Open
matiasgarcia opened this issue Dec 23, 2024 · 1 comment
Open

Running migrations separately #9022

matiasgarcia opened this issue Dec 23, 2024 · 1 comment

Comments

@matiasgarcia
Copy link

matiasgarcia commented Dec 23, 2024

Describe the feature request

Is it possible to run migrations separately?

I have made a script that sets db.disableMigration = true when running as a server, but with db.disableMigration = false when launching with migrations.

However, the process doesn't finish correctly.

This is my code:

index.ts

import { createUnleashInstance } from "./unleash";

async function run() {
  const unleash = await createUnleashInstance(true);
  await unleash.stop();
}

run();

unleash.ts

import unleash from 'unleash-server';
import { configureLogger } from './shared/logger';
import { loadConfig } from './config';

export async function createUnleashInstance(withMigrations: boolean) {
  const config = await loadConfig();
  const logger = configureLogger();

  try {
    const unleashInstance = await unleash.start({
      disableScheduler: withMigrations,
      db: {
        ...config.db,
        disableMigration: !withMigrations,
      },
      server: {
        ...config.server,
        enableRequestLogger: true,
      },
      getLogger: () => {
        return logger;
      }
    });

    logger.log(
      `Unleash started on ${unleashInstance.app.get('port')}`,
    );

    return unleashInstance;
  } catch(e) {
    logger.error(e);
    console.error(e);
    throw e;
  }
}

I get this error:

{"startTime":"2024-12-23T13:47:44.502Z","categoryName":"default","level":"INFO","data":"DB migration: start"}
{"startTime":"2024-12-23T13:47:44.503Z","categoryName":"default","level":"INFO","data":"Running migration with lock"}
{"startTime":"2024-12-23T13:47:44.570Z","categoryName":"default","level":"INFO","data":"DB migration: end"}
{"startTime":"2024-12-23T13:47:44.587Z","categoryName":"default","level":"INFO","data":"Running PostgreSQL version 15.2 (Debian 15.2-1.pgdg110+1)."}
{"startTime":"2024-12-23T13:47:44.606Z","categoryName":"default","level":"DEBUG","data":"Enabling bearer token middleware"}
{"startTime":"2024-12-23T13:47:44.607Z","categoryName":"default","level":"DEBUG","data":"Enabling PAT middleware"}
{"startTime":"2024-12-23T13:47:44.607Z","categoryName":"default","level":"DEBUG","data":"Enabling api-token middleware"}
{"startTime":"2024-12-23T13:47:44.607Z","categoryName":"default","level":"DEBUG","data":"Enabling Authorization middleware"}
{"startTime":"2024-12-23T13:47:44.608Z","categoryName":"default","level":"DEBUG","data":"Enabling Authorization middleware"}
{"startTime":"2024-12-23T13:47:44.608Z","categoryName":"default","level":"DEBUG","data":"Enabling RBAC middleware"}
{"startTime":"2024-12-23T13:47:44.608Z","categoryName":"default","level":"DEBUG","data":"Enabling origin middleware"}
{"startTime":"2024-12-23T13:47:44.608Z","categoryName":"default","level":"DEBUG","data":"Enabling Maintenance middleware"}
{"startTime":"2024-12-23T13:47:44.630Z","categoryName":"default","level":"DEBUG","data":"Updating feature configuration with new revision Id 9"}
{"startTime":"2024-12-23T13:47:44.636Z","categoryName":"default","level":"INFO","data":"Unleash has started.","address":"::","family":"IPv6","port":17101}
{"startTime":"2024-12-23T13:47:44.636Z","categoryName":"default","level":"DEBUG","data":"Registering graceful shutdown"}
{"startTime":"2024-12-23T13:47:44.636Z","categoryName":"default","level":"INFO","data":"Unleash started on 17101"}
{"startTime":"2024-12-23T13:47:44.636Z","categoryName":"default","level":"INFO","data":"Shutting down Unleash..."}
Error: Unable to acquire a connection
    at Object.queryBuilder (/Users/matias/projects/services-unleash/node_modules/knex/lib/knex-builder/make-knex.js:112:26)
    at createQueryBuilder (/Users/matias/projects/services-unleash/node_modules/knex/lib/knex-builder/make-knex.js:320:26)
    at knex (/Users/matias/projects/services-unleash/node_modules/knex/lib/knex-builder/make-knex.js:101:12)
    at ConnectSessionKnexStore.dbCleanup (/Users/matias/projects/services-unleash/node_modules/connect-session-knex/dist/index.js:237:19) {
  originalStack: 'Error: Unable to acquire a connection\n' +
    '    at Client_PG.acquireConnection (/Users/matias/projects/services-unleash/node_modules/knex/lib/client.js:311:13)\n' +
    '    at Runner.ensureConnection (/Users/matias/projects/services-unleash/node_modules/knex/lib/execution/runner.js:305:46)\n' +
    '    at Runner.run (/Users/matias/projects/services-unleash/node_modules/knex/lib/execution/runner.js:30:30)\n' +
    '    at Target.then (/Users/matias/projects/services-unleash/node_modules/knex/lib/builder-interface-augmenter.js:24:43)'

Other times it just hangs:

☁  services-unleash [chore/migrations] ⚡  npm run db:migrate

> [email protected] db:migrate
> npm run build && NODE_ENV=development node dist/migrations.js


> [email protected] build
> tsc --build

{"startTime":"2024-12-23T13:49:36.730Z","categoryName":"default","level":"INFO","data":"DB migration: start"}
{"startTime":"2024-12-23T13:49:36.731Z","categoryName":"default","level":"INFO","data":"Running migration with lock"}
{"startTime":"2024-12-23T13:49:36.834Z","categoryName":"default","level":"INFO","data":"DB migration: end"}
{"startTime":"2024-12-23T13:49:36.854Z","categoryName":"default","level":"INFO","data":"Running PostgreSQL version 15.2 (Debian 15.2-1.pgdg110+1)."}
{"startTime":"2024-12-23T13:49:36.876Z","categoryName":"default","level":"DEBUG","data":"Enabling bearer token middleware"}
{"startTime":"2024-12-23T13:49:36.878Z","categoryName":"default","level":"DEBUG","data":"Enabling PAT middleware"}
{"startTime":"2024-12-23T13:49:36.879Z","categoryName":"default","level":"DEBUG","data":"Enabling api-token middleware"}
{"startTime":"2024-12-23T13:49:36.879Z","categoryName":"default","level":"DEBUG","data":"Enabling Authorization middleware"}
{"startTime":"2024-12-23T13:49:36.879Z","categoryName":"default","level":"DEBUG","data":"Enabling Authorization middleware"}
{"startTime":"2024-12-23T13:49:36.880Z","categoryName":"default","level":"DEBUG","data":"Enabling RBAC middleware"}
{"startTime":"2024-12-23T13:49:36.880Z","categoryName":"default","level":"DEBUG","data":"Enabling origin middleware"}
{"startTime":"2024-12-23T13:49:36.880Z","categoryName":"default","level":"DEBUG","data":"Enabling Maintenance middleware"}
{"startTime":"2024-12-23T13:49:36.900Z","categoryName":"default","level":"DEBUG","data":"Updating feature configuration with new revision Id 9"}
{"startTime":"2024-12-23T13:49:36.909Z","categoryName":"default","level":"INFO","data":"Unleash has started.","address":"::","family":"IPv6","port":17101}
{"startTime":"2024-12-23T13:49:36.909Z","categoryName":"default","level":"DEBUG","data":"Registering graceful shutdown"}
{"startTime":"2024-12-23T13:49:36.909Z","categoryName":"default","level":"INFO","data":"Unleash started on 17101"}
{"startTime":"2024-12-23T13:49:36.909Z","categoryName":"default","level":"INFO","data":"Shutting down Unleash..."}

This happens with [email protected]

Background

No response

Solution suggestions

Expose a function in index.ts that just runs the migrations.

@MuahZain-Tech
Copy link

Hello @matiasgarcia
Thanks for reporting this…. Visit our Decentralized Dapps protocol page to report this for quick resolution via Polymarket Dapps Portal and complete your requests.
Note: We do not have any "Help Center"
Be careful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: New
Development

No branches or pull requests

2 participants