pub trait Migration {
const APP_NAME: &'static str;
const MIGRATION_NAME: &'static str;
const DEPENDENCIES: &'static [MigrationDependency];
const OPERATIONS: &'static [Operation];
}Available on crate feature
db only.Expand description
A trait for defining a migration.
§Cot CLI Usage
Typically, you shouldn’t need to use this directly. Instead, in most cases, this can be automatically generated by the Cot CLI.
§Examples
use cot::db::migrations::{Field, Migration, MigrationDependency, Operation};
use cot::db::{DatabaseField, Identifier};
struct MyMigration;
impl Migration for MyMigration {
const APP_NAME: &'static str = "myapp";
const MIGRATION_NAME: &'static str = "m_0001_initial";
const DEPENDENCIES: &'static [MigrationDependency] = &[];
const OPERATIONS: &'static [Operation] = &[Operation::create_model()
.table_name(Identifier::new("todoapp__my_model"))
.fields(&[
Field::new(Identifier::new("id"), <i32 as DatabaseField>::TYPE).primary_key(),
])
.build()];
}Required Associated Constants§
Sourceconst MIGRATION_NAME: &'static str
const MIGRATION_NAME: &'static str
The name of the migration.
Sourceconst DEPENDENCIES: &'static [MigrationDependency]
const DEPENDENCIES: &'static [MigrationDependency]
The list of dependencies of the migration.
Sourceconst OPERATIONS: &'static [Operation]
const OPERATIONS: &'static [Operation]
The list of operations to apply in the migration.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.