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

Import LB3 model JSON file to LB4 model class #2480

Closed
12 tasks done
bajtos opened this issue Feb 26, 2019 · 10 comments
Closed
12 tasks done

Import LB3 model JSON file to LB4 model class #2480

bajtos opened this issue Feb 26, 2019 · 10 comments

Comments

@bajtos
Copy link
Member

bajtos commented Feb 26, 2019

As an LB3 user migrating my model definition files to LB4, I would like to call lb4 CLI to generate an LB4 model class from my LB3 model JSON file.

lb4 import-lb3-models legacy-lb3app/server/server.js
# load the LB3 app
# ask the user which models to import
# create src/models/product.ts etc.

The initial version should handle property definitions only.

For example, let's take an LB3 Product model with a name property:

{
  "name": "Product",
  "base": "PersistedModel",
  "properties": {
    "name": {
      "type": "string",
      "required": true
    }
  }
}

This LB3 definition should be translated into an LB4 TypeScript model class:

@model()
class Product extends Entity {
  @property({required: true})
  name: string;
}

Acceptance criteria

See #2036 for the next step that will allow developers to take LB4 model and expose it via REST with little to no configuration.

Open discussion points & todos

  • Should we offer built-in models like User and AccessToken for importing?
  • Should we select all models by default?
  • How to automate model selection? Should we introduce a cli option like --models User,AccessToken? Use positional arguments like lb4 import-model my-lb3-app User AccessToken?
  • Process TODO & FIXME comments in the initial implementation CLI: Import LB3 model(s) into LB4 project [EXPERIMENTAL] #3688 and convert them to sub-tasks or follow-up issues
  • Write automated test to verify import of models attached to the following connectors:
    • SQL (MySQL or Postgres)
    • MongoDB (how is ObjectID type handled?)
    • Cloudant (how is _rev property handled?)

Out of scope

  • relations
  • remote methods
  • ACLs
  • mixins
  • Custom model property settings must be preserved, e.g. SQL column names.
  • A new section in the migration guide
@bajtos bajtos changed the title Import LB3 model Import LB3 model definition Feb 26, 2019
@bajtos bajtos changed the title Import LB3 model definition Import LB3 model JSON file to LB4 model class Feb 26, 2019
@marioestradarosa
Copy link
Contributor

@bajtos , currently the lb4 @model decorator can take the lb3 version model in json format as follows:

@model(
{
  "name": "Product",
  "properties": {
    "name": {
      "type": "string",
      "required": true
    }
  }
})
class Product extends Entity {
}

@emonddr
Copy link
Contributor

emonddr commented Apr 4, 2019

How are we going to handle the model-config.json ?

@buokae
Copy link

buokae commented Apr 11, 2019

Is there a migration manual somewhere? I have eight months left to migrate my project from lb3 to lb4 and no idea where to start.

@dhmlau dhmlau added the p3 label Apr 18, 2019
@dhmlau dhmlau added 2019Q3 and removed 2019Q2 labels May 14, 2019
@bajtos
Copy link
Member Author

bajtos commented Jun 24, 2019

@buokae

Is there a migration manual somewhere? I have eight months left to migrate my project from lb3 to lb4 and no idea where to start.

Not yet, unfortunately. Please follow the discussion in #1849.

@buokae
Copy link

buokae commented Jun 24, 2019

Alright, thank you.

@dhmlau dhmlau added the p1 label Jun 25, 2019
@dhmlau dhmlau added p2 and removed p1 labels Aug 20, 2019
@dhmlau dhmlau added this to the Sept 2019 milestone milestone Sep 3, 2019
@bajtos
Copy link
Member Author

bajtos commented Sep 9, 2019

How are we going to handle the model-config.json ?

In LB3, model setup has two steps:

  1. A model class is defined using data from the per-model JSON file.
  2. A model is attached to a datasource and exposed via REST API, this is controlled by configuration in model-config.json.

The goal of this story is to provide LB4 version for the first step only.

The second step will be handled by #2036, see also the spike that have already begun: #3617

@bajtos
Copy link
Member Author

bajtos commented Sep 9, 2019

The first draft of the implementation (early WIP): #3688

@bajtos
Copy link
Member Author

bajtos commented Sep 26, 2019

Custom model property settings must be preserved, e.g. SQL column names.

I'll be opening a follow-up story for this point.

A new section in the migration guide

We don't have much of migration guide yet, let's make this item a part of #3718.

Should we offer built-in models like User and AccessToken for importing?

Let's offer built-in models for the initial version and then use feedback from users to decide what changes (if any) we want to make.

Should we select all models by default?

Since we cannot import models inheriting from custom app models yet, I feel selecting all models by default will not work for most developers. I am also not sure how many developers will want to import LB3 built-in models like User and AccessToken.

How to automate model selection? Should we introduce a cli option like --models User,AccessToken? Use positional arguments like lb4 import-model my-lb3-app User AccessToken?

Let's wait until there is user demand for this feature.

Write automated test to verify import of models attached to the following connectors:

  • SQL (MySQL or Postgres)
  • MongoDB (how is ObjectID type handled?)
  • Cloudant (how is _rev property handled?)

I'll be opening a follow-up issue for MongoDB. Based on docs in our cloudant connector, _rev property has to be defined explicitly by users (app developers), therefore I don't expect any issues here. As for SQL, I am not aware of any potential issue either. Let's wait for user feedback before investing more effort into this area.

@bajtos
Copy link
Member Author

bajtos commented Sep 26, 2019

Created the following follow-up stories:

@dhmlau
Copy link
Member

dhmlau commented Oct 1, 2019

Closing as done!

@dhmlau dhmlau closed this as completed Oct 1, 2019
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

5 participants