use anyhow::Context;
use rusqlite::Transaction;
use super::Migration;
pub struct Migration0033 {}
impl Migration for Migration0033 {
fn name(&self) -> &str {
"Add paid invoice fact table and backfill settled lightning sends"
}
fn to_version(&self) -> i64 { 33 }
fn do_migration(&self, conn: &Transaction) -> anyhow::Result<()> {
conn.execute(
"CREATE TABLE bark_paid_invoice (
payment_hash TEXT PRIMARY KEY,
preimage TEXT NOT NULL,
paid_at DATETIME NOT NULL DEFAULT (strftime('%Y-%m-%d %H:%M:%f', 'now'))
)",
(),
).context("failed to create bark_paid_invoice table")?;
conn.execute(
"INSERT OR IGNORE INTO bark_paid_invoice (payment_hash, preimage, paid_at)
SELECT payment_hash, preimage, COALESCE(finished_at, strftime('%Y-%m-%d %H:%M:%f', 'now'))
FROM bark_lightning_send
WHERE preimage IS NOT NULL",
(),
).context("failed to backfill bark_paid_invoice from bark_lightning_send")?;
Ok(())
}
}