Fix some parts of migration

This commit is contained in:
eraden 2023-06-13 22:00:47 +02:00
parent 6eb9857066
commit 2974a180f5
10 changed files with 149 additions and 278 deletions

View File

@ -1,6 +1,6 @@
use sea_orm_migration::prelude::*; use sea_orm_migration::prelude::*;
use crate::{CreateIndexExt, DropTable, IntoColumnDef}; use crate::{CreateBridgeTable, DropTable};
/// ```sql /// ```sql
/// CREATE TABLE cart_discounts /// CREATE TABLE cart_discounts
@ -41,22 +41,10 @@ impl Migration {
/// ); /// );
/// ``` /// ```
async fn create_cart_discounts(m: &SchemaManager<'_>) -> Result<(), DbErr> { async fn create_cart_discounts(m: &SchemaManager<'_>) -> Result<(), DbErr> {
m.create_table( use CartDiscount::*;
Table::create()
.if_not_exists()
.table(CartDiscount::CartDiscounts)
.col(CartDiscount::CartId.col().uuid().not_null())
.col(CartDiscount::DiscountId.col().uuid().not_null())
.to_owned(),
)
.await?;
m.create_2_col_primary( m.create_bridge_table(CartDiscounts, CartId, DiscountId)
CartDiscount::CartDiscounts, .await?;
CartDiscount::CartId,
CartDiscount::DiscountId,
)
.await?;
Ok(()) Ok(())
} }
@ -69,22 +57,10 @@ impl Migration {
/// ); /// );
/// ``` /// ```
async fn create_cart_gift_cards(m: &SchemaManager<'_>) -> Result<(), DbErr> { async fn create_cart_gift_cards(m: &SchemaManager<'_>) -> Result<(), DbErr> {
m.create_table( use CartGiftCard::*;
Table::create()
.table(CartGiftCard::CartGiftCards)
.if_not_exists()
.col(CartGiftCard::CartId.col().uuid().not_null())
.col(CartGiftCard::GiftCardId.col().uuid().not_null())
.to_owned(),
)
.await?;
m.create_2_col_primary( m.create_bridge_table(CartGiftCards, CartId, GiftCardId)
CartGiftCard::CartGiftCards, .await?;
CartGiftCard::CartId,
CartGiftCard::GiftCardId,
)
.await?;
Ok(()) Ok(())
} }

View File

