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

Schema generator does not add new indexes when updating #957

Closed
bahdcoder opened this issue Oct 24, 2020 · 1 comment
Closed

Schema generator does not add new indexes when updating #957

bahdcoder opened this issue Oct 24, 2020 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@bahdcoder
Copy link

bahdcoder commented Oct 24, 2020

Describe the bug

When running schemaGenerator.updateSchema(), new unique indexes added to the column do not get created.

To Reproduce
Steps to reproduce the behavior:

  1. Create an entity such as Article with a slug string column.
  2. Create the articles table and slug field in the database.
  3. Run schema generator update schema method. Notice the new index is not created.

Expected behavior
A clear and concise description of what you expected to happen.

Additional context

  1. I have only tested this on mysql.
  2. I believe this is the origin of the problem after spending a moment debugging:
// @mikro-orm/knex/SchemaHelper

    hasSameIndex(prop, column) {
        if ([core_1.ReferenceType.SCALAR, core_1.ReferenceType.EMBEDDED].includes(prop.reference)) {
            // TODO: Check indexes on scalar fields instead of returning true.
            return true;
        }
        return prop.referencedColumnNames.some(referencedColumnName => {
            return !!column.fk && referencedColumnName === column.fk.referencedColumnName && prop.referencedTableName === column.fk.referencedTableName;
        });
    }

Versions

Dependency Version
node 12.17.0
typescript 3.9.5
mikro-orm 4.2.0
your-driver mysql
@bahdcoder bahdcoder changed the title Schema generator does not add new unique indexes when updating Schema generator does not add new indexes when updating Oct 24, 2020
@B4nan B4nan added the bug Something isn't working label Oct 26, 2020
@B4nan B4nan closed this as completed in dc81ef0 Oct 26, 2020
@B4nan
Copy link
Member

B4nan commented Oct 26, 2020

Index diffing happens in findIndexDifference method (hasSameIndex is used only for diffing FK indexes), but that was adding missing indexes only for those defined on entity level (those are stored in meta.indexes and meta.uniques), not on property level (stored on meta.properties[prop].index and unique respectively).

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