-
-
Notifications
You must be signed in to change notification settings - Fork 502
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
migration:create changes non-nullable to nullable, changes it back and back and forth for enum and custom type properties with default value #1559
Comments
Afaik in your custom type, Also, this has nothing to do with migrations, this is schema generator/diffing issue, migrations are just a layer on top of it. Btw mapping decimal to numbers is not very good idea, you can loose precision. You should map to strings or use some wrapper. In fact your custom type will most probably return strings as it is written now. |
Thanks for the advice, but actually in my production code, and I am mapping it into a bignumber.js instance like so: import { Type } from "@mikro-orm/core";
import { BigNumber as Decimal } from "bignumber.js";
const precision = 4;
const moneyColumnType = `DECIMAL(19, ${precision})`;
Decimal.set({ DECIMAL_PLACES: precision });
export { Decimal };
export class DecimalType extends Type<Decimal | undefined, string | undefined> {
convertToDatabaseValue(value: Decimal | string | undefined): string | undefined {
if (!value) { return value;}
return value.toString();
}
convertToJSValue(value: string | undefined): Decimal | undefined {
if (!value) { return undefined; }
return new Decimal(value);
}
getColumnType(): string {
return moneyColumnType;
}
} And it seems to work fine as well. How the type is mapped is not the point 😄️, but I can update the code if necessary. So should I report the issue to umzug? |
Have you tried it? This is not about "it works for creating the column", this is about diffing the column type, and for that the type needs to be normalized to what the information schema stores. And there I believe it has to be without the space - someone already reported this very same issue and without the space it was working as expected. Umzug has nothing to do with this, neither have the migrations - as I mentioned, this is about schema diffing inside |
I added some tests in the reproduce repo to test the mapping and updating of the And I am sorry I got confused back then and kept thinking it was about migration. I fully understand it's about |
Removing the space and using defaultRaw fixes the issue about the custom type in my case. Thanks! I am sorry that I still misunderstood you and thought it was about mapping the value to DB. Here are the code lines that I found related to enum issue: Setting mikro-orm/packages/knex/src/schema/SchemaHelper.ts Lines 224 to 231 in 288eee4
If set the
But I think the root cause should be inside this function, or mikro-orm/packages/knex/src/schema/SchemaGenerator.ts Lines 435 to 455 in 288eee4
For the enum property in the original code without the workaround, the result of diffing is only the default value is different, so only
is executed, which, however, removes |
This commit introduces new schema diffing capabilitites. Instead of shared code for creating and altering tables, we now build schema objects from entities and existing schema, and compare those (this will later allow to create down migrations too). - Better mapping - adds mapped types to abstract most of the column types (e.g. { type: t.decimal }) - FK diffing - Proper index diffing (before we compared just names) - Custom index expressions - Comment diffing - Column length diffing (e.g. numeric(10,2) or varchar(100)) - Changing PK types - Schena/namespace diffing (posgtres only) Closes #1486 Closes #1518 Closes #579 Closes #1559 Closes #1602 Closes #1480 Closes #1687
Describe the bug
Using mysql driver, for
enum
properties with default value and custom type properties with default values, repeatedmigration:create
runs creates new migration files which removes the properties'not null
, addsnot null
, removes it, ands it back and back and forth.To Reproduce
A repo with clearer description and steps to reproduce: https://github.com/ddadaal/mikro-orm-migration-changing-nonnullable-to-nullable
Expected behavior
No new migration files should be generated after the first
migration:create
, since there is no change at all in the entity.Versions
The text was updated successfully, but these errors were encountered: