What is the best way to bring items from your project into Umzug migrations?

I am facing an issue while trying to incorporate my existing code into a migration script using Umzug in the context of Sequelize within a NestJS project.

Here is my current Umzug configuration:

require('ts-node/register')
const umzug = new Umzug({
    migrations: {
        path: process.env.MIGRATIONS_PATH,
        pattern: /\.ts$/,
    },
    storage: 'sequelize',
    storageOptions: {
        sequelize: sequelize,
    }
});
await sequelize.sync().then(() => umzug.up())

The skeleton for the migration script looks like this:

import PostTypeId from "data/PostTypeId";

export async function up() {

}

export async function down() {

}

Upon running Umzug during app startup, I encounter the following error:

[Nest] 316   - 02/21/2021, 11:24:42 AM   [ExceptionHandler] Cannot find module 'data/PostTypeId'
Require stack:
- /home/node/app/backend/src/database/migrations/2021-02-17_22-11-00_game-data.ts
...
Error: Cannot find module 'data/PostTypeId'
Require stack:
...

The error clearly indicates that the required module cannot be imported. What would be the correct approach to import modules in an Umzug migration? While passing parameters could be an option, it may not suffice for varying requirements in different migrations.

Answer №1

If you want to utilize customized paths set in your tsconfig.json, consider using tsconfig-paths. Afterwards, execute the migrate.js script as outlined in the umzug example like so:

node -r tsconfig-paths/register migrate [up|down|create|...]

Answer №2

One issue I encountered was my inability to import modules from my project's source code as specified in my tsconfig.json:

"paths": {
  "data/*": [
    "src/data/*"
  ]
},

, although I could easily import modules from node_modules. I was unsure of how to incorporate the paths from tsconfig.json into Umuzg migrations, so I resorted to a workaround by using relative paths for imports: instead of

import PostTypeId from "data/PostTypeId";

I had to resort to

import PostTypeId from "../../data/PostTypeId";

It may not be the most elegant solution, but it gets the job done. If anyone has insights on how to utilize your own tsconfig.json in Umzug migrations, please do share your expertise.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with Prettier AutoFormatting in a project that combines TypeScript and JavaScript codebases

Recently, I've started incorporating TypeScript into an existing JavaScript project. The project is quite large, so I've decided to transition it to TypeScript gradually. Below is a snippet from my eslintrc.js file: module.exports = { parser: ...

Leverage a socket client when integrating with a NestJs microservice

Recently, I delved into the world of NestJs and found myself in a bit of a predicament while attempting to test my NestJs microservices app with a TCP client. The issue arose when trying to trigger an @EventPattern or @MessagePattern() using a non-Nest app ...

Utilizing Logical Operators in Typescript Typing

What is the preferred method for boolean comparisons in Typescript types? I have devised the following types for this purpose, but I am curious if there is a more standard or efficient approach: type And<T1 extends boolean, T2 extends boolean> = T1 ...

Receiving notifications upon deleting a record

Below is my code snippet that deletes a record from a table. async deleteTodo(id: number) { this.todosRepository.delete(id); } I am trying to figure out how to handle messages during the deletion process. For instance, if a user provides an identifi ...

Filtering without the includes() Method

I have two Objects that are structured as follows: export const recipes: Recipe[] = [ new Recipe( id: "Green", scenario: ["1", "2"]), new Recipe( id: "Blue", scenario: ["1", "2","2"]) ]; export const scenarios: Scenario[] = [ new Scenario( id: "1 ...

By default, showcase the value of the first item in the list selected in a mat-selection-list on a separate component

In my project, I have two essential components: 1)list (which displays a list of customers) 2)detail (which shows the details of a selected customer) These components are designed to be reusable and are being utilized within another component called cus ...

Error message stating: "A missing module (MODULE_NOT_FOUND) was detected in the nest.js code

Having a code base that runs smoothly on a Windows machine using node v10.16.3, I encountered an issue when trying to install the same code on a CentOS Linux box with node v12.16.3. The error message displayed is regarding a missing module '@angular-d ...

Is there a way to transfer the node_module folder to a different drive using npm without duplicating the API multiple times?

I have come across a problem in my workspace where Node projects are utilizing various version dependencies, resulting in duplicate copies of the same node module. This has made it extremely difficult to locate my files and is causing excessive storage c ...

Incorporating Sass into a TypeScript-enabled Create React App

Having recently transferred a create-react-app to typescript, I've encountered an issue where my scss files are not being recognized in the .tsx components. The way I'm importing them is as follows: import './styles/scss/style.scss'; ...

How to convert form fields into JSON format using Angular 2

Currently, I am in the process of learning angular2 and have encountered a roadblock. I have created a form where the values are populated through JSON. The form consists of both pre-filled fields and text input fields where users can enter data and select ...

What is the process of creating the /dist folder in an unreleased version of an npm package?

Currently working on implementing a pull request for this module: https://github.com/echoulen/react-pull-to-refresh ... It seems that the published module generates the /dist folder in the package.json prepublish npm script. I have my local version of the ...

Issue with `rxjs/Subject.d.ts`: The class `Subject<T>` is incorrectly extending the base class `Observable<T>`

I found a sample template code in this helpful tutorial and followed these two steps to get started - npm install // everything went smoothly, created node_modules folder with all dependencies npm start // encountered an error as shown below- node_mo ...

Develop a novel object framework by merging correlated data with identical keys

I am trying to organize the related data IOrderData by grouping them based on the productId and brandId. This will help create a new array of objects called IOrderTypeData, where the only difference between the objects is the delivery type. Each product id ...

Guide on wrapping text within a pie chart using d3 version 7.6.1 in conjunction with TypeScript

When attempting to create a pie chart, I came across two examples: one here https://bl.ocks.org/mbostock/7555321 and another here https://jsfiddle.net/05nezv4q/20/ which includes text. However, I'm working with TypeScript and D3 v7.6.1 and encounterin ...

Exploring the power of Vue3 with reactive nested objects and the inclusion of

It seems like I've encountered a bit of a challenge... Perhaps a bug in Vue3 with Typescript and the composition API, or maybe I'm missing something. I'm facing an issue where I'm not getting any intellisense in my IDE (Webstorm) when ...

Tips for resolving type checking errors in TypeScript and React

I encountered an error and would appreciate any assistance in resolving it. My tech stack consists of react, typescript, and Material UI. I am attempting to customize a button using the following link: https://mui.com/material-ui/customization/how-to-custo ...

Error encountered when utilizing a generic type that extends an associative array in Typescript

Consider this code snippet: interface IAssociativeArray { [key: string]: any; } function Modify<T extends IAssociativeArray>(obj: T) { obj.someProperty = "newValue"; } function Modify2(obj: IAssociativeArray) { obj.someProperty = "newV ...

Setting up Thrift in an Angular and Electron project

Attempting to incorporate Thrift API calls into my Angular application, I used the following command to generate client files: thrift-0.18.1.exe -r --gen js:ts <myService.thrift> The command successfully created both JavaScript (js) and TypeScript ( ...

Issue with Angular 7 and rxjs - Once catchError is triggered, the subscription stops receiving any further values

Consider the following code snippet: this.service1 .getValues() .pipe( mergeMap(response => this.service2.getMoreValues(response.id)), catchError(err => of({})) ) .subscribe(response) => { console.log(response) }); The issu ...

Use the ngFor directive to iterate over the most recently created array from the parent ng

I am looking to link material tabs with ngFor to generate arrays for child ngFor. Let's start from the beginning: <mat-tab-group> <mat-tab *ngFor="let tab of asyncTabs "> <ng-template mat-tab-label>{{tab.label}}</ng-template ...