Add some tables
This commit is contained in:
parent
9c1b57b3c5
commit
4d20af5974
@ -1,6 +1,7 @@
|
|||||||
pub use sea_orm_migration::prelude::*;
|
pub use sea_orm_migration::prelude::*;
|
||||||
|
|
||||||
mod m20230603_102634_types;
|
mod m20230603_102634_types;
|
||||||
|
mod m20230603_120814_addresses;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
pub struct Migrator;
|
pub struct Migrator;
|
||||||
@ -8,6 +9,9 @@ pub struct Migrator;
|
|||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl MigratorTrait for Migrator {
|
impl MigratorTrait for Migrator {
|
||||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||||
vec![Box::new(m20230603_102634_types::Migration)]
|
vec![
|
||||||
|
Box::new(m20230603_102634_types::Migration),
|
||||||
|
Box::new(m20230603_120814_addresses::Migration),
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use sea_orm::{EnumIter, Iterable};
|
use sea_orm::Iterable;
|
||||||
use sea_orm_migration::prelude::*;
|
use sea_orm_migration::prelude::*;
|
||||||
|
|
||||||
use crate::extension::postgres::Type;
|
use crate::extension::postgres::Type;
|
||||||
|
86
migration/src/m20230603_120814_addresses.rs
Normal file
86
migration/src/m20230603_120814_addresses.rs
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
use sea_orm_migration::prelude::*;
|
||||||
|
use sea_orm_migration::sea_orm::Statement;
|
||||||
|
use sea_query::expr::SimpleExpr;
|
||||||
|
|
||||||
|
use crate::sea_orm::DatabaseBackend;
|
||||||
|
|
||||||
|
#[derive(DeriveMigrationName)]
|
||||||
|
pub struct Migration;
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl MigrationTrait for Migration {
|
||||||
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
/*
|
||||||
|
|
||||||
|
id character varying NOT NULL,
|
||||||
|
customer_id character varying,
|
||||||
|
company character varying,
|
||||||
|
first_name character varying,
|
||||||
|
last_name character varying,
|
||||||
|
address_1 character varying,
|
||||||
|
address_2 character varying,
|
||||||
|
city character varying,
|
||||||
|
country_code character varying,
|
||||||
|
province character varying,
|
||||||
|
postal_code character varying,
|
||||||
|
phone character varying,
|
||||||
|
created_at timestamp with time zone DEFAULT now() NOT NULL,
|
||||||
|
updated_at timestamp with time zone DEFAULT now() NOT NULL,
|
||||||
|
deleted_at timestamp with time zone,
|
||||||
|
metadata jsonb
|
||||||
|
*/
|
||||||
|
|
||||||
|
manager
|
||||||
|
.get_connection()
|
||||||
|
.execute(Statement::from_string(
|
||||||
|
DatabaseBackend::Postgres,
|
||||||
|
"CREATE EXTENSION \"uuid-ossp\";".to_string(),
|
||||||
|
))
|
||||||
|
.await?;
|
||||||
|
manager
|
||||||
|
.create_table(
|
||||||
|
Table::create()
|
||||||
|
.table(Address::Addresses)
|
||||||
|
.if_not_exists()
|
||||||
|
.col(
|
||||||
|
ColumnDef::new(Address::Id)
|
||||||
|
.uuid()
|
||||||
|
.not_null()
|
||||||
|
.default(SimpleExpr::FunctionCall(Func::cust(Expr::cust(
|
||||||
|
"uuid_generate_v4",
|
||||||
|
))))
|
||||||
|
.primary_key(),
|
||||||
|
)
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
manager
|
||||||
|
.drop_table(Table::drop().table(Address::Addresses).to_owned())
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Learn more at https://docs.rs/sea-query#iden
|
||||||
|
#[derive(Iden)]
|
||||||
|
enum Address {
|
||||||
|
Addresses,
|
||||||
|
Id,
|
||||||
|
CustomerId,
|
||||||
|
Company,
|
||||||
|
FirstName,
|
||||||
|
LastName,
|
||||||
|
Address1,
|
||||||
|
Address2,
|
||||||
|
City,
|
||||||
|
CountryCode,
|
||||||
|
Province,
|
||||||
|
PostalCode,
|
||||||
|
Phone,
|
||||||
|
CreatedAt,
|
||||||
|
UpdatedAt,
|
||||||
|
DeletedAt,
|
||||||
|
Metadata,
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
use sea_orm::{EnumIter, Iterable};
|
use sea_orm::EnumIter;
|
||||||
use sea_orm_migration::prelude::*;
|
use sea_orm_migration::prelude::*;
|
||||||
|
|
||||||
#[derive(Iden, EnumIter)]
|
#[derive(Iden, EnumIter)]
|
||||||
|
Loading…
Reference in New Issue
Block a user