billing_customer.rs

 1use crate::db::{BillingCustomerId, UserId};
 2use sea_orm::entity::prelude::*;
 3
 4/// A billing customer.
 5#[derive(Clone, Debug, Default, PartialEq, Eq, DeriveEntityModel)]
 6#[sea_orm(table_name = "billing_customers")]
 7pub struct Model {
 8    #[sea_orm(primary_key)]
 9    pub id: BillingCustomerId,
10    pub user_id: UserId,
11    pub stripe_customer_id: String,
12    pub has_overdue_invoices: bool,
13    pub trial_started_at: Option<DateTime>,
14    pub created_at: DateTime,
15}
16
17#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
18pub enum Relation {
19    #[sea_orm(
20        belongs_to = "super::user::Entity",
21        from = "Column::UserId",
22        to = "super::user::Column::Id"
23    )]
24    User,
25    #[sea_orm(has_many = "super::billing_subscription::Entity")]
26    BillingSubscription,
27}
28
29impl Related<super::user::Entity> for Entity {
30    fn to() -> RelationDef {
31        Relation::User.def()
32    }
33}
34
35impl Related<super::billing_subscription::Entity> for Entity {
36    fn to() -> RelationDef {
37        Relation::BillingSubscription.def()
38    }
39}
40
41impl ActiveModelBehavior for ActiveModel {}