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

[EI-468] Create v1 migration views #385

Merged
merged 5 commits into from
Jun 12, 2024
Merged

Conversation

rtso
Copy link
Collaborator

@rtso rtso commented May 22, 2024

Description

As part of the v1 table deprecation, replace the v1 tables with views using the v2 tables. This will give the ecosystem a migration window to migrate their queries to the v2 tables and reduces ecosystem impact.

Test plan

Ran the SQL locally

@rtso rtso changed the title Create v1 migration views [EI-468] Create v1 migration views May 22, 2024
Copy link

linear bot commented May 22, 2024

@rtso rtso requested review from CapCap, ying-w, bowenyang007, yuunlimm and a team May 22, 2024 21:43
@rtso rtso force-pushed the rtso/v1-migration-views branch from 57447fb to 4eeb4f5 Compare May 22, 2024 21:44
Comment on lines 212 to 216
TRUE AS maximum_mutable,
TRUE AS uri_mutable,
TRUE AS description_mutable,
TRUE AS properties_mutable,
TRUE AS royalty_mutable,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not always TRUE

SELECT 
maximum_mutable,
uri_mutable,
description_mutable,
properties_mutable,
royalty_mutable,
COUNT(1)
FROM current_token_datas
GROUP BY 1,2,3,4,5
ORDER BY 1,2,3,4,5

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@bowenyang007 validated that most of these are true, so it's fine to hardcode it to avoid having to migrate the v1 logic over to the v2 processor

Copy link
Contributor

Choose a reason for hiding this comment

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

these are supposed to be used by marketplaces to indicate which fields are non modifiable. however basically everyone just used one minting contract that sets all of these to true so majority of these ended up being true. and nobody seems to care about these.
my thought is that we can remove them and nothing would happen since I haven’t seen any UI that exposes these. If someone ends up wanting them we could create a new table altogether (similar to royalty and other metadata that aren’t critical).

Field is not nullable, previously these could have different bool values

Copy link
Collaborator

Choose a reason for hiding this comment

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

So 2 options here:

  1. make these nullable and set to null. this changes the schema and could cause some compatibility issues
  2. keep as is.

@ying-w do you prefer one or the other?

transaction_version,
owner_address,
-- this is mainly for hashing the coin type for primary key
encode(sha256(asset_type::bytea), 'hex') as coin_type_hash,
Copy link
Contributor

Choose a reason for hiding this comment

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

do we actually have sha256 support enabled in alloy?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the intention to use this as a join? Because if so need to add this as an index on the underlying table

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I ran this in dbeaver and it worked so it seems like it's supported. Also I forgot to add a migration view for coin_infos, which is the only table this could join with. Yes we should add indexes on the underlying tables.

Copy link
Contributor

@CapCap CapCap left a comment

Choose a reason for hiding this comment

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

a few small concerns, but otherwise lgtm

@rtso
Copy link
Collaborator Author

rtso commented May 30, 2024

Need to add coin_infos

amount,
table_type_v1 AS table_type,
tov.inserted_at,
tdv.collection_id AS collection_data_id_hash,
Copy link
Contributor

@ying-w ying-w May 31, 2024

Choose a reason for hiding this comment

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

values are different, collection_id != collection_data_id_hash

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

can you give an example?

Copy link
Contributor

Choose a reason for hiding this comment

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

similar to coins, logic would be encode( sha256( (collection_creator_address || '::' || token_name)::bytea ), 'hex')

from here

hash(f"{standardize_address(self.creator)}::{self.name}")

Copy link
Collaborator Author

@rtso rtso May 31, 2024

Choose a reason for hiding this comment

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

The processing code does the hash already for v1 collections and tokens

let collection_id = collection_id_struct.to_id();

So basically everything that's v1 in tdv is already hashed.

Copy link
Contributor

Choose a reason for hiding this comment

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

just realized that, so just need ltrim

