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

fix(cli): emit correct property definitions for built-in types in discovered models #4143

Merged
merged 6 commits into from
Nov 21, 2019

Conversation

bajtos
Copy link
Member

@bajtos bajtos commented Nov 18, 2019

This pull request fixes model discovery to correctly handle built-in types and convert e.g. type: String to type: 'string', see #3806.

I split the change into several smaller commits:

  1. Add snapshots to CLI tests to give us better understanding of what code we are actually scaffolding. This is also needed to have a test that demonstrates the problem!

  2. Refactor the current implementation to make the fix easier: extract helper function converting discovered model to template data, extract findBuiltintType helper.

These first steps are not changing observable behavior. With the preparations done, we can make the fixes now.

  1. Emit correct property definitions for built-in types from lb4 discover.

  2. Disconnect the datasource after the model was discovered by lb4 model.

  3. Emit correct property definitions for built-in types from lb4 model.

Checklist

👉 Read and sign the CLA (Contributor License Agreement) 👈

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈

@bajtos bajtos added this to the Nov 2019 milestone milestone Nov 18, 2019
@bajtos bajtos self-assigned this Nov 18, 2019
@bajtos bajtos requested a review from jannyHou November 18, 2019 15:30
Copy link
Contributor

@jannyHou jannyHou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your refactor and fix is reasonable to me 👍 haven't reviewed the details of tests, but they look good in general.

@nabdelgadir
Copy link
Contributor

LGTM so far 👍

@bajtos
Copy link
Member Author

bajtos commented Nov 19, 2019

Added one more commit to fix lb4 model --dataSource {db} --table {name}.

The implementation is not as clean as I would like it to be - we have too many different code paths building model template data - but I guess it's good enough for now.

The pull request is ready for final review as far as I am concerned.

… data

Extract code converting model definition returned by juggler's discovery
function into LB4 model template data, move this code to a new function
that can be used independently.

Add few basic unit tests to start building fast unit-level test suite
verifying how different settings & property definitions are handled
by our discovery layer.

Signed-off-by: Miroslav Bajtoš <[email protected]>
Before this change, `lb4 discover` will emit property definitions
similar to this:

    @Property({
      type: String,
    })
    title: String;

This commit fixes the behavior to make it consistent with `lb4 model`
and `lb4 import-lb3-models` output:

    @Property({
      type: 'string',
    })
    title: string;

Signed-off-by: Miroslav Bajtoš <[email protected]>
Fix `lb4 model` to close the connection to the datasource after the
target model was discovered.

Before this change, the generator would hang because the connection pool
used by some DB connectors was preventing the process from finishing.

Signed-off-by: Miroslav Bajtoš <[email protected]>
Before this change, `lb4 model --dataSource` emits property definitions
similar to this:

    @Property({
      type: String,
    })
    title: String;

This commit fixes the behavior to make it consistent with `lb4 model`
and `lb4 import-lb3-models` output:

    @Property({
      type: 'string',
    })
    title: string;

Signed-off-by: Miroslav Bajtoš <[email protected]>
@bajtos bajtos merged commit 6a972db into master Nov 21, 2019
@bajtos bajtos deleted the fix/discovered-types branch November 21, 2019 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants