-
Notifications
You must be signed in to change notification settings - Fork 31
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
ACQ - Updated metadb derived tables #804
base: main
Are you sure you want to change the base?
Conversation
syncing arthur-aguilera fork
Updates to feesfines_accounts_actions table based on issue folio-org#501
adds po_notes per Issue folio-org#798
adds po_orders to runlist.
sql_metadb/derived_tables/po_notes
Outdated
@@ -0,0 +1,31 @@ | |||
--MetaDB: Table po_notes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the directive syntax at: https://metadb.dev/doc/#_metadbtable
Also note that the name is "Metadb" not "MetaDB".
@@ -55,6 +55,7 @@ po_lines_eresource.sql | |||
po_lines_locations.sql | |||
po_lines_phys_mat_type.sql | |||
po_lines_physical.sql | |||
po_orders.sql |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look right.
Updates po_orders to po_notes to reflect new derived table
adds directive syntax
updates directive syntax
@nassibnassar Hi Nassib - I updated the queries with the requested changes. I'm not sure how to update the pull request if needed. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See code comments
All queries:
- PR Title and Description are accurate and thorough
- PR is based on a new branch (not main)
- PR scope is not overly broad
- Query runs without errors
- Query output is correct
- Query logic is clear and well documented
- Query is readable and properly indented
- Table and column names are in all-lowercase
- Quotation marks are used only where necessary
- JSON extraction is in standard form, for example:
LDP: t #>> '{f1,f2,f3}' [for compatibility across LDP 1 & 2]
Metadb: jsonb_extract_path_text(t, f1, f2, f3)
Derived tables:
- First line is "--metadb:table" directive, followed by blank line
- User documentation in comment lines, followed by blank line
- File name is listed in
runlist.txt
after dependencies
COMMENT ON COLUMN feesfines_accounts_actions.fine_account_id IS 'User fine/fee account id, UUID' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.fine_account_amount IS 'Amount of the fine/fee' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.fine_date IS 'Date and time the account of the fine/fee was created' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.fine_updated_date IS 'Date and time the account of the fine/fee was updated' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.fee_fine_id IS 'ID of the fee/fine' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.owner_id IS 'ID of the account owner' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.fee_fine_owner IS 'Owner of the account' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.fee_fine_type IS 'Fee/fine that is up to the desecration of the user' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.material_type_id IS 'ID of the material type of the item' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.material_type IS 'Material type of the item' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.payment_status IS 'Overall status of the payment/waive/transfer/refund/cancel' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.fine_status IS 'Overall status of the fee/fine' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.account_user_id IS 'ID of the user' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.transaction_id IS 'Fine/fee action id, UUID' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.transaction_amount IS 'Amount of activity' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.account_balance IS 'Calculated amount of remaining balance based on original fee/fine and what has been paid/waived/transferred/refunded' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.type_action IS 'Type of activity including the type of transaction' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.transaction_date IS 'Date and time the transaction of the fine/fee was created' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.transaction_location IS 'The service point where the action was created' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.transaction_information IS 'Number or other transaction id related to payment' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.operator_id IS 'Person who processed activity (from login information)' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.payment_method IS 'Overall status of the action-setting' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.user_id IS 'User UUID' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.user_patron_group_id IS 'UUID for user patron group' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.patron_group_name IS 'User patron group' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.signed_transaction_amount IS 'Identifies the type_action value that decreases the balance of the account and adds a - to those values' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All comments are missing a ";" at the end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added ";" at the end of each comment.
|
||
COMMENT ON COLUMN feesfines_accounts_actions.transaction_information IS 'Number or other transaction id related to payment' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.operator_id IS 'Person who processed activity (from login information)' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong column name. Did you mean "action_created_by"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed operator_id comment
|
||
COMMENT ON COLUMN feesfines_accounts_actions.material_type IS 'Material type of the item' | ||
|
||
COMMENT ON COLUMN feesfines_accounts_actions.payment_status IS 'Overall status of the payment/waive/transfer/refund/cancel' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong column name. Did you mean "payment_status_name"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed the name of the column in main query to just "payment_status"
sql_metadb/derived_tables/po_notes
Outdated
|
||
COMMENT ON COLUMN po_notes.workflow_status IS 'workflow status of the purchase order' | ||
|
||
COMMENT ON COLUMN po_notes.po_note IS 'Purchase order note' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong column name. Did you mean "note"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to po_notes.note
Added ';' at the end of columns; added back in documentation for the table; changed payment_status_name to payment_status, and removed comment or operator_id
added documentation; added ";" at end of comments; corrected COMMENT ON COLUMN fields to match fields of main query.
@LauSchl Thank you so much for your comments! I hope I've fixed everything you found and have updated my branch. Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for po_notes table , it would be nice to be consistent with field names with other derived tables (see po_instance table): instead of "poNumber" we have "po_number", "creation_date" we have "created_date", "po_workflow_status" instead of just "workflow_status", po_note instead of "note"( i think there is also renewalNote and closeReason_note"), po_note_ordinality
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, there is a misspell "--Creates a dervied table" and created date needs to be cast : jsonb_extract_path_text(po.jsonb, 'metadata', 'createdDate')::timestamptz, unless you really need time. Comments need to be adjusted if you rename fields. Thanks, Natalya.
adds renewal and closure notes; updates column names to be aligned with other derived tables
@natalyapik Thank you! I updated the file with those changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me! Thanks Arthur.
sql_metadb/derived_tables/po_notes
Outdated
COMMENT ON COLUMN po_closeReason_note IS 'Notes entered when a purchase order is closed'; | ||
|
||
COMMENT ON COLUMN po_renewal_note IS 'Notes entered in the ongoing order information'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines result in a syntax error because the table name is missing.
CASE WHEN | ||
jsonb_extract_path_text(ff.jsonb, 'typeAction') IN | ||
('Paid partially','Paid fully','Waived partially','Waived fully','Credited partially','Credited fully') | ||
THEN jsonb_extract_path_text(ff.jsonb, 'amountAction')::numeric(12,2) * -1 | ||
ELSE jsonb_extract_path_text(ff.jsonb, 'amountAction')::numeric(12,2) | ||
END AS signed_transaction_amount |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this could be indented so that it will not be at the same indentation level as the FROM
.
Also there might be some way to avoid the WHEN
, THEN
, and ELSE
all being at the same indentation level.
|
||
DROP TABLE IF EXISTS feesfines_accounts_actions; | ||
|
||
CREATE TABLE feesfines_accounts_actions AS | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we remove blank lines in the middle of a query? Sorry that is not documented anywhere.
sql_metadb/derived_tables/po_notes
Outdated
DROP TABLE IF EXISTS po_notes; | ||
|
||
CREATE TABLE po_notes AS | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again if we could remove blank lines in the middle of a query.
sql_metadb/derived_tables/po_notes
Outdated
po.jsonb -> 'ongoing' ->> 'renewalNote' AS po_renewal_note | ||
FROM folio_orders.purchase_order AS po | ||
CROSS JOIN LATERAL jsonb_array_elements(jsonb_extract_path(po.jsonb, 'notes')) WITH ORDINALITY AS po_notes (jsonb); | ||
; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this an extra semicolon?
adds .sql to filename and removes blank lines in middle of query
removes blank lines and changes indentation for case when, then, else, end
@nassibnassar Hi Nassib, hopefully I've resolved the comments. I made have misunderstood what you were hoping to see with the CASE, WHEN, ELSE, END statement. Thanks! |
…s_action.sql Updates indentation for CASE, WHEN, ELSE, END
@sbeltaine I've updated the indentation for the CASE, WHEN, ELSE, END, per our discussion at ACQ-ERM today. |
There is so much going on in this PR and I'm having trouble following what was intended. It looks like |
fixes the name of the file which should be feesfines_accounts_actions.sql
Sorry @nassibnassar. That shouldn't have happened and that was my error. I returned it back to the correct name. I was going to add ".sql" just in case I missed it like I did with the po_notes, and then realized I had already added it so I went to delete it. I guess I backspaced one character too far. I'm sorry for adding more confusion. |
COMMENT ON COLUMN po_closeReason_note IS 'Notes entered when a purchase order is closed'; | ||
|
||
COMMENT ON COLUMN po_renewal_note IS 'Notes entered in the ongoing order information'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two of these aren't qualified.
I couldn't find any guidelines it it is necessary for this repo but since you added it
for all the other comments it would be consistent to add the tablename here as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The table name is needed to avoid a SQL syntax error.
Also could we have po_close_reason_note
instead of po_closeReason_note
for the column name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feesfines_accounts_actions.sql
All queries:
-
PR Title and Description are accurate and thorough
-
PR is based on a new branch (not main)
-
PR scope is not overly broad
-
Query runs without errors
-
Query output is correct
No Comments for actions_created_by table -
Query logic is clear and well documented
-
Query is readable and properly indented
-
Table and column names are in all-lowercase
-
Quotation marks are used only where necessary
-
JSON extraction is in standard form, for example:
LDP: t #>> '{f1,f2,f3}' [for compatibility across LDP 1 & 2]
Metadb: jsonb_extract_path_text(t, f1, f2, f3)
Derived tables:
- First line is "--metadb:table" directive, followed by blank line
- User documentation in comment lines, followed by blank line
- File name is listed in
runlist.txt
after dependencies
po_notes.sql All queries:
Derived tables:
|
The po_notes.sql table needs qualified references for tables listed in the Comments. The feesfines_accounts_actions.sql table needs Comments for the actions_created_by table. |
@sbeltaine To approve a PR (once it meets your approval in its entirety), please go to: Files changed > Review changes > Approve > Submit review |
We are getting there. Thanks for your patience. Could someone explain why two different tables have been combined into a single pull request? It would be easier to keep track of the many comments above if the PR had been simpler. |
@nassibnassar - Yes, it is better to submit one table in one PR. We reviewed how to do this in our ACQ meeting after walking through this PR, so future PRs will be limited to one table. |
Adds missing qualified references for tables listed in the Comments and renames po_closeReason_note to po_close_reason_note per Nassib
Adds comment for feesfines_accounts_actions.action_created_by
@sbeltaine I think I add those comments and fixed the column name in po_notes. @nassibnassar Yes, the multiple tables on one PR was my bad. Sharon was very helpful for learning how to do this better next time. Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the many comments, and otherwise it is looking good to me.
po_notes.jsonb #>> '{}' AS po_note, | ||
po_notes.ORDINALITY AS po_note_ordinality, | ||
po.jsonb -> 'closeReason' ->> 'note' AS po_close_reason_note, | ||
po.jsonb -> 'ongoing' ->> 'renewalNote' AS po_renewal_note |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could not find renewalNote in any databases or under "ongoing" in the JSON schema here: https://s3.amazonaws.com/foliodocs/api/mod-orders-storage/p/purchase-order.html
Did I look in the wrong place? Are you sure this is correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is on po_line table: https://s3.amazonaws.com/foliodocs/api/mod-orders-storage/p/po-line.html#orders_storage_po_lines__id__get
and it is extracted in the transformed table.@arthur-aguilera please delete "renewal note" from this derived table.
po.jsonb ->> 'poNumber' AS po_number, | ||
po.jsonb ->> 'workflowStatus' AS po_workflow_status, | ||
po_notes.jsonb #>> '{}' AS po_note, | ||
po_notes.ORDINALITY AS po_note_ordinality, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use all lowercase for identifiers. See: https://github.com/folio-org/folio-analytics/blob/main/CONTRIBUTING.md#8-naming-things
(po.jsonb -> 'metadata' ->> 'createdDate')::timestamptz AS created_date, | ||
po.jsonb ->> 'poNumber' AS po_number, | ||
po.jsonb ->> 'workflowStatus' AS po_workflow_status, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use jsonb_extract_path_text()
for JSON extraction (here and below).
--metadb:table feesfines_accounts_actions | ||
|
||
-- Create a derived table that takes feesfines_accounts as the main table | ||
-- join all transaction data from the feesfines_actions table | ||
-- add patron group information from user_group table | ||
--Creates a derived table that takes folio_feesfines.accounts as the main table |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you would, in both feesfines_accounts_actions.sql
and po_notes.sql
, please add a blank line after the --metadb:table
directive (see https://metadb.dev/doc/#_external_sql_directives) and a blank line in between individual SQL statements below.
SELECT | ||
po.id AS po_id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you would, please consider using indentation to make the query easier to read. For examples, see feesfines_accounts_actions.sql
above or the query within: https://github.com/metadb-project/metadb-examples/blob/main/folio/reports/missing_items.sql
Should this say po_notes? In the PR description. |
This pull request may have unresolved issues. |
Creates new po_orders derived table and adds the table to the runlist
Updates feesfines_accounts_acounts derived table