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

typeorm_metadata table not generated in migrations when adding a generated column #11141

Open
1 of 18 tasks
Woodz opened this issue Nov 22, 2024 · 0 comments
Open
1 of 18 tasks

Comments

@Woodz
Copy link

Woodz commented Nov 22, 2024

Issue description

Generated TypeOrm migration references missing typeorm_metadata table when a generated column is added

Expected Behavior

typeorm_metadata table is created the first time it is needed (e.g. a view or generated column is added)

Actual Behavior

typeorm_metadata table is created the first time it is needed only if a view is added, not a generated column

Generated migration file is something like:

import { MigrationInterface, QueryRunner } from "typeorm";

export class Test1732259899196 implements MigrationInterface {
    name = 'Test1732259899196'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE "<my schema>"."<my table>" ADD "<my generated column>" <datatype> GENERATED ALWAYS AS ( <implementation> )
  END
    ) STORED`);
        await queryRunner.query(`INSERT INTO "<my db>"."typeorm_metadata"("database", "schema", "table", "type", "name", "value") VALUES ($1, $2, $3, $4, $5, $6)`, ["<my db>","<my schema>","<my table>","GENERATED_COLUMN","<my generated column>","<implementation>"]);
    }

...
}

As you can see, there is no creation of typeorm_metadata table before insertion of the new row, which causes the migration to fail

Steps to reproduce

  • create a DB migration for a schema that has no views or generated columns with sync disabled (confirm typeorm_metadata table does not exist)
  • add a generated column
  • generate migration

My Environment

Dependency Version
Operating System MacOS
Node.js version 18.20.4
Typescript version 5.0
TypeORM version 0.3.19

Additional Context

Similar to #4923, but for virtual columns instead of views

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

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

No branches or pull requests

1 participant