Skip to content

Multi scheme migrations issue. #1143

@Mark1Z

Description

@Mark1Z

Describe the bug
Migrations do not respect table scheme.

Stack trace

TableExistsException: create table "test"."DEVICES" ("ID" serial primary key, "TOKEN" varchar(255) not null); - relation "DEVICES" already exists
    at PostgreSqlExceptionConverter.convertException (/home/virchenko/Projects/phyapi/node_modules/@mikro-orm/postgresql/PostgreSqlExceptionConverter.js:38:24)
    at PostgreSqlDriver.convertException (/home/virchenko/Projects/phyapi/node_modules/@mikro-orm/core/drivers/DatabaseDriver.js:171:54)
    at /home/virchenko/Projects/phyapi/node_modules/@mikro-orm/core/drivers/DatabaseDriver.js:175:24
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at Function.runSerial (/home/virchenko/Projects/phyapi/node_modules/@mikro-orm/core/utils/Utils.js:458:22)
    at MigrationRunner.run (/home/virchenko/Projects/phyapi/node_modules/@mikro-orm/migrations/MigrationRunner.js:17:13)

To Reproduce
Steps to reproduce the behavior:

  1. Create an entity, for example:
import { Entity, PrimaryKey, Property } from '@mikro-orm/core';

@Entity({
    tableName: 'test.DEVICES',
})
export class Device {
    @PrimaryKey({ fieldName: 'ID', type: 'number' })
    id!: number;

    @Property({ fieldName: 'TOKEN' })
    token!: string;
}
  1. Generate a migration:
npx mikro-orm migration:create

where output will be like this:

import { Migration } from '@mikro-orm/migrations';

export class Migration20201201130518 extends Migration {

  async up(): Promise<void> {
    this.addSql('create table "test"."DEVICES" ("ID" serial primary key, "TOKEN" varchar(255) not null);');
  }

}
  1. Apply the migration:
npx mikro-orm migration:up
  1. Generate a new migration:
npx mikro-orm migration:create

where output will be the same:

import { Migration } from '@mikro-orm/migrations';

export class Migration20201201130522 extends Migration {

  async up(): Promise<void> {
    this.addSql('create table "test"."DEVICES" ("ID" serial primary key, "TOKEN" varchar(255) not null);');
  }

}
  1. Apply the migration:
npx mikro-orm migration:up

Expected behavior
Correct migrations:

  • first migration with "create scheme 'test';" statement and down() method;
  • second migration must be empty.

Versions

Dependency Version
node v12.20.0
typescript 4.0.5
mikro-orm 4.3.0
PostgreSQL 13.1

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions