Expand description
Adapted from https://github.com/loco-rs/loco/blob/master/src/schema.rs
§Database Table Schema Helpers
This module defines functions and helpers for creating database table
schemas using the sea-orm and sea-query libraries.
§Example
The following example shows how the user migration file should be and using the schema helpers to create the Db fields.
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> {
let table = table_auto("users")
.col(pk_auto("id"))
.col(uuid("pid"))
.col(string_uniq("email"))
.col(string("password"))
.col(string("name"))
.col(string_null("reset_token"))
.col(timestamp_null("reset_sent_at"))
.to_owned();
manager.create_table(table).await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table("users").to_owned())
.await
}
}Functions§
- array
- array_
null - array_
uniq - big_
integer - big_
integer_ null - big_
integer_ uniq - big_
pk_ auto - Create a primary key column of big integer with auto-increment
- big_
unsigned - big_
unsigned_ null - big_
unsigned_ uniq - binary
- binary_
len - binary_
len_ null - binary_
len_ uniq - binary_
null - binary_
uniq - bit
- bit_
null - bit_
uniq - blob
- blob_
null - blob_
uniq - boolean
- boolean_
null - boolean_
uniq - char
- char_
len - char_
len_ null - char_
len_ uniq - char_
null - char_
uniq - custom
- custom_
null - date
- date_
null - date_
time - date_
time_ null - date_
time_ uniq - date_
uniq - decimal
- decimal_
len - decimal_
len_ null - decimal_
len_ uniq - decimal_
null - decimal_
uniq - double
- double_
null - double_
uniq - enumeration
- enumeration_
null - enumeration_
uniq - float
- float_
null - float_
uniq - integer
- integer_
null - integer_
uniq - interval
- interval_
null - interval_
uniq - json
- json_
binary - json_
binary_ null - json_
binary_ uniq - json_
null - json_
uniq - money
- money_
len - money_
len_ null - money_
len_ uniq - money_
null - money_
uniq - name
- Create an Alias.
- pk_auto
- Create a primary key column with auto-increment
- pk_uuid
- Create a UUID primary key
- small_
integer - small_
integer_ null - small_
integer_ uniq - small_
unsigned - small_
unsigned_ null - small_
unsigned_ uniq - string
- string_
len - string_
len_ null - string_
len_ uniq - string_
null - string_
uniq - table_
auto - Create a table with
created_atandupdated_atadded by default - text
- text_
null - text_
uniq - time
- time_
null - time_
uniq - timestamp
- timestamp_
null - timestamp_
uniq - timestamp_
with_ time_ zone - timestamp_
with_ time_ zone_ null - timestamp_
with_ time_ zone_ uniq - timestamps
- Add timestamp columns (
CreatedAtandUpdatedAt) to an existing table. - tiny_
integer - tiny_
integer_ null - tiny_
integer_ uniq - tiny_
unsigned - tiny_
unsigned_ null - tiny_
unsigned_ uniq - unsigned
- unsigned_
null - unsigned_
uniq - uuid
- uuid_
null - uuid_
uniq - var_
binary - var_
binary_ null - var_
binary_ uniq - varbit
- varbit_
null - varbit_
uniq - year
- year_
null - year_
uniq