-
Notifications
You must be signed in to change notification settings - Fork 17
fix(repo): Normalize cursor word length #493
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
Closed
Closed
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f5455ef
feat: added missing to network
petertonysmith94 6d558d3
fix: updated cursor to have normlized padding
petertonysmith94 b875bbd
fix: updated the message model to consistently form a Cursor
petertonysmith94 110b321
fix: updated the padding behaviour for cursors
petertonysmith94 f9e8cb2
fix(repo): Lint
luizstacio 248570f
fix: migration file
luizstacio 37d774e
Merge branch 'main' into ps/fix/normalize-cursor-word-length
luizstacio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
crates/domains/migrations/20250608000000_update_cursor_padding.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
-- Splits our input on the delimiter | ||
-- Leave the first element as it is | ||
-- Pad all subsequential words to the given pad length | ||
CREATE OR REPLACE FUNCTION split_and_pad( | ||
input_text TEXT, | ||
delimiter TEXT, | ||
pad_length INTEGER, | ||
pad_from INTEGER DEFAULT 0, | ||
pad_char TEXT DEFAULT '0' | ||
) | ||
RETURNS TEXT AS $$ | ||
BEGIN | ||
RETURN array_to_string( | ||
ARRAY( | ||
SELECT | ||
CASE | ||
WHEN row_number() OVER () = pad_from THEN elem | ||
ELSE lpad(elem, pad_length, pad_char) | ||
END | ||
FROM unnest(string_to_array(input_text, delimiter)) WITH ORDINALITY AS t(elem, ord) | ||
ORDER BY ord | ||
), | ||
delimiter | ||
); | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
-- Update all tables with `cursor` and pad each part of the word | ||
DO $$ | ||
DECLARE | ||
-- Skip over the first element (block_height) in our case | ||
-- We don't pad this element | ||
PAD_FROM CONSTANT INTEGER := 1 | ||
-- The padding length for all subsequential words after | ||
PAD_LENGTH CONSTANT INTEGER := 6; | ||
DELIMINATOR CONSTANT TEXT := '-'; | ||
BEGIN | ||
-- Update `inputs` table | ||
update inputs | ||
set cursor = split_and_pad(cursor, DELIMINATOR, PAD_LENGTH, PAD_FROM); | ||
|
||
-- Update `messages` table | ||
update messages | ||
set cursor = split_and_pad(cursor, DELIMINATOR, PAD_LENGTH, PAD_FROM); | ||
|
||
-- Update `transactions` table | ||
update transactions | ||
set cursor = split_and_pad(cursor, DELIMINATOR, PAD_LENGTH, PAD_FROM); | ||
|
||
-- Update `receipts` table | ||
update receipts | ||
set cursor = split_and_pad(cursor, DELIMINATOR, PAD_LENGTH, PAD_FROM); | ||
|
||
-- Update `utxos` table | ||
update utxos | ||
set cursor = split_and_pad(cursor, DELIMINATOR, PAD_LENGTH, PAD_FROM); | ||
|
||
-- Update `predicate_transactions` table | ||
update predicate_transactions | ||
set cursor = split_and_pad(cursor, DELIMINATOR, PAD_LENGTH, PAD_FROM); | ||
|
||
-- Update `outputs` table | ||
update outputs | ||
set cursor = split_and_pad(cursor, DELIMINATOR, PAD_LENGTH, PAD_FROM); | ||
END $$; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.