[][src]Module oxidizer::migration

Migrations

Migrations are handled by refinery and barrel. Go ahead and read their docs. The derive macro generates the migration code for each entity automatically. The only thing needed is include each Entity's migration in a file (module) A macro to generate the necessary code for each migration module is provided. NOTE: Please take note that this is highly experimental and it can change frequently.

This example is not tested
+ src/
+-- entities/
+--+-- mod.rs
+--+-- person.rs
+--+-- account.rs
+--migrations/
+--+-- mod.rs
+--+-- V00001__person.rs
+--+-- V00002__account.rs
  • V00001__person.rs
This example is not tested
use oxidizer::create_migration_module;
use oxidizer::entity::IEntity;

use crate::entities::Person;

create_migration_module!(Person);
  • migrations/mod.rs
This example is not tested
use oxidizer::include_migration_mods;

include_migration_mods!();

With the correct file struct you can now create a runner and apply migrations with:

use oxidizer::*;
#[tokio::test]
async fn test_migrate() {
 let runner = crate::migrations::runner();

 let uri = "postgres://postgres:alkje2lkaj2e@db/postgres";
 let max_open = 50; // mobc
 let ca_file: Option<&str> = None;
 let db = DB::connect(&uri, max_open, ca_file).await.unwrap();
 db.migrate(runner).await.unwrap();
}

Structs

Migration

Migration abstract layer