SeaORM database migrations for Mega, extracted from jupiter so day-to-day cargo check does not compile migration code unless needed.
mono enables jupiter/migrate. On startup, Storage::new calls jupiter_migrate::apply_migrations automatically (jupiter/src/storage/init.rs). No separate init CLI step is required.
After schema migrations, mono HTTP boot may run application data backfills (e.g. actor handle → campsite_user_id) using Campsite internal/member_identities and data_backfill_ledger. Deploy campsite-api with MEGA_INTERNAL_SECRET before mono with MEGA_OAUTH__MEGA_INTERNAL_SECRET.
Crates that need a migrated DB in tests should enable jupiter/migrate or ceres feature migrate.
cd jupiter-migrate/src/migration
sea-orm-cli migrate generate "your_migration_name"Commit the new file under jupiter-migrate/src/migration/.
After schema changes, regenerate callisto entities (adjust connection URL for your DB):
sea-orm-cli generate entity \
-u postgres://postgres:postgres@localhost:5432/mono \
-o jupiter/callisto/src \
--with-serde both \
--entity-format denseReview generated diffs in jupiter/callisto/src/ before committing.
Do not edit CLI-generated entity files for polymorphic/link joins or Model::new helpers — those live only in entity_ext/. Regenerating must overwrite table models cleanly.
After every regen:
- Re-add
pub mod entity_ext;tojupiter/callisto/src/mod.rs(codegen overwrites this file). - Keep
sea_orm_active_enums.rswebhook variant names readable (ClCreated, not CLI-mangled names).rs_type = "Enum"is correct for SeaORM 2.0 — call sites that need a string useto_value().valueorTryFrom<&str>. - Leave
entity_ext/alone — it owns:Model::newhelpers and ID utilities- Polymorphic / link-based
Relation+Related(no DB FKs), including:item_labels/item_assignees: dualbelongs_toonitem_id→mega_clandmega_issuemega_cl/mega_issue:has_manylabels (via), assignees, conversationsmega_conversation: link joins to CL/Issue;has_manyreactionsreactions:belongs_toconversationmega_code_review_thread:belongs_tomega_clonlinklabel:has_manyitem_labels
Join call sites that need those relations use callisto::entity_ext::<table>::Relation, not the generated entity Relation.
use jupiter_migrate::{apply_migrations, Migrator};apply_migrations(&db, refresh) runs pending migrations. Migrator is the SeaORM migrator trait implementation.