Skip to content

Commit 5ca2c0d

Browse files
committed
fix
1 parent 2ff6cea commit 5ca2c0d

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

toolkit/data-sources/db-sync/src/db_model.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ pub(crate) enum TxInConfiguration {
2323

2424
impl TxInConfiguration {
2525
pub(crate) async fn from_connection(pool: &Pool<Postgres>) -> Result<Self, SqlxError> {
26-
let query = sqlx::query_scalar::<_, i64>(
27-
"select count(*) from information_schema.tables where table_name = 'tx_in';",
28-
);
29-
30-
if query.fetch_all(pool).await?.first() == Some(&0) {
31-
Ok(Self::Consumed)
32-
} else {
33-
Ok(Self::Legacy)
26+
let consumed_by_tx_id_populated = sqlx::query_scalar::<_, bool>(
27+
"SELECT EXISTS (SELECT 1 FROM tx_out where consumed_by_tx_id is not null);",
28+
)
29+
.fetch_one(pool)
30+
.await?;
31+
32+
if consumed_by_tx_id_populated {
33+
return Ok(Self::Consumed);
3434
}
35+
36+
Ok(Self::Legacy)
3537
}
3638
}
3739

0 commit comments

Comments
 (0)