Issue with detecting changes in Typeorm migration functionality

My NestJS application utilizes TypeORM with a PostgreSQL database. Every time I attempt to create a migration to synchronize the database and apply changes, the generated migration file consistently contains the following queries (some irrelevant queries have been omitted for clarity):

export class portal1631976435381 implements MigrationInterface {
    name = 'portal1631976435381'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE "organization" DROP COLUMN "isTransporter"`);
        await queryRunner.query(`ALTER TABLE "organization" DROP COLUMN "crmId"`);
        await queryRunner.query(`ALTER TABLE "organization" DROP COLUMN "telephoneNumber"`);
        await queryRunner.query(`ALTER TABLE "organization" ADD "crmId" character varying`);
        await queryRunner.query(`ALTER TABLE "organization" ADD "telephoneNumber" character varying`);
        await queryRunner.query(`ALTER TABLE "organization" ADD "isTransporter" boolean NOT NULL DEFAULT false`);
        await queryRunner.query(`CREATE VIEW "inventory_based_on_receipt_item_view" AS SELECT "ri"."id" AS "receiptItemId" from someTableC`);
        await queryRunner.query(`INSERT INTO "typeorm_metadata"("type", "schema", "name", "value") VALUES ($1, $2, $3, $4)`, ["VIEW","public","inventory_based_on_receipt_item_view",]);
        // More similar queries...
    }
    public async down(queryRunner: QueryRunner): Promise<void> { ... }
}

Regardless of application changes, all viewEntities are dropped and recreated every time.

An issue arises as the

inventory_based_on_receipt_item_view
is created twice in the query, even though there should only be one entity with that name. Additionally, the three columns (crmId, telephoneNumber, isTransporter) in the organization table are consistently dropped and recreated with identical details.

I am seeking alternative methods or packages to optimize my workflow when migrating database tables, as regenerating the migration file each time there are entity changes proves cumbersome. Is there a more efficient workaround or tool available to streamline this process?

Answer №1

After some investigation, I discovered the issue. During the execution of the migration script, a new migration TS file is created in the migration folder while the previous migration files in the dist folder remain present. This results in the new migration file being appended to the existing one in the dist folder.

The problem can be resolved by deleting the dist folder before running the migration:generate command.

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

Encountering compilation errors during the vue-cli build process

My Vue 2.2.3 application is experiencing difficulties in the build process due to 4 TypeScript-related errors that are perplexing me. This is the error output displayed on the console: Failed to compile with 4 errors ...

Counting the frequency of associations in an SQL database

Consider a 2-column table in which there are always at least two instances of a value in the first column, and each unique value in that column is linked to distinct values in the second column. For instance: X | AA X | BB Z | CC Z | BB ...

The EmailInstructorsComponent is missing a component factory. Make sure you have added it to @NgModule.entryComponents

I am currently utilizing the ngx-admin template and attempting to create a modal that will open upon clicking a button. My goal is to display a form within the modal window, however, upon clicking the button, the modal opens but the form does not appear, r ...

Is there a way to verify the selected navigation item in the console?

Need help with checking the selected navigation using console.log? export const navItems: NavData[] = [ { name: 'Book #1', url: '/book', icon: 'fa fa-book', children: [{ name: 'Book #2', ...

Trouble locating controls within nested reactive forms in Mat Table

I am currently working on creating a form within a table using reactive forms and the material table. My goal is to enable users to add a row to the table and then edit it. To achieve this, I have included a FormArray inside my main FormGroup that adds an ...

Implementing the binding of components to another component post using forwardRef

I am looking to connect the Title and Body components with the Wrapper component. Previously, my component structure looked like this: import { FC } from 'react'; // binding required components const Title: FC<...> = () => {...} const ...

The TypeScript declaration for `gapi.client.storage` is being overlooked

When I call gapi.client.storage.buckets.list(), TypeScript gives me an error saying "Property 'storage' does not exist on type 'typeof client'." This issue is occurring within a Vue.js application where I am utilizing the GAPI library. ...

unable to retrieve cookies that have been set on the backend

My frontend is currently running on localhost:3000, while the backend, built with NestJS, is running on localhost:3006. When a user signs up or logs in, I am setting a cookie as follows: const setCookie = context.res.cookie('cookie-data', { ...

What is the process for inputting a predefined function into an interface?

In my project, I have a Locale interface that defines the properties of a locale for my component: interface Locale { src: string; alt: string; language: string; i18nFormat: string; } During debugging, I am using the built-in .toSource() function ...

Vue-test-utils encounters a `SyntaxError` when importing with Jest, throwing the error message "Cannot use import statement outside a module"

I'm facing an issue with my NuxtJS setup using Jest and Typescript. I can't seem to get my test to run properly due to an exception. Details: /home/xetra11/development/myapp/test/Navigation.spec.js:1 ({"Object.<anonymous>&quo ...

TypeScript encounters a problem when attempting to concatenate arrays with different signature overloads

I encountered the following error message: There is an issue with overloading. Overload 1 of 2, '(...items: ConcatArray<{ title: string; width: number; dataIndex: string; render: (level: string) => Element; }>[]): { title: string; width: nu ...

Encountering unanticipated breakpoints in compiled .Next files while using Visual Studio Code

As a newcomer to NextJS, I have encountered an issue that is disrupting my workflow. I followed the instructions in https://nextjs.org/docs/advanced-features/debugging#using-the-debugger-in-visual-studio-code to set up my launch.json file. Although I am ...

How can you define a function type for a rest parameter in Typescript?

At this point, I have a function that takes in two parameters: param 'a' as a string and 'b' as a function that returns a string. My intention is to call it using a rest parameter and specify the types accordingly. However, on line 10 ...

Retrieve the json translation file from the server using Angular and seamlessly integrate it into the browser

I recently obtained a JSON file from the server that contains translations for handling server error messages in my frontend application. I am wondering if it would be feasible to replace an existing empty JSON file in my app with this new file, or if it ...

``Engulfed in a sea of NgRx ViewModel

Apologies if this is unclear, there might be a fundamental aspect that I am overlooking, but here is my current issue: I am fetching a list of items from the backend, similar to: interface Item { id: number; userId: number; categoryId: number; } ...

Disable the yellow curly error lines in Visual Studio Code

Currently, I am utilizing VSCode with ESlint for Typescript development. I'm curious about how to turn off or remove the yellow curled error lines in my code editor, like the ones displayed in this example image: https://i.stack.imgur.com/Zdtza.png M ...

Is there a way to dynamically update the data on the view without needing to refresh the entire page?

In a scenario where users can mark an item as a favorite, the following code demonstrates how data is retrieved from the database for display in the user interface. Favorite service async fetchFavoriteItems(): Promise<firebase.firestore.QuerySnapshot& ...

the Sprite fails to appear on the screen

Can you help me figure out how to fix the issue I'm having with loading images in this component? Currently, when I refresh the page, the image does not load properly and appears resized to 1 pixel width. Should I wait for the image to fully load befo ...

Production Angular build encountered an error while trying to generate the index HTML file

Currently, I am working on a project with Angular and encountering an issue while running ng build. Although ng serve works fine, the ng build command throws the following error: error message I suspect that the error is related to Angular's optimiza ...

The use of import.meta is leading to test failures in a setup utilizing Jest, React, Typescript, and Vite

After migrating an app from Create-react-app to jest, the tests started failing due to issues with import.meta. While I managed to solve the problem in .tsx files using ts-jest-mock-import-meta library, the tests continue to fail in .ts files. This is how ...