1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! Database migrations with SeaORM.
//!
//! # Migration modules
//!
//! Each plugin keeps migrators in `migrations/` as Rust modules implementing
//! [`MigrationTrait`](sea_orm_migration::MigrationTrait):
//!
//! ```ignore
//! // migrations/m20260801_000001_create_items.rs
//! use sea_orm_migration::{prelude::*, schema::*};
//!
//! #[derive(DeriveMigrationName)]
//! pub struct Migration;
//!
//! #[async_trait::async_trait]
//! impl MigrationTrait for Migration {
//! async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
//! manager
//! .create_table(
//! Table::create()
//! .table(Items::Table)
//! .col(pk_auto(Items::Id))
//! .col(string(Items::Name))
//! .col(timestamp(Items::CreatedAt))
//! .to_owned(),
//! )
//! .await
//! }
//!
//! async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
//! manager.drop_table(Table::drop().table(Items::Table).to_owned()).await
//! }
//! }
//!
//! #[derive(DeriveIden)]
//! enum Items {
//! Table,
//! Id,
//! Name,
//! CreatedAt,
//! }
//! ```
//!
//! # Registering migrations
//!
//! ```ignore
//! // migrations/mod.rs
//! mod m20260801_000001_create_items;
//!
//! use sea_orm_migration::MigratorTrait;
//!
//! pub struct Migrator;
//!
//! impl MigratorTrait for Migrator {
//! fn migrations() -> Vec<Box<dyn MigrationTrait>> {
//! vec![Box::new(m20260801_000001_create_items::Migration)]
//! }
//! }
//!
//! define_register_migrations! {
//! plugin: MyPluginTag;
//! migrator: Migrator;
//! }
//! ```
//!
//! Add `migrations(migrations::Hook)` to [`define_plugin_install!`](crate::plugin_install::define_plugin_install).
//!
//! # Running migrations
//!
//! Lariv merges all plugin migrators into one composite migrator. Apply pending migrations:
//!
//! ```text
//! cargo run -- migrate
//! ```
//!
//! Or call [`MountedApp::run_migrations`](crate::app::MountedApp::run_migrations) programmatically
//! before `serve`.
//!
//! When restoring a database that already has the TotSchool Go/Lamu schema applied,
//! stamp Lariv migration rows without re-running DDL:
//!
//! ```text
//! cargo run -- mark-migrations
//! ```
//!
//! Or call [`MountedApp::mark_migrations`](crate::app::MountedApp::mark_migrations).
//!
//! # Migration tracking
//!
//! Applied revisions are recorded in the `seaql_migrations` table. All plugins share this
//! table — the framework runs every registered migrator through a single composite pass.