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

ACQ - Updated metadb derived tables #804

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

arthur-aguilera
Copy link
Contributor

Creates new po_orders derived table and adds the table to the runlist
Updates feesfines_accounts_acounts derived table

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.
@arthur-aguilera arthur-aguilera changed the title Updated metadb derived tables ACQ - Updated metadb derived tables Oct 23, 2023
@@ -0,0 +1,31 @@
--MetaDB: Table po_notes
Copy link
Contributor

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
Copy link
Contributor

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
@arthur-aguilera
Copy link
Contributor Author

@nassibnassar Hi Nassib - I updated the queries with the requested changes. I'm not sure how to update the pull request if needed. Thanks!

Copy link

@LauSchl LauSchl left a 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

sql_metadb/derived_tables/feesfines_accounts_actions.sql Outdated Show resolved Hide resolved
Comment on lines 46 to 96
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'
Copy link

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

Copy link
Contributor Author

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)'
Copy link

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"?

Copy link
Contributor Author

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'
Copy link

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"?

Copy link
Contributor Author

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 Show resolved Hide resolved

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'
Copy link

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"?

Copy link
Contributor Author

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

sql_metadb/derived_tables/po_notes Outdated Show resolved Hide resolved
sql_metadb/derived_tables/po_notes Outdated Show resolved Hide resolved
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.
@arthur-aguilera
Copy link
Contributor Author

@LauSchl Thank you so much for your comments! I hope I've fixed everything you found and have updated my branch. Thank you!

Copy link
Contributor

@natalyapik natalyapik left a 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

Copy link
Contributor

@natalyapik natalyapik left a 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
@arthur-aguilera
Copy link
Contributor Author

@natalyapik Thank you! I updated the file with those changes.

Copy link
Contributor

@natalyapik natalyapik left a 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.

Comment on lines 33 to 35
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';
Copy link
Contributor

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.

Comment on lines 35 to 40
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
Copy link
Contributor

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

Copy link
Contributor

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.

DROP TABLE IF EXISTS po_notes;

CREATE TABLE po_notes AS

Copy link
Contributor

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.

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);
;
Copy link
Contributor

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
@arthur-aguilera
Copy link
Contributor Author

@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!

@sbeltaine sbeltaine self-requested a review November 14, 2023 16:16
…s_action.sql

Updates indentation for CASE, WHEN, ELSE, END
@arthur-aguilera
Copy link
Contributor Author

@sbeltaine I've updated the indentation for the CASE, WHEN, ELSE, END, per our discussion at ACQ-ERM today.

@nassibnassar
Copy link
Contributor

There is so much going on in this PR and I'm having trouble following what was intended. It looks like feesfines_accounts_actions.sql has been accidentally renamed to feesfines_accounts_action.sql. Is that correct?

fixes the name of the file which should be feesfines_accounts_actions.sql
@arthur-aguilera
Copy link
Contributor Author

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 lines 31 to 33
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';
Copy link

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.

Copy link
Contributor

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?

Copy link
Contributor

@sbeltaine sbeltaine left a 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

@sbeltaine
Copy link
Contributor

sbeltaine commented Nov 21, 2023

po_notes.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
    query needs po_closeReason_note and po_renewal_note Comments to be qualified by making them
    po_notes.po_closeReason_note and po_notes.po_renewal_note

  • 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

@sbeltaine
Copy link
Contributor

sbeltaine commented Nov 21, 2023

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.

@nassibnassar
Copy link
Contributor

nassibnassar commented Nov 21, 2023

@sbeltaine To approve a PR (once it meets your approval in its entirety), please go to: Files changed > Review changes > Approve > Submit review

@nassibnassar
Copy link
Contributor

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.

@sbeltaine
Copy link
Contributor

@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
@arthur-aguilera
Copy link
Contributor Author

@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!

Copy link
Contributor

@nassibnassar nassibnassar left a 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
Copy link
Contributor

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?

Copy link
Contributor

@natalyapik natalyapik Dec 4, 2023

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,
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines +8 to +10
(po.jsonb -> 'metadata' ->> 'createdDate')::timestamptz AS created_date,
po.jsonb ->> 'poNumber' AS po_number,
po.jsonb ->> 'workflowStatus' AS po_workflow_status,
Copy link
Contributor

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).

Comment on lines 1 to +2
--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
Copy link
Contributor

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.

Comment on lines +6 to +7
SELECT
po.id AS po_id,
Copy link
Contributor

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

@nassibnassar
Copy link
Contributor

Creates new po_orders derived table and adds the table to the runlist Updates feesfines_accounts_acounts derived table

Should this say po_notes? In the PR description.

@nassibnassar
Copy link
Contributor

This pull request may have unresolved issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants