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

Function to generate Flow types from edit data #1616

Merged
merged 5 commits into from Oct 7, 2020

Conversation

mwiencek
Copy link
Member

@mwiencek mwiencek commented Jul 27, 2020

A SQL function, edit_data_type_info(), is added that generates "type info" for a single column of edit data.

A script, script/generate_edit_data_flow_type.js, is added which takes an edit type, selects edit_data_type_info() for every row of edit data for that type, and outputs a single merged Flow type representing the edit data overall for that type.

For example:

./script/generate_edit_data_flow_type.js --edit-type 92

Generates a Flow type for EDIT_RELATIONSHIP_DELETE.

The PROD_STANDBY database must be configured in DBDefs.pm to use this utility.

The underlying code used to build the Flow type may also be useful to generate Flow types for other JSON data, e.g. entities.json, so I've added script/generate_json_flow_type.js for this more general purpose too. Here's an example invoking that script:

cat entities.json | jq -c | script/generate_json_flow_type.js

(This expects the JSON object on a single line, so jq -c is used to compact the data first.)

I've committed the type generated for root/edit/details/RemoveRelationship.js as an example.

I think this will help with two things:

  1. The SQL function by itself is useful to see all the different data formats an edit type has, which can make it easier to identify places we can clean up the data later.
  2. The combined Flow type generated by edit_data_flow_type.js is useful for accessing the edit data safely (type-checked by Flow) in a React template. This isn't so important now, but in the future we'll likely want to move build_display_data etc. into JS.

@mwiencek
Copy link
Member Author

mwiencek commented Aug 26, 2020

Note that we can use script/edit_data_flow_type.js script/generate_json_flow_type.js to generate types for other JSON too, e.g. entities.json. I'd like to do that in another branch once this is merged. :)

Copy link
Member

@reosarevok reosarevok left a comment

Choose a reason for hiding this comment

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

LGTM but I didn't test

Copy link
Contributor

@yvanzo yvanzo left a comment

Choose a reason for hiding this comment

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

Successfully tested on production database with “Reorder relationships” edits (type ID = 99).

Would it make sense to have a wrapper script that uses PROD_STANDBY from DBDefs?

That would be nice to mention the command generating the added flow type in second commit too.

@mwiencek mwiencek force-pushed the edit-data-flow-types branch 3 times, most recently from f93d345 to 658b427 Compare October 1, 2020 00:49
@mwiencek
Copy link
Member Author

mwiencek commented Oct 1, 2020

Would it make sense to have a wrapper script that uses PROD_STANDBY from DBDefs?

Added a wrapper script for that (and updated the commit message/PR description with instructions). It sets statement_timeout = 0 so you shouldn't get timeouts anymore.

Also added script/generate_json_flow_type.js to generate a Flow type from other JSON.

Comment on lines +51 to +52
"pg": "8.3.3",
"pg-cursor": "2.3.3",
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm also using these in my json-dumps rework.

Copy link
Contributor

@yvanzo yvanzo left a comment

Choose a reason for hiding this comment

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

./script/generate_edit_data_flow_type.js --edit-type 92

returned:

/musicbrainz-server/root/utility/generateFlowType.js:37
      (isEditDataTypeInfo ?? parent.isEditDataTypeInfo);
                           ^

SyntaxError: Unexpected token ?
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/musicbrainz-server/script/generate_edit_data_flow_type.js:23:28)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)

using Node v10.19.0 currently installed in MusicBrainz Docker.

This will be used to connect directly to postgres from Node.js.
This will be used to connect directly to postgres from Node.js.
A SQL function, edit_data_type_info(), is added that generates "type
info" for a single column of edit data.

A script, script/generate_edit_data_flow_type.js, is added which takes
an edit type, selects edit_data_type_info() for every row of edit data
for that type, and outputs a single merged Flow type representing the
edit data overall for that type.

For example:

./script/generate_edit_data_flow_type.js --edit-type 92

Generates a Flow type for EDIT_RELATIONSHIP_DELETE.

The PROD_STANDBY database must be configured in DBDefs.pm to use this
utility.

The underlying code used to build the Flow type may also be useful to
generate Flow types for other JSON data, e.g. entities.json, so I've
added script/generate_json_flow_type.js for this more general purpose
too. Here's an example invoking that script:

cat entities.json | jq -c | script/generate_json_flow_type.js

(This expects the JSON object on a single line, so `jq -c` is used to
compact the data first.)
Command used:

./script/generate_edit_data_flow_type.js --edit-type 92
Copy link
Contributor

@yvanzo yvanzo left a comment

Choose a reason for hiding this comment

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

Works fine now. Code looks good too. Maybe document scripts also in HACKING.md?

@mwiencek
Copy link
Member Author

mwiencek commented Oct 7, 2020

Maybe document scripts also in HACKING.md?

I wasn't sure where to put that so I made a general Flow section. Have a quick look. :)

@mwiencek mwiencek force-pushed the edit-data-flow-types branch 2 times, most recently from 74ef207 to 319df9c Compare October 7, 2020 18:04
Copy link
Contributor

@yvanzo yvanzo left a comment

Choose a reason for hiding this comment

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

Each time I approve this pull request, there are new additions, so I approve it again!

HACKING.md Outdated Show resolved Hide resolved
HACKING.md Show resolved Hide resolved
@mwiencek
Copy link
Member Author

mwiencek commented Oct 7, 2020

OK, I'll commit the strict-local addition and merge this to save you from another approval. :)

@mwiencek mwiencek merged commit 3fa61b7 into metabrainz:master Oct 7, 2020
@mwiencek mwiencek deleted the edit-data-flow-types branch October 7, 2020 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants