1 parent
d91212d24c
commit
dbe7103687
21 files changed
+182
-154
No files matched your search
+53
-9
@@ -16,22 +16,24 @@ use tokio::sync::Mutex as AsyncMutex;
|
||||
|
||||
use crate::config::AppConfig;
|
||||
|
||||
pub const BASE_SCHEMA_VERSION: u32 = 49;
|
||||
pub const BASE_SCHEMA_VERSION: u32 = 50;
|
||||
const SQLITE_SCHEMA: &str = include_str!("../../migrations/sqlite/schema.sql");
|
||||
const MYSQL_SCHEMA: &str = include_str!("../../migrations/mysql/schema.sql");
|
||||
const PGSQL_SCHEMA: &str = include_str!("../../migrations/pgsql/schema.sql");
|
||||
|
||||
const SQLITE_MIGRATIONS: &[(u32, &str)] = &[(
|
||||
50,
|
||||
include_str!("../../migrations/sqlite/V050__compact_rows_and_signature_mode.sql"),
|
||||
51,
|
||||
include_str!(
|
||||
"../../migrations/sqlite/V051__adaptive_email_colors_and_message_loading_mode.sql"
|
||||
),
|
||||
)];
|
||||
const MYSQL_MIGRATIONS: &[(u32, &str)] = &[(
|
||||
50,
|
||||
include_str!("../../migrations/mysql/V050__compact_rows_and_signature_mode.sql"),
|
||||
51,
|
||||
include_str!("../../migrations/mysql/V051__adaptive_email_colors_and_message_loading_mode.sql"),
|
||||
)];
|
||||
const PGSQL_MIGRATIONS: &[(u32, &str)] = &[(
|
||||
50,
|
||||
include_str!("../../migrations/pgsql/V050__compact_rows_and_signature_mode.sql"),
|
||||
51,
|
||||
include_str!("../../migrations/pgsql/V051__adaptive_email_colors_and_message_loading_mode.sql"),
|
||||
)];
|
||||
|
||||
const TENANT_TABLES: &[&str] = &[
|
||||
@@ -1819,7 +1821,7 @@ fn read_legacy_sqlite(path: &Path) -> Result<Vec<LegacyTableData>, String> {
|
||||
.map_err(|e| format!("failed to read legacy SQLite schema version: {e}"))?;
|
||||
if version < BASE_SCHEMA_VERSION {
|
||||
return Err(format!(
|
||||
"legacy SQLite schema version {version} is older than the consolidated RustBox baseline {BASE_SCHEMA_VERSION}; upgrade to schema V049 first"
|
||||
"legacy SQLite schema version {version} is older than the consolidated RustBox baseline {BASE_SCHEMA_VERSION}; upgrade with a V050-capable RustBox release first"
|
||||
));
|
||||
}
|
||||
let latest_supported_sqlite = SQLITE_MIGRATIONS
|
||||
@@ -2180,7 +2182,7 @@ fn apply_sqlite_migrations(
|
||||
) -> Result<(), String> {
|
||||
if current < BASE_SCHEMA_VERSION {
|
||||
return Err(format!(
|
||||
"database schema version {current} is older than the consolidated RustBox baseline {BASE_SCHEMA_VERSION}; upgrade to schema V049 first"
|
||||
"database schema version {current} is older than the consolidated RustBox baseline {BASE_SCHEMA_VERSION}; upgrade with a V050-capable RustBox release first"
|
||||
));
|
||||
}
|
||||
let latest = latest_schema_version();
|
||||
@@ -2624,6 +2626,48 @@ mod tests {
|
||||
assert_eq!(tenant, imported);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sqlite_v051_migrates_existing_v050_preferences() {
|
||||
let conn = rusqlite::Connection::open_in_memory().unwrap();
|
||||
conn.execute_batch(
|
||||
"CREATE TABLE rustbox_accounts (user_hash TEXT PRIMARY KEY, table_prefix TEXT NOT NULL, schema_version INTEGER NOT NULL, updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP);\n\
|
||||
CREATE TABLE u_test__display_preferences (id INTEGER PRIMARY KEY, theme TEXT NOT NULL DEFAULT 'system');\n\
|
||||
CREATE TABLE u_test__mail_preferences (id INTEGER PRIMARY KEY, messages_per_page INTEGER NOT NULL DEFAULT 300);\n\
|
||||
INSERT INTO rustbox_accounts(user_hash, table_prefix, schema_version) VALUES('test', 'u_test__', 50);\n\
|
||||
INSERT INTO u_test__display_preferences(id) VALUES(1);\n\
|
||||
INSERT INTO u_test__mail_preferences(id) VALUES(1);",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
apply_sqlite_migrations(&conn, "u_test__", 50).unwrap();
|
||||
|
||||
let version: u32 = conn
|
||||
.query_row(
|
||||
"SELECT schema_version FROM rustbox_accounts WHERE table_prefix='u_test__'",
|
||||
[],
|
||||
|row| row.get(0),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(version, 51);
|
||||
|
||||
let adaptive: i64 = conn
|
||||
.query_row(
|
||||
"SELECT adaptive_email_colors FROM u_test__display_preferences WHERE id=1",
|
||||
[],
|
||||
|row| row.get(0),
|
||||
)
|
||||
.unwrap();
|
||||
let mode: String = conn
|
||||
.query_row(
|
||||
"SELECT message_loading_mode FROM u_test__mail_preferences WHERE id=1",
|
||||
[],
|
||||
|row| row.get(0),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(adaptive, 0);
|
||||
assert_eq!(mode, "pagination");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_sqlite_v050_is_imported_and_backed_up() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
|
||||
Reference in new issue
Block a user