Skip to content

Identifier gets discarded after running migration  #4744

@agnes512

Description

@agnes512

Current Behavior

If we run migration on model:

@model()
export class Order extends Entity {
  @property({
    type: 'number',
    id: true,
    generated: true,
  })
  orderId?: number;

  @property({
    type: 'number',
  })
  quantity: number;

  // other props..

  constructor(data?: Partial<Order>) {
    super(data);
  }
}

and check the DB:
Order, it doesn't have the identifier:
Screen Shot 2020-01-28 at 11 02 33 AM

We need to specify the column setting (column name esp, should be in lowercase) for the id property to have it on the table:

@model()
export class Order extends Entity {
  @property({
    type: 'number',
    id: true,
    generated: true,
    mysql: {  // this setting allows you to have different names for model and db column
      columnName: 'orderid',
      dataType: 'integer',
      dataLength: null,
      dataPrecision: null,
      dataScale: 0,
      nullable: 'NO',
    },
})
  orderId?: number;
...
}

so that we can have:
image

Expected Behavior

There is no documentation on that ( in LB4 at least).
Should:

  • have it documented
  • or fix the migration function

Additional information

So far the issue occurs when using MySQL or PostgreSQL as datasource.
Might have something to do with the function

/**
 * Get the escaped column name for a given model property
 * @param {String} model The model name
 * @param {String} property The property name
 * @returns {String} The escaped column name
 */
SQLConnector.prototype.columnEscaped = function(model, property) {
  return this.escapeName(this.column(model, property));
};

and also some escapeIdName functions in connector-postgres,mysql

Acceptance Criteria

  • should have it documented on LB4 site ( both migration and migration-cli pages)
  • fix how we check the identifier. If it's not an easy fix, should at least warn users that the identifier gets discarded and the column settings needs to be added.
  • add test cases ( for MySQL and Postgres at least)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions