pub mod tree_config_row;
pub mod voucher_row;
pub use self::{tree_config_row::*, voucher_row::*};
use super::BubblegumAccount;
pub struct BubblegumAccountsMigration;
impl sqlx_migrator::Migration<sqlx::Postgres> for BubblegumAccountsMigration {
fn app(&self) -> &str {
"bubblegum"
}
fn name(&self) -> &str {
"bubblegum_accounts"
}
fn operations(&self) -> Vec<Box<dyn sqlx_migrator::Operation<sqlx::Postgres>>> {
vec![
Box::new(TreeConfigMigrationOperation),
Box::new(VoucherMigrationOperation),
]
}
fn parents(&self) -> Vec<Box<dyn sqlx_migrator::Migration<sqlx::Postgres>>> {
vec![]
}
}
pub struct BubblegumAccountWithMetadata(
pub BubblegumAccount,
pub carbon_core::account::AccountMetadata,
);
impl From<(BubblegumAccount, carbon_core::account::AccountMetadata)>
for BubblegumAccountWithMetadata
{
fn from(value: (BubblegumAccount, carbon_core::account::AccountMetadata)) -> Self {
BubblegumAccountWithMetadata(value.0, value.1)
}
}
#[async_trait::async_trait]
impl carbon_core::postgres::operations::Insert for BubblegumAccountWithMetadata {
async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
let BubblegumAccountWithMetadata(account, metadata) = self;
match account {
BubblegumAccount::TreeConfig(account) => {
let row =
tree_config_row::TreeConfigRow::from_parts(*account.clone(), metadata.clone());
row.insert(pool).await?;
Ok(())
}
BubblegumAccount::Voucher(account) => {
let row = voucher_row::VoucherRow::from_parts(*account.clone(), metadata.clone());
row.insert(pool).await?;
Ok(())
}
}
}
}
#[async_trait::async_trait]
impl carbon_core::postgres::operations::Upsert for BubblegumAccountWithMetadata {
async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
let BubblegumAccountWithMetadata(account, metadata) = self;
match account {
BubblegumAccount::TreeConfig(account) => {
let row =
tree_config_row::TreeConfigRow::from_parts(*account.clone(), metadata.clone());
row.upsert(pool).await?;
Ok(())
}
BubblegumAccount::Voucher(account) => {
let row = voucher_row::VoucherRow::from_parts(*account.clone(), metadata.clone());
row.upsert(pool).await?;
Ok(())
}
}
}
}