generated from holaplex/hub-rust-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "Speed Up Mint Random Selects""
- Loading branch information
Showing
6 changed files
with
64 additions
and
8 deletions.
There are no files selected for viewing
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
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
55 changes: 55 additions & 0 deletions
55
migration/src/m20231020_123046_add_random_pick_to_collection_mints.rs
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,55 @@ | ||
use sea_orm_migration::prelude::*; | ||
|
||
#[derive(DeriveMigrationName)] | ||
pub struct Migration; | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.alter_table( | ||
Table::alter() | ||
.table(CollectionMints::Table) | ||
.add_column_if_not_exists( | ||
ColumnDef::new(CollectionMints::RandomPick) | ||
.big_integer() | ||
.not_null() | ||
.default(Expr::cust( | ||
"(floor(random() * 9223372036854775807))::bigint", | ||
)), | ||
) | ||
.to_owned(), | ||
) | ||
.await?; | ||
|
||
manager | ||
.create_index( | ||
IndexCreateStatement::new() | ||
.name("collection-mints-random_pick-idx") | ||
.table(CollectionMints::Table) | ||
.col((CollectionMints::RandomPick, IndexOrder::Asc)) | ||
.index_type(IndexType::BTree) | ||
.to_owned(), | ||
) | ||
.await | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
// Replace the sample below with your own migration scripts | ||
manager | ||
.alter_table( | ||
Table::alter() | ||
.table(CollectionMints::Table) | ||
.drop_column(CollectionMints::RandomPick) | ||
.to_owned(), | ||
) | ||
.await | ||
} | ||
} | ||
|
||
/// Learn more at https://docs.rs/sea-query#iden | ||
#[derive(Iden)] | ||
enum CollectionMints { | ||
Table, | ||
RandomPick, | ||
} |