Expand description
One-time database migrations.
A fresh database is stamped current and a legacy database is walked through the named migrations, once the version and server name gates decide it is safe to touch. Each step stamps a marker once it has run, and removing the marker of a step safe to run twice schedules it for the next start.
Re-exportsΒ§
use std::cmp::Ordering;πuse std::time::Duration;πuse futures::FutureExt;πuse futures::StreamExt;πuse futures::TryStreamExt;πuse ruma::OwnedUserId;πuse ruma::RoomId;πuse ruma::ServerName;πuse ruma::UserId;πuse tokio::time::sleep;πuse tuwunel_core::Err;πuse tuwunel_core::Result;πuse tuwunel_core::err;πuse tuwunel_core::format_small_string;πuse tuwunel_core::info;πuse tuwunel_core::info;πuse tuwunel_core::result::NotFound;πuse tuwunel_core::smallstr::SmallString;πuse tuwunel_core::smallvec::SmallVec;πuse tuwunel_core::utils::BoolExt;πuse tuwunel_core::utils::IterStream;πuse tuwunel_core::utils::ReadyExt;πuse tuwunel_core::utils::TryReadyExt;πuse tuwunel_core::warn;πuse tuwunel_database::Deserialized;πuse self::Rerun::Clear;πuse self::Rerun::Refuse;πuse self::account_status::migrate_account_status;πuse self::clear_servername_status::clear_servername_status;πuse self::clear_state_local_error_memos::clear_state_local_error_memos;πuse self::conduit::migrate_pdus;πuse self::email_bindings::migrate_email_bindings;πuse self::fix_bad_double_separator_in_state_cache::fix_bad_double_separator_in_state_cache;πuse self::fix_hashed_sentinel_passwords::fix_hashed_sentinel_passwords;πuse self::fix_readreceiptid_readreceipt_duplicates::fix_readreceiptid_readreceipt_duplicates;πuse self::fix_referencedevents_missing_sep::fix_referencedevents_missing_sep;πuse self::import_conduit_knocks::import_conduit_knocks;πuse self::injectivity::fix as fix_injectivity;πuse self::injectivity::mark_clean as mark_clean_injectivity;πuse self::migrate_media::migrate_media;πuse self::migrate_profile_keys::migrate_profile_keys;πuse self::moderation::migrate as migrate_moderation;πuse self::rebuild_roomid_tscount_pducount::rebuild_roomid_tscount_pducount;πuse self::redactions::restore_redactions;πuse self::remove_remote_media_userid::remove_remote_media_userid;πuse self::retroactively_fix_bad_data_from_roomuserid_joined::retroactively_fix_bad_data_from_roomuserid_joined;πuse self::split_conduit_highlight_counts::split_conduit_highlight_counts;πuse self::token_expiry::Restore;πuse self::token_expiry::migrate as migrate_token_expiry;πuse self::token_expiry::restore as restore_token_expiry;πuse self::token_expiry::restore_due;πuse self::upgrade_legacy_mediaid_user::upgrade_legacy_mediaid_user;πuse crate::Services;πuse crate::integrity::find as find_check;πuse crate::integrity::forbidden_names::Username;πuse crate::integrity::forbidden_names::matched as forbidden_patterns;πuse crate::integrity::forbidden_names::usernames as forbidden_usernames;π
ModulesΒ§
- account_
status π - clear_
servername_ πstatus - clear_
state_ πlocal_ error_ memos - conduit π
- email_
bindings π - fix_
bad_ πdouble_ separator_ in_ state_ cache - fix_
hashed_ πsentinel_ passwords - fix_
readreceiptid_ πreadreceipt_ duplicates - fix_
referencedevents_ πmissing_ sep - import_
conduit_ πknocks - injectivity π
- Repair reported short-id residue while preserving unproven data.
- migrate_
media π - migrate_
profile_ πkeys - moderation π
- rebuild_
roomid_ πtscount_ pducount - redactions π
- remove_
remote_ πmedia_ userid - retroactively_
fix_ πbad_ data_ from_ roomuserid_ joined - split_
conduit_ πhighlight_ counts - tally π
- token_
expiry π - upgrade_
legacy_ πmediaid_ user
StructsΒ§
EnumsΒ§
ConstantsΒ§
- ADOPTION π
- ADOPT_
ACCOUNT_ πSTATUS - ADOPT_
EMAIL_ πBINDINGS - CLEAR_
STATE_ πLOCAL_ ERROR_ MEMOS - DATABASE_
VERSION π - The current schema version.
- EVERY_
START π - FIX_
PDU_ πMISSING_ ROOM_ ID - FORCE_
MIGRATION_ πDELAY - FOREIGN_
LINEAGE_ πMARKER - A marker written by a sibling conduwuit-lineage server but never by tuwunel.
Its presence identifies a foreign database at a higher schema number even
after tuwunel has stamped its own
server_name, so a database opened by both servers in turn keeps booting rather than being refused as too new. - MARKERS π
- The steps every database records as settled, whether they ran or it began current.
- MEDIA_
CHECKUP π - MEDIA_
RENAME π - NO_
REPAIR π - OUTCOME_
RECORD π - PROFILE_
COPY π - REBUILD_
LIVE_ πTHREAD_ ACTIVITY - REBUILD_
RELATESTO_ πTYPED - REBUILD_
THREAD_ πSUMMARIES - REDACTIONS π
- SERVER_
NAME_ πKEY - SHA256_
MEDIA π - Stamped once the media directory names files by their sha256 names.
- SPLIT_
CONDUIT_ πHIGHLIGHT - UNVERIFIED π
StaticsΒ§
- RERUNS π
- How the repair of each integrity check is scheduled, or why it cannot be.
FunctionsΒ§
- backfill_
server_ πname - Stamp the marker on a database that pre-dates SERVER_NAME_KEY by probing for any user from the configured server. If none, the database belongs to a different server and reuse is refused.
- check_
database_ πversion - Gate the discovered schema version before migrations and the server_name
backfill run. The integer is comparable only within tuwunelβs own lineage; a
foreign database (Conduit and forks) numbers schema on a colliding ladder
and is recognized as foreign by
is_foreign_lineage, so its number is not gated. Within our lineage a version below 13 is refused as unmigratable and one above this build as too new to open safely; force_migration overrides the latter for a deliberate downgrade. - check_
server_ πname - Matrix resource ownership is based on the server name; changing it requires recreating the database from scratch. The marker is stamped once in fresh(); pre-marker databases are backfilled by probing for any user from the configured server.
- fresh π
- is_
foreign_ πlineage - Whether the database comes from a foreign (non-tuwunel) lineage: it predates our SERVER_NAME_KEY stamp, or carries a conduwuit-lineage migration marker that persists even after we stamp ours. Must be read before the server_name backfill, which removes the first signal.
- local_
user_ πid - Assembles a local user id from a localpart a foreign column records.
- marker_
present π - Whether a migration step has stamped its marker.
- migrate π
- Apply any migrations
- migrations π
- pending π
- Whether a named migration step still needs to run, refusing once shutdown begins.
- rebuild_
thread_ πsummaries - Rebuilds every stored thread summary, logging how many roots changed.
- rerun
- Schedules the repair of an integrity check for the next start.
- rerun_
markers π - run_
once π - Runs a pass that finishes whenever it succeeds, stamping its marker.
- scan_
room_ πaliases - stamp π
- until_
finished π - Runs a pass whose work may wait on a condition outside the database.
- warn_
forbidden_ πnames - Warns about existing names the configuration now forbids.