Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions crates/corro-types/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use camino::Utf8PathBuf;
use metrics::{gauge, histogram};
use parking_lot::RwLock;
use rangemap::RangeInclusiveSet;
use rusqlite::{Connection, OpenFlags, Transaction};
use rusqlite::{Connection, OpenFlags, OptionalExtension, Transaction};
use serde::{Deserialize, Serialize};
use serde_json::json;
use sqlite_pool::SqliteConn;
Expand All @@ -27,7 +27,7 @@ use tokio::{
time::timeout,
};
use tokio_util::sync::{CancellationToken, DropGuard};
use tracing::{debug, error, warn};
use tracing::{debug, error, info, warn};
use tripwire::Tripwire;

use crate::{
Expand Down Expand Up @@ -408,6 +408,18 @@ fn crsqlite_v0_17_migration(
let ts = Timestamp::from(clock.new_timestamp()).as_u64().to_string();

move |tx: &Transaction| -> rusqlite::Result<()> {
let version: Option<i64> = tx
.query_row(
"SELECT value FROM crsql_master WHERE key = 'version'",
[],
|row| row.get(0),
)
.optional()?;
// we only want to run this migration if the version is less than 17_00_00
if version.is_none_or(|v| v >= 17_00_00) {
return Ok(());
}

let tables: Vec<String> = tx.prepare("SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name LIKE '%__crsql_clock'")?.query_map([], |row| row.get(0))?.collect::<rusqlite::Result<Vec<_>>>()?;

for table in tables {
Expand Down
Loading