-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix creators re-ordering bug (metaplex-foundation#162)
* Remove asset_creator_unique as we now allow duplicate rows * fix creators re-ordering bug * pr comments * fix crgo file --------- Co-authored-by: Michael Danenberg <[email protected]>
- Loading branch information
1 parent
62bb23c
commit 5d0177a
Showing
7 changed files
with
139 additions
and
70 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use sea_orm_migration::prelude::*; | ||
|
||
use crate::model::table::AssetCreators; | ||
|
||
#[derive(DeriveMigrationName)] | ||
pub struct Migration; | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
// New index to serve as a replacement for "asset_creator_unique" when someone queries GetAssetsByCreator. | ||
// We add it before deleting the "asset_creator_unique" index to ensure no customer impact. | ||
manager | ||
.create_index( | ||
Index::create() | ||
.name("asset_creator_verified") | ||
.table(AssetCreators::Table) | ||
.col(AssetCreators::AssetId) | ||
.col(AssetCreators::Creator) | ||
.col(AssetCreators::Verified) | ||
.to_owned(), | ||
) | ||
.await?; | ||
|
||
// We no longer want to enforce uniques on the (asset_id, creator) pairs. | ||
// We may end up with duplicate (asset_id, creator) pairs during indexing, because a creator can change position. | ||
// Any stale rows (older seq/slot_updated) will be ignored, meaning the API users will never see duplicate creators. | ||
manager | ||
.drop_index( | ||
sea_query::Index::drop() | ||
.name("asset_creator_unique") | ||
.table(AssetCreators::Table) | ||
.to_owned(), | ||
) | ||
.await?; | ||
|
||
// This index is unused and can be removed. | ||
manager | ||
.drop_index( | ||
sea_query::Index::drop() | ||
.name("asset_verified_creator") | ||
.table(AssetCreators::Table) | ||
.to_owned(), | ||
) | ||
.await?; | ||
Ok(()) | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.create_index( | ||
Index::create() | ||
.unique() | ||
.name("asset_creator_unique") | ||
.table(AssetCreators::Table) | ||
.col(AssetCreators::AssetId) | ||
.col(AssetCreators::Creator) | ||
.to_owned(), | ||
) | ||
.await?; | ||
manager | ||
.create_index( | ||
Index::create() | ||
.name("asset_verified_creator") | ||
.table(AssetCreators::Table) | ||
.col(AssetCreators::AssetId) | ||
.col(AssetCreators::Verified) | ||
.to_owned(), | ||
) | ||
.await?; | ||
manager | ||
.drop_index( | ||
sea_query::Index::drop() | ||
.name("asset_creator_verified") | ||
.table(AssetCreators::Table) | ||
.to_owned(), | ||
) | ||
.await?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters