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

Multi scheme migrations issue. #1143

Closed
Mark1Z opened this issue Dec 1, 2020 · 2 comments
Closed

Multi scheme migrations issue. #1143

Mark1Z opened this issue Dec 1, 2020 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@Mark1Z
Copy link

Mark1Z commented Dec 1, 2020

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
@B4nan B4nan added the bug Something isn't working label Dec 1, 2020
@B4nan
Copy link
Member

B4nan commented Dec 2, 2020

Down migrations are planned, but that will require deeper refactoring of how the schema diffing works. I marked this as a bug as the second migration should be indeed empty. Will close this with a fix for that - the rest are feature proposals, not bugs - schema/namespace diffing is not implemented at all, just like down migrations. Feel free to create new issues/feature requests for that, they should be separate as those are distinct features.

@B4nan B4nan closed this as completed in 429d832 Dec 2, 2020
@B4nan
Copy link
Member

B4nan commented Dec 2, 2020

Fixed in 4.3.3-dev.12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants