Skip to content

Remove urn_state type#188

Merged
paytonrules merged 8 commits intostagingfrom
vdb-1214-remove-urn-state-type
Jun 5, 2020
Merged

Remove urn_state type#188
paytonrules merged 8 commits intostagingfrom
vdb-1214-remove-urn-state-type

Conversation

@paytonrules
Copy link
Copy Markdown
Contributor

I did this as three migrations. The first to replace the all_urns function with a much simpler one. The second to remove all references to urn_state, and the third to rename obsolete_urn_state to obsolete_urn_snapshot. The code changes (non SQL edition) are almost all around tests.

Copy link
Copy Markdown
Contributor

@rmulhol rmulhol left a comment

Choose a reason for hiding this comment

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

Looking really good! Planning to take a closer look later, but dropping some initial thoughts

@paytonrules paytonrules force-pushed the vdb-1214-remove-urn-state-type branch from 42eae41 to 54145b6 Compare May 13, 2020 21:46
Copy link
Copy Markdown
Contributor

@elizabethengelman elizabethengelman left a comment

Choose a reason for hiding this comment

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

LGTM, nice work!

I'm a little hesitant to merge this in while we're still working on urn_snapshot reconciliation, but I'd be curious to hear what others think!

Copy link
Copy Markdown
Contributor

@rmulhol rmulhol left a comment

Choose a reason for hiding this comment

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

Looks good to me - a couple minor comments, would be curious to hear your thoughts, nothing merge blocking

all_urns.block_height, ink, coalesce(art, 0), created, updated
FROM api.urn_snapshot
WHERE block_height <= all_urns.block_height
ORDER BY urn_identifier, ilk_identifier, updated DESC) AS latest_urns
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we just ORDER BY updated here (omitting urn_identifier, ilk_identifier)? Also, do we need AS latest_urns?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately we can't omit urn_identifier and ilk_identifier from ORDER BY because they are in the DISTINCT above. I'm not sure about latest_urns, I have to double-check.

AS $_$

SELECT *
FROM api.all_urns(get_urn.block_height)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems kinda heavyweight to query all_urns for one urn - might it be better to:

SELECT * FROM api.urn_snapshot WHERE ilk_identifier = x AND urn_identifier = y AND block_height <= n ORDER BY block_height DESC LIMIT 1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was trying to be consistent with the other ones that use all_urns, but you're probably right.

AS $$
SELECT *
FROM api.get_urn(
(SELECT identifier FROM maker.ilks WHERE ilks.id = flip.ilk_id),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hm, this is way out of scope for this PR, but it seems like api.get_flip should be returning a maker.flip and we should be deleting api.flip_bid_snapshot - basically a story to do exactly what you're doing here for a different place where we've got a type used in queries + a trigger table

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Mostly just caught my eye because we have an ilk_id and urn_id on that type, instead of the identifiers - which seems odd. If we're going to have a custom type for queries, I would have thought we would have done the join to get the identifiers in the query and not exposed internal DB FKs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not quite sure I followed that last bit - is there an action item here besides a story about flip_bid_snapshot?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No, sorry - kinda just thinking out loud. Will create stories for this stuff

@paytonrules paytonrules force-pushed the vdb-1214-remove-urn-state-type branch from e245ab2 to 591a585 Compare June 5, 2020 14:33
This replaces the complicated all_urns with a much simpler SQL call that
goes right at the urn_snapshots, now that we have them.
In addition remove the all_urn_states query test because that query
goes away, the get_urn_query_test because that query also goes away, and
the computed columns tests because those functions go away as well. Wee!

Finally convert any place that uses urn_state and use urn_snapshot
directly in the return types.
This is so you can tell what field is actually failing.
To make sure we return the urns in a predictable order I need to make
the query for distinct urn_snapshots a subquery, because the order by
updated only applies within the distinct grouping, to ensure we get the
latest urn. I also added a test for this query.
Assuming all_urns only returns unique individual urns (as it should)
using this in the other queries should mean you'll always only get one urn.
@paytonrules paytonrules force-pushed the vdb-1214-remove-urn-state-type branch from 591a585 to 2dbb3d7 Compare June 5, 2020 16:06
@paytonrules paytonrules merged commit c87f127 into staging Jun 5, 2020
@rmulhol rmulhol deleted the vdb-1214-remove-urn-state-type branch June 18, 2020 20:27
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.

3 participants