Comment on lines 102 to 103
JOIN collections_v2 cv
ON tdv.collection_id = cv.collection_id AND tdv.transaction_version = cv.transaction_version
Copy link
Contributor

Choose a reason for hiding this comment

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

i dont think this works, token_activities_v2 has new entries when tokens have activities whereas collections_v2 has new entries when collection properties change

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i guess the best we can do is joining on the current_ tables

Comment on lines 198 to 199
royalty_points_numerator,
royalty_points_denominator,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Need to join on new royalty tables

Comment on lines 15 to 41
CREATE OR REPLACE VIEW legacy_migration_v1.coin_activities AS
SElECT
transaction_version,
owner_address as event_account_address,
-- these two below are mildly concerning
0 as event_creation_number,
0 as event_sequence_number,
owner_address,
asset_type AS coin_type,
amount,
"type" AS activity_type,
is_gas_fee,
is_transaction_success,
entry_function_id_str,
block_height,
transaction_timestamp,
inserted_at,
event_index,
gas_fee_payer_address,
storage_refund_amount,
FROM public.fungible_asset_activities
WHERE token_standard = 'v1'
;
CREATE INDEX lm1_ca_ct_a_index ON public.fungible_asset_activities USING btree (asset_type, amount)
CREATE INDEX lm1_ca_ct_at_a_index ON public.fungible_asset_activities USING btree (asset_type, "type", amount)
CREATE INDEX lm1_ca_oa_ct_at_index ON public.fungible_asset_activities USING btree (owner_address, asset_type, "type", amount)
CREATE INDEX lm1_ca_oa_igf_index ON public.fungible_asset_activities USING btree (owner_address, is_gas_fee)
Copy link
Collaborator

Choose a reason for hiding this comment

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

have we tested any of this in terms of performance?

Comment on lines 38 to 41
CREATE INDEX lm1_ca_ct_a_index ON public.fungible_asset_activities USING btree (asset_type, amount)
CREATE INDEX lm1_ca_ct_at_a_index ON public.fungible_asset_activities USING btree (asset_type, "type", amount)
CREATE INDEX lm1_ca_oa_ct_at_index ON public.fungible_asset_activities USING btree (owner_address, asset_type, "type", amount)
CREATE INDEX lm1_ca_oa_igf_index ON public.fungible_asset_activities USING btree (owner_address, is_gas_fee)
Copy link
Contributor

Choose a reason for hiding this comment

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

@bowenyang007 this is where it's failing

@bowenyang007 bowenyang007 force-pushed the rtso/v1-migration-views branch 2 times, most recently from 1ec4f70 to 30c9263 Compare June 7, 2024 17:15
@bowenyang007 bowenyang007 changed the base branch from main to rtso/royalty June 7, 2024 17:15
@bowenyang007 bowenyang007 changed the base branch from rtso/royalty to main June 7, 2024 17:16
@bowenyang007 bowenyang007 force-pushed the rtso/v1-migration-views branch 7 times, most recently from 27564c8 to f595aba Compare June 10, 2024 21:53
@@ -52,11 +50,26 @@ SELECT transaction_version,
inserted_at
FROM public.fungible_asset_balances
WHERE token_standard = 'v1';
-- replace `coin_infos` with `fungible_asset_metadata`
CREATE OR REPLACE VIEW legacy_migration_v1.coin_infos AS
SELECT encode(sha256(asset_type::bytea), 'hex'),
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to rename this? as coin_type_hash

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes! Good catch.

@bowenyang007 bowenyang007 force-pushed the rtso/v1-migration-views branch from cd00178 to 445628a Compare June 12, 2024 05:31
@bowenyang007 bowenyang007 enabled auto-merge (squash) June 12, 2024 05:31
@bowenyang007 bowenyang007 merged commit 74c7839 into main Jun 12, 2024
7 checks passed
@bowenyang007 bowenyang007 deleted the rtso/v1-migration-views branch June 12, 2024 05:39
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.

5 participants