@ -3,7 +3,7 @@ use sea_orm_migration::prelude::*;
use crate::sea_orm::Iterable; use crate::sea_orm::Iterable;
use crate::{ use crate::{
auto_uuid_not_null, create_type, drop_type, to_fk_name, to_pk2_name, ts_def_now_not_null, auto_uuid_not_null, create_type, drop_type, to_fk_name, to_pk2_name, ts_def_now_not_null,
CreateIndexExt, DropTable, IntoColumnDef, CreateBridgeTable, DropTable, IntoColumnDef,
}; };
#[derive(DeriveMigrationName)] #[derive(DeriveMigrationName)]
@ -184,22 +184,10 @@ impl Migration {
/// discount_id uuid NOT NULL /// discount_id uuid NOT NULL
/// } /// }
async fn create_order_discounts(m: &SchemaManager<'_>) -> Result<(), DbErr> { async fn create_order_discounts(m: &SchemaManager<'_>) -> Result<(), DbErr> {
m.create_table( use OrderDiscount::*;
Table::create()
.table(OrderDiscount::OrderDiscounts)
.if_not_exists()
.col(OrderDiscount::OrderId.col().uuid().not_null())
.col(OrderDiscount::DiscountId.col().uuid().not_null())
.to_owned(),
)
.await?;
m.create_2_col_primary( m.create_bridge_table(OrderDiscounts, OrderId, DiscountId)
OrderDiscount::OrderDiscounts, .await?;
OrderDiscount::OrderId,
OrderDiscount::DiscountId,
)
.await?;
Ok(()) Ok(())
} }
@ -260,22 +248,10 @@ impl Migration {
/// } /// }
/// ``` /// ```
async fn create_order_gift_cards(m: &SchemaManager<'_>) -> Result<(), DbErr> { async fn create_order_gift_cards(m: &SchemaManager<'_>) -> Result<(), DbErr> {
m.create_table( use OrderGiftCard::*;
Table::create()
.table(OrderGiftCard::OrderGiftCards)
.if_not_exists()
.col(OrderGiftCard::OrderId.col().uuid().not_null())
.col(OrderGiftCard::GiftCardId.col().uuid().not_null())
.to_owned(),
)
.await?;
m.create_2_col_primary( m.create_bridge_table(OrderGiftCards, OrderId, GiftCardId)
OrderGiftCard::OrderGiftCards, .await?;
OrderGiftCard::OrderId,
OrderGiftCard::GiftCardId,
)
.await?;
Ok(()) Ok(())
} }
@ -294,28 +270,27 @@ impl Migration {
/// } /// }
/// ``` /// ```
async fn create_order_item_changes(m: &SchemaManager<'_>) -> Result<(), DbErr> { async fn create_order_item_changes(m: &SchemaManager<'_>) -> Result<(), DbErr> {
use OrderItemChange::*;
m.create_table( m.create_table(
Table::create() Table::create()
.table(OrderItemChange::OrderItemChanges) .table(OrderItemChanges)
.col(auto_uuid_not_null!(OrderItemChange::Id)) .col(auto_uuid_not_null!(Id))
.col(ts_def_now_not_null!(OrderItemChange::CreatedAt)) .col(ts_def_now_not_null!(CreatedAt))
.col(ts_def_now_not_null!(OrderItemChange::UpdatedAt)) .col(ts_def_now_not_null!(UpdatedAt))
.col(ColumnDef::new(OrderItemChange::DeletedAt).timestamp()) .col(DeletedAt.col().timestamp())
.col( .col(
ColumnDef::new(OrderItemChange::OrderItemChangeType) OrderItemChangeType
.col()
.enumeration( .enumeration(
crate::types::OrderItemChangeType::OrderItemChangeTypes, crate::types::OrderItemChangeType::OrderItemChangeTypes,
crate::types::OrderItemChangeType::iter().skip(1), crate::types::OrderItemChangeType::iter().skip(1),
) )
.not_null(), .not_null(),
) )
.col( .col(OrderEditId.col().uuid().not_null())
ColumnDef::new(OrderItemChange::OrderEditId) .col(OriginalLineItemId.col().uuid())
.uuid() .col(LineItemId.col().uuid())
.not_null(),
)
.col(ColumnDef::new(OrderItemChange::OriginalLineItemId).uuid())
.col(ColumnDef::new(OrderItemChange::LineItemId).uuid())
.to_owned(), .to_owned(),
) )
.await?; .await?;
@ -399,19 +374,21 @@ impl Migration {
/// } /// }
/// ``` /// ```
async fn create_payment_collections(m: &SchemaManager<'_>) -> Result<(), DbErr> { async fn create_payment_collections(m: &SchemaManager<'_>) -> Result<(), DbErr> {
use PaymentCollection::*;
m.create_table( m.create_table(
Table::create() Table::create()
.table(PaymentCollection::PaymentCollections) .table(PaymentCollections)
.col(auto_uuid_not_null!(PaymentCollection::Id)) .col(auto_uuid_not_null!(Id))
.col(ts_def_now_not_null!(PaymentCollection::CreatedAt)) .col(ts_def_now_not_null!(CreatedAt))
.col(ts_def_now_not_null!(PaymentCollection::UpdatedAt)) .col(ts_def_now_not_null!(UpdatedAt))
.col(PaymentCollection::DeletedAt.col().timestamp()) .col(DeletedAt.col().timestamp())
.col(PaymentCollection::PaymentCollectionType.col().enumeration( .col(PaymentCollectionType.col().enumeration(
crate::types::PaymentCollectionType::PaymentCollectionTypes, crate::types::PaymentCollectionType::PaymentCollectionTypes,
crate::types::PaymentCollectionType::iter().skip(1), crate::types::PaymentCollectionType::iter().skip(1),
)) ))
.col( .col(
PaymentCollection::Status Status
.col() .col()
.enumeration( .enumeration(
crate::types::PaymentCollectionStatus::PaymentCollectionStatuses, crate::types::PaymentCollectionStatus::PaymentCollectionStatuses,
@ -419,13 +396,13 @@ impl Migration {
) )
.not_null(), .not_null(),
) )
.col(PaymentCollection::Description.col().string()) .col(Description.col().string())
.col(PaymentCollection::Amount.col().integer().not_null()) .col(Amount.col().integer().not_null())
.col(PaymentCollection::AuthorizedAmount.col().integer()) .col(AuthorizedAmount.col().integer())
.col(PaymentCollection::RegionId.col().uuid().not_null()) .col(RegionId.col().uuid().not_null())
.col(PaymentCollection::CurrencyCode.col().string().not_null()) .col(CurrencyCode.col().string().not_null())
.col(PaymentCollection::Metadata.col().json_binary()) .col(Metadata.col().json_binary())
.col(PaymentCollection::CreatedBy.col().uuid().not_null()) .col(CreatedBy.col().uuid().not_null())
.to_owned(), .to_owned(),
) )
.await?; .await?;
@ -440,37 +417,18 @@ impl Migration {
/// } /// }
/// ``` /// ```
async fn create_payment_collection_payments(m: &SchemaManager<'_>) -> Result<(), DbErr> { async fn create_payment_collection_payments(m: &SchemaManager<'_>) -> Result<(), DbErr> {
m.create_table( use PaymentCollectionPayment::*;
Table::create()
.table(PaymentCollectionPayment::PaymentCollectionPayments)
.col(
PaymentCollectionPayment::PaymentCollectionId
.col()
.uuid()
.not_null(),
)
.col(PaymentCollectionPayment::PaymentId.col().uuid().not_null())
.to_owned(),
)
.await?;
m.create_2_col_primary( m.create_bridge_table(PaymentCollectionPayments, PaymentCollectionId, PaymentId)
PaymentCollectionPayment::PaymentCollectionPayments, .await?;
PaymentCollectionPayment::PaymentCollectionId,
PaymentCollectionPayment::PaymentId,
)
.await?;
m.create_foreign_key( m.create_foreign_key(
ForeignKeyCreateStatement::new() ForeignKeyCreateStatement::new()
.from( .from(PaymentCollectionPayments, PaymentCollectionId)
PaymentCollectionPayment::PaymentCollectionPayments,
PaymentCollectionPayment::PaymentCollectionId,
)
.to(PaymentCollection::PaymentCollections, PaymentCollection::Id) .to(PaymentCollection::PaymentCollections, PaymentCollection::Id)
.name(&to_fk_name( .name(&to_fk_name(
PaymentCollectionPayment::PaymentCollectionPayments, PaymentCollectionPayments,
PaymentCollectionPayment::PaymentCollectionId, PaymentCollectionId,
PaymentCollection::PaymentCollections, PaymentCollection::PaymentCollections,
PaymentCollection::Id, PaymentCollection::Id,
)) ))
@ -489,29 +447,12 @@ impl Migration {
/// } /// }
/// ```` /// ````
async fn create_payment_collection_sessions(m: &SchemaManager<'_>) -> Result<(), DbErr> { async fn create_payment_collection_sessions(m: &SchemaManager<'_>) -> Result<(), DbErr> {
m.create_table( use PaymentCollectionSession::*;
Table::create()
.table(PaymentCollectionSession::PaymentCollectionSessions)
.col(
PaymentCollectionSession::PaymentCollectionId
.col()
.uuid()
.not_null(),
)
.col(
PaymentCollectionSession::PaymentSessionId
.col()
.uuid()
.not_null(),
)
.to_owned(),
)
.await?;
m.create_2_col_primary( m.create_bridge_table(
PaymentCollectionSession::PaymentCollectionSessions, PaymentCollectionSessions,
PaymentCollectionSession::PaymentCollectionId, PaymentCollectionId,
PaymentCollectionSession::PaymentSessionId, PaymentSessionId,
) )
.await?; .await?;
Ok(()) Ok(())
@ -538,6 +479,7 @@ impl Migration {
.to_owned(), .to_owned(),
) )
.await?; .await?;
Ok(()) Ok(())
} }

View File

@ -1,7 +1,9 @@
use sea_orm_migration::prelude::*; use sea_orm_migration::prelude::*;
use crate::sea_orm::Iterable; use crate::sea_orm::Iterable;
use crate::{auto_uuid_not_null, create_type, drop_type, ts_def_now_not_null, DropTable}; use crate::{
auto_uuid_not_null, create_type, drop_type, ts_def_now_not_null, DropTable, IntoColumnDef,
};
#[derive(DeriveMigrationName)] #[derive(DeriveMigrationName)]
pub struct Migration; pub struct Migration;
@ -86,37 +88,36 @@ impl Migration {
/// ); /// );
/// ``` /// ```
async fn create_discounts(m: &SchemaManager<'_>) -> Result<(), DbErr> { async fn create_discounts(m: &SchemaManager<'_>) -> Result<(), DbErr> {
use Discount::*;
m.create_table( m.create_table(
Table::create() Table::create()
.table(Discount::Discounts) .table(Discounts)
.col(auto_uuid_not_null!(Discount::Id)) .col(auto_uuid_not_null!(Id))
.col(ColumnDef::new(Discount::Code).string().not_null()) .col(Code.col().string().not_null())
.col(ColumnDef::new(Discount::IsDynamic).boolean().not_null()) .col(IsDynamic.col().boolean().not_null())
.col(ColumnDef::new(Discount::RuleId).uuid()) .col(RuleId.col().uuid())
.col(ColumnDef::new(Discount::IsDisabled).boolean().not_null()) .col(IsDisabled.col().boolean().not_null())
.col(ColumnDef::new(Discount::ParentDiscountId).uuid()) .col(ParentDiscountId.col().uuid())
.col( .col(
ColumnDef::new(Discount::StartsAt) StartsAt
.col()
.timestamp() .timestamp()
.default(SimpleExpr::Custom("CURRENT_TIMESTAMP".into())) .default(SimpleExpr::Custom("CURRENT_TIMESTAMP".into()))
.not_null(), .not_null(),
) )
.col(ColumnDef::new(Discount::EndsAt).timestamp()) .col(EndsAt.col().timestamp())
.col(ts_def_now_not_null!(Discount::CreatedAt)) .col(ts_def_now_not_null!(Discount::CreatedAt))
.col(ts_def_now_not_null!(Discount::UpdatedAt)) .col(ts_def_now_not_null!(Discount::UpdatedAt))
.col(ColumnDef::new(Discount::DeletedAt).timestamp()) .col(DeletedAt.col().timestamp())
.col(ColumnDef::new(Discount::Metadata).json_binary()) .col(Metadata.col().json_binary())
.col(ColumnDef::new(Discount::UsageLimit).integer()) .col(UsageLimit.col().integer())
.col( .col(UsageCount.col().integer().default(0).not_null())
ColumnDef::new(Discount::UsageCount) .col(ValidDuration.col().string())
.integer()
.default(0)
.not_null(),
)
.col(ColumnDef::new(Discount::ValidDuration).string())
.to_owned(), .to_owned(),
) )
.await?; .await?;
Ok(()) Ok(())
} }
@ -134,29 +135,25 @@ impl Migration {
/// ); /// );
/// ``` /// ```
async fn create_discount_conditions(m: &SchemaManager<'_>) -> Result<(), DbErr> { async fn create_discount_conditions(m: &SchemaManager<'_>) -> Result<(), DbErr> {
use DiscountCondition::*;
m.create_table( m.create_table(
Table::create() Table::create()
.table(DiscountCondition::DiscountConditions) .table(DiscountConditions)
.col(auto_uuid_not_null!(DiscountCondition::Id)) .col(auto_uuid_not_null!(Id))
.col( .col(DiscountConditionType.col().enumeration(
ColumnDef::new(DiscountCondition::DiscountConditionType).enumeration( crate::types::DiscountConditionType::DiscountConditionTypes,
crate::types::DiscountConditionType::DiscountConditionTypes, crate::types::DiscountConditionType::iter().skip(1),
crate::types::DiscountConditionType::iter().skip(1), ))
), .col(Operator.col().enumeration(
)
.col(ColumnDef::new(DiscountCondition::Operator).enumeration(
crate::types::DiscountConditionOperator::DiscountConditionOperators, crate::types::DiscountConditionOperator::DiscountConditionOperators,
crate::types::DiscountConditionOperator::iter().skip(1), crate::types::DiscountConditionOperator::iter().skip(1),
)) ))
.col( .col(DiscountRuleId.col().uuid().not_null())
ColumnDef::new(DiscountCondition::DiscountRuleId) .col(ts_def_now_not_null!(CreatedAt))
.uuid() .col(ts_def_now_not_null!(UpdatedAt))
.not_null(), .col(DeletedAt.col().timestamp())
) .col(Metadata.col().json_binary())
.col(ts_def_now_not_null!(DiscountCondition::CreatedAt))
.col(ts_def_now_not_null!(DiscountCondition::UpdatedAt))
.col(ColumnDef::new(DiscountCondition::DeletedAt).timestamp())
.col(ColumnDef::new(DiscountCondition::Metadata).json_binary())
.to_owned(), .to_owned(),
) )
.await?; .await?;
@ -174,26 +171,16 @@ impl Migration {
/// ); /// );
/// ``` /// ```
async fn create_discount_condition_customer_groups(m: &SchemaManager<'_>) -> Result<(), DbErr> { async fn create_discount_condition_customer_groups(m: &SchemaManager<'_>) -> Result<(), DbErr> {
use DiscountConditionCustomerGroup::*;
m.create_table( m.create_table(
Table::create() Table::create()
.table(DiscountConditionCustomerGroup::DiscountConditionCustomerGroups) .table(DiscountConditionCustomerGroups)
.col( .col(CustomerGroupId.col().uuid().not_null())
ColumnDef::new(DiscountConditionCustomerGroup::CustomerGroupId) .col(ConditionId.col().uuid().not_null())
.uuid() .col(ts_def_now_not_null!(CreatedAt))
.not_null(), .col(ts_def_now_not_null!(UpdatedAt))
) .col(Metadata.col().json_binary())
.col(
ColumnDef::new(DiscountConditionCustomerGroup::ConditionId)
.uuid()
.not_null(),
)
.col(ts_def_now_not_null!(
DiscountConditionCustomerGroup::CreatedAt
))
.col(ts_def_now_not_null!(
DiscountConditionCustomerGroup::UpdatedAt
))
.col(ColumnDef::new(DiscountConditionCustomerGroup::Metadata).json_binary())
.to_owned(), .to_owned(),
) )
.await?; .await?;
@ -211,22 +198,16 @@ impl Migration {
/// ); /// );
/// ``` /// ```
async fn create_discount_condition_products(m: &SchemaManager<'_>) -> Result<(), DbErr> { async fn create_discount_condition_products(m: &SchemaManager<'_>) -> Result<(), DbErr> {
use DiscountConditionProduct::*;
m.create_table( m.create_table(
Table::create() Table::create()
.table(DiscountConditionProduct::DiscountConditionProducts) .table(DiscountConditionProducts)
.col( .col(ProductId.col().uuid().not_null())
ColumnDef::new(DiscountConditionProduct::ProductId) .col(ConditionId.col().uuid().not_null())
.uuid() .col(ts_def_now_not_null!(CreatedAt))
.not_null(), .col(ts_def_now_not_null!(UpdatedAt))
) .col(Metadata.col().json_binary())
.col(
ColumnDef::new(DiscountConditionProduct::ConditionId)
.uuid()
.not_null(),
)
.col(ts_def_now_not_null!(DiscountConditionProduct::CreatedAt))
.col(ts_def_now_not_null!(DiscountConditionProduct::UpdatedAt))
.col(ColumnDef::new(DiscountConditionProduct::Metadata).json_binary())
.to_owned(), .to_owned(),
) )
.await?; .await?;

View File

@ -39,6 +39,7 @@ async fn main() {
migrate_schema!(cli, Discounts, DiscountsMigrator); migrate_schema!(cli, Discounts, DiscountsMigrator);
migrate_schema!(cli, Checkouts, CheckoutsMigrator); migrate_schema!(cli, Checkouts, CheckoutsMigrator);
migrate_schema!(cli, Shipping, ShippingMigrator); migrate_schema!(cli, Shipping, ShippingMigrator);
migrate_schema!(cli, Stocks, StocksMigrator);
} }
pub async fn run_cli<M>(cli: &mut Cli, schema: PostgreSQLSchema, migrator: M) pub async fn run_cli<M>(cli: &mut Cli, schema: PostgreSQLSchema, migrator: M)

View File

@ -77,24 +77,25 @@ impl Migration {
/// ); /// );
/// ``` /// ```
async fn create_currencies(m: &SchemaManager<'_>) -> Result<(), DbErr> { async fn create_currencies(m: &SchemaManager<'_>) -> Result<(), DbErr> {
use Currency::*;
m.create_table( m.create_table(
Table::create() Table::create()
.table(Currency::Currencies) .table(Currencies)
.col(Currency::Code.col().string().not_null()) .col(Code.col().string().not_null())
.col(Currency::Symbol.col().string().not_null()) .col(Symbol.col().string().not_null())
.col(Currency::SymbolNative.col().string().not_null()) .col(SymbolNative.col().string().not_null())
.col(Currency::Name.col().string().not_null()) .col(Name.col().string().not_null())
.to_owned(), .primary_key(
) IndexCreateStatement::new()
.await?; .table(Currencies)
m.create_index( .col(Code)
IndexCreateStatement::new() .primary(),
.table(Currency::Currencies) )
.col(Currency::Code)
.primary()
.to_owned(), .to_owned(),
) )
.await?; .await?;
Ok(()) Ok(())
} }

View File

@ -10,6 +10,7 @@ pub enum PostgreSQLSchema {
Discounts, Discounts,
Checkouts, Checkouts,
Shipping, Shipping,
Stocks,
} }
impl PostgreSQLSchema { impl PostgreSQLSchema {
@ -21,6 +22,7 @@ impl PostgreSQLSchema {
PostgreSQLSchema::Discounts => "discounts", PostgreSQLSchema::Discounts => "discounts",
PostgreSQLSchema::Checkouts => "checkouts", PostgreSQLSchema::Checkouts => "checkouts",
PostgreSQLSchema::Shipping => "shipping", PostgreSQLSchema::Shipping => "shipping",
PostgreSQLSchema::Stocks => "stocks",
} }
} }
} }

View File

@ -54,48 +54,7 @@ pub trait IntoColumnDef: IntoIden {
impl<T: IntoIden> IntoColumnDef for T {} impl<T: IntoIden> IntoColumnDef for T {}
#[async_trait] #[async_trait]
pub trait CreateIndexExt { pub trait CreateBridgeTable {
async fn create_2_col_primary<T, C1, C2>(
&self,
table: T,
col1: C1,
col2: C2,
) -> Result<(), DbErr>
where
T: IntoIden + Copy + 'static + Sync + Send,
C1: IntoIden + Copy + 'static + Sync + Send,
C2: IntoIden + Copy + 'static + Sync + Send;
}
#[async_trait]
impl CreateIndexExt for SchemaManager<'_> {
async fn create_2_col_primary<T, C1, C2>(
&self,
table: T,
col1: C1,
col2: C2,
) -> Result<(), DbErr>
where
T: IntoIden + Copy + 'static + Sync + Send,
C1: IntoIden + Copy + 'static + Sync + Send,
C2: IntoIden + Copy + 'static + Sync + Send,
{
self.create_index(
IndexCreateStatement::new()
.table(table)
.col(col1)
.col(col2)
.name(&to_pk2_name(table, col1, col2))
.primary()
.if_not_exists()
.to_owned(),
)
.await
}
}
#[async_trait]
pub trait CreateBridgeTable: CreateIndexExt {
async fn create_bridge_table<T, C1, C2>( async fn create_bridge_table<T, C1, C2>(
&self, &self,
table: T, table: T,
@ -106,6 +65,22 @@ pub trait CreateBridgeTable: CreateIndexExt {
T: IntoIden + Copy + 'static + Sync + Send, T: IntoIden + Copy + 'static + Sync + Send,
C1: IntoIden + Copy + 'static + Sync + Send, C1: IntoIden + Copy + 'static + Sync + Send,
C2: IntoIden + Copy + 'static + Sync + Send; C2: IntoIden + Copy + 'static + Sync + Send;
fn bridge_primary_key<T, C1, C2>(&self, table: T, col1: C1, col2: C2) -> IndexCreateStatement
where
T: IntoIden + Copy + 'static + Sync + Send,
C1: IntoIden + Copy + 'static + Sync + Send,
C2: IntoIden + Copy + 'static + Sync + Send,
{
IndexCreateStatement::new()
.table(table)
.col(col1)
.col(col2)
.name(&to_pk2_name(table, col1, col2))
.primary()
.if_not_exists()
.to_owned()
}
} }
#[async_trait] #[async_trait]
@ -126,12 +101,11 @@ impl CreateBridgeTable for SchemaManager<'_> {
.table(table) .table(table)
.col(col1.col().uuid().not_null()) .col(col1.col().uuid().not_null())
.col(col2.col().uuid().not_null()) .col(col2.col().uuid().not_null())
.primary_key(&mut self.bridge_primary_key(table, col1, col2))
.to_owned(), .to_owned(),
) )
.await?; .await?;
self.create_2_col_primary(table, col1, col2).await?;
Ok(()) Ok(())
} }
} }
@ -321,7 +295,7 @@ impl From<Check> for Constraint {
impl Display for Constraint { impl Display for Constraint {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self { match self {
Constraint::Check(check) => f.write_fmt(format_args!("CHECK {check}")), Constraint::Check(check) => f.write_fmt(format_args!("CHECK ({check})")),
} }
} }
} }

View File

@ -3,8 +3,8 @@ use sea_orm_migration::prelude::*;
use crate::constraint::Check; use crate::constraint::Check;
use crate::sea_orm::Iterable; use crate::sea_orm::Iterable;
use crate::{ use crate::{
auto_uuid_not_null, ts_def_now_not_null, AsIden, CreateConstraint, CreateIndexExt, DropTable, auto_uuid_not_null, ts_def_now_not_null, AsIden, CreateBridgeTable, CreateConstraint,
IntoColumnDef, DropTable, IntoColumnDef,
}; };
#[derive(DeriveMigrationName)] #[derive(DeriveMigrationName)]
@ -351,13 +351,11 @@ impl Migration {
.col(ts_def_now_not_null!(CreatedAt)) .col(ts_def_now_not_null!(CreatedAt))
.col(ts_def_now_not_null!(UpdatedAt)) .col(ts_def_now_not_null!(UpdatedAt))
.col(Metadata.col().json_binary()) .col(Metadata.col().json_binary())
.primary_key(&mut m.bridge_primary_key(ShippingTaxRates, ShippingOptionId, RateId))
.to_owned(), .to_owned(),
) )
.await?; .await?;
m.create_2_col_primary(ShippingTaxRates, ShippingOptionId, RateId)
.await?;
Ok(()) Ok(())
} }
} }

