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

LB3 model import: preserve connector-specific metadata in property definitions #3810

Closed
5 tasks done
bajtos opened this issue Sep 26, 2019 · 4 comments
Closed
5 tasks done

Comments

@bajtos
Copy link
Member

bajtos commented Sep 26, 2019

Consider the following LB3 model definition:

{
  "name": "Product",
  "base": "PersistedModel",
  "properties": {
    "name": {
      "type": "string",
      "required": true,
      "mysql": {
        "column": "NAME",
        "length": 80,
      }
    }
  }
}

Expected property definition in LB4 model file:

@property{
  type: 'string',
    mysql: {
      column: 'NAME',
      length: 80,
    },
})
name: string;

Acceptance criteria

  • add migration unit tests for preserving db metadata in model properties
  • check a migrated lb-next app manually that was migrated from an lb3 app with the above criteria
  • open additional issues for any open challenges migrating apps with above criteria
  • Update Importing-LB3-models.md, remove the relevant point from the list of known limitations
  • remove blocks on dependent issues (LB3 model import: handle ObjectID type for MongoDB #3814)
@deepakrkris
Copy link
Contributor

@bajtos I find that lb4 import-lb3-models command already supports including connector metadata in property definitions (I checked out of curiosity because the existing code does not restrict flowing of db metadata from lb3)

@deepakrkris
Copy link
Contributor

I was able to create the following typescript class from the LoopBack 3x db example , Todo model json
public.todo.json.txt ,

import {Entity, model, property} from '@loopback/repository';

@model({
  settings: {
    replaceOnPUT: false,
    postgresql: {schema: 'public', table: 'todo'},
    idInjection: true
  }
})
export class Todo extends Entity {
  @property({
    type: 'number',
    required: true,
    precision: 64,
    scale: 0,
    id: true,
    postgresql: {columnName: 'id', dataType: 'bigint', dataLength: null, dataPrecision: 64, dataScale: 0, nullable: 'NO'},
  })
  id: number;

  @property({
    type: 'string',
    length: 25,
    postgresql: {columnName: 'title', dataType: 'character varying', dataLength: 25, dataPrecision: null, dataScale: null, nullable: 'YES'},
  })
  title?: string;

  @property({
    type: 'string',
    length: 25,
    postgresql: {columnName: 'desc', dataType: 'character varying', dataLength: 25, dataPrecision: null, dataScale: null, nullable: 'YES'},
  })
  desc?: string;

  @property({
    type: 'boolean',
    postgresql: {columnName: 'iscomplete', dataType: 'boolean', dataLength: null, dataPrecision: null, dataScale: null, nullable: 'YES'},
  })
  iscomplete?: boolean;

  @property({
    type: 'number',
    precision: 64,
    scale: 0,
    postgresql: {columnName: 'todolistid', dataType: 'bigint', dataLength: null, dataPrecision: 64, dataScale: 0, nullable: 'YES'},
  })
  todolistid?: number;

  // Define well-known properties here

  // Indexer property to allow additional data
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  [prop: string]: any;

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

export interface TodoRelations {
  // describe navigational properties here
}

export type TodoWithRelations = Todo & TodoRelations;

@deepakrkris
Copy link
Contributor

I tried changing the property name of desc to desc2 just to check if the column metadata is used indeed, and it all works perfectly.

@bajtos
Copy link
Member Author

bajtos commented Feb 25, 2020

I find that lb4 import-lb3-models command already supports including connector metadata in property definitions
I tried changing the property name of desc to desc2 just to check if the column metadata is used indeed, and it all works perfectly.

That's awesome, it means we have less work to do 🚀

Your updated Acceptance criteria looks good to me.

  • add migration unit tests for preserving db metadata in model properties
  • check a migrated lb-next app manually that was migrated from an lb3 app with the above criteria
  • open additional issues for any open challenges migrating apps with above criteria
  • Update Importing-LB3-models.md, remove the relevant point from the list of known limitations
  • remove blocks on dependent issues (LB3 model import: handle ObjectID type for MongoDB #3814)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants