0

I need to generate the migration with TypeORM and it does it with this command:

npm run typeorm migration:generate -n test

but the problem is that it generates the migrations that include the DB name

 await queryRunner.query(`CREATE TABLE \`testdb\`.\`lbs_user\` (\`id\` char(36) NOT ...

can I somehow remove "testdb"?

this is the config file

{
    "type": "mysql",
    "host": conf.env.migrationDatabase.host,
    "port": conf.env.migrationDatabase.port,
    "username": conf.env.migrationDatabase.username,
    "password": conf.env.migrationDatabase.password,
    "database": conf.env.migrationDatabase.dbName, //the database name is -> testdb
    "entityPrefix": conf.env.database.entityPrefix,
    "synchronize": false,  
    "migrationsTableName": `${conf.env.database.entityPrefix}migrations`,
    "entities": ["src/modules/db/entities/**/*.entity.ts"],
    "migrations": ["src/migrations/**/*.ts"],
    "cli": {      
        "migrationsDir": "src/migrations",
    }
}

Entity declaration:

@Entity("user")
export class UserEntity {
    @PrimaryColumn({ generated: "uuid" })
    id: string;

    @Column({
        unique: true,
    })
    email: string;

levansuper
  • 741
  • 1
  • 7
  • 13
  • can you add your entity class? Just the class/entity declaration, not definition of all fields. I see you have in your config file `"entityPrefix": conf.env.database.entityPrefix,` - can that be affecting it? – Stefan Oct 19 '21 at 13:52
  • thanks for the response. Added the entity. I checked "entityPrefix" and that's not it, it just adds the prefix in front of the tables. in this case "lbs_" – levansuper Oct 19 '21 at 13:53
  • But i guess you can manually edit your migration, right? That shouldn't make problem to you anyway, right? – Stefan Oct 19 '21 at 14:09
  • yes of course, but that's not the way I want to go. want to make sure whatever is generated, it works without any manual interference – levansuper Oct 19 '21 at 14:15

1 Answers1

1

In the end, it appeared that I was using an old version of typeorm. upgraded to version 0.2.38 and no database name is generated anymore.

levansuper
  • 741
  • 1
  • 7
  • 13