View File

@ -4,7 +4,7 @@ use crate::constraint::Check;
use crate::sea_orm::Iterable; use crate::sea_orm::Iterable;
use crate::{ use crate::{
auto_uuid_not_null, ts_def_now_not_null, AsIden, CreateBridgeTable, CreateConstraint, auto_uuid_not_null, ts_def_now_not_null, AsIden, CreateBridgeTable, CreateConstraint,
CreateIndexExt, DropTable, IntoColumnDef, DropTable, IntoColumnDef,
}; };
#[derive(DeriveMigrationName)] #[derive(DeriveMigrationName)]
@ -460,13 +460,11 @@ impl Migration {
.col(ts_def_now_not_null!(CreatedAt)) .col(ts_def_now_not_null!(CreatedAt))
.col(ts_def_now_not_null!(UpdatedAt)) .col(ts_def_now_not_null!(UpdatedAt))
.col(Metadata.col().json_binary()) .col(Metadata.col().json_binary())
.primary_key(&mut m.bridge_primary_key(ProductTaxRates, ProductId, RateId))
.to_owned(), .to_owned(),
) )
.await?; .await?;
m.create_2_col_primary(ProductTaxRates, ProductId, RateId)
.await?;
Ok(()) Ok(())
} }
/// ```sql /// ```sql
@ -519,13 +517,11 @@ impl Migration {
.col(ts_def_now_not_null!(CreatedAt)) .col(ts_def_now_not_null!(CreatedAt))
.col(ts_def_now_not_null!(UpdatedAt)) .col(ts_def_now_not_null!(UpdatedAt))
.col(Metadata.col().json_binary()) .col(Metadata.col().json_binary())
.primary_key(&mut m.bridge_primary_key(ProductTypeTaxRates, ProductTypeId, RateId))
.to_owned(), .to_owned(),
) )
.await?; .await?;
m.create_2_col_primary(ProductTypeTaxRates, ProductTypeId, RateId)
.await?;
Ok(()) Ok(())
} }
/// ```sql /// ```sql

View File

@ -2,10 +2,10 @@ mod m20230603_120810_products;
use sea_orm_migration::{MigrationTrait, MigratorTrait}; use sea_orm_migration::{MigrationTrait, MigratorTrait};
pub struct ShocksMigrator; pub struct StocksMigrator;
#[async_trait::async_trait] #[async_trait::async_trait]
impl MigratorTrait for ShocksMigrator { impl MigratorTrait for StocksMigrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> { fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![Box::new(m20230603_120810_products::Migration)] vec![Box::new(m20230603_120810_products::Migration)]
} }