Skip to content

Commit

Permalink
correct where clause for creators on conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
kespinola committed Dec 18, 2024
1 parent 5455623 commit b911413
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 52 deletions.
3 changes: 1 addition & 2 deletions program_transformers/src/token/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ use {
digital_asset_types::dao::{token_accounts, tokens},
sea_orm::{
entity::ActiveValue,
query::QueryTrait,
sea_query::query::OnConflict,
sea_query::{Alias, Condition, Expr},
ConnectionTrait, DatabaseConnection, DbBackend, EntityTrait, TransactionTrait,
DatabaseConnection, EntityTrait, TransactionTrait,
},
solana_sdk::program_option::COption,
spl_token::state::AccountState,
Expand Down
42 changes: 36 additions & 6 deletions program_transformers/src/token_metadata/master_edition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ use {
},
sea_orm::{
entity::{ActiveValue, EntityTrait},
query::QueryTrait,
sea_query::query::OnConflict,
ConnectionTrait, DatabaseTransaction, DbBackend,
sea_query::{query::OnConflict, Alias, Condition, Expr},
DatabaseTransaction,
},
solana_sdk::pubkey::Pubkey,
};
Expand Down Expand Up @@ -74,17 +73,48 @@ pub async fn save_master_edition(
..Default::default()
};

let query = asset_v1_account_attachments::Entity::insert(model)
asset_v1_account_attachments::Entity::insert(model)
.on_conflict(
OnConflict::columns([asset_v1_account_attachments::Column::Id])
.update_columns([
asset_v1_account_attachments::Column::AttachmentType,
asset_v1_account_attachments::Column::Data,
asset_v1_account_attachments::Column::SlotUpdated,
])
.action_cond_where(
Condition::all()
.add(
Expr::tbl(
Alias::new("excluded"),
asset_v1_account_attachments::Column::AttachmentType,
)
.ne(Expr::tbl(
asset_v1_account_attachments::Entity,
asset_v1_account_attachments::Column::AttachmentType,
)),
)
.add(
Expr::tbl(
Alias::new("excluded"),
asset_v1_account_attachments::Column::Data,
)
.ne(Expr::tbl(
asset_v1_account_attachments::Entity,
asset_v1_account_attachments::Column::Data,
)),
)
.add(
Expr::tbl(
asset_v1_account_attachments::Entity,
asset_v1_account_attachments::Column::SlotUpdated,
)
.lte(slot as i64),
),
)
.to_owned(),
)
.build(DbBackend::Postgres);
txn.execute(query).await?;
.exec_without_returning(txn)
.await
.map_err(|db_err| ProgramTransformerError::AssetIndexError(db_err.to_string()))?;
Ok(())
}
Loading

0 comments on commit b911413

Please sign in to comment.