diff --git a/Cargo.lock b/Cargo.lock index 181526a4b..a9028d929 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1840,6 +1840,8 @@ version = "0.7.2" dependencies = [ "async-trait", "blockbuster", + "borsh 0.9.3", + "borsh-derive 0.9.3", "bs58 0.4.0", "futures", "indexmap 1.9.3", @@ -3219,7 +3221,6 @@ name = "migration" version = "0.7.2" dependencies = [ "async-std", - "digital_asset_types", "enum-iterator", "enum-iterator-derive", "sea-orm-migration", diff --git a/README.md b/README.md index e9dbb9692..87d87aa79 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ ## IMPORTANT: See Prerequisites below ## Digital Asset RPC API Infrastructure -This repo houses the API Ingester and Database Types components of the Metaplex Digital Asset RPC API. Together these -components are responsible for the aggregation of Solana Validator Data into an extremely fast and well typed api. This -api provides a nice interface on top of the Metaplex programs. It abstracts the byte layout on chain, allows for -super-fast querying and searching, as well as serves the merkle proofs needed to operate over compressed nfts. + +This repo houses the API Ingester and Database Types components of the Metaplex Digital Asset RPC API. Together these +components are responsible for the aggregation of Solana Validator Data into an extremely fast and well typed api. This +api provides a nice interface on top of the Metaplex programs. It abstracts the byte layout on chain, allows for +super-fast querying and searching, as well as serves the merkle proofs needed to operate over compressed nfts. ### Components + 1. Ingester -> A background processing system that gets messages from a [Messenger](https://github.com/metaplex-foundation/digital-asset-validator-plugin), and uses [BlockBuster](https://github.com/metaplex-foundation/blockbuster) Parsers to store the canonical representation of Metaplex types in a storage system. This system also holds the re-articulated Merkle tree that supports the compressed NFTs system. 2. Api -> A JSON Rpc api that serves Metaplex objects. This api allows filtering, pagination and searching over Metaplex data. This data includes serving the merkle proofs for the compressed NFTs system. It is intended to be run right alongside the Solana RPC and works in much the same way. Just like the solana RPC takes data from the validator and serves it in a new format, so this api takes data off the validator and serves it. @@ -14,24 +16,27 @@ The API specification is located here https://github.com/metaplex-foundation/api This spec is what providers of this api must implement against. ### Infrastructure and Deployment Examples -Along with the above rust binaries, this repo also maintains examples and best practice settings for running the entire infrastructure. -The example infrastructure is as follows. -* A Solana No-Vote Validator - This validator is configured to only have secure access to the validator ledger and account data under consensus. -* A Geyser Plugin (Plerkle) - The above validator is further configured to load this geyser plugin that sends Plerkle Serialized Messages over a messaging system. -* A Redis Cluster (Stream Optimized) - The example messaging system is a light weight redis deployment that supports the streaming configuration. -* A Kubernetes Cluster - The orchestration system for the API and Ingester processes. Probably overkill for a small installation, but it's a rock solid platform for critical software. +Along with the above rust binaries, this repo also maintains examples and best practice settings for running the entire infrastructure. +The example infrastructure is as follows. + +- A Solana No-Vote Validator - This validator is configured to only have secure access to the validator ledger and account data under consensus. +- A Geyser Plugin (Plerkle) - The above validator is further configured to load this geyser plugin that sends Plerkle Serialized Messages over a messaging system. +- A Redis Cluster (Stream Optimized) - The example messaging system is a light weight redis deployment that supports the streaming configuration. +- A Kubernetes Cluster - The orchestration system for the API and Ingester processes. Probably overkill for a small installation, but it's a rock solid platform for critical software. This repo houses Helm Charts, Docker files and Terraform files to assist in the deployment of the example infrastructure. ### Developing #### Prerequisites: + You must clone the https://github.com/metaplex-foundation/blockbuster repo, this is un publishable for now due to active development in like 1000 branches and serious mathematics avoiding dependency hell. Because this is a multi component system the easiest way to develop or locally test this system is with docker but developing locally without docker is possible. #### Regenerating DB Types + Edit the init.sql, then run `docker compose up db` Then with a local `DATABASE_URL` var exported like this `export DATABASE_URL=postgres://solana:solana@localhost/solana` you can run `sea-orm-cli generate entity -o ./digital_asset_types/src/dao/generated/ --database-url $DATABASE_URL --with-serde both --expanded-format` @@ -40,18 +45,19 @@ If you need to install `sea-orm-cli` run `cargo install sea-orm-cli`. Note: The current SeaORM types were generated using version 0.9.3 so unless you want to upgrade you can install using `cargo install sea-orm-cli --version 0.9.3`. -Also note: The migration `m20230224_093722_performance_improvements` needs to be commented out of the migration lib.rs in order for the Sea ORM `Relations` to generate correctly. - #### Developing Locally - *Prerequisites* - * A Postgres Server running with the database setup according to ./init.sql - * A Redis instance that has streams enabled or a version that supports streams - * A local solana validator with the Plerkle plugin running. - * Environment Variables set to allow your validator, ingester and api to access those prerequisites. + +_Prerequisites_ + +- A Postgres Server running with the database setup according to ./init.sql +- A Redis instance that has streams enabled or a version that supports streams +- A local solana validator with the Plerkle plugin running. +- Environment Variables set to allow your validator, ingester and api to access those prerequisites. See [Plugin Configuration](https://github.com/metaplex-foundation/digital-asset-validator-plugin#building-locally) for how to locally configure the test validator plugin to work. For the API you need the following environment variables: + ```bash APP_DATABASE_URL=postgres://solana:solana@db/solana #change to your db host APP_SERVER_PORT=9090 @@ -62,6 +68,7 @@ cargo run -p das_api ``` For the Ingester you need the following environment variables: + ```bash INGESTER_DATABASE_CONFIG: '{listener_channel="backfill_item_added", url="postgres://solana:solana@db/solana"}' # your database host INGESTER_MESSENGER_CONFIG: '{messenger_type="Redis", connection_config={ redis_connection_str="redis://redis" } }' #your redis @@ -72,13 +79,14 @@ INGESTER_RPC_CONFIG: '{url="http://validator:8899", commitment="finalized"}' # y cargo run -p nft_ingester ``` - When making changes you will need to stop the cargo process and re-run. Someday we will have auto rebuild for local cargo stuff but for now you are on your own. #### NOTE + ``` -INGESTER_ROLE +INGESTER_ROLE ``` + This environment variable can be used to split the work load. All for a combined setup @@ -89,44 +97,49 @@ Background for just the background tasks. For production you should split the coponents up. ### Developing With Docker + Developing with Docker is much easier, but has some nuances to it. This test docker compose system relies on a programs folder being accessible, this folder needs to have the shared object files for the following programs -* Token Metadata -* Bubblegum -* Gummyroll -* Token 2022 -* Latest version of the Associated token program + +- Token Metadata +- Bubblegum +- Gummyroll +- Token 2022 +- Latest version of the Associated token program You need to run the following script in order to get the .so files. ```bash ./prepare-local-docker-env.sh ``` -This script downloads these programs from mainnet and puts them in the `programs/` folder. + +This script grabs all the code for these programs and compiles it, and chucks it into your programs folder. Go grab some coffe because this will take a while/ +If you get some permissions errors, just sudo delete the programs directory and start again. #### Authentication with Docker and AWS -_This step is not normally needed for basic local docker usage._ -```aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin {your aws container registry}``` +`aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin {your aws container registry}` #### Running the application -We use ``docker-compose`` to build the multi-container Docker application. On some systems its ``docker compose``. +We use `docker-compose` to build the multi-container Docker application. On some systems its `docker compose`. + ```bash -docker-compose build +docker-compose build ``` + This builds the docker container for API and the Ingester components and will download the appropriate Redis, Postgres and Solana+plerkle docker images. Keep in mind that the version `latest` on the Solana Validator image will match the latest version available on the docs, for other versions please change that version in your docker compose file. ```bash -docker-compose up +docker-compose up ``` #### Developing -When making changes you will need to ``docker compose up --build --force-recreate`` again to get the latest changes. +When making changes you will need to `docker compose up --build --force-recreate` again to get the latest changes. Also when mucking about with the docker file if your gut tells you that something is wrong, and you are getting build errors run `docker compose build --no-cache` -Sometimes you will want to delete the db do so with `sudo rm -rf db-data`. You can also delete the ledger with `sudo rm -rf ledger`. +Sometimes you will want to delete the db do so with `sudo rm -rf db-data`. You can also delete the ledger with `sudo rm -rf ledger`. #### Running Bubblegum Test Sequences @@ -137,13 +150,16 @@ sudo rm -rf db-data/ sudo rm -rf ledger/ docker compose up --force-recreate --build ``` + _In another terminal:_ + ```bash cd tools/txn_forwarder/bubblegum_tests/ ./run-bubblegum-sequences.sh ``` You should see it log something like: + ``` Running 10 scenarios forwards mint_transfer_burn.scenario initial asset table state passed @@ -160,18 +176,23 @@ ALL TESTS PASSED FORWARDS! ``` You can also run the sequences in reverse: + ```bash ./run-bubblegum-sequences.sh reverse ``` + And after it runs you should see `ALL TESTS PASSED IN REVERSE!` A few detailed notes about this test script: -* This script is not all-encompassing. It is only meant to automate some normal basic tests that were previously done manually. The reason this test is not added to CI is because requires a more powerful system to run the Docker application, which contains the no-vote Solana validator. -* The test sequences are in `.scenario` files, but instead of sending those files to the `txn_forwarder` directly (which supports the file format), we parse them out and send them individually using the `single` parameter. This is because using the `.scenario` file directly results in random ordering of the transactions and we are explicity trying to test them going forwards and in reverse. -* In general the expected database results are the same when running the transactions forwards and backwards. However, for assets that are decompressed, this is not true because we don't index some of the asset information from Bubblegum mint indexing if we already know the asset has been decompressed. We instead let Token Metadata account based indexing fill in that information. This is not reflected by this test script so the results differ when running these sequences in reverse. The differing results are reflected in test files with the `_reverse` suffix. + +- This script is not all-encompassing. It is only meant to automate some normal basic tests that were previously done manually. The reason this test is not added to CI is because requires a more powerful system to run the Docker application, which contains the no-vote Solana validator. +- The test sequences are in `.scenario` files, but instead of sending those files to the `txn_forwarder` directly (which supports the file format), we parse them out and send them individually using the `single` parameter. This is because using the `.scenario` file directly results in random ordering of the transactions and we are explicity trying to test them going forwards and in reverse. +- In general the expected database results are the same when running the transactions forwards and backwards. However, for assets that are decompressed, this is not true because we don't index some of the asset information from Bubblegum mint indexing if we already know the asset has been decompressed. We instead let Token Metadata account based indexing fill in that information. This is not reflected by this test script so the results differ when running these sequences in reverse. The differing results are reflected in test files with the `_reverse` suffix. #### Logs + To get a reasonable amount of logs while running Docker, direct grafana logs to a file: + ``` grafana: ... @@ -179,7 +200,9 @@ grafana: ... - GF_LOG_MODE=file ``` -and set Solana Rust logs to error level (it is already set to error level now in the current docker compose file): + +and set Solana Rust logs to error level: + ``` solana: ... @@ -190,10 +213,13 @@ and set Solana Rust logs to error level (it is already set to error level now in #### Interacting with API Once everything is working you can see that there is a api being served on + ``` http://localhost:9090 ``` + And a Metrics System on + ``` http://localhost:3000 ``` @@ -234,10 +260,12 @@ curl --request POST --url http://localhost:9090 --header 'Content-Type: applicat }' | json_pp ``` -# Deploying to Kubernetes +# Deploying to Kubernetes + Using skaffold you can deploy to k8s, make sure you authenticate with your docker registry Make sure you have the env vars you need to satisfy this part of the skaffold.yaml + ```yaml ... setValueTemplates: @@ -259,6 +287,7 @@ Make sure you have the env vars you need to satisfy this part of the skaffold.ya metrics.data_dog_api_key: "{{.DATA_DOG_API}}" ... ``` + ```bash skaffold build --file-output skaffold-state.json --cache-artifacts=false ## Your namepsace may differ. @@ -266,21 +295,26 @@ skaffold deploy -p devnet --build-artifacts skaffold-state.json --namespace devn ``` # METRICS + Here are the metrics that various parts of ths system expose; ## NFT INGESTER + ### ACKING + count ingester.ack - number of messages acked tagged by stream count ingester.stream.ack_error - error acking a message count ingester.stream.receive_error - error getting stream data ### Stream Metrics + ingester.stream_redelivery - Stream tagged of messages re delivered ingester.stream_size - Size of stream, tagged by stream ingester.stream_size_error - Error getting the stream size ### Stream Specific Metrics + All these metrics are tagged by stream count ingester.seen time ingester.proc_time @@ -290,6 +324,7 @@ count ingester.not_implemented count ingester.ingest_error ### BG Tasks + time ingester.bgtask.proc_time count ingester.bgtask.success count ingester.bgtask.error @@ -298,17 +333,15 @@ time ingester.bgtask.bus_time count ingester.bgtask.identical ### BACKFILLER + count ingester.backfiller.task_panic count ingester.backfiller.task_error guage ingester.backfiller.missing_trees ### Startup + ingester.startup ## API -api_call - - - - +api_call diff --git a/digital_asset_types/Cargo.toml b/digital_asset_types/Cargo.toml index 1f049e509..314073d9f 100644 --- a/digital_asset_types/Cargo.toml +++ b/digital_asset_types/Cargo.toml @@ -8,6 +8,8 @@ publish = { workspace = true } [dependencies] async-trait = { workspace = true } blockbuster = { workspace = true } +borsh = { version = "0.9.3", optional = true } +borsh-derive = { version = "0.9.3", optional = true } bs58 = { workspace = true } futures = { workspace = true } indexmap = { workspace = true } diff --git a/digital_asset_types/src/dao/extensions/asset.rs b/digital_asset_types/src/dao/extensions/asset.rs new file mode 100644 index 000000000..ed3757bf2 --- /dev/null +++ b/digital_asset_types/src/dao/extensions/asset.rs @@ -0,0 +1,104 @@ +use sea_orm::{EntityTrait, EnumIter, Related, RelationDef, RelationTrait}; + +use crate::dao::{ + asset, asset_authority, asset_creators, asset_data, asset_grouping, + asset_v1_account_attachments, + sea_orm_active_enums::{OwnerType, RoyaltyTargetType}, +}; + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + AssetData, + AssetV1AccountAttachments, + AssetAuthority, + AssetCreators, + AssetGrouping, +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::AssetData => asset::Entity::belongs_to(asset_data::Entity) + .from(asset::Column::AssetData) + .to(asset_data::Column::Id) + .into(), + Self::AssetV1AccountAttachments => { + asset::Entity::has_many(asset_v1_account_attachments::Entity).into() + } + Self::AssetAuthority => asset::Entity::has_many(asset_authority::Entity).into(), + Self::AssetCreators => asset::Entity::has_many(asset_creators::Entity).into(), + Self::AssetGrouping => asset::Entity::has_many(asset_grouping::Entity).into(), + } + } +} + +impl Related for asset::Entity { + fn to() -> RelationDef { + Relation::AssetData.def() + } +} + +impl Related for asset::Entity { + fn to() -> RelationDef { + Relation::AssetV1AccountAttachments.def() + } +} + +impl Related for asset::Entity { + fn to() -> RelationDef { + Relation::AssetAuthority.def() + } +} + +impl Related for asset::Entity { + fn to() -> RelationDef { + Relation::AssetCreators.def() + } +} + +impl Related for asset::Entity { + fn to() -> RelationDef { + Relation::AssetGrouping.def() + } +} + +impl Default for RoyaltyTargetType { + fn default() -> Self { + Self::Creators + } +} + +impl Default for asset::Model { + fn default() -> Self { + Self { + id: vec![], + alt_id: None, + specification_version: None, + specification_asset_class: None, + owner: None, + owner_type: OwnerType::Single, + delegate: None, + frozen: Default::default(), + supply: Default::default(), + supply_mint: None, + compressed: Default::default(), + compressible: Default::default(), + seq: None, + tree_id: None, + leaf: None, + nonce: None, + royalty_target_type: RoyaltyTargetType::Unknown, + royalty_target: None, + royalty_amount: Default::default(), + asset_data: None, + created_at: None, + burnt: Default::default(), + slot_updated: None, + data_hash: None, + creator_hash: None, + owner_delegate_seq: None, + leaf_seq: None, + base_info_seq: None, + } + } +} diff --git a/digital_asset_types/src/dao/extensions/asset_authority.rs b/digital_asset_types/src/dao/extensions/asset_authority.rs new file mode 100644 index 000000000..30ec05617 --- /dev/null +++ b/digital_asset_types/src/dao/extensions/asset_authority.rs @@ -0,0 +1,25 @@ +use sea_orm::{EntityTrait, EnumIter, Related, RelationDef, RelationTrait}; + +use crate::dao::{asset, asset_authority}; + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + Asset, +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::Asset => asset_authority::Entity::belongs_to(asset::Entity) + .from(asset_authority::Column::AssetId) + .to(asset::Column::Id) + .into(), + } + } +} + +impl Related for asset_authority::Entity { + fn to() -> RelationDef { + Relation::Asset.def() + } +} diff --git a/digital_asset_types/src/dao/extensions/asset_creators.rs b/digital_asset_types/src/dao/extensions/asset_creators.rs new file mode 100644 index 000000000..35d36e98d --- /dev/null +++ b/digital_asset_types/src/dao/extensions/asset_creators.rs @@ -0,0 +1,25 @@ +use sea_orm::{EntityTrait, EnumIter, Related, RelationDef, RelationTrait}; + +use crate::dao::{asset, asset_creators}; + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + Asset, +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::Asset => asset_creators::Entity::belongs_to(asset::Entity) + .from(asset_creators::Column::AssetId) + .to(asset::Column::Id) + .into(), + } + } +} + +impl Related for asset_creators::Entity { + fn to() -> RelationDef { + Relation::Asset.def() + } +} diff --git a/digital_asset_types/src/dao/extensions/asset_data.rs b/digital_asset_types/src/dao/extensions/asset_data.rs new file mode 100644 index 000000000..93bb00bfc --- /dev/null +++ b/digital_asset_types/src/dao/extensions/asset_data.rs @@ -0,0 +1,22 @@ +use sea_orm::{EntityTrait, EnumIter, Related, RelationDef, RelationTrait}; + +use crate::dao::{asset, asset_data}; + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + Asset, +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::Asset => asset_data::Entity::has_many(asset::Entity).into(), + } + } +} + +impl Related for asset_data::Entity { + fn to() -> RelationDef { + Relation::Asset.def() + } +} diff --git a/digital_asset_types/src/dao/extensions/asset_grouping.rs b/digital_asset_types/src/dao/extensions/asset_grouping.rs new file mode 100644 index 000000000..1d1bce87a --- /dev/null +++ b/digital_asset_types/src/dao/extensions/asset_grouping.rs @@ -0,0 +1,25 @@ +use sea_orm::{EntityTrait, EnumIter, Related, RelationDef, RelationTrait}; + +use crate::dao::{asset, asset_grouping}; + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + Asset, +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::Asset => asset_grouping::Entity::belongs_to(asset::Entity) + .from(asset_grouping::Column::AssetId) + .to(asset::Column::Id) + .into(), + } + } +} + +impl Related for asset_grouping::Entity { + fn to() -> RelationDef { + Relation::Asset.def() + } +} diff --git a/digital_asset_types/src/dao/extensions/asset_v1_account_attachment.rs b/digital_asset_types/src/dao/extensions/asset_v1_account_attachment.rs new file mode 100644 index 000000000..c231b6e92 --- /dev/null +++ b/digital_asset_types/src/dao/extensions/asset_v1_account_attachment.rs @@ -0,0 +1,25 @@ +use sea_orm::{EntityTrait, EnumIter, Related, RelationDef, RelationTrait}; + +use crate::dao::{asset, asset_v1_account_attachments}; + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation { + Asset, +} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + match self { + Self::Asset => asset_v1_account_attachments::Entity::belongs_to(asset::Entity) + .from(asset_v1_account_attachments::Column::AssetId) + .to(asset::Column::Id) + .into(), + } + } +} + +impl Related for asset_v1_account_attachments::Entity { + fn to() -> RelationDef { + Relation::Asset.def() + } +} diff --git a/digital_asset_types/src/dao/extensions/instruction.rs b/digital_asset_types/src/dao/extensions/instruction.rs new file mode 100644 index 000000000..c58a91891 --- /dev/null +++ b/digital_asset_types/src/dao/extensions/instruction.rs @@ -0,0 +1,52 @@ +use crate::dao::sea_orm_active_enums::Instruction; + +impl From<&str> for Instruction { + fn from(s: &str) -> Self { + match s { + "Burn" => Instruction::Burn, + "CancelRedeem" => Instruction::CancelRedeem, + "Compress" => Instruction::Compress, + "DecompressV1" => Instruction::DecompressV1, + "Delegate" => Instruction::Delegate, + "MintToCollectionV1" => Instruction::MintToCollectionV1, + "MintV1" => Instruction::MintV1, + "Redeem" => Instruction::Redeem, + "SetAndVerifyCollection" => Instruction::SetAndVerifyCollection, + "Transfer" => Instruction::Transfer, + "UnverifyCollection" => Instruction::UnverifyCollection, + "UnverifyCreator" => Instruction::UnverifyCreator, + "VerifyCollection" => Instruction::VerifyCollection, + "VerifyCreator" => Instruction::VerifyCreator, + "UpdateMetadata" => Instruction::UpdateMetadata, + _ => Instruction::Unknown, + } + } +} + +pub trait PascalCase { + fn to_pascal_case(&self) -> String; +} + +impl PascalCase for Instruction { + fn to_pascal_case(&self) -> String { + let s = match self { + Instruction::Burn => "Burn", + Instruction::CancelRedeem => "CancelRedeem", + Instruction::Compress => "Compress", + Instruction::DecompressV1 => "DecompressV1", + Instruction::Delegate => "Delegate", + Instruction::MintToCollectionV1 => "MintToCollectionV1", + Instruction::MintV1 => "MintV1", + Instruction::Redeem => "Redeem", + Instruction::SetAndVerifyCollection => "SetAndVerifyCollection", + Instruction::Transfer => "Transfer", + Instruction::Unknown => "Unknown", + Instruction::UnverifyCollection => "UnverifyCollection", + Instruction::UnverifyCreator => "UnverifyCreator", + Instruction::VerifyCollection => "VerifyCollection", + Instruction::VerifyCreator => "VerifyCreator", + Instruction::UpdateMetadata => "UpdateMetadata", + }; + s.to_string() + } +} diff --git a/digital_asset_types/src/dao/extensions/mod.rs b/digital_asset_types/src/dao/extensions/mod.rs new file mode 100644 index 000000000..bcfc3e130 --- /dev/null +++ b/digital_asset_types/src/dao/extensions/mod.rs @@ -0,0 +1,7 @@ +pub mod asset; +pub mod asset_authority; +pub mod asset_creators; +pub mod asset_data; +pub mod asset_grouping; +pub mod asset_v1_account_attachment; +pub mod instruction; diff --git a/digital_asset_types/src/dao/generated/asset.rs b/digital_asset_types/src/dao/generated/asset.rs index 0c32be2fe..e03ae6866 100644 --- a/digital_asset_types/src/dao/generated/asset.rs +++ b/digital_asset_types/src/dao/generated/asset.rs @@ -93,13 +93,7 @@ impl PrimaryKeyTrait for PrimaryKey { } #[derive(Copy, Clone, Debug, EnumIter)] -pub enum Relation { - AssetData, - AssetV1AccountAttachments, - AssetCreators, - AssetAuthority, - AssetGrouping, -} +pub enum Relation {} impl ColumnTrait for Column { type EntityName = Entity; @@ -139,48 +133,7 @@ impl ColumnTrait for Column { impl RelationTrait for Relation { fn def(&self) -> RelationDef { - match self { - Self::AssetData => Entity::belongs_to(super::asset_data::Entity) - .from(Column::AssetData) - .to(super::asset_data::Column::Id) - .into(), - Self::AssetV1AccountAttachments => { - Entity::has_many(super::asset_v1_account_attachments::Entity).into() - } - Self::AssetCreators => Entity::has_many(super::asset_creators::Entity).into(), - Self::AssetAuthority => Entity::has_many(super::asset_authority::Entity).into(), - Self::AssetGrouping => Entity::has_many(super::asset_grouping::Entity).into(), - } - } -} - -impl Related for Entity { - fn to() -> RelationDef { - Relation::AssetData.def() - } -} - -impl Related for Entity { - fn to() -> RelationDef { - Relation::AssetV1AccountAttachments.def() - } -} - -impl Related for Entity { - fn to() -> RelationDef { - Relation::AssetCreators.def() - } -} - -impl Related for Entity { - fn to() -> RelationDef { - Relation::AssetAuthority.def() - } -} - -impl Related for Entity { - fn to() -> RelationDef { - Relation::AssetGrouping.def() + panic!("No RelationDef") } } diff --git a/digital_asset_types/src/dao/generated/asset_authority.rs b/digital_asset_types/src/dao/generated/asset_authority.rs index 88d0ed72f..5ba29e6bd 100644 --- a/digital_asset_types/src/dao/generated/asset_authority.rs +++ b/digital_asset_types/src/dao/generated/asset_authority.rs @@ -45,9 +45,7 @@ impl PrimaryKeyTrait for PrimaryKey { } #[derive(Copy, Clone, Debug, EnumIter)] -pub enum Relation { - Asset, -} +pub enum Relation {} impl ColumnTrait for Column { type EntityName = Entity; @@ -65,18 +63,7 @@ impl ColumnTrait for Column { impl RelationTrait for Relation { fn def(&self) -> RelationDef { - match self { - Self::Asset => Entity::belongs_to(super::asset::Entity) - .from(Column::AssetId) - .to(super::asset::Column::Id) - .into(), - } - } -} - -impl Related for Entity { - fn to() -> RelationDef { - Relation::Asset.def() + panic!("No RelationDef") } } diff --git a/digital_asset_types/src/dao/generated/asset_creators.rs b/digital_asset_types/src/dao/generated/asset_creators.rs index 21f34dcf7..af4f0c768 100644 --- a/digital_asset_types/src/dao/generated/asset_creators.rs +++ b/digital_asset_types/src/dao/generated/asset_creators.rs @@ -49,9 +49,7 @@ impl PrimaryKeyTrait for PrimaryKey { } #[derive(Copy, Clone, Debug, EnumIter)] -pub enum Relation { - Asset, -} +pub enum Relation {} impl ColumnTrait for Column { type EntityName = Entity; @@ -71,18 +69,7 @@ impl ColumnTrait for Column { impl RelationTrait for Relation { fn def(&self) -> RelationDef { - match self { - Self::Asset => Entity::belongs_to(super::asset::Entity) - .from(Column::AssetId) - .to(super::asset::Column::Id) - .into(), - } - } -} - -impl Related for Entity { - fn to() -> RelationDef { - Relation::Asset.def() + panic!("No RelationDef") } } diff --git a/digital_asset_types/src/dao/generated/asset_data.rs b/digital_asset_types/src/dao/generated/asset_data.rs index f6bf697b2..c96c265e6 100644 --- a/digital_asset_types/src/dao/generated/asset_data.rs +++ b/digital_asset_types/src/dao/generated/asset_data.rs @@ -57,9 +57,7 @@ impl PrimaryKeyTrait for PrimaryKey { } #[derive(Copy, Clone, Debug, EnumIter)] -pub enum Relation { - Asset, -} +pub enum Relation {} impl ColumnTrait for Column { type EntityName = Entity; @@ -82,15 +80,7 @@ impl ColumnTrait for Column { impl RelationTrait for Relation { fn def(&self) -> RelationDef { - match self { - Self::Asset => Entity::has_many(super::asset::Entity).into(), - } - } -} - -impl Related for Entity { - fn to() -> RelationDef { - Relation::Asset.def() + panic!("No RelationDef") } } diff --git a/digital_asset_types/src/dao/generated/asset_grouping.rs b/digital_asset_types/src/dao/generated/asset_grouping.rs index 5d5c0e749..8196d33bd 100644 --- a/digital_asset_types/src/dao/generated/asset_grouping.rs +++ b/digital_asset_types/src/dao/generated/asset_grouping.rs @@ -49,9 +49,7 @@ impl PrimaryKeyTrait for PrimaryKey { } #[derive(Copy, Clone, Debug, EnumIter)] -pub enum Relation { - Asset, -} +pub enum Relation {} impl ColumnTrait for Column { type EntityName = Entity; @@ -71,18 +69,7 @@ impl ColumnTrait for Column { impl RelationTrait for Relation { fn def(&self) -> RelationDef { - match self { - Self::Asset => Entity::belongs_to(super::asset::Entity) - .from(Column::AssetId) - .to(super::asset::Column::Id) - .into(), - } - } -} - -impl Related for Entity { - fn to() -> RelationDef { - Relation::Asset.def() + panic!("No RelationDef") } } diff --git a/digital_asset_types/src/dao/generated/asset_v1_account_attachments.rs b/digital_asset_types/src/dao/generated/asset_v1_account_attachments.rs index f8b0ff21a..2d571b25e 100644 --- a/digital_asset_types/src/dao/generated/asset_v1_account_attachments.rs +++ b/digital_asset_types/src/dao/generated/asset_v1_account_attachments.rs @@ -46,9 +46,7 @@ impl PrimaryKeyTrait for PrimaryKey { } #[derive(Copy, Clone, Debug, EnumIter)] -pub enum Relation { - Asset, -} +pub enum Relation {} impl ColumnTrait for Column { type EntityName = Entity; @@ -66,18 +64,7 @@ impl ColumnTrait for Column { impl RelationTrait for Relation { fn def(&self) -> RelationDef { - match self { - Self::Asset => Entity::belongs_to(super::asset::Entity) - .from(Column::AssetId) - .to(super::asset::Column::Id) - .into(), - } - } -} - -impl Related for Entity { - fn to() -> RelationDef { - Relation::Asset.def() + panic!("No RelationDef") } } diff --git a/digital_asset_types/src/dao/generated/cl_audits.rs b/digital_asset_types/src/dao/generated/cl_audits.rs deleted file mode 100644 index 661cc9cb1..000000000 --- a/digital_asset_types/src/dao/generated/cl_audits.rs +++ /dev/null @@ -1,94 +0,0 @@ -//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3 -use sea_orm::entity::prelude::*; -use serde::{Deserialize, Serialize}; - -use std::convert::From; - -#[derive(Copy, Clone, Default, Debug, DeriveEntity)] -pub struct Entity; - -impl EntityName for Entity { - fn table_name(&self) -> &str { - "cl_audits" - } -} - -#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel, Serialize, Deserialize)] -pub struct Model { - pub id: i64, - pub tree: Vec, - pub node_idx: i64, - pub leaf_idx: Option, - pub seq: i64, - pub level: i64, - pub hash: Vec, - pub created_at: DateTime, - pub tx: String, -} - -#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] -pub enum Column { - Id, - Tree, - NodeIdx, - LeafIdx, - Seq, - Level, - Hash, - CreatedAt, - Tx, -} - -#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] -pub enum PrimaryKey { - Id, -} - -impl PrimaryKeyTrait for PrimaryKey { - type ValueType = i64; - fn auto_increment() -> bool { - true - } -} - -#[derive(Copy, Clone, Debug, EnumIter)] -pub enum Relation {} - -impl ColumnTrait for Column { - type EntityName = Entity; - fn def(&self) -> ColumnDef { - match self { - Self::Id => ColumnType::BigInteger.def(), - Self::Tree => ColumnType::Binary.def(), - Self::NodeIdx => ColumnType::BigInteger.def(), - Self::LeafIdx => ColumnType::BigInteger.def().null(), - Self::Seq => ColumnType::BigInteger.def(), - Self::Level => ColumnType::BigInteger.def(), - Self::Hash => ColumnType::Binary.def(), - Self::CreatedAt => ColumnType::DateTime.def(), - Self::Tx => ColumnType::String(None).def(), - } - } -} - -impl RelationTrait for Relation { - fn def(&self) -> RelationDef { - panic!("No RelationDef") - } -} - -impl ActiveModelBehavior for ActiveModel {} - -impl From for ActiveModel { - fn from(item: crate::dao::cl_items::ActiveModel) -> Self { - ActiveModel { - tree: item.tree, - level: item.level, - node_idx: item.node_idx, - hash: item.hash, - seq: item.seq, - leaf_idx: item.leaf_idx, - ..Default::default() - } - } -} diff --git a/digital_asset_types/src/dao/generated/mod.rs b/digital_asset_types/src/dao/generated/mod.rs index 68e1db8fa..cb7314768 100644 --- a/digital_asset_types/src/dao/generated/mod.rs +++ b/digital_asset_types/src/dao/generated/mod.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3 +//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3 pub mod prelude; @@ -9,7 +9,6 @@ pub mod asset_data; pub mod asset_grouping; pub mod asset_v1_account_attachments; pub mod backfill_items; -pub mod cl_audits; pub mod cl_audits_v2; pub mod cl_items; pub mod raw_txn; diff --git a/digital_asset_types/src/dao/generated/prelude.rs b/digital_asset_types/src/dao/generated/prelude.rs index 58d11a50a..070ecee41 100644 --- a/digital_asset_types/src/dao/generated/prelude.rs +++ b/digital_asset_types/src/dao/generated/prelude.rs @@ -1,6 +1,5 @@ -//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3 +//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3 -#![allow(unused_imports)] pub use super::asset::Entity as Asset; pub use super::asset_authority::Entity as AssetAuthority; pub use super::asset_creators::Entity as AssetCreators; diff --git a/digital_asset_types/src/dao/generated/sea_orm_active_enums.rs b/digital_asset_types/src/dao/generated/sea_orm_active_enums.rs index 5688d3821..7576ec245 100644 --- a/digital_asset_types/src/dao/generated/sea_orm_active_enums.rs +++ b/digital_asset_types/src/dao/generated/sea_orm_active_enums.rs @@ -4,32 +4,14 @@ use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)] -#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "task_status")] -pub enum TaskStatus { - #[sea_orm(string_value = "failed")] - Failed, - #[sea_orm(string_value = "pending")] - Pending, - #[sea_orm(string_value = "running")] - Running, - #[sea_orm(string_value = "success")] - Success, -} -#[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)] -#[sea_orm( - rs_type = "String", - db_type = "Enum", - enum_name = "specification_versions" -)] -pub enum SpecificationVersions { +#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "owner_type")] +pub enum OwnerType { + #[sea_orm(string_value = "single")] + Single, + #[sea_orm(string_value = "token")] + Token, #[sea_orm(string_value = "unknown")] Unknown, - #[sea_orm(string_value = "v0")] - V0, - #[sea_orm(string_value = "v1")] - V1, - #[sea_orm(string_value = "v2")] - V2, } #[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)] #[sea_orm( @@ -48,16 +30,6 @@ pub enum RoyaltyTargetType { Unknown, } #[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)] -#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "owner_type")] -pub enum OwnerType { - #[sea_orm(string_value = "single")] - Single, - #[sea_orm(string_value = "token")] - Token, - #[sea_orm(string_value = "unknown")] - Unknown, -} -#[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)] #[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "mutability")] pub enum Mutability { #[sea_orm(string_value = "immutable")] @@ -68,12 +40,20 @@ pub enum Mutability { Unknown, } #[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)] -#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "chain_mutability")] -pub enum ChainMutability { - #[sea_orm(string_value = "immutable")] - Immutable, - #[sea_orm(string_value = "mutable")] - Mutable, +#[sea_orm( + rs_type = "String", + db_type = "Enum", + enum_name = "v1_account_attachments" +)] +pub enum V1AccountAttachments { + #[sea_orm(string_value = "edition")] + Edition, + #[sea_orm(string_value = "edition_marker")] + EditionMarker, + #[sea_orm(string_value = "master_edition_v1")] + MasterEditionV1, + #[sea_orm(string_value = "master_edition_v2")] + MasterEditionV2, #[sea_orm(string_value = "unknown")] Unknown, } @@ -106,24 +86,43 @@ pub enum SpecificationAssetClass { Unknown, } #[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)] +#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "chain_mutability")] +pub enum ChainMutability { + #[sea_orm(string_value = "immutable")] + Immutable, + #[sea_orm(string_value = "mutable")] + Mutable, + #[sea_orm(string_value = "unknown")] + Unknown, +} +#[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)] +#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "task_status")] +pub enum TaskStatus { + #[sea_orm(string_value = "failed")] + Failed, + #[sea_orm(string_value = "pending")] + Pending, + #[sea_orm(string_value = "running")] + Running, + #[sea_orm(string_value = "success")] + Success, +} +#[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)] #[sea_orm( rs_type = "String", db_type = "Enum", - enum_name = "v1_account_attachments" + enum_name = "specification_versions" )] -pub enum V1AccountAttachments { - #[sea_orm(string_value = "edition")] - Edition, - #[sea_orm(string_value = "edition_marker")] - EditionMarker, - #[sea_orm(string_value = "master_edition_v1")] - MasterEditionV1, - #[sea_orm(string_value = "master_edition_v2")] - MasterEditionV2, +pub enum SpecificationVersions { #[sea_orm(string_value = "unknown")] Unknown, + #[sea_orm(string_value = "v0")] + V0, + #[sea_orm(string_value = "v1")] + V1, + #[sea_orm(string_value = "v2")] + V2, } - #[derive(Debug, Clone, PartialEq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)] #[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "instruction")] pub enum Instruction { @@ -153,54 +152,10 @@ pub enum Instruction { UnverifyCollection, #[sea_orm(string_value = "unverify_creator")] UnverifyCreator, + #[sea_orm(string_value = "update_metadata")] + UpdateMetadata, #[sea_orm(string_value = "verify_collection")] VerifyCollection, #[sea_orm(string_value = "verify_creator")] VerifyCreator, - #[sea_orm(string_value = "update_metadata")] - UpdateMetadata, -} -// Added manually for convenience. -impl Instruction { - pub fn from_str(s: &str) -> Self { - match s { - "Burn" => Instruction::Burn, - "CancelRedeem" => Instruction::CancelRedeem, - "Compress" => Instruction::Compress, - "DecompressV1" => Instruction::DecompressV1, - "Delegate" => Instruction::Delegate, - "MintToCollectionV1" => Instruction::MintToCollectionV1, - "MintV1" => Instruction::MintV1, - "Redeem" => Instruction::Redeem, - "SetAndVerifyCollection" => Instruction::SetAndVerifyCollection, - "Transfer" => Instruction::Transfer, - "UnverifyCollection" => Instruction::UnverifyCollection, - "UnverifyCreator" => Instruction::UnverifyCreator, - "VerifyCollection" => Instruction::VerifyCollection, - "VerifyCreator" => Instruction::VerifyCreator, - "UpdateMetadata" => Instruction::UpdateMetadata, - _ => Instruction::Unknown, - } - } - - pub const fn to_str(s: &Self) -> &str { - match s { - Instruction::Burn => "Burn", - Instruction::CancelRedeem => "CancelReddem", - Instruction::Compress => "Compress", - Instruction::DecompressV1 => "DecompressV1", - Instruction::Delegate => "Delegate", - Instruction::MintToCollectionV1 => "MintToCollectionV1", - Instruction::MintV1 => "MintV1", - Instruction::Redeem => "Redeem", - Instruction::SetAndVerifyCollection => "SetAndVerifyCollection", - Instruction::Transfer => "Transfer", - Instruction::UnverifyCollection => "UnverifyCollection", - Instruction::UnverifyCreator => "UnverifyCreator", - Instruction::VerifyCollection => "VerifyCollection", - Instruction::VerifyCreator => "VerifyCreator", - Instruction::UpdateMetadata => "UpdateMetadata", - _ => "Unknown", - } - } } diff --git a/digital_asset_types/src/dao/mod.rs b/digital_asset_types/src/dao/mod.rs index 9f688dcbb..bf1e540ab 100644 --- a/digital_asset_types/src/dao/mod.rs +++ b/digital_asset_types/src/dao/mod.rs @@ -7,6 +7,8 @@ use self::sea_orm_active_enums::{ }; pub use full_asset::*; pub use generated::*; +pub mod extensions; + use sea_orm::{ entity::*, sea_query::Expr, @@ -168,7 +170,7 @@ impl SearchAssetsQuery { // If creator_address or creator_verified is set, join with asset_creators let mut joins = Vec::new(); if self.creator_address.is_some() || self.creator_verified.is_some() { - let rel = asset_creators::Relation::Asset + let rel = extensions::asset_creators::Relation::Asset .def() .rev() .on_condition(|left, right| { @@ -181,7 +183,7 @@ impl SearchAssetsQuery { if let Some(a) = self.authority_address.to_owned() { conditions = conditions.add(asset_authority::Column::Authority.eq(a)); - let rel = asset_authority::Relation::Asset + let rel = extensions::asset_authority::Relation::Asset .def() .rev() .on_condition(|left, right| { @@ -197,7 +199,7 @@ impl SearchAssetsQuery { .add(asset_grouping::Column::GroupKey.eq(g.0)) .add(asset_grouping::Column::GroupValue.eq(g.1)); conditions = conditions.add(cond); - let rel = asset_grouping::Relation::Asset + let rel = extensions::asset_grouping::Relation::Asset .def() .rev() .on_condition(|left, right| { @@ -211,7 +213,7 @@ impl SearchAssetsQuery { if let Some(ju) = self.json_uri.to_owned() { let cond = Condition::all().add(asset_data::Column::MetadataUrl.eq(ju)); conditions = conditions.add(cond); - let rel = asset_data::Relation::Asset + let rel = extensions::asset_data::Relation::Asset .def() .rev() .on_condition(|left, right| { @@ -233,7 +235,7 @@ impl SearchAssetsQuery { SimpleExpr::Custom(format!("chain_data->>'name' LIKE '%{}%'", name_as_str)); conditions = conditions.add(name_expr); - let rel = asset_data::Relation::Asset + let rel = extensions::asset_data::Relation::Asset .def() .rev() .on_condition(|left, right| { diff --git a/digital_asset_types/src/dao/scopes/asset.rs b/digital_asset_types/src/dao/scopes/asset.rs index fccec9594..58e4cbbaf 100644 --- a/digital_asset_types/src/dao/scopes/asset.rs +++ b/digital_asset_types/src/dao/scopes/asset.rs @@ -2,6 +2,7 @@ use crate::{ dao::{ asset::{self}, asset_authority, asset_creators, asset_data, asset_grouping, cl_audits_v2, + extensions::{self, instruction::PascalCase}, sea_orm_active_enums::Instruction, Cursor, FullAsset, GroupingSize, Pagination, }, @@ -70,7 +71,7 @@ pub async fn get_by_creator( get_by_related_condition( conn, condition, - asset::Relation::AssetCreators, + extensions::asset::Relation::AssetCreators, sort_by, sort_direction, pagination, @@ -130,7 +131,7 @@ pub async fn get_by_grouping( Condition::all() .add(condition) .add(asset::Column::Supply.gt(0)), - asset::Relation::AssetGrouping, + extensions::asset::Relation::AssetGrouping, sort_by, sort_direction, pagination, @@ -204,7 +205,7 @@ pub async fn get_by_authority( get_by_related_condition( conn, cond, - asset::Relation::AssetAuthority, + extensions::asset::Relation::AssetAuthority, sort_by, sort_direction, pagination, @@ -464,7 +465,7 @@ pub async fn fetch_transactions( .into_iter() .map(|transaction| { let tx = bs58::encode(transaction.tx).into_string(); - let ix = Instruction::to_str(&transaction.instruction).to_string(); + let ix = Instruction::to_pascal_case(&transaction.instruction).to_string(); (tx, ix) }) .collect(); diff --git a/migration/Cargo.toml b/migration/Cargo.toml index 219a7683d..c0202ffdd 100644 --- a/migration/Cargo.toml +++ b/migration/Cargo.toml @@ -7,7 +7,6 @@ publish = { workspace = true } [dependencies] async-std = { workspace = true, features = ["attributes", "tokio1"] } -digital_asset_types = { workspace = true, features = ["json_types", "sql_types"] } enum-iterator = { workspace = true } enum-iterator-derive = { workspace = true } sea-orm-migration = { workspace = true, features = ["runtime-tokio-rustls", "sqlx-postgres"] } diff --git a/migration/src/lib.rs b/migration/src/lib.rs index 1dc9ac22d..17c482976 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -36,6 +36,8 @@ mod m20240104_203133_add_cl_audits_v2; mod m20240104_203328_remove_cl_audits; mod m20240116_130744_add_update_metadata_ix; +pub mod model; + pub struct Migrator; #[async_trait::async_trait] diff --git a/migration/src/m20221020_052135_add_asset_hashes.rs b/migration/src/m20221020_052135_add_asset_hashes.rs index b2fe6f4c2..bf0a41f6a 100644 --- a/migration/src/m20221020_052135_add_asset_hashes.rs +++ b/migration/src/m20221020_052135_add_asset_hashes.rs @@ -1,6 +1,7 @@ -use digital_asset_types::dao::asset; use sea_orm_migration::prelude::*; +use crate::model::table::Asset; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -10,24 +11,16 @@ impl MigrationTrait for Migration { manager .alter_table( sea_query::Table::alter() - .table(asset::Entity) - .add_column( - ColumnDef::new(Alias::new("data_hash")) - .string() - .char_len(50), - ) + .table(Asset::Table) + .add_column(ColumnDef::new(Asset::DataHash).string().char_len(50)) .to_owned(), ) .await?; manager .alter_table( sea_query::Table::alter() - .table(asset::Entity) - .add_column( - ColumnDef::new(Alias::new("creator_hash")) - .string() - .char_len(50), - ) + .table(Asset::Table) + .add_column(ColumnDef::new(Asset::CreatorHash).string().char_len(50)) .to_owned(), ) .await?; @@ -38,16 +31,16 @@ impl MigrationTrait for Migration { manager .alter_table( sea_query::Table::alter() - .table(asset::Entity) - .drop_column(Alias::new("data_hash")) + .table(Asset::Table) + .drop_column(Asset::DataHash) .to_owned(), ) .await?; manager .alter_table( sea_query::Table::alter() - .table(asset::Entity) - .drop_column(Alias::new("creator_hash")) + .table(Asset::Table) + .drop_column(Asset::CreatorHash) .to_owned(), ) .await?; diff --git a/migration/src/m20221022_140350_add_creator_asset_unique_index.rs b/migration/src/m20221022_140350_add_creator_asset_unique_index.rs index 72deb33d9..6f4c21142 100644 --- a/migration/src/m20221022_140350_add_creator_asset_unique_index.rs +++ b/migration/src/m20221022_140350_add_creator_asset_unique_index.rs @@ -1,6 +1,7 @@ -use digital_asset_types::dao::asset_creators; use sea_orm_migration::prelude::*; +use crate::model::table::AssetCreators; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -11,16 +12,16 @@ impl MigrationTrait for Migration { .drop_index( sea_query::Index::drop() .name("asset_creator") - .table(asset_creators::Entity) + .table(AssetCreators::Table) .to_owned(), ) .await?; manager .alter_table( Table::alter() - .table(asset_creators::Entity) + .table(AssetCreators::Table) .add_column( - ColumnDef::new(Alias::new("position")) + ColumnDef::new(AssetCreators::Position) .small_integer() .not_null() .default(-1), @@ -33,9 +34,9 @@ impl MigrationTrait for Migration { Index::create() .unique() .name("asset_creator_unique") - .col(asset_creators::Column::AssetId) - .col(asset_creators::Column::Creator) - .table(asset_creators::Entity) + .col(AssetCreators::AssetId) + .col(AssetCreators::Creator) + .table(AssetCreators::Table) .to_owned(), ) .await?; @@ -44,9 +45,9 @@ impl MigrationTrait for Migration { Index::create() .unique() .name("asset_creator_pos_unique") - .col(asset_creators::Column::AssetId) - .col(Alias::new("position")) - .table(asset_creators::Entity) + .col(AssetCreators::AssetId) + .col(AssetCreators::Position) + .table(AssetCreators::Table) .to_owned(), ) .await?; @@ -58,7 +59,7 @@ impl MigrationTrait for Migration { .drop_index( sea_query::Index::drop() .name("asset_creator_unique") - .table(asset_creators::Entity) + .table(AssetCreators::Table) .to_owned(), ) .await?; @@ -66,7 +67,7 @@ impl MigrationTrait for Migration { .drop_index( sea_query::Index::drop() .name("asset_creator_pos_unique") - .table(asset_creators::Entity) + .table(AssetCreators::Table) .to_owned(), ) .await?; @@ -74,9 +75,9 @@ impl MigrationTrait for Migration { .create_index( sea_query::Index::create() .name("asset_creator") - .col(asset_creators::Column::AssetId) - .col(asset_creators::Column::Creator) - .table(asset_creators::Entity) + .col(AssetCreators::AssetId) + .col(AssetCreators::Creator) + .table(AssetCreators::Table) .to_owned(), ) .await?; diff --git a/migration/src/m20221025_182127_remove_creator_error_unique_index.rs b/migration/src/m20221025_182127_remove_creator_error_unique_index.rs index 37d7f4b93..fdc32a218 100644 --- a/migration/src/m20221025_182127_remove_creator_error_unique_index.rs +++ b/migration/src/m20221025_182127_remove_creator_error_unique_index.rs @@ -1,6 +1,7 @@ -use digital_asset_types::dao::asset_creators; use sea_orm_migration::prelude::*; +use crate::model::table::AssetCreators; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -12,7 +13,7 @@ impl MigrationTrait for Migration { .drop_index( sea_query::Index::drop() .name("asset_creators_asset_id") - .table(asset_creators::Entity) + .table(AssetCreators::Table) .to_owned(), ) .await?; diff --git a/migration/src/m20221026_155220_add_bg_tasks.rs b/migration/src/m20221026_155220_add_bg_tasks.rs index 8586a6013..a0aa1ed59 100644 --- a/migration/src/m20221026_155220_add_bg_tasks.rs +++ b/migration/src/m20221026_155220_add_bg_tasks.rs @@ -31,7 +31,10 @@ impl MigrationTrait for Migration { .col(ColumnDef::new(Tasks::Data).json_binary().not_null()) .col( ColumnDef::new(Tasks::Status) - .enumeration(Tasks::TaskStatus, all::().collect::>()) + .enumeration( + Tasks::TaskStatus, + all::().map(|e| e).collect::>(), + ) .not_null(), ) .col(ColumnDef::new(Tasks::CreatedAt).date_time().not_null()) diff --git a/migration/src/m20221104_094327_add_backfiller_failed.rs b/migration/src/m20221104_094327_add_backfiller_failed.rs index a5972ad46..20fed6e4d 100644 --- a/migration/src/m20221104_094327_add_backfiller_failed.rs +++ b/migration/src/m20221104_094327_add_backfiller_failed.rs @@ -1,6 +1,7 @@ -use digital_asset_types::dao::backfill_items; use sea_orm_migration::prelude::*; +use crate::model::table::BackfillItems; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -11,9 +12,9 @@ impl MigrationTrait for Migration { manager .alter_table( Table::alter() - .table(backfill_items::Entity) + .table(BackfillItems::Table) .add_column( - ColumnDef::new(Alias::new("failed")) + ColumnDef::new(BackfillItems::Failed) .boolean() .not_null() .default(false), @@ -28,8 +29,8 @@ impl MigrationTrait for Migration { manager .alter_table( Table::alter() - .table(backfill_items::Entity) - .drop_column(Alias::new("failed")) + .table(BackfillItems::Table) + .drop_column(BackfillItems::Failed) .to_owned(), ) .await diff --git a/migration/src/m20221114_173041_add_collection_info.rs b/migration/src/m20221114_173041_add_collection_info.rs index d48b890c3..c4f210bff 100644 --- a/migration/src/m20221114_173041_add_collection_info.rs +++ b/migration/src/m20221114_173041_add_collection_info.rs @@ -1,6 +1,7 @@ -use digital_asset_types::dao::asset; use sea_orm_migration::prelude::*; +use crate::model::table::Asset; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -10,7 +11,7 @@ impl MigrationTrait for Migration { manager .alter_table( sea_query::Table::alter() - .table(asset::Entity) + .table(Asset::Table) .add_column(ColumnDef::new(Alias::new("collection")).binary()) .to_owned(), ) @@ -19,7 +20,7 @@ impl MigrationTrait for Migration { manager .alter_table( sea_query::Table::alter() - .table(asset::Entity) + .table(Asset::Table) .add_column( ColumnDef::new(Alias::new("collection_verified")) .boolean() @@ -37,7 +38,7 @@ impl MigrationTrait for Migration { manager .alter_table( sea_query::Table::alter() - .table(asset::Entity) + .table(Asset::Table) .drop_column(Alias::new("collection")) .to_owned(), ) @@ -45,7 +46,7 @@ impl MigrationTrait for Migration { manager .alter_table( sea_query::Table::alter() - .table(asset::Entity) + .table(Asset::Table) .drop_column(Alias::new("collection_verified")) .to_owned(), ) diff --git a/migration/src/m20221115_165700_add_backfiller_locked.rs b/migration/src/m20221115_165700_add_backfiller_locked.rs index 0d5955c7d..aca1e33d7 100644 --- a/migration/src/m20221115_165700_add_backfiller_locked.rs +++ b/migration/src/m20221115_165700_add_backfiller_locked.rs @@ -1,6 +1,7 @@ -use digital_asset_types::dao::backfill_items; use sea_orm_migration::prelude::*; +use crate::model::table::BackfillItems; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -11,9 +12,9 @@ impl MigrationTrait for Migration { manager .alter_table( Table::alter() - .table(backfill_items::Entity) + .table(BackfillItems::Table) .add_column( - ColumnDef::new(Alias::new("locked")) + ColumnDef::new(BackfillItems::Locked) .boolean() .not_null() .default(false), @@ -28,8 +29,8 @@ impl MigrationTrait for Migration { manager .alter_table( Table::alter() - .table(backfill_items::Entity) - .drop_column(Alias::new("locked")) + .table(BackfillItems::Table) + .drop_column(BackfillItems::Locked) .to_owned(), ) .await diff --git a/migration/src/m20221116_110500_add_backfiller_failed_and_locked_indeces.rs b/migration/src/m20221116_110500_add_backfiller_failed_and_locked_indeces.rs index 605568ff2..3db51dd53 100644 --- a/migration/src/m20221116_110500_add_backfiller_failed_and_locked_indeces.rs +++ b/migration/src/m20221116_110500_add_backfiller_failed_and_locked_indeces.rs @@ -1,6 +1,7 @@ -use digital_asset_types::dao::backfill_items; use sea_orm_migration::prelude::*; +use crate::model::table::BackfillItems; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -11,8 +12,8 @@ impl MigrationTrait for Migration { .create_index( Index::create() .name("backfill_items_failed_idx") - .col(backfill_items::Column::Failed) - .table(backfill_items::Entity) + .col(BackfillItems::Failed) + .table(BackfillItems::Table) .to_owned(), ) .await?; @@ -20,9 +21,9 @@ impl MigrationTrait for Migration { .create_index( Index::create() .name("backfill_items_tree_failed_idx") - .col(backfill_items::Column::Tree) - .col(backfill_items::Column::Failed) - .table(backfill_items::Entity) + .col(BackfillItems::Tree) + .col(BackfillItems::Failed) + .table(BackfillItems::Table) .to_owned(), ) .await?; @@ -30,8 +31,8 @@ impl MigrationTrait for Migration { .create_index( Index::create() .name("backfill_items_locked_idx") - .col(backfill_items::Column::Locked) - .table(backfill_items::Entity) + .col(BackfillItems::Locked) + .table(BackfillItems::Table) .to_owned(), ) .await?; @@ -39,9 +40,9 @@ impl MigrationTrait for Migration { .create_index( Index::create() .name("backfill_items_tree_locked_idx") - .col(backfill_items::Column::Tree) - .col(backfill_items::Column::Locked) - .table(backfill_items::Entity) + .col(BackfillItems::Tree) + .col(BackfillItems::Locked) + .table(BackfillItems::Table) .to_owned(), ) .await?; @@ -54,7 +55,7 @@ impl MigrationTrait for Migration { .drop_index( sea_query::Index::drop() .name("backfill_items_failed_idx") - .table(backfill_items::Entity) + .table(BackfillItems::Table) .to_owned(), ) .await?; @@ -62,7 +63,7 @@ impl MigrationTrait for Migration { .drop_index( sea_query::Index::drop() .name("backfill_items_tree_failed_idx") - .table(backfill_items::Entity) + .table(BackfillItems::Table) .to_owned(), ) .await?; @@ -70,7 +71,7 @@ impl MigrationTrait for Migration { .drop_index( sea_query::Index::drop() .name("backfill_items_locked_idx") - .table(backfill_items::Entity) + .table(BackfillItems::Table) .to_owned(), ) .await?; @@ -78,7 +79,7 @@ impl MigrationTrait for Migration { .drop_index( sea_query::Index::drop() .name("backfill_items_tree_locked_idx") - .table(backfill_items::Entity) + .table(BackfillItems::Table) .to_owned(), ) .await?; diff --git a/migration/src/m20230105_160722_drop_collection_info.rs b/migration/src/m20230105_160722_drop_collection_info.rs index 833b91caa..907a9eff5 100644 --- a/migration/src/m20230105_160722_drop_collection_info.rs +++ b/migration/src/m20230105_160722_drop_collection_info.rs @@ -1,6 +1,7 @@ -use digital_asset_types::dao::asset; use sea_orm_migration::prelude::*; +use crate::model::table::Asset; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -10,7 +11,7 @@ impl MigrationTrait for Migration { manager .alter_table( sea_query::Table::alter() - .table(asset::Entity) + .table(Asset::Table) .drop_column(Alias::new("collection")) .to_owned(), ) @@ -18,7 +19,7 @@ impl MigrationTrait for Migration { manager .alter_table( sea_query::Table::alter() - .table(asset::Entity) + .table(Asset::Table) .drop_column(Alias::new("collection_verified")) .to_owned(), ) @@ -31,7 +32,7 @@ impl MigrationTrait for Migration { manager .alter_table( sea_query::Table::alter() - .table(asset::Entity) + .table(Asset::Table) .add_column(ColumnDef::new(Alias::new("collection")).binary()) .to_owned(), ) @@ -40,7 +41,7 @@ impl MigrationTrait for Migration { manager .alter_table( sea_query::Table::alter() - .table(asset::Entity) + .table(Asset::Table) .add_column( ColumnDef::new(Alias::new("collection_verified")) .boolean() diff --git a/migration/src/m20230106_051135_unique_groupings.rs b/migration/src/m20230106_051135_unique_groupings.rs index 2dc0d4663..b538cb195 100644 --- a/migration/src/m20230106_051135_unique_groupings.rs +++ b/migration/src/m20230106_051135_unique_groupings.rs @@ -1,6 +1,7 @@ -use digital_asset_types::dao::asset_grouping; use sea_orm_migration::prelude::*; +use crate::model::table::AssetGrouping; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -11,7 +12,7 @@ impl MigrationTrait for Migration { .drop_index( sea_query::Index::drop() .name("asset_grouping_value") - .table(asset_grouping::Entity) + .table(AssetGrouping::Table) .to_owned(), ) .await?; @@ -20,9 +21,9 @@ impl MigrationTrait for Migration { Index::create() .unique() .name("asset_grouping_key_unique") - .col(asset_grouping::Column::AssetId) - .col(asset_grouping::Column::GroupKey) - .table(asset_grouping::Entity) + .col(AssetGrouping::AssetId) + .col(AssetGrouping::GroupKey) + .table(AssetGrouping::Table) .to_owned(), ) .await?; @@ -34,7 +35,7 @@ impl MigrationTrait for Migration { .drop_index( sea_query::Index::drop() .name("asset_grouping_key_unique") - .table(asset_grouping::Entity) + .table(AssetGrouping::Table) .to_owned(), ) .await?; @@ -43,9 +44,9 @@ impl MigrationTrait for Migration { .create_index( sea_query::Index::create() .name("asset_grouping_value") - .col(asset_grouping::Column::AssetId) - .col(asset_grouping::Column::GroupKey) - .table(asset_grouping::Entity) + .col(AssetGrouping::AssetId) + .col(AssetGrouping::GroupKey) + .table(AssetGrouping::Table) .to_owned(), ) .await?; diff --git a/migration/src/m20230131_140613_change_token_account_indexes.rs b/migration/src/m20230131_140613_change_token_account_indexes.rs index 2ee601c62..3d28256cf 100644 --- a/migration/src/m20230131_140613_change_token_account_indexes.rs +++ b/migration/src/m20230131_140613_change_token_account_indexes.rs @@ -1,8 +1,9 @@ -use digital_asset_types::dao::token_accounts; use sea_orm_migration::{ prelude::*, sea_orm::{ConnectionTrait, DatabaseBackend, Statement}, }; + +use crate::model::table::TokenAccounts; #[derive(DeriveMigrationName)] pub struct Migration; @@ -13,7 +14,7 @@ impl MigrationTrait for Migration { .drop_index( sea_query::Index::drop() .name("ta_amount") - .table(token_accounts::Entity) + .table(TokenAccounts::Table) .to_owned(), ) .await?; @@ -22,7 +23,7 @@ impl MigrationTrait for Migration { .drop_index( sea_query::Index::drop() .name("ta_amount_del") - .table(token_accounts::Entity) + .table(TokenAccounts::Table) .to_owned(), ) .await?; @@ -31,7 +32,7 @@ impl MigrationTrait for Migration { .drop_index( sea_query::Index::drop() .name("ta_slot_updated_idx") - .table(token_accounts::Entity) + .table(TokenAccounts::Table) .to_owned(), ) .await?; @@ -59,8 +60,8 @@ impl MigrationTrait for Migration { sea_query::Index::create() .name("ta_amount") .index_type(sea_query::IndexType::BTree) - .col(token_accounts::Column::Amount) - .table(token_accounts::Entity) + .col(TokenAccounts::Amount) + .table(TokenAccounts::Table) .to_owned(), ) .await?; @@ -70,8 +71,8 @@ impl MigrationTrait for Migration { sea_query::Index::create() .name("ta_amount_del") .index_type(sea_query::IndexType::BTree) - .col(token_accounts::Column::DelegatedAmount) - .table(token_accounts::Entity) + .col(TokenAccounts::DelegatedAmount) + .table(TokenAccounts::Table) .to_owned(), ) .await?; @@ -81,18 +82,10 @@ impl MigrationTrait for Migration { sea_query::Index::create() .name("ta_slot_updated_idx") .index_type(sea_query::IndexType::BTree) - .table(token_accounts::Entity) + .table(TokenAccounts::Table) .to_owned(), ) .await?; Ok(()) } } - -/// Learn more at https://docs.rs/sea-query#iden -#[allow(dead_code)] -#[allow(clippy::upper_case_acronyms)] -#[derive(Iden)] -enum Index { - BRIN, -} diff --git a/migration/src/m20230203_205959_improve_upsert_perf.rs b/migration/src/m20230203_205959_improve_upsert_perf.rs index 02ae33dd0..584f8ab47 100644 --- a/migration/src/m20230203_205959_improve_upsert_perf.rs +++ b/migration/src/m20230203_205959_improve_upsert_perf.rs @@ -1,8 +1,9 @@ -use digital_asset_types::dao::{asset_data, tokens}; use sea_orm_migration::{ prelude::*, sea_orm::{ConnectionTrait, DatabaseBackend, Statement}, }; + +use crate::model::table::{AssetData, Tokens}; #[derive(DeriveMigrationName)] pub struct Migration; @@ -13,7 +14,7 @@ impl MigrationTrait for Migration { .drop_index( sea_query::Index::drop() .name("t_slot_updated_idx") - .table(tokens::Entity) + .table(Tokens::Table) .to_owned(), ) .await?; @@ -22,7 +23,7 @@ impl MigrationTrait for Migration { .drop_index( sea_query::Index::drop() .name("t_supply") - .table(tokens::Entity) + .table(Tokens::Table) .to_owned(), ) .await?; @@ -31,7 +32,7 @@ impl MigrationTrait for Migration { .drop_index( sea_query::Index::drop() .name("t_decimals") - .table(tokens::Entity) + .table(Tokens::Table) .to_owned(), ) .await?; @@ -64,7 +65,7 @@ impl MigrationTrait for Migration { .drop_index( sea_query::Index::drop() .name("slot_updated_idx") - .table(asset_data::Entity) + .table(AssetData::Table) .to_owned(), ) .await?; diff --git a/migration/src/m20230310_162227_add_indexes_to_bg.rs b/migration/src/m20230310_162227_add_indexes_to_bg.rs index 5dcdc9bfd..2100ec552 100644 --- a/migration/src/m20230310_162227_add_indexes_to_bg.rs +++ b/migration/src/m20230310_162227_add_indexes_to_bg.rs @@ -1,9 +1,10 @@ -use digital_asset_types::dao::tasks; use sea_orm_migration::{ prelude::*, sea_orm::{ConnectionTrait, DatabaseBackend, Statement}, }; +use crate::model::table::Tasks; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -50,7 +51,7 @@ impl MigrationTrait for Migration { .drop_index( sea_query::Index::drop() .name("tasks_created_at") - .table(tasks::Entity) + .table(Tasks::Table) .to_owned(), ) .await?; @@ -58,7 +59,7 @@ impl MigrationTrait for Migration { .drop_index( sea_query::Index::drop() .name("tasks_locked_until") - .table(tasks::Entity) + .table(Tasks::Table) .to_owned(), ) .await?; @@ -66,7 +67,7 @@ impl MigrationTrait for Migration { .drop_index( sea_query::Index::drop() .name("task_attempts") - .table(tasks::Entity) + .table(Tasks::Table) .to_owned(), ) .await?; @@ -74,7 +75,7 @@ impl MigrationTrait for Migration { .drop_index( sea_query::Index::drop() .name("task_status") - .table(tasks::Entity) + .table(Tasks::Table) .to_owned(), ) .await?; diff --git a/migration/src/m20230510_183736_add_indices_to_assets.rs b/migration/src/m20230510_183736_add_indices_to_assets.rs index 3a7e58f1d..7b66de18a 100644 --- a/migration/src/m20230510_183736_add_indices_to_assets.rs +++ b/migration/src/m20230510_183736_add_indices_to_assets.rs @@ -1,6 +1,7 @@ -use digital_asset_types::dao::{asset_authority, asset_creators}; use sea_orm_migration::prelude::*; +use crate::model::table::{AssetAuthority, AssetCreators}; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -11,8 +12,8 @@ impl MigrationTrait for Migration { .create_index( Index::create() .name("idx_asset_creators_asset_id") - .col(asset_creators::Column::AssetId) - .table(asset_creators::Entity) + .col(AssetCreators::AssetId) + .table(AssetCreators::Table) .to_owned(), ) .await?; @@ -21,8 +22,8 @@ impl MigrationTrait for Migration { .create_index( Index::create() .name("idx_asset_creators_creator") - .col(asset_creators::Column::Creator) - .table(asset_creators::Entity) + .col(AssetCreators::Creator) + .table(AssetCreators::Table) .to_owned(), ) .await?; @@ -31,8 +32,8 @@ impl MigrationTrait for Migration { .create_index( Index::create() .name("idx_asset_authority_authority") - .col(asset_authority::Column::Authority) - .table(asset_authority::Entity) + .col(AssetAuthority::Authority) + .table(AssetAuthority::Table) .to_owned(), ) .await?; @@ -44,7 +45,7 @@ impl MigrationTrait for Migration { .drop_index( Index::drop() .name("idx_asset_creators_asset_id") - .table(asset_creators::Entity) + .table(AssetCreators::Table) .to_owned(), ) .await?; @@ -53,7 +54,7 @@ impl MigrationTrait for Migration { .drop_index( Index::drop() .name("idx_asset_creators_creator") - .table(asset_creators::Entity) + .table(AssetCreators::Table) .to_owned(), ) .await?; @@ -62,7 +63,7 @@ impl MigrationTrait for Migration { .drop_index( Index::drop() .name("idx_asset_authority_authority") - .table(asset_authority::Entity) + .table(AssetAuthority::Table) .to_owned(), ) .await?; diff --git a/migration/src/m20230516_185005_add_reindex_to_assets.rs b/migration/src/m20230516_185005_add_reindex_to_assets.rs index 81d339701..ce5a86725 100644 --- a/migration/src/m20230516_185005_add_reindex_to_assets.rs +++ b/migration/src/m20230516_185005_add_reindex_to_assets.rs @@ -1,6 +1,7 @@ -use digital_asset_types::dao::asset_data; use sea_orm_migration::prelude::*; +use crate::model::table::AssetData; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -10,12 +11,8 @@ impl MigrationTrait for Migration { manager .alter_table( sea_query::Table::alter() - .table(asset_data::Entity) - .add_column( - ColumnDef::new(Alias::new("reindex")) - .boolean() - .default(false), - ) + .table(AssetData::Table) + .add_column(ColumnDef::new(AssetData::Reindex).boolean().default(false)) .to_owned(), ) .await?; @@ -26,8 +23,8 @@ impl MigrationTrait for Migration { manager .alter_table( sea_query::Table::alter() - .table(asset_data::Entity) - .drop_column(Alias::new("reindex")) + .table(AssetData::Table) + .drop_column(AssetData::Reindex) .to_owned(), ) .await?; diff --git a/migration/src/m20230526_120101_add_owner_delegate_sequence_number.rs b/migration/src/m20230526_120101_add_owner_delegate_sequence_number.rs index 330629abd..312ab84d0 100644 --- a/migration/src/m20230526_120101_add_owner_delegate_sequence_number.rs +++ b/migration/src/m20230526_120101_add_owner_delegate_sequence_number.rs @@ -1,6 +1,7 @@ -use digital_asset_types::dao::asset; use sea_orm_migration::prelude::*; +use crate::model::table::Asset; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -10,8 +11,8 @@ impl MigrationTrait for Migration { manager .alter_table( Table::alter() - .table(asset::Entity) - .add_column(ColumnDef::new(Alias::new("owner_delegate_seq")).big_integer()) + .table(Asset::Table) + .add_column(ColumnDef::new(Asset::OwnerDelegateSeq).big_integer()) .to_owned(), ) .await?; @@ -23,8 +24,8 @@ impl MigrationTrait for Migration { manager .alter_table( Table::alter() - .table(asset::Entity) - .drop_column(Alias::new("owner_delegate_seq")) + .table(Asset::Table) + .drop_column(Asset::OwnerDelegateSeq) .to_owned(), ) .await?; diff --git a/migration/src/m20230620_120101_add_was_decompressed.rs b/migration/src/m20230620_120101_add_was_decompressed.rs index f2abae13c..beefe7cc7 100644 --- a/migration/src/m20230620_120101_add_was_decompressed.rs +++ b/migration/src/m20230620_120101_add_was_decompressed.rs @@ -1,6 +1,7 @@ -use digital_asset_types::dao::asset; use sea_orm_migration::prelude::*; +use crate::model::table::Asset; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -10,7 +11,7 @@ impl MigrationTrait for Migration { manager .alter_table( Table::alter() - .table(asset::Entity) + .table(Asset::Table) .add_column( ColumnDef::new(Alias::new("was_decompressed")) .boolean() @@ -28,7 +29,7 @@ impl MigrationTrait for Migration { manager .alter_table( Table::alter() - .table(asset::Entity) + .table(Asset::Table) .drop_column(Alias::new("was_decompressed")) .to_owned(), ) diff --git a/migration/src/m20230623_120101_add_leaf_sequence_number.rs b/migration/src/m20230623_120101_add_leaf_sequence_number.rs index 6ffee258d..95ba4cb91 100644 --- a/migration/src/m20230623_120101_add_leaf_sequence_number.rs +++ b/migration/src/m20230623_120101_add_leaf_sequence_number.rs @@ -1,6 +1,7 @@ -use digital_asset_types::dao::asset; use sea_orm_migration::prelude::*; +use crate::model::table::Asset; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -10,8 +11,8 @@ impl MigrationTrait for Migration { manager .alter_table( Table::alter() - .table(asset::Entity) - .add_column(ColumnDef::new(Alias::new("leaf_seq")).big_integer()) + .table(Asset::Table) + .add_column(ColumnDef::new(Asset::LeafSeq).big_integer()) .to_owned(), ) .await?; @@ -23,8 +24,8 @@ impl MigrationTrait for Migration { manager .alter_table( Table::alter() - .table(asset::Entity) - .drop_column(Alias::new("leaf_seq")) + .table(Asset::Table) + .drop_column(Asset::LeafSeq) .to_owned(), ) .await?; diff --git a/migration/src/m20230720_120101_add_asset_grouping_verified.rs b/migration/src/m20230720_120101_add_asset_grouping_verified.rs index 8f1cfd4cc..801d379bd 100644 --- a/migration/src/m20230720_120101_add_asset_grouping_verified.rs +++ b/migration/src/m20230720_120101_add_asset_grouping_verified.rs @@ -1,6 +1,7 @@ -use digital_asset_types::dao::asset_grouping; use sea_orm_migration::prelude::*; +use crate::model::table::AssetGrouping; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -11,9 +12,9 @@ impl MigrationTrait for Migration { manager .alter_table( Table::alter() - .table(asset_grouping::Entity) + .table(AssetGrouping::Table) .add_column( - ColumnDef::new(Alias::new("verified")) + ColumnDef::new(AssetGrouping::Verified) .boolean() .not_null() .default(false), @@ -28,8 +29,8 @@ impl MigrationTrait for Migration { manager .alter_table( Table::alter() - .table(asset_grouping::Entity) - .drop_column(Alias::new("verified")) + .table(AssetGrouping::Table) + .drop_column(AssetGrouping::Verified) .to_owned(), ) .await diff --git a/migration/src/m20230724_120101_add_group_info_seq.rs b/migration/src/m20230724_120101_add_group_info_seq.rs index 89f2414a5..131bb208e 100644 --- a/migration/src/m20230724_120101_add_group_info_seq.rs +++ b/migration/src/m20230724_120101_add_group_info_seq.rs @@ -1,6 +1,7 @@ -use digital_asset_types::dao::asset_grouping; use sea_orm_migration::prelude::*; +use crate::model::table::AssetGrouping; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -11,8 +12,8 @@ impl MigrationTrait for Migration { manager .alter_table( Table::alter() - .table(asset_grouping::Entity) - .add_column(ColumnDef::new(Alias::new("group_info_seq")).big_integer()) + .table(AssetGrouping::Table) + .add_column(ColumnDef::new(AssetGrouping::GroupInfoSeq).big_integer()) .to_owned(), ) .await?; @@ -25,8 +26,8 @@ impl MigrationTrait for Migration { manager .alter_table( Table::alter() - .table(asset_grouping::Entity) - .drop_column(Alias::new("group_info_seq")) + .table(AssetGrouping::Table) + .drop_column(AssetGrouping::GroupInfoSeq) .to_owned(), ) .await?; diff --git a/migration/src/m20230726_013107_remove_not_null_constraint_from_group_value.rs b/migration/src/m20230726_013107_remove_not_null_constraint_from_group_value.rs index 2ed0879ee..6a2098779 100644 --- a/migration/src/m20230726_013107_remove_not_null_constraint_from_group_value.rs +++ b/migration/src/m20230726_013107_remove_not_null_constraint_from_group_value.rs @@ -1,6 +1,7 @@ -use digital_asset_types::dao::asset_grouping; use sea_orm_migration::prelude::*; +use crate::model::table::AssetGrouping; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -10,8 +11,8 @@ impl MigrationTrait for Migration { manager .alter_table( sea_query::Table::alter() - .table(asset_grouping::Entity) - .modify_column(ColumnDef::new(asset_grouping::Column::GroupValue).null()) + .table(AssetGrouping::Table) + .modify_column(ColumnDef::new(AssetGrouping::GroupValue).null()) .to_owned(), ) .await?; @@ -25,8 +26,8 @@ impl MigrationTrait for Migration { manager .alter_table( sea_query::Table::alter() - .table(asset_grouping::Entity) - .modify_column(ColumnDef::new(asset_grouping::Column::GroupValue).not_null()) + .table(AssetGrouping::Table) + .modify_column(ColumnDef::new(AssetGrouping::GroupValue).not_null()) .to_owned(), ) .await?; diff --git a/migration/src/m20230918_182123_add_raw_name_symbol.rs b/migration/src/m20230918_182123_add_raw_name_symbol.rs index 86f019543..5915ecac8 100644 --- a/migration/src/m20230918_182123_add_raw_name_symbol.rs +++ b/migration/src/m20230918_182123_add_raw_name_symbol.rs @@ -1,6 +1,7 @@ -use digital_asset_types::dao::asset_data; use sea_orm_migration::prelude::*; +use crate::model::table::AssetData; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -10,16 +11,16 @@ impl MigrationTrait for Migration { manager .alter_table( sea_query::Table::alter() - .table(asset_data::Entity) - .add_column(ColumnDef::new(Alias::new("raw_name")).binary()) + .table(AssetData::Table) + .add_column(ColumnDef::new(AssetData::RawName).binary()) .to_owned(), ) .await?; manager .alter_table( sea_query::Table::alter() - .table(asset_data::Entity) - .add_column(ColumnDef::new(Alias::new("raw_symbol")).binary()) + .table(AssetData::Table) + .add_column(ColumnDef::new(AssetData::RawSymbol).binary()) .to_owned(), ) .await?; @@ -30,8 +31,8 @@ impl MigrationTrait for Migration { manager .alter_table( sea_query::Table::alter() - .table(asset_data::Entity) - .drop_column(Alias::new("raw_name")) + .table(AssetData::Table) + .drop_column(AssetData::RawName) .to_owned(), ) .await?; @@ -39,8 +40,8 @@ impl MigrationTrait for Migration { manager .alter_table( sea_query::Table::alter() - .table(asset_data::Entity) - .drop_column(Alias::new("raw_symbol")) + .table(AssetData::Table) + .drop_column(AssetData::RawSymbol) .to_owned(), ) .await?; diff --git a/migration/src/m20230919_072154_cl_audits.rs b/migration/src/m20230919_072154_cl_audits.rs index 172c290d6..a3efecb27 100644 --- a/migration/src/m20230919_072154_cl_audits.rs +++ b/migration/src/m20230919_072154_cl_audits.rs @@ -1,5 +1,7 @@ use sea_orm_migration::prelude::*; +use crate::model::table::ClAudits; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -42,18 +44,3 @@ impl MigrationTrait for Migration { .await } } - -/// Learn more at https://docs.rs/sea-query#iden -#[derive(Iden)] -pub enum ClAudits { - Table, - Id, - Tree, - NodeIdx, - LeafIdx, - Seq, - Level, - Hash, - CreatedAt, - Tx, -} diff --git a/migration/src/m20231019_120101_add_seq_numbers_bgum_update_metadata.rs b/migration/src/m20231019_120101_add_seq_numbers_bgum_update_metadata.rs index 29d5f546b..29161637a 100644 --- a/migration/src/m20231019_120101_add_seq_numbers_bgum_update_metadata.rs +++ b/migration/src/m20231019_120101_add_seq_numbers_bgum_update_metadata.rs @@ -1,6 +1,7 @@ -use digital_asset_types::dao::{asset, asset_data}; use sea_orm_migration::prelude::*; +use crate::model::table::{Asset, AssetData}; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -10,8 +11,8 @@ impl MigrationTrait for Migration { manager .alter_table( Table::alter() - .table(asset_data::Entity) - .add_column(ColumnDef::new(Alias::new("base_info_seq")).big_integer()) + .table(AssetData::Table) + .add_column(ColumnDef::new(AssetData::BaseInfoSeq).big_integer()) .to_owned(), ) .await?; @@ -19,8 +20,8 @@ impl MigrationTrait for Migration { manager .alter_table( Table::alter() - .table(asset::Entity) - .add_column(ColumnDef::new(Alias::new("base_info_seq")).big_integer()) + .table(Asset::Table) + .add_column(ColumnDef::new(Asset::BaseInfoSeq).big_integer()) .to_owned(), ) .await?; @@ -32,8 +33,8 @@ impl MigrationTrait for Migration { manager .alter_table( Table::alter() - .table(asset_data::Entity) - .drop_column(Alias::new("base_info_seq")) + .table(AssetData::Table) + .drop_column(AssetData::BaseInfoSeq) .to_owned(), ) .await?; @@ -41,8 +42,8 @@ impl MigrationTrait for Migration { manager .alter_table( Table::alter() - .table(asset::Entity) - .drop_column(Alias::new("base_info_seq")) + .table(Asset::Table) + .drop_column(Asset::BaseInfoSeq) .to_owned(), ) .await?; diff --git a/migration/src/m20231206_120101_remove_was_decompressed.rs b/migration/src/m20231206_120101_remove_was_decompressed.rs index 16319339a..ea6cf7c22 100644 --- a/migration/src/m20231206_120101_remove_was_decompressed.rs +++ b/migration/src/m20231206_120101_remove_was_decompressed.rs @@ -1,6 +1,7 @@ -use digital_asset_types::dao::asset; use sea_orm_migration::prelude::*; +use crate::model::table::Asset; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -10,8 +11,8 @@ impl MigrationTrait for Migration { manager .alter_table( Table::alter() - .table(asset::Entity) - .drop_column(Alias::new("was_decompressed")) + .table(Asset::Table) + .drop_column(Asset::WasDecompressed) .to_owned(), ) .await?; @@ -23,9 +24,9 @@ impl MigrationTrait for Migration { manager .alter_table( Table::alter() - .table(asset::Entity) + .table(Asset::Table) .add_column( - ColumnDef::new(Alias::new("was_decompressed")) + ColumnDef::new(Asset::WasDecompressed) .boolean() .not_null() .default(false), diff --git a/migration/src/m20240104_203133_add_cl_audits_v2.rs b/migration/src/m20240104_203133_add_cl_audits_v2.rs index ed1561ff2..0fef946e1 100644 --- a/migration/src/m20240104_203133_add_cl_audits_v2.rs +++ b/migration/src/m20240104_203133_add_cl_audits_v2.rs @@ -1,8 +1,11 @@ -use enum_iterator::{all, Sequence}; +use enum_iterator::all; use sea_orm_migration::prelude::*; use sea_orm_migration::sea_orm::{ConnectionTrait, DatabaseBackend, Statement}; use sea_orm_migration::sea_query::extension::postgres::Type; +use crate::model::r#enum::BubblegumInstruction; +use crate::model::table::ClAuditsV2; + #[derive(DeriveMigrationName)] pub struct Migration; @@ -75,35 +78,3 @@ impl MigrationTrait for Migration { Ok(()) } } - -/// Learn more at https://docs.rs/sea-query#iden -#[derive(Iden)] -pub enum ClAuditsV2 { - Table, - Id, - Tree, - LeafIdx, - Seq, - CreatedAt, - Tx, - Instruction, -} - -#[derive(Iden, Debug, PartialEq, Sequence)] -enum BubblegumInstruction { - Unknown, - MintV1, - Redeem, - CancelRedeem, - Transfer, - Delegate, - DecompressV1, - Compress, - Burn, - VerifyCreator, - UnverifyCreator, - VerifyCollection, - UnverifyCollection, - SetAndVerifyCollection, - MintToCollectionV1, -} diff --git a/migration/src/m20240104_203328_remove_cl_audits.rs b/migration/src/m20240104_203328_remove_cl_audits.rs index c0e115edb..0a10302f4 100644 --- a/migration/src/m20240104_203328_remove_cl_audits.rs +++ b/migration/src/m20240104_203328_remove_cl_audits.rs @@ -2,7 +2,7 @@ use sea_orm::Statement; use sea_orm_migration::prelude::*; use sea_orm_migration::sea_orm::{ConnectionTrait, DatabaseBackend}; -use crate::m20230919_072154_cl_audits::ClAudits; +use crate::model::table::ClAudits; #[derive(DeriveMigrationName)] pub struct Migration; diff --git a/migration/src/m20240116_130744_add_update_metadata_ix.rs b/migration/src/m20240116_130744_add_update_metadata_ix.rs index 8f5a3bcef..7f35f8b48 100644 --- a/migration/src/m20240116_130744_add_update_metadata_ix.rs +++ b/migration/src/m20240116_130744_add_update_metadata_ix.rs @@ -1,6 +1,7 @@ -use crate::m20240104_203133_add_cl_audits_v2::ClAuditsV2; use sea_orm_migration::{prelude::*, sea_query::extension::postgres::Type}; +use crate::model::table::ClAuditsV2; + #[derive(DeriveMigrationName)] pub struct Migration; diff --git a/migration/src/model/enum.rs b/migration/src/model/enum.rs new file mode 100644 index 000000000..4479367b0 --- /dev/null +++ b/migration/src/model/enum.rs @@ -0,0 +1,31 @@ +use enum_iterator::Sequence; +use sea_orm_migration::{prelude::*, sea_orm::EnumIter}; + +#[derive(Copy, Clone, Iden, EnumIter)] +pub enum Mutability { + Immutable, + Mutable, + Unknown, +} + +#[derive(Iden, Debug, PartialEq, Sequence)] +pub enum BubblegumInstruction { + Unknown, + MintV1, + Redeem, + CancelRedeem, + Transfer, + Delegate, + DecompressV1, + Compress, + Burn, + VerifyCreator, + UnverifyCreator, + VerifyCollection, + UnverifyCollection, + SetAndVerifyCollection, + MintToCollectionV1, + // Any new values cannot be added here, or else they will be added twice by the migrator (which will fail). + // We need to use an alias instead. + // UpdateMetadata, +} diff --git a/migration/src/model/mod.rs b/migration/src/model/mod.rs new file mode 100644 index 000000000..581e012a3 --- /dev/null +++ b/migration/src/model/mod.rs @@ -0,0 +1,2 @@ +pub mod r#enum; +pub mod table; diff --git a/migration/src/model/table.rs b/migration/src/model/table.rs new file mode 100644 index 000000000..a77e4abc0 --- /dev/null +++ b/migration/src/model/table.rs @@ -0,0 +1,168 @@ +use sea_orm_migration::prelude::*; + +#[derive(Copy, Clone, Iden)] +pub enum AssetCreators { + Table, + Id, + AssetId, + Creator, + Position, + Share, + Verified, + Seq, +} + +#[derive(Copy, Clone, Iden)] +pub enum AssetAuthority { + Table, + Id, + AssetId, + Authority, + SlotUpdated, + Seq, +} + +#[derive(Copy, Clone, Iden)] +pub enum AssetGrouping { + Table, + Id, + AssetId, + GroupKey, + GroupValue, + Seq, + SlotUpdated, + Verified, + GroupInfoSeq, +} + +#[derive(Copy, Clone, Iden)] +pub enum BackfillItems { + Table, + Id, + Tree, + Seq, + Slot, + ForceChk, + Backfilled, + Failed, + Locked, +} + +#[derive(Copy, Clone, Iden)] +pub enum Asset { + Table, + Id, + AltId, + SpecificationVersion, + SpecificationAssetClass, + Owner, + OwnerType, + Delegate, + Frozen, + Supply, + SupplyMint, + Compressed, + Compressible, + Seq, + TreeId, + Leaf, + Nonce, + RoyaltyTargetType, + RoyaltyTarget, + RoyaltyAmount, + AssetData, + CreatedAt, + Burnt, + SlotUpdated, + DataHash, + CreatorHash, + OwnerDelegateSeq, + WasDecompressed, + LeafSeq, + BaseInfoSeq, +} + +#[derive(Copy, Clone, Iden)] +pub enum AssetData { + Table, + Id, + ChainDataMutability, + ChainData, + MetadataUrl, + MetadataMutability, + Metadata, + SlotUpdated, + Reindex, + RawName, + RawSymbol, + BaseInfoSeq, +} + +#[derive(Copy, Clone, Iden)] +pub enum Tasks { + Table, + TaskType, + Data, + Status, + CreatedAt, + LockedUntil, + LockedBy, + MaxAttempts, + Attempts, + Duration, + Errors, +} + +#[derive(Copy, Clone, Iden)] +pub enum TokenAccounts { + Table, + Pubkey, + Mint, + Amount, + Owner, + Frozen, + CloseAuthority, + Delegate, + DelegatedAmount, + SlotUpdated, + TokenProgram, +} + +#[derive(Copy, Clone, Iden)] +pub enum Tokens { + Table, + Mint, + Supply, + Decimals, + TokenProgram, + MintAuthority, + FreezeAuthority, + CloseAuthority, + SlotUpdated, +} + +#[derive(Copy, Clone, Iden)] +pub enum ClAudits { + Table, + Id, + Tree, + NodeIdx, + LeafIdx, + Seq, + Level, + Hash, + CreatedAt, + Tx, +} + +#[derive(Copy, Clone, Iden)] +pub enum ClAuditsV2 { + Table, + Id, + Tree, + LeafIdx, + Seq, + CreatedAt, + Tx, + Instruction, +} diff --git a/nft_ingester/src/program_transformers/bubblegum/db.rs b/nft_ingester/src/program_transformers/bubblegum/db.rs index d9b6b23b9..b3b1070bd 100644 --- a/nft_ingester/src/program_transformers/bubblegum/db.rs +++ b/nft_ingester/src/program_transformers/bubblegum/db.rs @@ -2,6 +2,7 @@ use crate::error::IngesterError; use digital_asset_types::dao::{ asset, asset_authority, asset_creators, asset_data, asset_grouping, backfill_items, cl_audits_v2, cl_items, + extensions::instruction::PascalCase, sea_orm_active_enums::{ ChainMutability, Instruction, Mutability, OwnerType, RoyaltyTargetType, SpecificationAssetClass, SpecificationVersions, @@ -99,7 +100,7 @@ where let tx_id_bytes = bs58::decode(txn_id) .into_vec() .map_err(|_e| IngesterError::ChangeLogEventMalformed)?; - let ix = Instruction::from_str(instruction); + let ix = Instruction::from(instruction); if ix == Instruction::Unknown { error!("Unknown instruction: {}", instruction); } diff --git a/nft_ingester/src/program_transformers/token_metadata/master_edition.rs b/nft_ingester/src/program_transformers/token_metadata/master_edition.rs index 4e30970b6..ebb3ad942 100644 --- a/nft_ingester/src/program_transformers/token_metadata/master_edition.rs +++ b/nft_ingester/src/program_transformers/token_metadata/master_edition.rs @@ -1,7 +1,7 @@ use crate::error::IngesterError; use blockbuster::token_metadata::state::{Key, MasterEditionV1, MasterEditionV2}; use digital_asset_types::dao::{ - asset, asset_v1_account_attachments, + asset, asset_v1_account_attachments, extensions, sea_orm_active_enums::{SpecificationAssetClass, V1AccountAttachments}, }; use plerkle_serialization::Pubkey as FBPubkey; @@ -57,7 +57,10 @@ pub async fn save_master_edition( let master_edition: Option<(asset_v1_account_attachments::Model, Option)> = asset_v1_account_attachments::Entity::find_by_id(id.0.to_vec()) .find_also_related(asset::Entity) - .join(JoinType::InnerJoin, asset::Relation::AssetData.def()) + .join( + JoinType::InnerJoin, + extensions::asset::Relation::AssetData.def(), + ) .one(txn) .await?; let ser = serde_json::to_value(me_data) diff --git a/tools/bgtask_creator/src/main.rs b/tools/bgtask_creator/src/main.rs index 35058b42c..8a3240fe0 100644 --- a/tools/bgtask_creator/src/main.rs +++ b/tools/bgtask_creator/src/main.rs @@ -1,3 +1,5 @@ +use digital_asset_types::dao::extensions; + use { clap::{value_parser, Arg, ArgAction, Command}, digital_asset_types::dao::{ @@ -476,7 +478,10 @@ fn find_by_type<'a>( ( asset_data::Entity::find() - .join(JoinType::InnerJoin, asset_data::Relation::Asset.def()) + .join( + JoinType::InnerJoin, + extensions::asset_data::Relation::Asset.def(), + ) .join_rev( JoinType::InnerJoin, tokens::Entity::belongs_to(asset::Entity)