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

REALMC-10362: Update CLI to handle data_sources dirs with just rules or just schemas/relationships #267

Merged
merged 6 commits into from
Mar 7, 2022

Conversation

malexandert
Copy link
Contributor

@malexandert malexandert commented Feb 22, 2022

JIRA: https://jira.mongodb.org/browse/REALMC-10362

Essentially doing a similar thing to this PR. After this PR, pushing, pulling, and diffing an app should work in cases where:

  • a collection folder (data_sources/<data_source>/<database>/<collection>) contains solely a rules.json file
  • a collection folder contains solely a pair of schema.json and relationships.json files

This change was necessary because, as part of Schema Separation, an app is allowed to have a rule without an associated schema and vice versa

Copy link
Contributor

@makesitgo makesitgo left a comment

Choose a reason for hiding this comment

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

initial batch of thoughts/comments from me.

my main concern is I think I'd have expected these changes to be more "additive" than they currently are, and I want to make sure we're not breaking the CLI for any older apps out there

internal/local/structure_v2.go Outdated Show resolved Hide resolved
internal/local/structure_v2.go Outdated Show resolved Hide resolved
internal/local/structure_v2.go Outdated Show resolved Hide resolved
internal/local/structure_v2.go Outdated Show resolved Hide resolved
internal/local/structure_v2.go Show resolved Hide resolved
@malexandert malexandert force-pushed the REALMC-10362 branch 2 times, most recently from b1578f5 to 92457a0 Compare February 25, 2022 16:58
Copy link
Contributor

@jandersongo jandersongo left a comment

Choose a reason for hiding this comment

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

lgtm!

internal/local/structure_v2.go Outdated Show resolved Hide resolved
Copy link
Contributor

@caiyingshen caiyingshen left a comment

Choose a reason for hiding this comment

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

LGTM 😎 just a couple questions and nits from me!

internal/local/structure_v2.go Outdated Show resolved Hide resolved

rulePath := filepath.Join(collPath, FileRules.String())
if _, err := os.Stat(rulePath); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

[opt] could we use Stat() to check the file paths to see if the conditions for a valid data source folder are met before parsing them? up to you, I'm not sure how much of a performance improvement this would be

Copy link
Contributor

Choose a reason for hiding this comment

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

the parseJSON call below (L#305) actually starts with an os.Stat call and returns early if the path doesn't exist, so your optimization is already built in here

i think the existing code just took the route of calling os.Stat ahead of parseJSON just to be clear about the intent for skipping directories without rules.json files present (rather than rely on a rule == nil check)

internal/local/structure_v2.go Outdated Show resolved Hide resolved
@malexandert malexandert changed the title REALMC-10362: Update CLI to import schemas separate from rules REALMC-10362: Update CLI to handle data_sources dirs with just rules or just schemas/relationships Feb 28, 2022
Copy link
Contributor

@makesitgo makesitgo left a comment

Choose a reason for hiding this comment

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

just a last few questions from me here before this is ready to go... nice work!


rulePath := filepath.Join(collPath, FileRules.String())
if _, err := os.Stat(rulePath); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

the parseJSON call below (L#305) actually starts with an os.Stat call and returns early if the path doesn't exist, so your optimization is already built in here

i think the existing code just took the route of calling os.Stat ahead of parseJSON just to be clear about the intent for skipping directories without rules.json files present (rather than rely on a rule == nil check)

internal/local/structure_v2.go Outdated Show resolved Hide resolved
internal/local/structure_v2_test.go Show resolved Hide resolved
Copy link
Contributor

@makesitgo makesitgo left a comment

Choose a reason for hiding this comment

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

one last question about our ability within writeDataSources to not have to write a rules.json file (which at least currently, shouldn't come up)

otherwise, nothing blocking on this from me, nice work!

🆒 beans

return err

schema := rule[NameSchema]
if schema != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

let's use the if schema, ok := rule[NameSchema]; ok { syntax here (we avoided it previously b/c we always wanted to replace nil with map[string]interface{}{} which i suppose is no longer the case)


schema := rule[NameSchema]
if schema != nil {
dataSchema, err := MarshalJSON(schema)
Copy link
Contributor

Choose a reason for hiding this comment

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

[meganit/naming] could in theory tighten the scope of this named var to just data now that we're in this okSchema closure

@malexandert malexandert merged commit 6d562ce into 10gen:master Mar 7, 2022
dpish pushed a commit to dpish/realm-cli that referenced this pull request Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants