Skip to content

Commit 1b7d2ad

Browse files
committed
fix
1 parent 3029489 commit 1b7d2ad

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,25 @@ 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>(
26+
let tx_in_exists = sqlx::query_scalar::<_, i64>(
2727
"select count(*) from information_schema.tables where table_name = 'tx_in';",
28-
);
28+
)
29+
.fetch_one(pool)
30+
.await? == 1;
2931

30-
if query.fetch_all(pool).await?.first() == Some(&0) {
31-
Ok(Self::Consumed)
32-
} else {
33-
Ok(Self::Legacy)
32+
if !tx_in_exists {
33+
return Ok(Self::Consumed);
3434
}
35+
36+
let tx_in_populated = sqlx::query_scalar::<_, bool>("SELECT EXISTS (SELECT 1 FROM tx_in);")
37+
.fetch_one(pool)
38+
.await?;
39+
40+
if tx_in_populated {
41+
return Ok(Self::Legacy);
42+
}
43+
44+
Ok(Self::Consumed)
3545
}
3646
}
3747

0 commit comments

Comments
 (0)