1use sea_orm::DatabaseBackend;
2use sea_orm_migration::prelude::*;
3
4#[derive(DeriveIden)]
5pub enum Base {
6 Id,
7 CreatedAt,
8 UpdatedAt,
9}
10
11pub struct BaseTable {}
12
13impl BaseTable {
14 pub fn create<T: IntoTableRef>(table: T, manager: &SchemaManager) -> TableCreateStatement {
15 Table::create()
16 .table(table)
17 .col(
18 ColumnDef::new(Base::Id)
19 .uuid()
20 .not_null()
21 .primary_key()
22 .default(match manager.get_database_backend() {
23 DatabaseBackend::MySql | DatabaseBackend::Sqlite => Expr::cust("(uuid())"),
24 DatabaseBackend::Postgres => PgFunc::gen_random_uuid().into(),
25 }),
26 )
27 .col(
28 ColumnDef::new(Base::CreatedAt)
29 .timestamp_with_time_zone()
30 .not_null()
31 .default(Expr::current_timestamp()),
32 )
33 .col(
34 ColumnDef::new(Base::UpdatedAt)
35 .timestamp_with_time_zone()
36 .not_null()
37 .default(Expr::current_timestamp()),
38 )
39 .to_owned()
40 }
41}