gitdataai/libs/migrate/user_billing_history.rs

57 lines
1.4 KiB
Rust

use sea_orm_migration::prelude::*;
pub struct Migration;
impl MigrationName for Migration {
fn name(&self) -> &str {
"user_billing_history"
}
}
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.get_connection()
.execute_unprepared(
r#"
create table if not exists user_billing_history
(
uid uuid not null
primary key,
user_uuid uuid not null,
amount numeric not null,
currency text not null,
reason text not null,
extra jsonb,
created_at timestamp with time zone not null
);
create index if not exists idx_user_billing_history_user
on user_billing_history (user_uuid);
create index if not exists idx_user_billing_history_created_at
on user_billing_history (created_at);
"#,
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.get_connection()
.execute_unprepared(
r#"
drop index if exists idx_user_billing_history_created_at;
drop index if exists idx_user_billing_history_user;
drop table if exists user_billing_history;
"#,
)
.await?;
Ok(())
}
}