Skip to content

Commit

Permalink
refactor: upgrade sea-orm to v1 (#63)
Browse files Browse the repository at this point in the history
* chore(deps): bump sea-orm to v1

* chore(deps): bump sea-orm-migration to v1

* refactor(migration/user): use schema

* refactor(migration/user_feed_item): use schema

* refactor(migration/post): use schema

* refactor(migration/activity): use schema

* refactor(migration/received_follow): use schema

* refactor(migration/received_like): use schema

* refactor(migration/received_announce): use schema

* refactor(migration/user_feed_hatsu_extension): use schema

* refactor(migration/user_feed): use schema
  • Loading branch information
kwaa authored Sep 13, 2024
1 parent 9a59222 commit 625e1e3
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 182 deletions.
83 changes: 52 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,22 @@ reqwest = { version = "0.12", default-features = false, features = [
"rustls-tls",
] }
scraper = "0.20"
sea-orm = { version = "0.12", features = [
sea-orm = { version = "1.0", features = [
# https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime
"runtime-tokio-rustls",
"sqlx-postgres",
"sqlx-sqlite",
"runtime-tokio-rustls",
"macros",
"with-chrono",
"with-json",
"with-uuid",
] }
sea-orm-migration = { version = "1.0", features = [
# https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime
"runtime-tokio-rustls",
"sqlx-postgres",
"sqlx-sqlite",
] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1.0", features = ["full"] }
Expand Down
18 changes: 3 additions & 15 deletions crates/db_migration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@ repository.workspace = true
name = "hatsu_db_migration"
path = "src/lib.rs"

[dependencies.tokio]
workspace = true

[dependencies.sea-orm-migration]
version = "0.12"
features = [
# Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI.
# View the list of supported features at https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime.
# e.g.
# "runtime-tokio-rustls", # `ASYNC_RUNTIME` feature
# "sqlx-postgres", # `DATABASE_DRIVER` feature
"runtime-tokio-rustls",
"sqlx-postgres",
"sqlx-sqlite"
]
[dependencies]
tokio = { workspace = true }
sea-orm-migration = { workspace = true }
36 changes: 18 additions & 18 deletions crates/db_migration/src/m20240131_000001_user.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sea_orm_migration::prelude::*;
use sea_orm_migration::{prelude::*, schema::*};

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand All @@ -13,23 +13,23 @@ impl MigrationTrait for Migration {
Table::create()
.table(User::Table)
.if_not_exists()
.col(ColumnDef::new(User::Id).string().not_null().primary_key())
.col(ColumnDef::new(User::Name).string().not_null().unique_key())
.col(ColumnDef::new(User::PreferredUsername).string().not_null())
.col(ColumnDef::new(User::Summary).string())
.col(ColumnDef::new(User::Icon).string())
.col(ColumnDef::new(User::Image).string())
.col(ColumnDef::new(User::Inbox).string().not_null())
.col(ColumnDef::new(User::Outbox).string().not_null())
.col(ColumnDef::new(User::Followers).string().not_null())
.col(ColumnDef::new(User::Following).string().not_null())
.col(ColumnDef::new(User::Local).boolean().not_null())
.col(ColumnDef::new(User::PublicKey).string().not_null())
.col(ColumnDef::new(User::PrivateKey).string())
.col(ColumnDef::new(User::FeedJson).string())
.col(ColumnDef::new(User::FeedAtom).string())
.col(ColumnDef::new(User::FeedRss).string())
.col(ColumnDef::new(User::LastRefreshedAt).string().not_null())
.col(string(User::Id).primary_key())
.col(string_uniq(User::Name))
.col(string(User::PreferredUsername))
.col(string_null(User::Summary))
.col(string_null(User::Icon))
.col(string_null(User::Image))
.col(string(User::Inbox))
.col(string(User::Outbox))
.col(string(User::Followers))
.col(string(User::Following))
.col(boolean(User::Local))
.col(string(User::PublicKey))
.col(string_null(User::PrivateKey))
.col(string_null(User::FeedJson))
.col(string_null(User::FeedAtom))
.col(string_null(User::FeedRss))
.col(string(User::LastRefreshedAt))
.to_owned(),
)
.await?;
Expand Down
25 changes: 10 additions & 15 deletions crates/db_migration/src/m20240131_000002_user_feed_item.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sea_orm_migration::prelude::*;
use sea_orm_migration::{prelude::*, schema::*};

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand All @@ -11,20 +11,15 @@ impl MigrationTrait for Migration {
Table::create()
.table(UserFeedItem::Table)
.if_not_exists()
.col(
ColumnDef::new(UserFeedItem::Id)
.string()
.not_null()
.primary_key(),
)
.col(ColumnDef::new(UserFeedItem::UserId).string().not_null())
.col(ColumnDef::new(UserFeedItem::PostId).string())
.col(ColumnDef::new(UserFeedItem::Title).string())
.col(ColumnDef::new(UserFeedItem::Summary).string())
.col(ColumnDef::new(UserFeedItem::Language).string())
.col(ColumnDef::new(UserFeedItem::Tags).string())
.col(ColumnDef::new(UserFeedItem::DatePublished).string())
.col(ColumnDef::new(UserFeedItem::DateModified).string())
.col(string(UserFeedItem::Id).primary_key())
.col(string(UserFeedItem::UserId))
.col(string_null(UserFeedItem::PostId))
.col(string_null(UserFeedItem::Title))
.col(string_null(UserFeedItem::Summary))
.col(string_null(UserFeedItem::Language))
.col(string_null(UserFeedItem::Tags))
.col(string_null(UserFeedItem::DatePublished))
.col(string_null(UserFeedItem::DateModified))
.to_owned(),
)
.await?;
Expand Down
20 changes: 10 additions & 10 deletions crates/db_migration/src/m20240131_000003_post.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sea_orm_migration::prelude::*;
use sea_orm_migration::{prelude::*, schema::*};

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand All @@ -13,15 +13,15 @@ impl MigrationTrait for Migration {
Table::create()
.table(Post::Table)
.if_not_exists()
.col(ColumnDef::new(Post::Id).string().not_null().primary_key())
.col(ColumnDef::new(Post::Object).text().not_null())
.col(ColumnDef::new(Post::AttributedTo).string().not_null())
.col(ColumnDef::new(Post::InReplyTo).string())
.col(ColumnDef::new(Post::InReplyToRoot).string())
.col(ColumnDef::new(Post::Published).string().not_null())
.col(ColumnDef::new(Post::Updated).string())
.col(ColumnDef::new(Post::LastRefreshedAt).string().not_null())
.col(ColumnDef::new(Post::Local).boolean().not_null())
.col(string(Post::Id).primary_key())
.col(text(Post::Object))
.col(string(Post::AttributedTo))
.col(string_null(Post::InReplyTo))
.col(string_null(Post::InReplyToRoot))
.col(string(Post::Published))
.col(string_null(Post::Updated))
.col(string(Post::LastRefreshedAt))
.col(boolean(Post::Local))
.to_owned(),
)
.await?;
Expand Down
12 changes: 6 additions & 6 deletions crates/db_migration/src/m20240131_000004_activity.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sea_orm_migration::prelude::*;
use sea_orm_migration::{prelude::*, schema::*};

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand All @@ -11,11 +11,11 @@ impl MigrationTrait for Migration {
Table::create()
.table(Activity::Table)
.if_not_exists()
.col(ColumnDef::new(Activity::Id).uuid().not_null().primary_key())
.col(ColumnDef::new(Activity::Activity).json().not_null())
.col(ColumnDef::new(Activity::Actor).string().not_null())
.col(ColumnDef::new(Activity::Kind).string().not_null())
.col(ColumnDef::new(Activity::Published).string())
.col(uuid(Activity::Id).primary_key())
.col(json(Activity::Activity))
.col(string(Activity::Actor))
.col(string(Activity::Kind))
.col(string_null(Activity::Published))
.to_owned(),
)
.await?;
Expand Down
15 changes: 5 additions & 10 deletions crates/db_migration/src/m20240131_000005_received_follow.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sea_orm_migration::prelude::*;
use sea_orm_migration::{prelude::*, schema::*};

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand All @@ -11,15 +11,10 @@ impl MigrationTrait for Migration {
Table::create()
.table(ReceivedFollow::Table)
.if_not_exists()
.col(
ColumnDef::new(ReceivedFollow::Id)
.string()
.not_null()
.primary_key(),
)
.col(ColumnDef::new(ReceivedFollow::Actor).string().not_null())
.col(ColumnDef::new(ReceivedFollow::To).text())
.col(ColumnDef::new(ReceivedFollow::Object).string().not_null())
.col(string(ReceivedFollow::Id).primary_key())
.col(string(ReceivedFollow::Actor))
.col(text_null(ReceivedFollow::To))
.col(string(ReceivedFollow::Object))
.to_owned(),
)
.await?;
Expand Down
Loading

0 comments on commit 625e1e3

Please sign in to comment.