Vendor dependencies

This commit is contained in:
2026-08-01 16:11:49 +03:00
parent 7f139a0241
commit 6b5e7f0f8b
29706 changed files with 9575646 additions and 0 deletions
@@ -0,0 +1,44 @@
use sea_orm_migration::{prelude::*, schema::*};
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table("cake")
.col(pk_auto("id"))
.col(string("name"))
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("cake_name_index")
.table("cake")
.col("name")
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table("cake").to_owned())
.await?;
if std::env::var_os("ABORT_MIGRATION").eq(&Some("YES".into())) {
return Err(DbErr::Migration(
"Abort migration and rollback changes".into(),
));
}
Ok(())
}
}
@@ -0,0 +1,43 @@
use sea_orm_migration::sea_orm::DbBackend;
use sea_orm_migration::{prelude::*, schema::*};
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table("fruit")
.col(pk_auto("id"))
.col(string("name"))
.col(integer("cake_id"))
.foreign_key(
ForeignKey::create()
.name("fk-fruit-cake_id")
.from("fruit", "cake_id")
.to("cake", "id"),
)
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
if manager.get_database_backend() != DbBackend::Sqlite {
manager
.drop_foreign_key(
ForeignKey::drop()
.table("fruit")
.name("fk-fruit-cake_id")
.to_owned(),
)
.await?;
}
manager
.drop_table(Table::drop().table("fruit").to_owned())
.await
}
}
@@ -0,0 +1,49 @@
use sea_orm_migration::prelude::*;
use sea_orm_migration::sea_orm::{entity::*, query::*};
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let db = manager.get_connection();
cake::ActiveModel {
name: Set("Cheesecake".to_owned()),
..Default::default()
}
.insert(db)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let db = manager.get_connection();
cake::Entity::delete_many()
.filter(cake::Column::Name.eq("Cheesecake"))
.exec(db)
.await?;
Ok(())
}
}
mod cake {
use sea_orm_migration::sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "cake")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub name: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}
}
@@ -0,0 +1,47 @@
use sea_orm_migration::prelude::{sea_query::extension::postgres::Type, *};
use sea_orm_migration::sea_orm::{ConnectionTrait, DbBackend};
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let db = manager.get_connection();
if db.get_database_backend() == DbBackend::Postgres {
manager
.create_type(
Type::create()
.as_enum(Tea::Enum)
.values([Tea::EverydayTea, Tea::BreakfastTea])
.to_owned(),
)
.await?;
}
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let db = manager.get_connection();
if db.get_database_backend() == DbBackend::Postgres {
manager
.drop_type(Type::drop().name(Tea::Enum).to_owned())
.await?;
}
Ok(())
}
}
#[derive(DeriveIden)]
pub enum Tea {
#[sea_orm(iden = "tea")]
Enum,
#[sea_orm(iden = "EverydayTea")]
EverydayTea,
#[sea_orm(iden = "BreakfastTea")]
BreakfastTea,
}
@@ -0,0 +1,30 @@
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let insert = Query::insert()
.into_table("cake")
.columns(["name"])
.values_panic(["Tiramisu".into()])
.to_owned();
manager.execute(insert).await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let delete = Query::delete()
.from_table("cake")
.and_where(Expr::col("name").eq("Tiramisu"))
.to_owned();
manager.execute(delete).await?;
Ok(())
}
}
@@ -0,0 +1,63 @@
use sea_orm_migration::prelude::*;
use sea_orm_migration::sea_orm::{entity::*, query::*};
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let db = manager.get_connection();
let transaction = db.begin().await?;
cake::ActiveModel {
name: Set("Cheesecake".to_owned()),
..Default::default()
}
.insert(&transaction)
.await?;
if std::env::var_os("ABORT_MIGRATION").eq(&Some("YES".into())) {
return Err(DbErr::Migration(
"Abort migration and rollback changes".into(),
));
}
transaction.commit().await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let db = manager.get_connection();
let transaction = db.begin().await?;
cake::Entity::delete_many()
.filter(cake::Column::Name.eq("Cheesecake"))
.exec(&transaction)
.await?;
transaction.commit().await?;
Ok(())
}
}
mod cake {
use sea_orm_migration::sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "cake")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub name: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}
}
@@ -0,0 +1,63 @@
use sea_orm_migration::prelude::*;
use sea_orm_migration::schema::*;
use sea_orm_migration::sea_orm::DbBackend;
pub struct Migration {
pub use_transaction: Option<bool>,
pub should_fail: bool,
}
impl MigrationName for Migration {
fn name(&self) -> &str {
"m20250101_000001_create_test_table"
}
}
#[async_trait::async_trait]
impl MigrationTrait for Migration {
fn use_transaction(&self) -> Option<bool> {
self.use_transaction
}
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let expect_txn = self
.use_transaction
.unwrap_or(manager.get_database_backend() == DbBackend::Postgres);
assert_eq!(
manager.get_connection().is_transaction(),
expect_txn,
"up: expected is_transaction() = {expect_txn}"
);
manager
.create_table(
Table::create()
.table("test_table")
.col(pk_auto("id"))
.col(string("name"))
.to_owned(),
)
.await?;
if self.should_fail {
return Err(DbErr::Migration("intentional failure".into()));
}
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let expect_txn = self
.use_transaction
.unwrap_or(manager.get_database_backend() == DbBackend::Postgres);
assert_eq!(
manager.get_connection().is_transaction(),
expect_txn,
"down: expected is_transaction() = {expect_txn}"
);
manager
.drop_table(Table::drop().table("test_table").to_owned())
.await
}
}
@@ -0,0 +1,50 @@
use sea_orm_migration::prelude::*;
use sea_orm_migration::schema::*;
pub struct Migration;
impl MigrationName for Migration {
fn name(&self) -> &str {
"m20250101_000002_manual_transaction"
}
}
#[async_trait::async_trait]
impl MigrationTrait for Migration {
fn use_transaction(&self) -> Option<bool> {
Some(false)
}
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
assert!(
!manager.get_connection().is_transaction(),
"outer manager should not be in a transaction"
);
let m = manager.begin().await?;
assert!(
m.get_connection().is_transaction(),
"inner manager should be in a transaction"
);
m.create_table(
Table::create()
.table("manual_txn_table")
.col(pk_auto("id"))
.col(string("name"))
.to_owned(),
)
.await?;
m.commit().await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let m = manager.begin().await?;
m.drop_table(Table::drop().table("manual_txn_table").to_owned())
.await?;
m.commit().await?;
Ok(())
}
}
@@ -0,0 +1,8 @@
pub mod m20220118_000001_create_cake_table;
pub mod m20220118_000002_create_fruit_table;
pub mod m20220118_000003_seed_cake_table;
pub mod m20220118_000004_create_tea_enum;
pub mod m20220923_000001_seed_cake_table;
pub mod m20230109_000001_seed_cake_table;
pub mod m20250101_000001_create_test_table;
pub mod m20250101_000002_manual_transaction;