From 62670837929d479d1665577184ad944f39b963ad Mon Sep 17 00:00:00 2001 From: jarrel Date: Mon, 23 Oct 2023 14:47:35 -0700 Subject: [PATCH] Update migration --- cmd/token_normalization_migrate/main.go | 493 ++++++++++++++++++ db/gen/coredb/batch.go | 56 +- db/gen/coredb/models_gen.go | 36 +- db/gen/coredb/query.sql.go | 102 ++-- .../tmp_token_normalization_backfill.sql.go | 8 +- db/gen/coredb/token_gallery.sql.go | 10 +- .../core/000111_add_token_definitions.up.sql | 54 -- ...11_token_norm_add_token_definitions.up.sql | 24 + ...rm_add_token_definition_constraints.up.sql | 74 +++ ..._norm_update_feed_entity_score_view.up.sql | 57 ++ ...norm_update_contract_relevance_view.up.sql | 26 + ...en_norm_update_owned_contracts_view.up.sql | 69 +++ ..._update_admires_token_id_constraint.up.sql | 2 + ...m_update_events_token_id_constraint.up.sql | 2 + ...e_notifications_token_id_constraint.up.sql | 2 + ..._profile_images_token_id_constraint.up.sql | 2 + ...norm_token_medias_deprecate_columns.up.sql | 12 + graphql/schema/schema.graphql | 6 +- 18 files changed, 889 insertions(+), 146 deletions(-) create mode 100644 cmd/token_normalization_migrate/main.go delete mode 100644 db/migrations/core/000111_add_token_definitions.up.sql create mode 100644 db/migrations/core/000111_token_norm_add_token_definitions.up.sql create mode 100644 db/migrations/core/000112_token_norm_add_token_definition_constraints.up.sql create mode 100644 db/migrations/core/000113_token_norm_update_feed_entity_score_view.up.sql create mode 100644 db/migrations/core/000114_token_norm_update_contract_relevance_view.up.sql create mode 100644 db/migrations/core/000115_token_norm_update_owned_contracts_view.up.sql create mode 100644 db/migrations/core/000116_token_norm_update_admires_token_id_constraint.up.sql create mode 100644 db/migrations/core/000117_token_norm_update_events_token_id_constraint.up.sql create mode 100644 db/migrations/core/000118_token_norm_update_notifications_token_id_constraint.up.sql create mode 100644 db/migrations/core/000119_token_norm_update_profile_images_token_id_constraint.up.sql create mode 100644 db/migrations/core/000120_token_norm_token_medias_deprecate_columns.up.sql diff --git a/cmd/token_normalization_migrate/main.go b/cmd/token_normalization_migrate/main.go new file mode 100644 index 000000000..a1b490418 --- /dev/null +++ b/cmd/token_normalization_migrate/main.go @@ -0,0 +1,493 @@ +// Script to populate token_definitions table from tokens and token_medias tables +package main + +import ( + "context" + "database/sql" + "fmt" + "time" + + "github.com/gammazero/workerpool" + "github.com/spf13/cobra" + "github.com/spf13/viper" + + "github.com/mikeydub/go-gallery/server" + "github.com/mikeydub/go-gallery/service/persist" + "github.com/mikeydub/go-gallery/service/persist/postgres" +) + +const ( + poolSize = 12 // concurrent workers to use + batchSize = 100 // number of rows to process at a time +) + +func init() { + rootCmd.AddCommand(saveCmd) + rootCmd.AddCommand(migrateCmd) + server.SetDefaults() + viper.SetDefault("POSTGRES_USER", "gallery_migrator") + pq = postgres.MustCreateClient() + pq.SetMaxIdleConns(2 * poolSize) + +} + +func main() { + rootCmd.Execute() +} + +var rootCmd = &cobra.Command{ + Use: "tokenmigrate", + Short: "create token_definitions table", +} + +var saveCmd = &cobra.Command{ + Use: "stage", + Short: "create staging table for chunking tokens", + Run: func(cmd *cobra.Command, args []string) { + defer pq.Close() + saveStagingTable(pq) + }, +} + +var migrateCmd = &cobra.Command{ + Use: "migrate", + Short: "create token_definitions table", + Run: func(cmd *cobra.Command, args []string) { + defer pq.Close() + migrate(context.Background(), pq) + }, +} + +var ( + pq *sql.DB + batchTokensStmt *sql.Stmt + batchMediasStmt *sql.Stmt + batchInsertStmt *sql.Stmt +) + +const createStagingTable = ` +drop table if exists token_chunks; + +create table token_chunks( + id serial primary key, + chain int not null, + contract_id varchar not null, + token_id varchar not null, + address varchar not null +); + +insert into token_chunks(chain, contract_id, token_id, address) ( +select + tokens.chain, + tokens.contract, + tokens.token_id, + contracts.address +from tokens +join contracts on tokens.contract = contracts.id +group by 1, 2, 3, 4 +order by 1, 2, 3, 4);` + +const batchTokensQuery = ` +with chunk as (select * from token_chunks where id >= $1 and id < $2) +select + c.id chunk_id, + c.chain chunk_chain, + c.contract_id chunk_contract_id, + c.token_id chunk_token_id, + t.token_type token_token_type, + t.external_url token_external_url, + t.fallback_media token_fallback_media, + t.deleted as token_deleted, + c.address contract_address +from tokens t +join chunk c on (t.chain, t.contract, t.token_id) = (c.chain, c.contract_id, c.token_id) +order by t.deleted desc, t.last_updated desc;` + +const batchMediasQuery = ` +with chunk as (select * from token_chunks where id >= $1 and id < $2) +select + c.id chunk_id, + c.chain chunk_chain, + c.contract_id chunk_contract_id, + c.token_id chunk_token_id, + tm.id token_media_id, + tm.name media_name, + tm.description media_description, + tm.metadata media_metadata, + tm.media media_media, + tm.active media_active +from token_medias tm +join chunk c on (tm.chain, tm.contract_id, tm.token_id) = (c.chain, c.contract_id, c.token_id) + and not tm.deleted +order by tm.active desc, tm.last_updated desc;` + +const dropConstraints = ` +alter table token_definitions set (autovacuum_enabled = false); +alter table token_definitions set unlogged; +alter table token_definitions drop constraint if exists token_definitions_pkey; +alter table token_definitions drop constraint if exists token_definitions_contract_id_fkey; +alter table token_definitions drop constraint if exists token_definitions_token_media_id_fkey; +alter table token_definitions drop constraint if exists token_definitions_contract_id_chain_contract_address_fkey; +drop index if exists token_definitions_chain_contract_id_token_idx; +drop index if exists token_definitions_chain_contract_address_token_idx; +drop index if exists token_definitions_contract_id_idx;` + +const addConstraints = ` +alter table token_definitions set (autovacuum_enabled = true); +alter table token_definitions set logged; +alter table token_definitions add primary key(id); +alter table token_definitions add constraint token_definitions_contract_id_fkey foreign key(contract_id) references contracts(id); +alter table token_definitions add constraint token_definitions_token_media_id_fkey foreign key(token_media_id) references token_medias(id); +alter table token_definitions add constraint token_definitions_contract_id_chain_contract_address_fkey foreign key(contract_id, chain, contract_address) references contracts(id, chain, address) on update cascade; +create unique index if not exists token_definitions_chain_contract_id_token_idx on token_definitions(chain, contract_id, token_id) where not deleted; +create unique index token_definitions_chain_contract_address_token_idx on token_definitions(chain, contract_address, token_id) where not deleted; +create index token_definitions_contract_id_idx on token_definitions(contract_id) where not deleted; +analyze token_definitions;` + +const insertBatch = ` +insert into token_definitions ( + id, + name, + description, + external_url, + metadata, + fallback_media, + contract_id, + token_media_id, + chain, + contract_address, + token_id, + token_type +) ( + select + id, + nullif(name, ''), + nullif(description, ''), + nullif(external_url, ''), + metadata, + fallback_media, + nullif(contract_id, ''), + nullif(token_media_id, ''), + chain, + contract_address, + token_id, + token_type + from ( + select + unnest($1::varchar[]) id, + unnest($2::varchar[]) name, + unnest($3::varchar[]) description, + unnest($4::varchar[]) external_url, + unnest($5::jsonb[]) metadata, + unnest($6::jsonb[]) fallback_media, + unnest($7::varchar[]) contract_id, + unnest($8::varchar[]) token_media_id, + unnest($9::int[]) chain, + unnest($10::varchar[]) contract_address, + unnest($11::varchar[]) token_id, + unnest($12::varchar[]) token_type + ) vals +);` + +type instanceData struct { + ChunkID int + Chain persist.Chain + ContractID persist.NullString + TokenTokenID persist.NullString + TokenName persist.NullString + TokenDescription persist.NullString + TokenTokenType persist.TokenType + TokenExternalURL persist.NullString + TokenFallbackMedia persist.FallbackMedia + TokenMediaID persist.NullString + TokenDeleted bool + ContractAddress persist.Address + MediaName persist.NullString + MediaDescription persist.NullString + MediaMetadata persist.TokenMetadata + MediaMedia persist.Media + MediaActive persist.NullBool +} + +type mergedData struct { + ID []persist.DBID + Name []persist.NullString + Description []persist.NullString + ExternalURL []persist.NullString + Metadata []persist.TokenMetadata + Fallback []persist.FallbackMedia + ContractID []persist.NullString + MediaID []persist.NullString + Chain []persist.Chain + ContractAddress []persist.Address + TokenID []persist.NullString + TokenType []persist.TokenType + MediaActive []bool + MediaMedia []persist.Media +} + +func mustBeEmpty(tx *sql.Tx) { + var currentCount int + err := pq.QueryRow("select count(*) from token_definitions").Scan(¤tCount) + check(err) + if currentCount > 0 { + panic(fmt.Sprintf("token_definitions table is not empty, current count: %d", currentCount)) + } +} + +func analyzeTokens(tx *sql.Tx) { + _, err := tx.Exec("analyze tokens;") + check(err) +} + +func lockTables(tx *sql.Tx) { + _, err := tx.Exec("lock table tokens in access share mode;") + check(err) + _, err = tx.Exec("lock table token_medias in access share mode;") + check(err) +} + +func prepareStatements(ctx context.Context) { + var err error + batchTokensStmt, err = pq.PrepareContext(ctx, batchTokensQuery) + check(err) + batchMediasStmt, err = pq.PrepareContext(ctx, batchMediasQuery) + check(err) + batchInsertStmt, err = pq.PrepareContext(ctx, insertBatch) + check(err) +} + +func migrate(ctx context.Context, pq *sql.DB) { + globalStart := time.Now() + + tx, err := pq.BeginTx(ctx, nil) + + check(err) + mustBeEmpty(tx) + analyzeTokens(tx) + lockTables(tx) + prepareStatements(ctx) + + fmt.Print("dropping constraints") + now := time.Now() + _, err = pq.Exec(dropConstraints) + check(err) + fmt.Printf("...done in %s\n", time.Since(now)) + + wp := workerpool.New(poolSize) + + start := 0 + end := start + batchSize + totalTokens := totalTokensToProcess() + totalBatches := totalTokens / batchSize + + for chunkID := 0; start < totalTokens; chunkID++ { + chunkID := chunkID + s := start + e := end + wp.Submit(func() { + batchStart := time.Now() + fmt.Printf("handling chunk(id=%d) [%d, %d); %d/%d \n", chunkID, s, e, chunkID, totalBatches) + + tokenCh := make(chan bool) + mediaCh := make(chan bool) + + var tokenRows *sql.Rows + var tokenQueryStart time.Time + var tokenQueryEnd time.Time + var mediaRows *sql.Rows + var mediaQueryStart time.Time + var mediaQueryEnd time.Time + + go func() { + tokenQueryStart = time.Now() + tokenRows, err = batchTokensStmt.Query(s, e) + check(err) + tokenQueryEnd = time.Now() + tokenCh <- true + }() + + go func() { + mediaQueryStart = time.Now() + mediaRows, err = batchMediasStmt.Query(s, e) + check(err) + mediaQueryEnd = time.Now() + mediaCh <- true + }() + + <-tokenCh + <-mediaCh + + idToIdx := make(map[int]int) + + m := mergedData{ + ID: make([]persist.DBID, 0, batchSize), + Name: make([]persist.NullString, 0, batchSize), + Description: make([]persist.NullString, 0, batchSize), + ExternalURL: make([]persist.NullString, 0, batchSize), + Metadata: make([]persist.TokenMetadata, 0, batchSize), + Fallback: make([]persist.FallbackMedia, 0, batchSize), + ContractID: make([]persist.NullString, 0, batchSize), + MediaID: make([]persist.NullString, 0, batchSize), + Chain: make([]persist.Chain, 0, batchSize), + ContractAddress: make([]persist.Address, 0, batchSize), + TokenID: make([]persist.NullString, 0, batchSize), + TokenType: make([]persist.TokenType, 0, batchSize), + MediaActive: make([]bool, 0, batchSize), + MediaMedia: make([]persist.Media, 0, batchSize), + } + + instanceCount := 0 + + for tokenRows.Next() { + instanceCount += 1 + var r instanceData + err := tokenRows.Scan( + &r.ChunkID, + &r.Chain, + &r.ContractID, + &r.TokenTokenID, + &r.TokenTokenType, + &r.TokenExternalURL, + &r.TokenFallbackMedia, + &r.TokenDeleted, + &r.ContractAddress, + ) + check(err) + + if _, ok := idToIdx[r.ChunkID]; !ok { + idToIdx[r.ChunkID] = len(m.ID) + m.ID = append(m.ID, persist.GenerateID()) + m.Chain = append(m.Chain, r.Chain) + m.ContractID = append(m.ContractID, r.ContractID) + m.TokenID = append(m.TokenID, r.TokenTokenID) + m.TokenType = append(m.TokenType, r.TokenTokenType) + m.ExternalURL = append(m.ExternalURL, r.TokenExternalURL) + m.Fallback = append(m.Fallback, r.TokenFallbackMedia) + m.ContractAddress = append(m.ContractAddress, r.ContractAddress) + // To be filled in later from media query + m.Name = append(m.Name, "") + m.Description = append(m.Description, "") + m.Metadata = append(m.Metadata, persist.TokenMetadata{}) + m.MediaID = append(m.MediaID, "") + m.MediaActive = append(m.MediaActive, false) + m.MediaMedia = append(m.MediaMedia, persist.Media{}) + } else if !r.TokenDeleted { + idx := idToIdx[r.ChunkID] + if m.TokenType[idx] == "" { + m.TokenType[idx] = r.TokenTokenType + } + if m.ContractID[idx].String() == "" { + m.ContractID[idx] = r.ContractID + } + if m.Fallback[idx].ImageURL.String() == "" { + m.Metadata[idx] = r.MediaMetadata + } + if m.ExternalURL[idx].String() == "" { + m.ExternalURL[idx] = r.TokenExternalURL + } + } + } + tokenRows.Close() + + for mediaRows.Next() { + var r instanceData + err := mediaRows.Scan( + &r.ChunkID, + &r.Chain, + &r.ContractID, + &r.TokenTokenID, + &r.TokenMediaID, + &r.MediaName, + &r.MediaDescription, + &r.MediaMetadata, + &r.MediaMedia, + &r.MediaActive, + ) + check(err) + idx, ok := idToIdx[r.ChunkID] + if !ok { + panic(fmt.Sprintf("no token found for media with staging_id=%d", r.ChunkID)) + } + if m.Name[idx].String() == "" { + m.Name[idx] = r.MediaName + } + if m.Description[idx].String() == "" { + m.Description[idx] = r.MediaDescription + } + if len(m.Metadata[idx]) == 0 { + m.Metadata[idx] = r.MediaMetadata + } + if m.MediaID[idx].String() == "" { + m.MediaID[idx] = r.TokenMediaID + } else if !m.MediaActive[idx] && r.MediaActive.Bool() { + m.MediaID[idx] = r.TokenMediaID + } else if !m.MediaMedia[idx].IsServable() && r.MediaMedia.IsServable() { + m.MediaID[idx] = r.TokenMediaID + } else if r.MediaMedia.MediaType.IsMorePriorityThan(m.MediaMedia[idx].MediaType) { + m.MediaID[idx] = r.TokenMediaID + } + } + mediaRows.Close() + + insertStart := time.Now() + _, err := tx.Stmt(batchInsertStmt).Exec( + m.ID, + m.Name, + m.Description, + m.ExternalURL, + m.Metadata, + m.Fallback, + m.ContractID, + m.MediaID, + m.Chain, + m.ContractAddress, + m.TokenID, + m.TokenType, + ) + check(err) + insertEnd := time.Now() + + fmt.Printf("chunk(id=%d) [%d, %d); tokenQuery %s; mediaQuery %s; insert %s; total %s\n", chunkID, s, e, tokenQueryEnd.Sub(tokenQueryStart), mediaQueryEnd.Sub(mediaQueryStart), insertEnd.Sub(insertStart), time.Since(batchStart)) + }) + + start = end + end = start + batchSize + } + + wp.StopWait() + + fmt.Println("adding back constraints") + now = time.Now() + _, err = tx.Exec(addConstraints) + check(err) + + err = tx.Commit() + check(err) + + fmt.Printf("took %s to migrate tokens; adding constaints=%s\n", time.Since(globalStart), time.Since(now)) +} + +func saveStagingTable(pq *sql.DB) { + r, err := pq.Exec(createStagingTable) + check(err) + rows, err := r.RowsAffected() + check(err) + _, err = pq.Exec("analyze token_chunks") + check(err) + fmt.Printf("created staging table with %d rows\n", rows) +} + +func totalTokensToProcess() (t int) { + err := pq.QueryRow("select count(*) from token_chunks;").Scan(&t) + check(err) + fmt.Printf("total tokens to process: %d\n", t) + return t +} + +func check(err error) { + if err != nil { + panic(err) + } + +} diff --git a/db/gen/coredb/batch.go b/db/gen/coredb/batch.go index c53b6db0c..7b8b9dc3a 100644 --- a/db/gen/coredb/batch.go +++ b/db/gen/coredb/batch.go @@ -2189,7 +2189,7 @@ with new_tokens as ( select added.id, row_number() over () added_order from (select jsonb_array_elements_text(data -> 'collection_new_token_ids') id from feed_events f where f.id = $1 and f.deleted = false) added ) -select t.id, t.deleted, t.version, t.created_at, t.last_updated, t.name__deprecated, t.description__deprecated, t.collectors_note, t.token_uri__deprecated, t.token_type__deprecated, t.token_id__deprecated, t.quantity, t.ownership_history__deprecated, t.external_url__deprecated, t.block_number, t.owner_user_id, t.owned_by_wallets, t.chain__deprecated, t.contract_id, t.is_user_marked_spam, t.is_provider_marked_spam__deprecated, t.last_synced, t.fallback_media__deprecated, t.token_media_id__deprecated, t.is_creator_token, t.is_holder_token, t.displayable, t.token_definition_id from new_tokens a join tokens t on a.id = t.id and t.displayable and t.deleted = false order by a.added_order +select t.id, t.deleted, t.version, t.created_at, t.last_updated, t.name__deprecated, t.description__deprecated, t.collectors_note, t.token_type__deprecated, t.token_id__deprecated, t.quantity, t.ownership_history__deprecated, t.external_url__deprecated, t.block_number, t.owner_user_id, t.owned_by_wallets, t.chain, t.contract_id, t.is_user_marked_spam, t.is_provider_marked_spam__deprecated, t.last_synced, t.token_uri__deprecated, t.fallback_media__deprecated, t.token_media_id__deprecated, t.is_creator_token, t.token_definition_id, t.is_holder_token, t.displayable from new_tokens a join tokens t on a.id = t.id and t.displayable and t.deleted = false order by a.added_order ` type GetNewTokensByFeedEventIdBatchBatchResults struct { @@ -2237,7 +2237,6 @@ func (b *GetNewTokensByFeedEventIdBatchBatchResults) Query(f func(int, []Token, &i.NameDeprecated, &i.DescriptionDeprecated, &i.CollectorsNote, - &i.TokenUriDeprecated, &i.TokenTypeDeprecated, &i.TokenIDDeprecated, &i.Quantity, @@ -2246,17 +2245,18 @@ func (b *GetNewTokensByFeedEventIdBatchBatchResults) Query(f func(int, []Token, &i.BlockNumber, &i.OwnerUserID, &i.OwnedByWallets, - &i.ChainDeprecated, + &i.Chain, &i.ContractID, &i.IsUserMarkedSpam, &i.IsProviderMarkedSpamDeprecated, &i.LastSynced, + &i.TokenUriDeprecated, &i.FallbackMediaDeprecated, &i.TokenMediaIDDeprecated, &i.IsCreatorToken, + &i.TokenDefinitionID, &i.IsHolderToken, &i.Displayable, - &i.TokenDefinitionID, ); err != nil { return err } @@ -2881,7 +2881,7 @@ func (b *GetSharedFollowersBatchPaginateBatchResults) Close() error { } const getTokenByIdBatch = `-- name: GetTokenByIdBatch :batchone -select id, deleted, version, created_at, last_updated, name__deprecated, description__deprecated, collectors_note, token_uri__deprecated, token_type__deprecated, token_id__deprecated, quantity, ownership_history__deprecated, external_url__deprecated, block_number, owner_user_id, owned_by_wallets, chain__deprecated, contract_id, is_user_marked_spam, is_provider_marked_spam__deprecated, last_synced, fallback_media__deprecated, token_media_id__deprecated, is_creator_token, is_holder_token, displayable, token_definition_id from tokens where id = $1 and displayable and deleted = false +select id, deleted, version, created_at, last_updated, name__deprecated, description__deprecated, collectors_note, token_type__deprecated, token_id__deprecated, quantity, ownership_history__deprecated, external_url__deprecated, block_number, owner_user_id, owned_by_wallets, chain, contract_id, is_user_marked_spam, is_provider_marked_spam__deprecated, last_synced, token_uri__deprecated, fallback_media__deprecated, token_media_id__deprecated, is_creator_token, token_definition_id, is_holder_token, displayable from tokens where id = $1 and displayable and deleted = false ` type GetTokenByIdBatchBatchResults struct { @@ -2922,7 +2922,6 @@ func (b *GetTokenByIdBatchBatchResults) QueryRow(f func(int, Token, error)) { &i.NameDeprecated, &i.DescriptionDeprecated, &i.CollectorsNote, - &i.TokenUriDeprecated, &i.TokenTypeDeprecated, &i.TokenIDDeprecated, &i.Quantity, @@ -2931,17 +2930,18 @@ func (b *GetTokenByIdBatchBatchResults) QueryRow(f func(int, Token, error)) { &i.BlockNumber, &i.OwnerUserID, &i.OwnedByWallets, - &i.ChainDeprecated, + &i.Chain, &i.ContractID, &i.IsUserMarkedSpam, &i.IsProviderMarkedSpamDeprecated, &i.LastSynced, + &i.TokenUriDeprecated, &i.FallbackMediaDeprecated, &i.TokenMediaIDDeprecated, &i.IsCreatorToken, + &i.TokenDefinitionID, &i.IsHolderToken, &i.Displayable, - &i.TokenDefinitionID, ) if f != nil { f(t, i, err) @@ -2955,7 +2955,7 @@ func (b *GetTokenByIdBatchBatchResults) Close() error { } const getTokenByIdIgnoreDisplayableBatch = `-- name: GetTokenByIdIgnoreDisplayableBatch :batchone -select id, deleted, version, created_at, last_updated, name__deprecated, description__deprecated, collectors_note, token_uri__deprecated, token_type__deprecated, token_id__deprecated, quantity, ownership_history__deprecated, external_url__deprecated, block_number, owner_user_id, owned_by_wallets, chain__deprecated, contract_id, is_user_marked_spam, is_provider_marked_spam__deprecated, last_synced, fallback_media__deprecated, token_media_id__deprecated, is_creator_token, is_holder_token, displayable, token_definition_id from tokens where id = $1 and deleted = false +select id, deleted, version, created_at, last_updated, name__deprecated, description__deprecated, collectors_note, token_type__deprecated, token_id__deprecated, quantity, ownership_history__deprecated, external_url__deprecated, block_number, owner_user_id, owned_by_wallets, chain, contract_id, is_user_marked_spam, is_provider_marked_spam__deprecated, last_synced, token_uri__deprecated, fallback_media__deprecated, token_media_id__deprecated, is_creator_token, token_definition_id, is_holder_token, displayable from tokens where id = $1 and deleted = false ` type GetTokenByIdIgnoreDisplayableBatchBatchResults struct { @@ -2996,7 +2996,6 @@ func (b *GetTokenByIdIgnoreDisplayableBatchBatchResults) QueryRow(f func(int, To &i.NameDeprecated, &i.DescriptionDeprecated, &i.CollectorsNote, - &i.TokenUriDeprecated, &i.TokenTypeDeprecated, &i.TokenIDDeprecated, &i.Quantity, @@ -3005,17 +3004,18 @@ func (b *GetTokenByIdIgnoreDisplayableBatchBatchResults) QueryRow(f func(int, To &i.BlockNumber, &i.OwnerUserID, &i.OwnedByWallets, - &i.ChainDeprecated, + &i.Chain, &i.ContractID, &i.IsUserMarkedSpam, &i.IsProviderMarkedSpamDeprecated, &i.LastSynced, + &i.TokenUriDeprecated, &i.FallbackMediaDeprecated, &i.TokenMediaIDDeprecated, &i.IsCreatorToken, + &i.TokenDefinitionID, &i.IsHolderToken, &i.Displayable, - &i.TokenDefinitionID, ) if f != nil { f(t, i, err) @@ -3029,7 +3029,7 @@ func (b *GetTokenByIdIgnoreDisplayableBatchBatchResults) Close() error { } const getTokenByUserTokenIdentifiersBatch = `-- name: GetTokenByUserTokenIdentifiersBatch :batchone -select t.id, t.deleted, t.version, t.created_at, t.last_updated, t.name__deprecated, t.description__deprecated, t.collectors_note, t.token_uri__deprecated, t.token_type__deprecated, t.token_id__deprecated, t.quantity, t.ownership_history__deprecated, t.external_url__deprecated, t.block_number, t.owner_user_id, t.owned_by_wallets, t.chain__deprecated, t.contract_id, t.is_user_marked_spam, t.is_provider_marked_spam__deprecated, t.last_synced, t.fallback_media__deprecated, t.token_media_id__deprecated, t.is_creator_token, t.is_holder_token, t.displayable, t.token_definition_id +select t.id, t.deleted, t.version, t.created_at, t.last_updated, t.name__deprecated, t.description__deprecated, t.collectors_note, t.token_type__deprecated, t.token_id__deprecated, t.quantity, t.ownership_history__deprecated, t.external_url__deprecated, t.block_number, t.owner_user_id, t.owned_by_wallets, t.chain, t.contract_id, t.is_user_marked_spam, t.is_provider_marked_spam__deprecated, t.last_synced, t.token_uri__deprecated, t.fallback_media__deprecated, t.token_media_id__deprecated, t.is_creator_token, t.token_definition_id, t.is_holder_token, t.displayable from tokens t, token_definitions td where t.token_definition_id = td.token_definition_id and t.owner_user_id = $1 @@ -3089,7 +3089,6 @@ func (b *GetTokenByUserTokenIdentifiersBatchBatchResults) QueryRow(f func(int, T &i.NameDeprecated, &i.DescriptionDeprecated, &i.CollectorsNote, - &i.TokenUriDeprecated, &i.TokenTypeDeprecated, &i.TokenIDDeprecated, &i.Quantity, @@ -3098,17 +3097,18 @@ func (b *GetTokenByUserTokenIdentifiersBatchBatchResults) QueryRow(f func(int, T &i.BlockNumber, &i.OwnerUserID, &i.OwnedByWallets, - &i.ChainDeprecated, + &i.Chain, &i.ContractID, &i.IsUserMarkedSpam, &i.IsProviderMarkedSpamDeprecated, &i.LastSynced, + &i.TokenUriDeprecated, &i.FallbackMediaDeprecated, &i.TokenMediaIDDeprecated, &i.IsCreatorToken, + &i.TokenDefinitionID, &i.IsHolderToken, &i.Displayable, - &i.TokenDefinitionID, ) if f != nil { f(t, i, err) @@ -3315,7 +3315,7 @@ func (b *GetTokenOwnerByIDBatchBatchResults) Close() error { } const getTokensByCollectionIdBatch = `-- name: GetTokensByCollectionIdBatch :batchmany -select t.id, t.deleted, t.version, t.created_at, t.last_updated, t.name__deprecated, t.description__deprecated, t.collectors_note, t.token_uri__deprecated, t.token_type__deprecated, t.token_id__deprecated, t.quantity, t.ownership_history__deprecated, t.external_url__deprecated, t.block_number, t.owner_user_id, t.owned_by_wallets, t.chain__deprecated, t.contract_id, t.is_user_marked_spam, t.is_provider_marked_spam__deprecated, t.last_synced, t.fallback_media__deprecated, t.token_media_id__deprecated, t.is_creator_token, t.is_holder_token, t.displayable, t.token_definition_id from collections c, +select t.id, t.deleted, t.version, t.created_at, t.last_updated, t.name__deprecated, t.description__deprecated, t.collectors_note, t.token_type__deprecated, t.token_id__deprecated, t.quantity, t.ownership_history__deprecated, t.external_url__deprecated, t.block_number, t.owner_user_id, t.owned_by_wallets, t.chain, t.contract_id, t.is_user_marked_spam, t.is_provider_marked_spam__deprecated, t.last_synced, t.token_uri__deprecated, t.fallback_media__deprecated, t.token_media_id__deprecated, t.is_creator_token, t.token_definition_id, t.is_holder_token, t.displayable from collections c, unnest(c.nfts) with ordinality as u(nft_id, nft_ord) join tokens t on t.id = u.nft_id where c.id = $1 @@ -3378,7 +3378,6 @@ func (b *GetTokensByCollectionIdBatchBatchResults) Query(f func(int, []Token, er &i.NameDeprecated, &i.DescriptionDeprecated, &i.CollectorsNote, - &i.TokenUriDeprecated, &i.TokenTypeDeprecated, &i.TokenIDDeprecated, &i.Quantity, @@ -3387,17 +3386,18 @@ func (b *GetTokensByCollectionIdBatchBatchResults) Query(f func(int, []Token, er &i.BlockNumber, &i.OwnerUserID, &i.OwnedByWallets, - &i.ChainDeprecated, + &i.Chain, &i.ContractID, &i.IsUserMarkedSpam, &i.IsProviderMarkedSpamDeprecated, &i.LastSynced, + &i.TokenUriDeprecated, &i.FallbackMediaDeprecated, &i.TokenMediaIDDeprecated, &i.IsCreatorToken, + &i.TokenDefinitionID, &i.IsHolderToken, &i.Displayable, - &i.TokenDefinitionID, ); err != nil { return err } @@ -3417,7 +3417,7 @@ func (b *GetTokensByCollectionIdBatchBatchResults) Close() error { } const getTokensByUserIdBatch = `-- name: GetTokensByUserIdBatch :batchmany -select t.id, t.deleted, t.version, t.created_at, t.last_updated, t.name__deprecated, t.description__deprecated, t.collectors_note, t.token_uri__deprecated, t.token_type__deprecated, t.token_id__deprecated, t.quantity, t.ownership_history__deprecated, t.external_url__deprecated, t.block_number, t.owner_user_id, t.owned_by_wallets, t.chain__deprecated, t.contract_id, t.is_user_marked_spam, t.is_provider_marked_spam__deprecated, t.last_synced, t.fallback_media__deprecated, t.token_media_id__deprecated, t.is_creator_token, t.is_holder_token, t.displayable, t.token_definition_id +select t.id, t.deleted, t.version, t.created_at, t.last_updated, t.name__deprecated, t.description__deprecated, t.collectors_note, t.token_type__deprecated, t.token_id__deprecated, t.quantity, t.ownership_history__deprecated, t.external_url__deprecated, t.block_number, t.owner_user_id, t.owned_by_wallets, t.chain, t.contract_id, t.is_user_marked_spam, t.is_provider_marked_spam__deprecated, t.last_synced, t.token_uri__deprecated, t.fallback_media__deprecated, t.token_media_id__deprecated, t.is_creator_token, t.token_definition_id, t.is_holder_token, t.displayable from tokens t join token_definitions td on t.token_definition_id = td.id where t.owner_user_id = $1 @@ -3480,7 +3480,6 @@ func (b *GetTokensByUserIdBatchBatchResults) Query(f func(int, []Token, error)) &i.NameDeprecated, &i.DescriptionDeprecated, &i.CollectorsNote, - &i.TokenUriDeprecated, &i.TokenTypeDeprecated, &i.TokenIDDeprecated, &i.Quantity, @@ -3489,17 +3488,18 @@ func (b *GetTokensByUserIdBatchBatchResults) Query(f func(int, []Token, error)) &i.BlockNumber, &i.OwnerUserID, &i.OwnedByWallets, - &i.ChainDeprecated, + &i.Chain, &i.ContractID, &i.IsUserMarkedSpam, &i.IsProviderMarkedSpamDeprecated, &i.LastSynced, + &i.TokenUriDeprecated, &i.FallbackMediaDeprecated, &i.TokenMediaIDDeprecated, &i.IsCreatorToken, + &i.TokenDefinitionID, &i.IsHolderToken, &i.Displayable, - &i.TokenDefinitionID, ); err != nil { return err } @@ -3519,7 +3519,7 @@ func (b *GetTokensByUserIdBatchBatchResults) Close() error { } const getTokensByWalletIdsBatch = `-- name: GetTokensByWalletIdsBatch :batchmany -select id, deleted, version, created_at, last_updated, name__deprecated, description__deprecated, collectors_note, token_uri__deprecated, token_type__deprecated, token_id__deprecated, quantity, ownership_history__deprecated, external_url__deprecated, block_number, owner_user_id, owned_by_wallets, chain__deprecated, contract_id, is_user_marked_spam, is_provider_marked_spam__deprecated, last_synced, fallback_media__deprecated, token_media_id__deprecated, is_creator_token, is_holder_token, displayable, token_definition_id from tokens where owned_by_wallets && $1 and displayable and deleted = false +select id, deleted, version, created_at, last_updated, name__deprecated, description__deprecated, collectors_note, token_type__deprecated, token_id__deprecated, quantity, ownership_history__deprecated, external_url__deprecated, block_number, owner_user_id, owned_by_wallets, chain, contract_id, is_user_marked_spam, is_provider_marked_spam__deprecated, last_synced, token_uri__deprecated, fallback_media__deprecated, token_media_id__deprecated, is_creator_token, token_definition_id, is_holder_token, displayable from tokens where owned_by_wallets && $1 and displayable and deleted = false order by tokens.created_at desc, tokens.name desc, tokens.id desc ` @@ -3568,7 +3568,6 @@ func (b *GetTokensByWalletIdsBatchBatchResults) Query(f func(int, []Token, error &i.NameDeprecated, &i.DescriptionDeprecated, &i.CollectorsNote, - &i.TokenUriDeprecated, &i.TokenTypeDeprecated, &i.TokenIDDeprecated, &i.Quantity, @@ -3577,17 +3576,18 @@ func (b *GetTokensByWalletIdsBatchBatchResults) Query(f func(int, []Token, error &i.BlockNumber, &i.OwnerUserID, &i.OwnedByWallets, - &i.ChainDeprecated, + &i.Chain, &i.ContractID, &i.IsUserMarkedSpam, &i.IsProviderMarkedSpamDeprecated, &i.LastSynced, + &i.TokenUriDeprecated, &i.FallbackMediaDeprecated, &i.TokenMediaIDDeprecated, &i.IsCreatorToken, + &i.TokenDefinitionID, &i.IsHolderToken, &i.Displayable, - &i.TokenDefinitionID, ); err != nil { return err } diff --git a/db/gen/coredb/models_gen.go b/db/gen/coredb/models_gen.go index 8bcf2dc55..3577022ce 100644 --- a/db/gen/coredb/models_gen.go +++ b/db/gen/coredb/models_gen.go @@ -498,7 +498,6 @@ type Token struct { NameDeprecated sql.NullString `json:"name__deprecated"` DescriptionDeprecated sql.NullString `json:"description__deprecated"` CollectorsNote sql.NullString `json:"collectors_note"` - TokenUriDeprecated sql.NullString `json:"token_uri__deprecated"` TokenTypeDeprecated sql.NullString `json:"token_type__deprecated"` TokenIDDeprecated sql.NullString `json:"token_id__deprecated"` Quantity persist.HexString `json:"quantity"` @@ -507,17 +506,18 @@ type Token struct { BlockNumber sql.NullInt64 `json:"block_number"` OwnerUserID persist.DBID `json:"owner_user_id"` OwnedByWallets persist.DBIDList `json:"owned_by_wallets"` - ChainDeprecated sql.NullInt32 `json:"chain__deprecated"` + Chain persist.Chain `json:"chain"` ContractID persist.DBID `json:"contract_id"` IsUserMarkedSpam sql.NullBool `json:"is_user_marked_spam"` IsProviderMarkedSpamDeprecated sql.NullBool `json:"is_provider_marked_spam__deprecated"` LastSynced time.Time `json:"last_synced"` + TokenUriDeprecated sql.NullString `json:"token_uri__deprecated"` FallbackMediaDeprecated pgtype.JSONB `json:"fallback_media__deprecated"` TokenMediaIDDeprecated sql.NullString `json:"token_media_id__deprecated"` IsCreatorToken bool `json:"is_creator_token"` + TokenDefinitionID persist.DBID `json:"token_definition_id"` IsHolderToken bool `json:"is_holder_token"` Displayable bool `json:"displayable"` - TokenDefinitionID persist.DBID `json:"token_definition_id"` } type TokenDefinition struct { @@ -590,6 +590,36 @@ type TokenProcessingJob struct { Deleted bool `json:"deleted"` } +type TokensBackup struct { + ID persist.DBID `json:"id"` + Deleted bool `json:"deleted"` + Version sql.NullInt32 `json:"version"` + CreatedAt time.Time `json:"created_at"` + LastUpdated time.Time `json:"last_updated"` + Name sql.NullString `json:"name"` + Description sql.NullString `json:"description"` + CollectorsNote sql.NullString `json:"collectors_note"` + TokenUri sql.NullString `json:"token_uri"` + TokenType sql.NullString `json:"token_type"` + TokenID persist.DBID `json:"token_id"` + Quantity sql.NullString `json:"quantity"` + OwnershipHistory []pgtype.JSONB `json:"ownership_history"` + ExternalUrl sql.NullString `json:"external_url"` + BlockNumber sql.NullInt64 `json:"block_number"` + OwnerUserID persist.DBID `json:"owner_user_id"` + OwnedByWallets []string `json:"owned_by_wallets"` + Chain persist.Chain `json:"chain"` + Contract sql.NullString `json:"contract"` + IsUserMarkedSpam sql.NullBool `json:"is_user_marked_spam"` + IsProviderMarkedSpam sql.NullBool `json:"is_provider_marked_spam"` + LastSynced time.Time `json:"last_synced"` + FallbackMedia pgtype.JSONB `json:"fallback_media"` + TokenMediaID persist.DBID `json:"token_media_id"` + IsCreatorToken bool `json:"is_creator_token"` + IsHolderToken bool `json:"is_holder_token"` + Displayable bool `json:"displayable"` +} + type TopRecommendedUser struct { RecommendedUserID persist.DBID `json:"recommended_user_id"` Frequency int64 `json:"frequency"` diff --git a/db/gen/coredb/query.sql.go b/db/gen/coredb/query.sql.go index 88397ffe9..7a577dc2c 100644 --- a/db/gen/coredb/query.sql.go +++ b/db/gen/coredb/query.sql.go @@ -1472,7 +1472,7 @@ func (q *Queries) GetAllTimeTrendingUserIDs(ctx context.Context, limit int32) ([ const getAllTokensWithContractsByIDs = `-- name: GetAllTokensWithContractsByIDs :many select - tokens.id, tokens.deleted, tokens.version, tokens.created_at, tokens.last_updated, tokens.name__deprecated, tokens.description__deprecated, tokens.collectors_note, tokens.token_uri__deprecated, tokens.token_type__deprecated, tokens.token_id__deprecated, tokens.quantity, tokens.ownership_history__deprecated, tokens.external_url__deprecated, tokens.block_number, tokens.owner_user_id, tokens.owned_by_wallets, tokens.chain__deprecated, tokens.contract_id, tokens.is_user_marked_spam, tokens.is_provider_marked_spam__deprecated, tokens.last_synced, tokens.fallback_media__deprecated, tokens.token_media_id__deprecated, tokens.is_creator_token, tokens.is_holder_token, tokens.displayable, tokens.token_definition_id, + tokens.id, tokens.deleted, tokens.version, tokens.created_at, tokens.last_updated, tokens.name__deprecated, tokens.description__deprecated, tokens.collectors_note, tokens.token_type__deprecated, tokens.token_id__deprecated, tokens.quantity, tokens.ownership_history__deprecated, tokens.external_url__deprecated, tokens.block_number, tokens.owner_user_id, tokens.owned_by_wallets, tokens.chain, tokens.contract_id, tokens.is_user_marked_spam, tokens.is_provider_marked_spam__deprecated, tokens.last_synced, tokens.token_uri__deprecated, tokens.fallback_media__deprecated, tokens.token_media_id__deprecated, tokens.is_creator_token, tokens.token_definition_id, tokens.is_holder_token, tokens.displayable, contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id, ( select wallets.address @@ -1503,7 +1503,6 @@ type GetAllTokensWithContractsByIDsRow struct { NameDeprecated sql.NullString `json:"name__deprecated"` DescriptionDeprecated sql.NullString `json:"description__deprecated"` CollectorsNote sql.NullString `json:"collectors_note"` - TokenUriDeprecated sql.NullString `json:"token_uri__deprecated"` TokenTypeDeprecated sql.NullString `json:"token_type__deprecated"` TokenIDDeprecated sql.NullString `json:"token_id__deprecated"` Quantity persist.HexString `json:"quantity"` @@ -1512,17 +1511,18 @@ type GetAllTokensWithContractsByIDsRow struct { BlockNumber sql.NullInt64 `json:"block_number"` OwnerUserID persist.DBID `json:"owner_user_id"` OwnedByWallets persist.DBIDList `json:"owned_by_wallets"` - ChainDeprecated sql.NullInt32 `json:"chain__deprecated"` + Chain persist.Chain `json:"chain"` ContractID persist.DBID `json:"contract_id"` IsUserMarkedSpam sql.NullBool `json:"is_user_marked_spam"` IsProviderMarkedSpamDeprecated sql.NullBool `json:"is_provider_marked_spam__deprecated"` LastSynced time.Time `json:"last_synced"` + TokenUriDeprecated sql.NullString `json:"token_uri__deprecated"` FallbackMediaDeprecated pgtype.JSONB `json:"fallback_media__deprecated"` TokenMediaIDDeprecated sql.NullString `json:"token_media_id__deprecated"` IsCreatorToken bool `json:"is_creator_token"` + TokenDefinitionID persist.DBID `json:"token_definition_id"` IsHolderToken bool `json:"is_holder_token"` Displayable bool `json:"displayable"` - TokenDefinitionID persist.DBID `json:"token_definition_id"` ID_2 persist.DBID `json:"id_2"` Deleted_2 bool `json:"deleted_2"` Version_2 sql.NullInt32 `json:"version_2"` @@ -1532,7 +1532,7 @@ type GetAllTokensWithContractsByIDsRow struct { Symbol sql.NullString `json:"symbol"` Address persist.Address `json:"address"` CreatorAddress persist.Address `json:"creator_address"` - Chain persist.Chain `json:"chain"` + Chain_2 persist.Chain `json:"chain_2"` ProfileBannerUrl sql.NullString `json:"profile_banner_url"` ProfileImageUrl sql.NullString `json:"profile_image_url"` BadgeUrl sql.NullString `json:"badge_url"` @@ -1562,7 +1562,6 @@ func (q *Queries) GetAllTokensWithContractsByIDs(ctx context.Context, arg GetAll &i.NameDeprecated, &i.DescriptionDeprecated, &i.CollectorsNote, - &i.TokenUriDeprecated, &i.TokenTypeDeprecated, &i.TokenIDDeprecated, &i.Quantity, @@ -1571,17 +1570,18 @@ func (q *Queries) GetAllTokensWithContractsByIDs(ctx context.Context, arg GetAll &i.BlockNumber, &i.OwnerUserID, &i.OwnedByWallets, - &i.ChainDeprecated, + &i.Chain, &i.ContractID, &i.IsUserMarkedSpam, &i.IsProviderMarkedSpamDeprecated, &i.LastSynced, + &i.TokenUriDeprecated, &i.FallbackMediaDeprecated, &i.TokenMediaIDDeprecated, &i.IsCreatorToken, + &i.TokenDefinitionID, &i.IsHolderToken, &i.Displayable, - &i.TokenDefinitionID, &i.ID_2, &i.Deleted_2, &i.Version_2, @@ -1591,7 +1591,7 @@ func (q *Queries) GetAllTokensWithContractsByIDs(ctx context.Context, arg GetAll &i.Symbol, &i.Address, &i.CreatorAddress, - &i.Chain, + &i.Chain_2, &i.ProfileBannerUrl, &i.ProfileImageUrl, &i.BadgeUrl, @@ -2760,7 +2760,7 @@ func (q *Queries) GetMerchDiscountCodeByTokenID(ctx context.Context, tokenHex pe const getMissingThumbnailTokensByIDRange = `-- name: GetMissingThumbnailTokensByIDRange :many SELECT - tokens.id, tokens.deleted, tokens.version, tokens.created_at, tokens.last_updated, tokens.name__deprecated, tokens.description__deprecated, tokens.collectors_note, tokens.token_uri__deprecated, tokens.token_type__deprecated, tokens.token_id__deprecated, tokens.quantity, tokens.ownership_history__deprecated, tokens.external_url__deprecated, tokens.block_number, tokens.owner_user_id, tokens.owned_by_wallets, tokens.chain__deprecated, tokens.contract_id, tokens.is_user_marked_spam, tokens.is_provider_marked_spam__deprecated, tokens.last_synced, tokens.fallback_media__deprecated, tokens.token_media_id__deprecated, tokens.is_creator_token, tokens.is_holder_token, tokens.displayable, tokens.token_definition_id, + tokens.id, tokens.deleted, tokens.version, tokens.created_at, tokens.last_updated, tokens.name__deprecated, tokens.description__deprecated, tokens.collectors_note, tokens.token_type__deprecated, tokens.token_id__deprecated, tokens.quantity, tokens.ownership_history__deprecated, tokens.external_url__deprecated, tokens.block_number, tokens.owner_user_id, tokens.owned_by_wallets, tokens.chain, tokens.contract_id, tokens.is_user_marked_spam, tokens.is_provider_marked_spam__deprecated, tokens.last_synced, tokens.token_uri__deprecated, tokens.fallback_media__deprecated, tokens.token_media_id__deprecated, tokens.is_creator_token, tokens.token_definition_id, tokens.is_holder_token, tokens.displayable, contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id, ( SELECT wallets.address @@ -2789,7 +2789,6 @@ type GetMissingThumbnailTokensByIDRangeRow struct { NameDeprecated sql.NullString `json:"name__deprecated"` DescriptionDeprecated sql.NullString `json:"description__deprecated"` CollectorsNote sql.NullString `json:"collectors_note"` - TokenUriDeprecated sql.NullString `json:"token_uri__deprecated"` TokenTypeDeprecated sql.NullString `json:"token_type__deprecated"` TokenIDDeprecated sql.NullString `json:"token_id__deprecated"` Quantity persist.HexString `json:"quantity"` @@ -2798,17 +2797,18 @@ type GetMissingThumbnailTokensByIDRangeRow struct { BlockNumber sql.NullInt64 `json:"block_number"` OwnerUserID persist.DBID `json:"owner_user_id"` OwnedByWallets persist.DBIDList `json:"owned_by_wallets"` - ChainDeprecated sql.NullInt32 `json:"chain__deprecated"` + Chain persist.Chain `json:"chain"` ContractID persist.DBID `json:"contract_id"` IsUserMarkedSpam sql.NullBool `json:"is_user_marked_spam"` IsProviderMarkedSpamDeprecated sql.NullBool `json:"is_provider_marked_spam__deprecated"` LastSynced time.Time `json:"last_synced"` + TokenUriDeprecated sql.NullString `json:"token_uri__deprecated"` FallbackMediaDeprecated pgtype.JSONB `json:"fallback_media__deprecated"` TokenMediaIDDeprecated sql.NullString `json:"token_media_id__deprecated"` IsCreatorToken bool `json:"is_creator_token"` + TokenDefinitionID persist.DBID `json:"token_definition_id"` IsHolderToken bool `json:"is_holder_token"` Displayable bool `json:"displayable"` - TokenDefinitionID persist.DBID `json:"token_definition_id"` ID_2 persist.DBID `json:"id_2"` Deleted_2 bool `json:"deleted_2"` Version_2 sql.NullInt32 `json:"version_2"` @@ -2818,7 +2818,7 @@ type GetMissingThumbnailTokensByIDRangeRow struct { Symbol sql.NullString `json:"symbol"` Address persist.Address `json:"address"` CreatorAddress persist.Address `json:"creator_address"` - Chain persist.Chain `json:"chain"` + Chain_2 persist.Chain `json:"chain_2"` ProfileBannerUrl sql.NullString `json:"profile_banner_url"` ProfileImageUrl sql.NullString `json:"profile_image_url"` BadgeUrl sql.NullString `json:"badge_url"` @@ -2848,7 +2848,6 @@ func (q *Queries) GetMissingThumbnailTokensByIDRange(ctx context.Context, arg Ge &i.NameDeprecated, &i.DescriptionDeprecated, &i.CollectorsNote, - &i.TokenUriDeprecated, &i.TokenTypeDeprecated, &i.TokenIDDeprecated, &i.Quantity, @@ -2857,17 +2856,18 @@ func (q *Queries) GetMissingThumbnailTokensByIDRange(ctx context.Context, arg Ge &i.BlockNumber, &i.OwnerUserID, &i.OwnedByWallets, - &i.ChainDeprecated, + &i.Chain, &i.ContractID, &i.IsUserMarkedSpam, &i.IsProviderMarkedSpamDeprecated, &i.LastSynced, + &i.TokenUriDeprecated, &i.FallbackMediaDeprecated, &i.TokenMediaIDDeprecated, &i.IsCreatorToken, + &i.TokenDefinitionID, &i.IsHolderToken, &i.Displayable, - &i.TokenDefinitionID, &i.ID_2, &i.Deleted_2, &i.Version_2, @@ -2877,7 +2877,7 @@ func (q *Queries) GetMissingThumbnailTokensByIDRange(ctx context.Context, arg Ge &i.Symbol, &i.Address, &i.CreatorAddress, - &i.Chain, + &i.Chain_2, &i.ProfileBannerUrl, &i.ProfileImageUrl, &i.BadgeUrl, @@ -3403,7 +3403,7 @@ func (q *Queries) GetReprocessJobRangeByID(ctx context.Context, id int) (Reproce const getSVGTokensWithContractsByIDs = `-- name: GetSVGTokensWithContractsByIDs :many SELECT - tokens.id, tokens.deleted, tokens.version, tokens.created_at, tokens.last_updated, tokens.name__deprecated, tokens.description__deprecated, tokens.collectors_note, tokens.token_uri__deprecated, tokens.token_type__deprecated, tokens.token_id__deprecated, tokens.quantity, tokens.ownership_history__deprecated, tokens.external_url__deprecated, tokens.block_number, tokens.owner_user_id, tokens.owned_by_wallets, tokens.chain__deprecated, tokens.contract_id, tokens.is_user_marked_spam, tokens.is_provider_marked_spam__deprecated, tokens.last_synced, tokens.fallback_media__deprecated, tokens.token_media_id__deprecated, tokens.is_creator_token, tokens.is_holder_token, tokens.displayable, tokens.token_definition_id, + tokens.id, tokens.deleted, tokens.version, tokens.created_at, tokens.last_updated, tokens.name__deprecated, tokens.description__deprecated, tokens.collectors_note, tokens.token_type__deprecated, tokens.token_id__deprecated, tokens.quantity, tokens.ownership_history__deprecated, tokens.external_url__deprecated, tokens.block_number, tokens.owner_user_id, tokens.owned_by_wallets, tokens.chain, tokens.contract_id, tokens.is_user_marked_spam, tokens.is_provider_marked_spam__deprecated, tokens.last_synced, tokens.token_uri__deprecated, tokens.fallback_media__deprecated, tokens.token_media_id__deprecated, tokens.is_creator_token, tokens.token_definition_id, tokens.is_holder_token, tokens.displayable, contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id, ( SELECT wallets.address @@ -3435,7 +3435,6 @@ type GetSVGTokensWithContractsByIDsRow struct { NameDeprecated sql.NullString `json:"name__deprecated"` DescriptionDeprecated sql.NullString `json:"description__deprecated"` CollectorsNote sql.NullString `json:"collectors_note"` - TokenUriDeprecated sql.NullString `json:"token_uri__deprecated"` TokenTypeDeprecated sql.NullString `json:"token_type__deprecated"` TokenIDDeprecated sql.NullString `json:"token_id__deprecated"` Quantity persist.HexString `json:"quantity"` @@ -3444,17 +3443,18 @@ type GetSVGTokensWithContractsByIDsRow struct { BlockNumber sql.NullInt64 `json:"block_number"` OwnerUserID persist.DBID `json:"owner_user_id"` OwnedByWallets persist.DBIDList `json:"owned_by_wallets"` - ChainDeprecated sql.NullInt32 `json:"chain__deprecated"` + Chain persist.Chain `json:"chain"` ContractID persist.DBID `json:"contract_id"` IsUserMarkedSpam sql.NullBool `json:"is_user_marked_spam"` IsProviderMarkedSpamDeprecated sql.NullBool `json:"is_provider_marked_spam__deprecated"` LastSynced time.Time `json:"last_synced"` + TokenUriDeprecated sql.NullString `json:"token_uri__deprecated"` FallbackMediaDeprecated pgtype.JSONB `json:"fallback_media__deprecated"` TokenMediaIDDeprecated sql.NullString `json:"token_media_id__deprecated"` IsCreatorToken bool `json:"is_creator_token"` + TokenDefinitionID persist.DBID `json:"token_definition_id"` IsHolderToken bool `json:"is_holder_token"` Displayable bool `json:"displayable"` - TokenDefinitionID persist.DBID `json:"token_definition_id"` ID_2 persist.DBID `json:"id_2"` Deleted_2 bool `json:"deleted_2"` Version_2 sql.NullInt32 `json:"version_2"` @@ -3464,7 +3464,7 @@ type GetSVGTokensWithContractsByIDsRow struct { Symbol sql.NullString `json:"symbol"` Address persist.Address `json:"address"` CreatorAddress persist.Address `json:"creator_address"` - Chain persist.Chain `json:"chain"` + Chain_2 persist.Chain `json:"chain_2"` ProfileBannerUrl sql.NullString `json:"profile_banner_url"` ProfileImageUrl sql.NullString `json:"profile_image_url"` BadgeUrl sql.NullString `json:"badge_url"` @@ -3494,7 +3494,6 @@ func (q *Queries) GetSVGTokensWithContractsByIDs(ctx context.Context, arg GetSVG &i.NameDeprecated, &i.DescriptionDeprecated, &i.CollectorsNote, - &i.TokenUriDeprecated, &i.TokenTypeDeprecated, &i.TokenIDDeprecated, &i.Quantity, @@ -3503,17 +3502,18 @@ func (q *Queries) GetSVGTokensWithContractsByIDs(ctx context.Context, arg GetSVG &i.BlockNumber, &i.OwnerUserID, &i.OwnedByWallets, - &i.ChainDeprecated, + &i.Chain, &i.ContractID, &i.IsUserMarkedSpam, &i.IsProviderMarkedSpamDeprecated, &i.LastSynced, + &i.TokenUriDeprecated, &i.FallbackMediaDeprecated, &i.TokenMediaIDDeprecated, &i.IsCreatorToken, + &i.TokenDefinitionID, &i.IsHolderToken, &i.Displayable, - &i.TokenDefinitionID, &i.ID_2, &i.Deleted_2, &i.Version_2, @@ -3523,7 +3523,7 @@ func (q *Queries) GetSVGTokensWithContractsByIDs(ctx context.Context, arg GetSVG &i.Symbol, &i.Address, &i.CreatorAddress, - &i.Chain, + &i.Chain_2, &i.ProfileBannerUrl, &i.ProfileImageUrl, &i.BadgeUrl, @@ -3734,7 +3734,7 @@ func (q *Queries) GetSocialsByUserID(ctx context.Context, id persist.DBID) (pers } const getTokenById = `-- name: GetTokenById :one -select id, deleted, version, created_at, last_updated, name__deprecated, description__deprecated, collectors_note, token_uri__deprecated, token_type__deprecated, token_id__deprecated, quantity, ownership_history__deprecated, external_url__deprecated, block_number, owner_user_id, owned_by_wallets, chain__deprecated, contract_id, is_user_marked_spam, is_provider_marked_spam__deprecated, last_synced, fallback_media__deprecated, token_media_id__deprecated, is_creator_token, is_holder_token, displayable, token_definition_id from tokens where id = $1 and displayable and deleted = false +select id, deleted, version, created_at, last_updated, name__deprecated, description__deprecated, collectors_note, token_type__deprecated, token_id__deprecated, quantity, ownership_history__deprecated, external_url__deprecated, block_number, owner_user_id, owned_by_wallets, chain, contract_id, is_user_marked_spam, is_provider_marked_spam__deprecated, last_synced, token_uri__deprecated, fallback_media__deprecated, token_media_id__deprecated, is_creator_token, token_definition_id, is_holder_token, displayable from tokens where id = $1 and displayable and deleted = false ` func (q *Queries) GetTokenById(ctx context.Context, id persist.DBID) (Token, error) { @@ -3749,7 +3749,6 @@ func (q *Queries) GetTokenById(ctx context.Context, id persist.DBID) (Token, err &i.NameDeprecated, &i.DescriptionDeprecated, &i.CollectorsNote, - &i.TokenUriDeprecated, &i.TokenTypeDeprecated, &i.TokenIDDeprecated, &i.Quantity, @@ -3758,23 +3757,24 @@ func (q *Queries) GetTokenById(ctx context.Context, id persist.DBID) (Token, err &i.BlockNumber, &i.OwnerUserID, &i.OwnedByWallets, - &i.ChainDeprecated, + &i.Chain, &i.ContractID, &i.IsUserMarkedSpam, &i.IsProviderMarkedSpamDeprecated, &i.LastSynced, + &i.TokenUriDeprecated, &i.FallbackMediaDeprecated, &i.TokenMediaIDDeprecated, &i.IsCreatorToken, + &i.TokenDefinitionID, &i.IsHolderToken, &i.Displayable, - &i.TokenDefinitionID, ) return i, err } const getTokenByUserTokenIdentifiers = `-- name: GetTokenByUserTokenIdentifiers :one -select id, deleted, version, created_at, last_updated, name__deprecated, description__deprecated, collectors_note, token_uri__deprecated, token_type__deprecated, token_id__deprecated, quantity, ownership_history__deprecated, external_url__deprecated, block_number, owner_user_id, owned_by_wallets, chain__deprecated, contract_id, is_user_marked_spam, is_provider_marked_spam__deprecated, last_synced, fallback_media__deprecated, token_media_id__deprecated, is_creator_token, is_holder_token, displayable, token_definition_id +select id, deleted, version, created_at, last_updated, name__deprecated, description__deprecated, collectors_note, token_type__deprecated, token_id__deprecated, quantity, ownership_history__deprecated, external_url__deprecated, block_number, owner_user_id, owned_by_wallets, chain, contract_id, is_user_marked_spam, is_provider_marked_spam__deprecated, last_synced, token_uri__deprecated, fallback_media__deprecated, token_media_id__deprecated, is_creator_token, token_definition_id, is_holder_token, displayable from tokens where owner_user_id = $1 and token_definition_id = (select id from token_definitions td where (td.chain, td.contract_address, td.token_id) = ($2, $3, $4) and not deleted) and not tokens.deleted @@ -3805,7 +3805,6 @@ func (q *Queries) GetTokenByUserTokenIdentifiers(ctx context.Context, arg GetTok &i.NameDeprecated, &i.DescriptionDeprecated, &i.CollectorsNote, - &i.TokenUriDeprecated, &i.TokenTypeDeprecated, &i.TokenIDDeprecated, &i.Quantity, @@ -3814,17 +3813,18 @@ func (q *Queries) GetTokenByUserTokenIdentifiers(ctx context.Context, arg GetTok &i.BlockNumber, &i.OwnerUserID, &i.OwnedByWallets, - &i.ChainDeprecated, + &i.Chain, &i.ContractID, &i.IsUserMarkedSpam, &i.IsProviderMarkedSpamDeprecated, &i.LastSynced, + &i.TokenUriDeprecated, &i.FallbackMediaDeprecated, &i.TokenMediaIDDeprecated, &i.IsCreatorToken, + &i.TokenDefinitionID, &i.IsHolderToken, &i.Displayable, - &i.TokenDefinitionID, ) return i, err } @@ -3981,7 +3981,7 @@ func (q *Queries) GetTokenDefinitionByTokenIdentifiers(ctx context.Context, arg } const getTokenFullDetailsByContractId = `-- name: GetTokenFullDetailsByContractId :many -select tokens.id, tokens.deleted, tokens.version, tokens.created_at, tokens.last_updated, tokens.name__deprecated, tokens.description__deprecated, tokens.collectors_note, tokens.token_uri__deprecated, tokens.token_type__deprecated, tokens.token_id__deprecated, tokens.quantity, tokens.ownership_history__deprecated, tokens.external_url__deprecated, tokens.block_number, tokens.owner_user_id, tokens.owned_by_wallets, tokens.chain__deprecated, tokens.contract_id, tokens.is_user_marked_spam, tokens.is_provider_marked_spam__deprecated, tokens.last_synced, tokens.fallback_media__deprecated, tokens.token_media_id__deprecated, tokens.is_creator_token, tokens.is_holder_token, tokens.displayable, tokens.token_definition_id, token_definitions.id, token_definitions.created_at, token_definitions.last_updated, token_definitions.deleted, token_definitions.name, token_definitions.description, token_definitions.token_type, token_definitions.token_id, token_definitions.external_url, token_definitions.chain, token_definitions.metadata, token_definitions.fallback_media, token_definitions.contract_address, token_definitions.contract_id, token_definitions.token_media_id, contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id +select tokens.id, tokens.deleted, tokens.version, tokens.created_at, tokens.last_updated, tokens.name__deprecated, tokens.description__deprecated, tokens.collectors_note, tokens.token_type__deprecated, tokens.token_id__deprecated, tokens.quantity, tokens.ownership_history__deprecated, tokens.external_url__deprecated, tokens.block_number, tokens.owner_user_id, tokens.owned_by_wallets, tokens.chain, tokens.contract_id, tokens.is_user_marked_spam, tokens.is_provider_marked_spam__deprecated, tokens.last_synced, tokens.token_uri__deprecated, tokens.fallback_media__deprecated, tokens.token_media_id__deprecated, tokens.is_creator_token, tokens.token_definition_id, tokens.is_holder_token, tokens.displayable, token_definitions.id, token_definitions.created_at, token_definitions.last_updated, token_definitions.deleted, token_definitions.name, token_definitions.description, token_definitions.token_type, token_definitions.token_id, token_definitions.external_url, token_definitions.chain, token_definitions.metadata, token_definitions.fallback_media, token_definitions.contract_address, token_definitions.contract_id, token_definitions.token_media_id, contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id from tokens join token_definitions on tokens.token_definition_id = token_definitions.id join contracts on token_definitions.contract_id = contracts.id @@ -4013,7 +4013,6 @@ func (q *Queries) GetTokenFullDetailsByContractId(ctx context.Context, id persis &i.Token.NameDeprecated, &i.Token.DescriptionDeprecated, &i.Token.CollectorsNote, - &i.Token.TokenUriDeprecated, &i.Token.TokenTypeDeprecated, &i.Token.TokenIDDeprecated, &i.Token.Quantity, @@ -4022,17 +4021,18 @@ func (q *Queries) GetTokenFullDetailsByContractId(ctx context.Context, id persis &i.Token.BlockNumber, &i.Token.OwnerUserID, &i.Token.OwnedByWallets, - &i.Token.ChainDeprecated, + &i.Token.Chain, &i.Token.ContractID, &i.Token.IsUserMarkedSpam, &i.Token.IsProviderMarkedSpamDeprecated, &i.Token.LastSynced, + &i.Token.TokenUriDeprecated, &i.Token.FallbackMediaDeprecated, &i.Token.TokenMediaIDDeprecated, &i.Token.IsCreatorToken, + &i.Token.TokenDefinitionID, &i.Token.IsHolderToken, &i.Token.Displayable, - &i.Token.TokenDefinitionID, &i.TokenDefinition.ID, &i.TokenDefinition.CreatedAt, &i.TokenDefinition.LastUpdated, @@ -4078,7 +4078,7 @@ func (q *Queries) GetTokenFullDetailsByContractId(ctx context.Context, id persis } const getTokenFullDetailsByUserId = `-- name: GetTokenFullDetailsByUserId :many -select tokens.id, tokens.deleted, tokens.version, tokens.created_at, tokens.last_updated, tokens.name__deprecated, tokens.description__deprecated, tokens.collectors_note, tokens.token_uri__deprecated, tokens.token_type__deprecated, tokens.token_id__deprecated, tokens.quantity, tokens.ownership_history__deprecated, tokens.external_url__deprecated, tokens.block_number, tokens.owner_user_id, tokens.owned_by_wallets, tokens.chain__deprecated, tokens.contract_id, tokens.is_user_marked_spam, tokens.is_provider_marked_spam__deprecated, tokens.last_synced, tokens.fallback_media__deprecated, tokens.token_media_id__deprecated, tokens.is_creator_token, tokens.is_holder_token, tokens.displayable, tokens.token_definition_id, token_definitions.id, token_definitions.created_at, token_definitions.last_updated, token_definitions.deleted, token_definitions.name, token_definitions.description, token_definitions.token_type, token_definitions.token_id, token_definitions.external_url, token_definitions.chain, token_definitions.metadata, token_definitions.fallback_media, token_definitions.contract_address, token_definitions.contract_id, token_definitions.token_media_id, contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id +select tokens.id, tokens.deleted, tokens.version, tokens.created_at, tokens.last_updated, tokens.name__deprecated, tokens.description__deprecated, tokens.collectors_note, tokens.token_type__deprecated, tokens.token_id__deprecated, tokens.quantity, tokens.ownership_history__deprecated, tokens.external_url__deprecated, tokens.block_number, tokens.owner_user_id, tokens.owned_by_wallets, tokens.chain, tokens.contract_id, tokens.is_user_marked_spam, tokens.is_provider_marked_spam__deprecated, tokens.last_synced, tokens.token_uri__deprecated, tokens.fallback_media__deprecated, tokens.token_media_id__deprecated, tokens.is_creator_token, tokens.token_definition_id, tokens.is_holder_token, tokens.displayable, token_definitions.id, token_definitions.created_at, token_definitions.last_updated, token_definitions.deleted, token_definitions.name, token_definitions.description, token_definitions.token_type, token_definitions.token_id, token_definitions.external_url, token_definitions.chain, token_definitions.metadata, token_definitions.fallback_media, token_definitions.contract_address, token_definitions.contract_id, token_definitions.token_media_id, contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id from tokens join token_definitions on tokens.token_definition_id = token_definitions.id join contracts on token_definitions.contract_id = contracts.id @@ -4110,7 +4110,6 @@ func (q *Queries) GetTokenFullDetailsByUserId(ctx context.Context, ownerUserID p &i.Token.NameDeprecated, &i.Token.DescriptionDeprecated, &i.Token.CollectorsNote, - &i.Token.TokenUriDeprecated, &i.Token.TokenTypeDeprecated, &i.Token.TokenIDDeprecated, &i.Token.Quantity, @@ -4119,17 +4118,18 @@ func (q *Queries) GetTokenFullDetailsByUserId(ctx context.Context, ownerUserID p &i.Token.BlockNumber, &i.Token.OwnerUserID, &i.Token.OwnedByWallets, - &i.Token.ChainDeprecated, + &i.Token.Chain, &i.Token.ContractID, &i.Token.IsUserMarkedSpam, &i.Token.IsProviderMarkedSpamDeprecated, &i.Token.LastSynced, + &i.Token.TokenUriDeprecated, &i.Token.FallbackMediaDeprecated, &i.Token.TokenMediaIDDeprecated, &i.Token.IsCreatorToken, + &i.Token.TokenDefinitionID, &i.Token.IsHolderToken, &i.Token.Displayable, - &i.Token.TokenDefinitionID, &i.TokenDefinition.ID, &i.TokenDefinition.CreatedAt, &i.TokenDefinition.LastUpdated, @@ -4175,7 +4175,7 @@ func (q *Queries) GetTokenFullDetailsByUserId(ctx context.Context, ownerUserID p } const getTokenFullDetailsByUserTokenIdentifiers = `-- name: GetTokenFullDetailsByUserTokenIdentifiers :one -select tokens.id, tokens.deleted, tokens.version, tokens.created_at, tokens.last_updated, tokens.name__deprecated, tokens.description__deprecated, tokens.collectors_note, tokens.token_uri__deprecated, tokens.token_type__deprecated, tokens.token_id__deprecated, tokens.quantity, tokens.ownership_history__deprecated, tokens.external_url__deprecated, tokens.block_number, tokens.owner_user_id, tokens.owned_by_wallets, tokens.chain__deprecated, tokens.contract_id, tokens.is_user_marked_spam, tokens.is_provider_marked_spam__deprecated, tokens.last_synced, tokens.fallback_media__deprecated, tokens.token_media_id__deprecated, tokens.is_creator_token, tokens.is_holder_token, tokens.displayable, tokens.token_definition_id, token_definitions.id, token_definitions.created_at, token_definitions.last_updated, token_definitions.deleted, token_definitions.name, token_definitions.description, token_definitions.token_type, token_definitions.token_id, token_definitions.external_url, token_definitions.chain, token_definitions.metadata, token_definitions.fallback_media, token_definitions.contract_address, token_definitions.contract_id, token_definitions.token_media_id, contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id +select tokens.id, tokens.deleted, tokens.version, tokens.created_at, tokens.last_updated, tokens.name__deprecated, tokens.description__deprecated, tokens.collectors_note, tokens.token_type__deprecated, tokens.token_id__deprecated, tokens.quantity, tokens.ownership_history__deprecated, tokens.external_url__deprecated, tokens.block_number, tokens.owner_user_id, tokens.owned_by_wallets, tokens.chain, tokens.contract_id, tokens.is_user_marked_spam, tokens.is_provider_marked_spam__deprecated, tokens.last_synced, tokens.token_uri__deprecated, tokens.fallback_media__deprecated, tokens.token_media_id__deprecated, tokens.is_creator_token, tokens.token_definition_id, tokens.is_holder_token, tokens.displayable, token_definitions.id, token_definitions.created_at, token_definitions.last_updated, token_definitions.deleted, token_definitions.name, token_definitions.description, token_definitions.token_type, token_definitions.token_id, token_definitions.external_url, token_definitions.chain, token_definitions.metadata, token_definitions.fallback_media, token_definitions.contract_address, token_definitions.contract_id, token_definitions.token_media_id, contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id from tokens join token_definitions on tokens.token_definition_id = token_definitions.id join contracts on token_definitions.contract_id = contracts.id @@ -4218,7 +4218,6 @@ func (q *Queries) GetTokenFullDetailsByUserTokenIdentifiers(ctx context.Context, &i.Token.NameDeprecated, &i.Token.DescriptionDeprecated, &i.Token.CollectorsNote, - &i.Token.TokenUriDeprecated, &i.Token.TokenTypeDeprecated, &i.Token.TokenIDDeprecated, &i.Token.Quantity, @@ -4227,17 +4226,18 @@ func (q *Queries) GetTokenFullDetailsByUserTokenIdentifiers(ctx context.Context, &i.Token.BlockNumber, &i.Token.OwnerUserID, &i.Token.OwnedByWallets, - &i.Token.ChainDeprecated, + &i.Token.Chain, &i.Token.ContractID, &i.Token.IsUserMarkedSpam, &i.Token.IsProviderMarkedSpamDeprecated, &i.Token.LastSynced, + &i.Token.TokenUriDeprecated, &i.Token.FallbackMediaDeprecated, &i.Token.TokenMediaIDDeprecated, &i.Token.IsCreatorToken, + &i.Token.TokenDefinitionID, &i.Token.IsHolderToken, &i.Token.Displayable, - &i.Token.TokenDefinitionID, &i.TokenDefinition.ID, &i.TokenDefinition.CreatedAt, &i.TokenDefinition.LastUpdated, @@ -4308,7 +4308,7 @@ func (q *Queries) GetTokenOwnerByID(ctx context.Context, id persist.DBID) (User, } const getTokensByContractIdPaginate = `-- name: GetTokensByContractIdPaginate :many -select t.id, t.deleted, t.version, t.created_at, t.last_updated, t.name__deprecated, t.description__deprecated, t.collectors_note, t.token_uri__deprecated, t.token_type__deprecated, t.token_id__deprecated, t.quantity, t.ownership_history__deprecated, t.external_url__deprecated, t.block_number, t.owner_user_id, t.owned_by_wallets, t.chain__deprecated, t.contract_id, t.is_user_marked_spam, t.is_provider_marked_spam__deprecated, t.last_synced, t.fallback_media__deprecated, t.token_media_id__deprecated, t.is_creator_token, t.is_holder_token, t.displayable, t.token_definition_id from tokens t +select t.id, t.deleted, t.version, t.created_at, t.last_updated, t.name__deprecated, t.description__deprecated, t.collectors_note, t.token_type__deprecated, t.token_id__deprecated, t.quantity, t.ownership_history__deprecated, t.external_url__deprecated, t.block_number, t.owner_user_id, t.owned_by_wallets, t.chain, t.contract_id, t.is_user_marked_spam, t.is_provider_marked_spam__deprecated, t.last_synced, t.token_uri__deprecated, t.fallback_media__deprecated, t.token_media_id__deprecated, t.is_creator_token, t.token_definition_id, t.is_holder_token, t.displayable from tokens t join users u on u.id = t.owner_user_id join contracts c on t.contract_id = c.id where (c.id = $1 or c.parent_id = $1) @@ -4365,7 +4365,6 @@ func (q *Queries) GetTokensByContractIdPaginate(ctx context.Context, arg GetToke &i.NameDeprecated, &i.DescriptionDeprecated, &i.CollectorsNote, - &i.TokenUriDeprecated, &i.TokenTypeDeprecated, &i.TokenIDDeprecated, &i.Quantity, @@ -4374,17 +4373,18 @@ func (q *Queries) GetTokensByContractIdPaginate(ctx context.Context, arg GetToke &i.BlockNumber, &i.OwnerUserID, &i.OwnedByWallets, - &i.ChainDeprecated, + &i.Chain, &i.ContractID, &i.IsUserMarkedSpam, &i.IsProviderMarkedSpamDeprecated, &i.LastSynced, + &i.TokenUriDeprecated, &i.FallbackMediaDeprecated, &i.TokenMediaIDDeprecated, &i.IsCreatorToken, + &i.TokenDefinitionID, &i.IsHolderToken, &i.Displayable, - &i.TokenDefinitionID, ); err != nil { return nil, err } diff --git a/db/gen/coredb/tmp_token_normalization_backfill.sql.go b/db/gen/coredb/tmp_token_normalization_backfill.sql.go index 94e3ccb89..cfe61fccb 100644 --- a/db/gen/coredb/tmp_token_normalization_backfill.sql.go +++ b/db/gen/coredb/tmp_token_normalization_backfill.sql.go @@ -12,7 +12,7 @@ import ( ) const getTokenBackfillBatch = `-- name: GetTokenBackfillBatch :many -select tokens.id, tokens.deleted, tokens.version, tokens.created_at, tokens.last_updated, tokens.name__deprecated, tokens.description__deprecated, tokens.collectors_note, tokens.token_uri__deprecated, tokens.token_type__deprecated, tokens.token_id__deprecated, tokens.quantity, tokens.ownership_history__deprecated, tokens.external_url__deprecated, tokens.block_number, tokens.owner_user_id, tokens.owned_by_wallets, tokens.chain__deprecated, tokens.contract_id, tokens.is_user_marked_spam, tokens.is_provider_marked_spam__deprecated, tokens.last_synced, tokens.fallback_media__deprecated, tokens.token_media_id__deprecated, tokens.is_creator_token, tokens.is_holder_token, tokens.displayable, tokens.token_definition_id, token_medias.id, token_medias.created_at, token_medias.last_updated, token_medias.version, token_medias.contract_id__deprecated, token_medias.token_id__deprecated, token_medias.chain__deprecated, token_medias.active, token_medias.metadata__deprecated, token_medias.media, token_medias.name__deprecated, token_medias.description__deprecated, token_medias.processing_job_id, token_medias.deleted +select tokens.id, tokens.deleted, tokens.version, tokens.created_at, tokens.last_updated, tokens.name__deprecated, tokens.description__deprecated, tokens.collectors_note, tokens.token_type__deprecated, tokens.token_id__deprecated, tokens.quantity, tokens.ownership_history__deprecated, tokens.external_url__deprecated, tokens.block_number, tokens.owner_user_id, tokens.owned_by_wallets, tokens.chain, tokens.contract_id, tokens.is_user_marked_spam, tokens.is_provider_marked_spam__deprecated, tokens.last_synced, tokens.token_uri__deprecated, tokens.fallback_media__deprecated, tokens.token_media_id__deprecated, tokens.is_creator_token, tokens.token_definition_id, tokens.is_holder_token, tokens.displayable, token_medias.id, token_medias.created_at, token_medias.last_updated, token_medias.version, token_medias.contract_id__deprecated, token_medias.token_id__deprecated, token_medias.chain__deprecated, token_medias.active, token_medias.metadata__deprecated, token_medias.media, token_medias.name__deprecated, token_medias.description__deprecated, token_medias.processing_job_id, token_medias.deleted from tokens left join token_medias on tokens.token_media_id__deprecated = token_medias.id where $1 < tokens.id and tokens.id <= $2 @@ -46,7 +46,6 @@ func (q *Queries) GetTokenBackfillBatch(ctx context.Context, arg GetTokenBackfil &i.Token.NameDeprecated, &i.Token.DescriptionDeprecated, &i.Token.CollectorsNote, - &i.Token.TokenUriDeprecated, &i.Token.TokenTypeDeprecated, &i.Token.TokenIDDeprecated, &i.Token.Quantity, @@ -55,17 +54,18 @@ func (q *Queries) GetTokenBackfillBatch(ctx context.Context, arg GetTokenBackfil &i.Token.BlockNumber, &i.Token.OwnerUserID, &i.Token.OwnedByWallets, - &i.Token.ChainDeprecated, + &i.Token.Chain, &i.Token.ContractID, &i.Token.IsUserMarkedSpam, &i.Token.IsProviderMarkedSpamDeprecated, &i.Token.LastSynced, + &i.Token.TokenUriDeprecated, &i.Token.FallbackMediaDeprecated, &i.Token.TokenMediaIDDeprecated, &i.Token.IsCreatorToken, + &i.Token.TokenDefinitionID, &i.Token.IsHolderToken, &i.Token.Displayable, - &i.Token.TokenDefinitionID, &i.TokenMedia.ID, &i.TokenMedia.CreatedAt, &i.TokenMedia.LastUpdated, diff --git a/db/gen/coredb/token_gallery.sql.go b/db/gen/coredb/token_gallery.sql.go index d1edb20ea..06d5b5610 100644 --- a/db/gen/coredb/token_gallery.sql.go +++ b/db/gen/coredb/token_gallery.sql.go @@ -161,9 +161,9 @@ with token_definitions_insert as ( , last_updated = excluded.last_updated , last_synced = greatest(excluded.last_synced,tokens.last_synced) , contract_id = excluded.contract_id - returning id, deleted, version, created_at, last_updated, name__deprecated, description__deprecated, collectors_note, token_uri__deprecated, token_type__deprecated, token_id__deprecated, quantity, ownership_history__deprecated, external_url__deprecated, block_number, owner_user_id, owned_by_wallets, chain__deprecated, contract_id, is_user_marked_spam, is_provider_marked_spam__deprecated, last_synced, fallback_media__deprecated, token_media_id__deprecated, is_creator_token, is_holder_token, displayable, token_definition_id + returning id, deleted, version, created_at, last_updated, name__deprecated, description__deprecated, collectors_note, token_type__deprecated, token_id__deprecated, quantity, ownership_history__deprecated, external_url__deprecated, block_number, owner_user_id, owned_by_wallets, chain, contract_id, is_user_marked_spam, is_provider_marked_spam__deprecated, last_synced, token_uri__deprecated, fallback_media__deprecated, token_media_id__deprecated, is_creator_token, token_definition_id, is_holder_token, displayable ) -select tokens.id, tokens.deleted, tokens.version, tokens.created_at, tokens.last_updated, tokens.name__deprecated, tokens.description__deprecated, tokens.collectors_note, tokens.token_uri__deprecated, tokens.token_type__deprecated, tokens.token_id__deprecated, tokens.quantity, tokens.ownership_history__deprecated, tokens.external_url__deprecated, tokens.block_number, tokens.owner_user_id, tokens.owned_by_wallets, tokens.chain__deprecated, tokens.contract_id, tokens.is_user_marked_spam, tokens.is_provider_marked_spam__deprecated, tokens.last_synced, tokens.fallback_media__deprecated, tokens.token_media_id__deprecated, tokens.is_creator_token, tokens.is_holder_token, tokens.displayable, tokens.token_definition_id, token_definitions.id, token_definitions.created_at, token_definitions.last_updated, token_definitions.deleted, token_definitions.name, token_definitions.description, token_definitions.token_type, token_definitions.token_id, token_definitions.external_url, token_definitions.chain, token_definitions.metadata, token_definitions.fallback_media, token_definitions.contract_address, token_definitions.contract_id, token_definitions.token_media_id, contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id +select tokens.id, tokens.deleted, tokens.version, tokens.created_at, tokens.last_updated, tokens.name__deprecated, tokens.description__deprecated, tokens.collectors_note, tokens.token_type__deprecated, tokens.token_id__deprecated, tokens.quantity, tokens.ownership_history__deprecated, tokens.external_url__deprecated, tokens.block_number, tokens.owner_user_id, tokens.owned_by_wallets, tokens.chain, tokens.contract_id, tokens.is_user_marked_spam, tokens.is_provider_marked_spam__deprecated, tokens.last_synced, tokens.token_uri__deprecated, tokens.fallback_media__deprecated, tokens.token_media_id__deprecated, tokens.is_creator_token, tokens.token_definition_id, tokens.is_holder_token, tokens.displayable, token_definitions.id, token_definitions.created_at, token_definitions.last_updated, token_definitions.deleted, token_definitions.name, token_definitions.description, token_definitions.token_type, token_definitions.token_id, token_definitions.external_url, token_definitions.chain, token_definitions.metadata, token_definitions.fallback_media, token_definitions.contract_address, token_definitions.contract_id, token_definitions.token_media_id, contracts.id, contracts.deleted, contracts.version, contracts.created_at, contracts.last_updated, contracts.name, contracts.symbol, contracts.address, contracts.creator_address, contracts.chain, contracts.profile_banner_url, contracts.profile_image_url, contracts.badge_url, contracts.description, contracts.owner_address, contracts.is_provider_marked_spam, contracts.parent_id, contracts.override_creator_user_id from tokens_insert tokens join token_definitions_insert token_definitions on tokens.token_definition_id = token_definitions.id join contracts on token_definitions.contract_id = contracts.id @@ -251,7 +251,6 @@ func (q *Queries) UpsertTokens(ctx context.Context, arg UpsertTokensParams) ([]U &i.Token.NameDeprecated, &i.Token.DescriptionDeprecated, &i.Token.CollectorsNote, - &i.Token.TokenUriDeprecated, &i.Token.TokenTypeDeprecated, &i.Token.TokenIDDeprecated, &i.Token.Quantity, @@ -260,17 +259,18 @@ func (q *Queries) UpsertTokens(ctx context.Context, arg UpsertTokensParams) ([]U &i.Token.BlockNumber, &i.Token.OwnerUserID, &i.Token.OwnedByWallets, - &i.Token.ChainDeprecated, + &i.Token.Chain, &i.Token.ContractID, &i.Token.IsUserMarkedSpam, &i.Token.IsProviderMarkedSpamDeprecated, &i.Token.LastSynced, + &i.Token.TokenUriDeprecated, &i.Token.FallbackMediaDeprecated, &i.Token.TokenMediaIDDeprecated, &i.Token.IsCreatorToken, + &i.Token.TokenDefinitionID, &i.Token.IsHolderToken, &i.Token.Displayable, - &i.Token.TokenDefinitionID, &i.TokenDefinition.ID, &i.TokenDefinition.CreatedAt, &i.TokenDefinition.LastUpdated, diff --git a/db/migrations/core/000111_add_token_definitions.up.sql b/db/migrations/core/000111_add_token_definitions.up.sql deleted file mode 100644 index 5c4ad6c80..000000000 --- a/db/migrations/core/000111_add_token_definitions.up.sql +++ /dev/null @@ -1,54 +0,0 @@ --- Ensures that changes to a contract are mirrored in the token_definitions table. A unique constraint on (chain, address) already exists to guarantee uniqueness within the table itself. -create unique index contracts_id_chain_address_idx on contracts(id, chain, address); - -create table if not exists token_definitions ( - id character varying(255) primary key, - created_at timestamp with time zone not null default current_timestamp, - last_updated timestamp with time zone not null default current_timestamp, - deleted boolean not null default false, - name character varying, - description character varying, - token_type character varying, - token_id character varying, - external_url character varying, - chain integer, - metadata jsonb, - fallback_media jsonb, - contract_address character varying(255) not null, - contract_id character varying(255), - token_media_id character varying(255) references token_medias(id), - foreign key(contract_id, chain, contract_address) references contracts(id, chain, address) on update cascade -); -create unique index if not exists token_definitions_chain_contract_id_token_idx on token_definitions(chain, contract_id, token_id) where not deleted; -create unique index if not exists token_definitions_chain_contract_address_token_idx on token_definitions(chain, contract_address, token_id) where not deleted; -create index token_definitions_contract_id_idx on token_definitions(contract_id) where not deleted; - --- Make nullable in a later migration after back filling -alter table tokens add column if not exists token_definition_id character varying(255) references token_definitions(id); - -create unique index if not exists tokens_owner_token_definition_idx on tokens(owner_user_id, token_definition_id) where not deleted; -alter table tokens rename column contract to contract_id; -alter table tokens rename column chain to chain__deprecated; -alter table tokens rename column token_id to token_id__deprecated; -alter table tokens rename column name to name__deprecated; -alter table tokens rename column description to description__deprecated; -alter table tokens rename column token_type to token_type__deprecated; -alter table tokens rename column ownership_history to ownership_history__deprecated; -alter table tokens rename column external_url to external_url__deprecated; -alter table tokens rename column is_provider_marked_spam to is_provider_marked_spam__deprecated; -alter table tokens rename column token_uri to token_uri__deprecated; -alter table tokens rename column fallback_media to fallback_media__deprecated; -alter table tokens rename column token_media_id to token_media_id__deprecated; - -alter table token_medias rename column name to name__deprecated; -alter table token_medias rename column description to description__deprecated; -alter table token_medias rename column metadata to metadata__deprecated; -alter table token_medias rename column contract_id to contract_id__deprecated; -alter table token_medias rename column token_id to token_id__deprecated; -alter table token_medias rename column chain to chain__deprecated; -alter table token_medias alter column name__deprecated drop not null; -alter table token_medias alter column description__deprecated drop not null; -alter table token_medias alter column metadata__deprecated drop not null; -alter table token_medias alter column contract_id__deprecated drop not null; -alter table token_medias alter column token_id__deprecated drop not null; -alter table token_medias alter column chain__deprecated drop not null; diff --git a/db/migrations/core/000111_token_norm_add_token_definitions.up.sql b/db/migrations/core/000111_token_norm_add_token_definitions.up.sql new file mode 100644 index 000000000..ceb9f8585 --- /dev/null +++ b/db/migrations/core/000111_token_norm_add_token_definitions.up.sql @@ -0,0 +1,24 @@ +-- Ensures that changes to a contract are mirrored in the token_definitions table. A unique constraint on (chain, address) already exists to guarantee uniqueness within the table itself. +create unique index contracts_id_chain_address_idx on contracts(id, chain, address); + +create table if not exists token_definitions ( + id character varying(255) primary key, + created_at timestamp with time zone not null default current_timestamp, + last_updated timestamp with time zone not null default current_timestamp, + deleted boolean not null default false, + name character varying, + description character varying, + token_type character varying, + token_id character varying, + external_url character varying, + chain integer, + metadata jsonb, + fallback_media jsonb, + contract_address character varying(255) not null, + contract_id character varying(255) references contracts(id) not null, + token_media_id character varying(255) references token_medias(id), + foreign key(contract_id, chain, contract_address) references contracts(id, chain, address) on update cascade +); +create unique index if not exists token_definitions_chain_contract_id_token_idx on token_definitions(chain, contract_id, token_id) where not deleted; +create unique index if not exists token_definitions_chain_contract_address_token_idx on token_definitions(chain, contract_address, token_id) where not deleted; +create index token_definitions_contract_id_idx on token_definitions(contract_id) where not deleted; diff --git a/db/migrations/core/000112_token_norm_add_token_definition_constraints.up.sql b/db/migrations/core/000112_token_norm_add_token_definition_constraints.up.sql new file mode 100644 index 000000000..86ae0b603 --- /dev/null +++ b/db/migrations/core/000112_token_norm_add_token_definition_constraints.up.sql @@ -0,0 +1,74 @@ +/* Migrate to rebuild the tokens table with the token_definition_id column */ +begin; + +-- Temporarily increase work_mem to speed up the migration so prevent data spilling to disk +set local work_mem = '5500 MB'; + +-- Only allow reads to the table +lock table tokens in access exclusive mode; + +-- Create a copy of the tokens table with the new column +create table tokens_with_token_definition_fk as +select + t.id, + t.deleted, + t.version, + t.created_at, + t.last_updated, + t.name, + t.description, + t.collectors_note, + t.token_type, + t.token_id, + t.quantity, + t.ownership_history, + t.external_url, + t.block_number, + t.owner_user_id, + t.owned_by_wallets, + t.chain, + t.contract, + t.is_user_marked_spam, + t.is_provider_marked_spam, + t.last_synced, + t.token_uri, + t.fallback_media, + t.token_media_id, + t.is_creator_token, + td.id token_definition_id +from tokens t +join token_definitions td on (t.chain, t.contract, t.token_id) = (td.chain, td.contract_id, td.token_id) and not td.deleted; + +-- Add back the generated columns +alter table tokens_with_token_definition_fk add column is_holder_token boolean not null generated always as (cardinality(owned_by_wallets) > 0) stored; +alter table tokens_with_token_definition_fk add column displayable boolean not null generated always as (cardinality(owned_by_wallets) > 0 or is_creator_token) stored; + +-- Add back constraints +alter table tokens_with_token_definition_fk add primary key(id); +alter table tokens_with_token_definition_fk add constraint contracts_contract_id_fkey foreign key(contract) references contracts(id) on delete cascade on update cascade; +alter table tokens_with_token_definition_fk alter column token_definition_id set not null; +alter table tokens_with_token_definition_fk alter column contract set not null; +alter table tokens_with_token_definition_fk add constraint token_definitions_token_definition_id_fkey foreign key(token_definition_id) references token_definitions(id) on update cascade; +create index if not exists tokens_owner_user_id_chain_idx on tokens_with_token_definition_fk(owner_user_id, chain) where not deleted; +create unique index if not exists tokens_owner_token_definition_idx on tokens_with_token_definition_fk(owner_user_id, token_definition_id) where not deleted; + +-- Rename the table, create a backup of the old table +alter table tokens rename to tokens_backup; +alter table tokens_with_token_definition_fk rename to tokens; + +-- Rename columns while were at it +alter table tokens rename column contract to contract_id; + +-- Keep migrated columns around for a bit +alter table tokens rename column token_id to token_id__deprecated; +alter table tokens rename column name to name__deprecated; +alter table tokens rename column description to description__deprecated; +alter table tokens rename column token_type to token_type__deprecated; +alter table tokens rename column ownership_history to ownership_history__deprecated; +alter table tokens rename column external_url to external_url__deprecated; +alter table tokens rename column is_provider_marked_spam to is_provider_marked_spam__deprecated; +alter table tokens rename column token_uri to token_uri__deprecated; +alter table tokens rename column fallback_media to fallback_media__deprecated; +alter table tokens rename column token_media_id to token_media_id__deprecated; + +end; diff --git a/db/migrations/core/000113_token_norm_update_feed_entity_score_view.up.sql b/db/migrations/core/000113_token_norm_update_feed_entity_score_view.up.sql new file mode 100644 index 000000000..b80d9f63b --- /dev/null +++ b/db/migrations/core/000113_token_norm_update_feed_entity_score_view.up.sql @@ -0,0 +1,57 @@ +create or replace view feed_entity_score_view as ( + with report_after as ( + select now() - interval '7 day' ts + ), + + selected_posts as ( + select posts.id, posts.created_at, posts.actor_id, posts.contract_ids, count(distinct comments.id) + count(distinct admires.id) interactions + from posts + left join comments on comments.post_id = posts.id + left join admires on admires.post_id = posts.id + where posts.created_at >= (select ts from report_after) + and not posts.deleted + group by posts.id, posts.created_at, posts.actor_id, posts.contract_ids + ), + + selected_events as ( + select feed_events.id, feed_events.event_time created_at, feed_events.owner_id actor_id, feed_events.action, count(distinct comments.id) + count(distinct admires.id) interactions + from feed_events + left join comments on comments.feed_event_id = feed_events.id + left join admires on admires.feed_event_id = feed_events.id + where feed_events.event_time >= (select ts from report_after) + and not feed_events.deleted + group by feed_events.id, feed_events.event_time, feed_events.owner_id, feed_events.action + ), + + event_contracts as ( + select feed_event_id, array_agg(contract_id) contract_ids + from ( + select feed_events.id feed_event_id, contracts.id contract_id + from + feed_events, + -- The only event that we currently store with token ids is the 'GalleryUpdated' event which includes the 'gallery_new_token_ids' field + lateral jsonb_each((data->>'gallery_new_token_ids')::jsonb) x(key, value), + jsonb_array_elements_text(x.value) tid(id), + tokens, + contracts + where + feed_events.event_time >= (select ts from report_after) + and not feed_events.deleted + and tid.id = tokens.id + and contracts.id = tokens.contract_id + and not tokens.deleted + and not contracts.deleted + group by feed_events.id, contracts.id + ) t + group by feed_event_id + ) + + select id, created_at, actor_id, action, contract_ids, interactions, 0 feed_entity_type, now()::timestamptz as last_updated + from selected_events + left join event_contracts on selected_events.id = event_contracts.feed_event_id + + union all + + select id, created_at, actor_id, '', contract_ids, interactions, 1 feed_entity_type, now()::timestamptz as last_updated + from selected_posts +); diff --git a/db/migrations/core/000114_token_norm_update_contract_relevance_view.up.sql b/db/migrations/core/000114_token_norm_update_contract_relevance_view.up.sql new file mode 100644 index 000000000..dbe81d3e8 --- /dev/null +++ b/db/migrations/core/000114_token_norm_update_contract_relevance_view.up.sql @@ -0,0 +1,26 @@ +drop materialized view if exists contract_relevance; + +create materialized view contract_relevance as ( + with users_per_contract as ( + select con.id from contracts con, collections col, unnest(col.nfts) as col_token_id + inner join tokens t on t.id = col_token_id and t.deleted = false + where t.contract_id = con.id and col.owner_user_id = t.owner_user_id + and col.deleted = false and con.deleted = false group by (con.id, t.owner_user_id) + ), + min_count as ( + -- The baseline score is 0, because contracts that aren't displayed by anyone on + -- Gallery are potentially contracts we want to filter out entirely + select 0 as count + ), + max_count as ( + select count(id) from users_per_contract group by id order by count(id) desc limit 1 + ) + select id, (min_count.count + count(users_per_contract.id)) / (min_count.count + max_count.count)::decimal as score + from users_per_contract, min_count, max_count group by (id, min_count.count, max_count.count) + union + -- Null id contains the minimum score + select null as id, min_count.count / (min_count.count + max_count.count)::decimal as score + from min_count, max_count +); + +create unique index contract_relevance_id_idx on contract_relevance(id); diff --git a/db/migrations/core/000115_token_norm_update_owned_contracts_view.up.sql b/db/migrations/core/000115_token_norm_update_owned_contracts_view.up.sql new file mode 100644 index 000000000..f2c23b3c8 --- /dev/null +++ b/db/migrations/core/000115_token_norm_update_owned_contracts_view.up.sql @@ -0,0 +1,69 @@ +begin; + +drop materialized view if exists owned_contracts; +create materialized view owned_contracts as ( + with owned_contracts as ( + select + users.id as user_id, + users.created_at as user_created_at, + contracts.id as contract_id, + count(tokens.id) as owned_count + from users + join tokens on + tokens.deleted = false + and users.id = tokens.owner_user_id + and coalesce(tokens.is_user_marked_spam, false) = false + join contracts on + contracts.deleted = false + and tokens.contract_id = contracts.id + where + users.deleted = false + and users.universal = false + group by + users.id, + contracts.id + ), + displayed_tokens as ( + select + owned_contracts.user_id, + owned_contracts.contract_id, + tokens.id as token_id + from owned_contracts, galleries, collections, tokens + where + galleries.deleted = false + and collections.deleted = false + and galleries.owner_user_id = owned_contracts.user_id + and collections.owner_user_id = owned_contracts.user_id + and tokens.owner_user_id = owned_contracts.user_id + and tokens.contract_id = owned_contracts.contract_id + and tokens.id = any(collections.nfts) + group by + owned_contracts.user_id, + owned_contracts.contract_id, + tokens.id + ), + displayed_contracts as ( + select user_id, contract_id, count(token_id) as displayed_count from displayed_tokens + group by + user_id, + contract_id + ) + select + owned_contracts.user_id, + owned_contracts.user_created_at, + owned_contracts.contract_id, + owned_contracts.owned_count, + coalesce(displayed_contracts.displayed_count, 0) as displayed_count, + (displayed_contracts.displayed_count is not null)::bool as displayed, + now()::timestamptz as last_updated + from owned_contracts + left join displayed_contracts on + displayed_contracts.user_id = owned_contracts.user_id and + displayed_contracts.contract_id = owned_contracts.contract_id +); + +create unique index owned_contracts_user_contract_idx on owned_contracts(user_id, contract_id); +create index owned_contracts_user_displayed_idx on owned_contracts(user_id, displayed); +create index owned_contracts_user_created_at_idx on owned_contracts(user_created_at); + +commit; diff --git a/db/migrations/core/000116_token_norm_update_admires_token_id_constraint.up.sql b/db/migrations/core/000116_token_norm_update_admires_token_id_constraint.up.sql new file mode 100644 index 000000000..f921594c5 --- /dev/null +++ b/db/migrations/core/000116_token_norm_update_admires_token_id_constraint.up.sql @@ -0,0 +1,2 @@ +alter table admires drop constraint admires_token_id_fkey; +alter table admires add constraint admires_token_id_fkey foreign key(token_id) references tokens(id); diff --git a/db/migrations/core/000117_token_norm_update_events_token_id_constraint.up.sql b/db/migrations/core/000117_token_norm_update_events_token_id_constraint.up.sql new file mode 100644 index 000000000..86f3393ce --- /dev/null +++ b/db/migrations/core/000117_token_norm_update_events_token_id_constraint.up.sql @@ -0,0 +1,2 @@ +alter table events drop constraint events_token_id_fkey; +alter table events add constraint events_token_id_fkey foreign key(token_id) references tokens(id); diff --git a/db/migrations/core/000118_token_norm_update_notifications_token_id_constraint.up.sql b/db/migrations/core/000118_token_norm_update_notifications_token_id_constraint.up.sql new file mode 100644 index 000000000..4c3a8e6fa --- /dev/null +++ b/db/migrations/core/000118_token_norm_update_notifications_token_id_constraint.up.sql @@ -0,0 +1,2 @@ +alter table notifications drop constraint notifications_token_id_fkey; +alter table notifications add constraint notifications_token_id_fkey foreign key(token_id) references tokens(id); diff --git a/db/migrations/core/000119_token_norm_update_profile_images_token_id_constraint.up.sql b/db/migrations/core/000119_token_norm_update_profile_images_token_id_constraint.up.sql new file mode 100644 index 000000000..bcc5c6daf --- /dev/null +++ b/db/migrations/core/000119_token_norm_update_profile_images_token_id_constraint.up.sql @@ -0,0 +1,2 @@ +alter table profile_images drop constraint profile_images_token_id_fkey; +alter table profile_images add constraint profile_images_token_id_fkey foreign key(token_id) references tokens(id); diff --git a/db/migrations/core/000120_token_norm_token_medias_deprecate_columns.up.sql b/db/migrations/core/000120_token_norm_token_medias_deprecate_columns.up.sql new file mode 100644 index 000000000..eae846588 --- /dev/null +++ b/db/migrations/core/000120_token_norm_token_medias_deprecate_columns.up.sql @@ -0,0 +1,12 @@ +alter table token_medias rename column name to name__deprecated; +alter table token_medias rename column description to description__deprecated; +alter table token_medias rename column metadata to metadata__deprecated; +alter table token_medias rename column contract_id to contract_id__deprecated; +alter table token_medias rename column token_id to token_id__deprecated; +alter table token_medias rename column chain to chain__deprecated; +alter table token_medias alter column name__deprecated drop not null; +alter table token_medias alter column description__deprecated drop not null; +alter table token_medias alter column metadata__deprecated drop not null; +alter table token_medias alter column contract_id__deprecated drop not null; +alter table token_medias alter column token_id__deprecated drop not null; +alter table token_medias alter column chain__deprecated drop not null; diff --git a/graphql/schema/schema.graphql b/graphql/schema/schema.graphql index fa8e768c8..4b58c5c24 100644 --- a/graphql/schema/schema.graphql +++ b/graphql/schema/schema.graphql @@ -1637,7 +1637,11 @@ type SyncCreatedTokensForExistingContractPayload { viewer: Viewer } -union RefreshTokenPayloadOrError = RefreshTokenPayload | ErrInvalidInput | ErrSyncFailed | ErrTokenNotFound +union RefreshTokenPayloadOrError = + RefreshTokenPayload + | ErrInvalidInput + | ErrSyncFailed + | ErrTokenNotFound type RefreshTokenPayload { token: Token