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

How do I migrate in CI/CD pipeline ? #2976

Closed
meyvan opened this issue Jul 28, 2024 · 3 comments
Closed

How do I migrate in CI/CD pipeline ? #2976

meyvan opened this issue Jul 28, 2024 · 3 comments
Labels
type: bug 🐛 Something isn't working

Comments

@meyvan
Copy link

meyvan commented Jul 28, 2024

Describe the bug
Following the docs: https://docs.vendure.io/guides/developer-guide/migrations/ I can create a migration in local.

But how am I supposed to run the migration in an existing running server ?

I CANNOT RUN npx vendure migrate and select "Run pending migrations" because this will run inside Github Actions and how am I suppose to select the option ?

To Reproduce
Steps to reproduce the behavior:

  1. Follow https://docs.vendure.io/guides/developer-guide/migrations/
  2. Run npx vendure migrate option in Github Actions
  3. Option cannot be selected in pipeline

Expected behavior
A simple way is to allow sending in arguments like --run

Environment (please complete the following information):

  • @vendure/core version: v3.0.0
  • Nodejs version: v18.19.1
  • Database (mysql/postgres etc): postgres
@meyvan meyvan added the type: bug 🐛 Something isn't working label Jul 28, 2024
@jyling
Copy link
Contributor

jyling commented Jul 29, 2024

https://docs.vendure.io/guides/developer-guide/migrations/#3-run-the-migration

Assuming the migration file looks correct, the next time you start the server, 
the migration will be run automatically. This is because the runMigrations 
function is called in the src/index.ts file:

Migration should run automatically when you start the server, unless I misunderstood your issue ?

@meyvan
Copy link
Author

meyvan commented Jul 29, 2024

Automatically updating the DB schema when server is started is a Anti-DevOps principle. We should be able to control when and how we run the migrations. And for that npx vendure migrate command is good, but it is interactive, which cannot(or hard to achieve) in a Github Actions CI/CD pipeline.

A better option is to send in arguments like --no-interaction combined with --runMigration or other arguments like that

Nevertheless, I found a way to run the migration separately.

And to anyone coming here, at the time of writing, copy the

import {  runMigrations } from '@vendure/core';
import { config } from './vendure-config';

runMigrations(config)
    .then(() => console.log('Migration Complete'))
    .catch(err => {
        console.log(err);
    });

into a separate file and run it using ts-node migrate.ts , whenever and wherever you like

@meyvan meyvan closed this as completed Jul 29, 2024
@michaelbromley
Copy link
Member

@meyvan non-interactive mode for CLI commands is coming in an upcoming feature release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants