chore: reorganize project into monorepo
This commit is contained in:
22
backend/migration/Cargo.toml
Normal file
22
backend/migration/Cargo.toml
Normal file
@@ -0,0 +1,22 @@
|
||||
[package]
|
||||
name = "migration"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
name = "migration"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
loco-rs = { workspace = true }
|
||||
|
||||
|
||||
[dependencies.sea-orm-migration]
|
||||
version = "1.1.0"
|
||||
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
|
||||
]
|
||||
36
backend/migration/src/lib.rs
Normal file
36
backend/migration/src/lib.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
#![allow(elided_lifetimes_in_paths)]
|
||||
#![allow(clippy::wildcard_imports)]
|
||||
pub use sea_orm_migration::prelude::*;
|
||||
mod m20220101_000001_users;
|
||||
|
||||
mod m20260327_060643_posts;
|
||||
mod m20260327_061007_comments;
|
||||
mod m20260327_061008_tags;
|
||||
mod m20260327_061234_friend_links;
|
||||
mod m20260327_061300_reviews;
|
||||
mod m20260328_000001_add_post_slug_to_comments;
|
||||
mod m20260328_000002_create_site_settings;
|
||||
mod m20260328_000003_add_site_url_to_site_settings;
|
||||
mod m20260328_000004_add_posts_search_index;
|
||||
mod m20260328_000005_categories;
|
||||
pub struct Migrator;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigratorTrait for Migrator {
|
||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||
vec![
|
||||
Box::new(m20220101_000001_users::Migration),
|
||||
Box::new(m20260327_060643_posts::Migration),
|
||||
Box::new(m20260327_061007_comments::Migration),
|
||||
Box::new(m20260327_061008_tags::Migration),
|
||||
Box::new(m20260327_061234_friend_links::Migration),
|
||||
Box::new(m20260327_061300_reviews::Migration),
|
||||
Box::new(m20260328_000001_add_post_slug_to_comments::Migration),
|
||||
Box::new(m20260328_000002_create_site_settings::Migration),
|
||||
Box::new(m20260328_000003_add_site_url_to_site_settings::Migration),
|
||||
Box::new(m20260328_000004_add_posts_search_index::Migration),
|
||||
Box::new(m20260328_000005_categories::Migration),
|
||||
// inject-above (do not remove this comment)
|
||||
]
|
||||
}
|
||||
}
|
||||
41
backend/migration/src/m20220101_000001_users.rs
Normal file
41
backend/migration/src/m20220101_000001_users.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
use loco_rs::schema::*;
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
create_table(
|
||||
m,
|
||||
"users",
|
||||
&[
|
||||
("id", ColType::PkAuto),
|
||||
("pid", ColType::Uuid),
|
||||
("email", ColType::StringUniq),
|
||||
("password", ColType::String),
|
||||
("api_key", ColType::StringUniq),
|
||||
("name", ColType::String),
|
||||
("reset_token", ColType::StringNull),
|
||||
("reset_sent_at", ColType::TimestampWithTimeZoneNull),
|
||||
("email_verification_token", ColType::StringNull),
|
||||
(
|
||||
"email_verification_sent_at",
|
||||
ColType::TimestampWithTimeZoneNull,
|
||||
),
|
||||
("email_verified_at", ColType::TimestampWithTimeZoneNull),
|
||||
("magic_link_token", ColType::StringNull),
|
||||
("magic_link_expiration", ColType::TimestampWithTimeZoneNull),
|
||||
],
|
||||
&[],
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
drop_table(m, "users").await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
33
backend/migration/src/m20260327_060643_posts.rs
Normal file
33
backend/migration/src/m20260327_060643_posts.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use loco_rs::schema::*;
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
create_table(
|
||||
m,
|
||||
"posts",
|
||||
&[
|
||||
("id", ColType::PkAuto),
|
||||
("title", ColType::StringNull),
|
||||
("slug", ColType::String),
|
||||
("description", ColType::StringNull),
|
||||
("content", ColType::TextNull),
|
||||
("category", ColType::StringNull),
|
||||
("tags", ColType::JsonBinaryNull),
|
||||
("post_type", ColType::StringNull),
|
||||
("image", ColType::StringNull),
|
||||
("pinned", ColType::BooleanNull),
|
||||
],
|
||||
&[],
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
drop_table(m, "posts").await
|
||||
}
|
||||
}
|
||||
31
backend/migration/src/m20260327_061007_comments.rs
Normal file
31
backend/migration/src/m20260327_061007_comments.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use loco_rs::schema::*;
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
create_table(
|
||||
m,
|
||||
"comments",
|
||||
&[
|
||||
("id", ColType::PkAuto),
|
||||
("post_id", ColType::UuidNull),
|
||||
("author", ColType::StringNull),
|
||||
("email", ColType::StringNull),
|
||||
("avatar", ColType::StringNull),
|
||||
("content", ColType::TextNull),
|
||||
("reply_to", ColType::UuidNull),
|
||||
("approved", ColType::BooleanNull),
|
||||
],
|
||||
&[],
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
drop_table(m, "comments").await
|
||||
}
|
||||
}
|
||||
26
backend/migration/src/m20260327_061008_tags.rs
Normal file
26
backend/migration/src/m20260327_061008_tags.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use loco_rs::schema::*;
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
create_table(
|
||||
m,
|
||||
"tags",
|
||||
&[
|
||||
("id", ColType::PkAuto),
|
||||
("name", ColType::StringNull),
|
||||
("slug", ColType::String),
|
||||
],
|
||||
&[],
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
drop_table(m, "tags").await
|
||||
}
|
||||
}
|
||||
30
backend/migration/src/m20260327_061234_friend_links.rs
Normal file
30
backend/migration/src/m20260327_061234_friend_links.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use loco_rs::schema::*;
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
create_table(
|
||||
m,
|
||||
"friend_links",
|
||||
&[
|
||||
("id", ColType::PkAuto),
|
||||
("site_name", ColType::StringNull),
|
||||
("site_url", ColType::String),
|
||||
("avatar_url", ColType::StringNull),
|
||||
("description", ColType::StringNull),
|
||||
("category", ColType::StringNull),
|
||||
("status", ColType::StringNull),
|
||||
],
|
||||
&[],
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
drop_table(m, "friend_links").await
|
||||
}
|
||||
}
|
||||
32
backend/migration/src/m20260327_061300_reviews.rs
Normal file
32
backend/migration/src/m20260327_061300_reviews.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use loco_rs::schema::*;
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
create_table(
|
||||
m,
|
||||
"reviews",
|
||||
&[
|
||||
("id", ColType::PkAuto),
|
||||
("title", ColType::StringNull),
|
||||
("review_type", ColType::StringNull),
|
||||
("rating", ColType::IntegerNull),
|
||||
("review_date", ColType::StringNull),
|
||||
("status", ColType::StringNull),
|
||||
("description", ColType::StringNull),
|
||||
("tags", ColType::StringNull),
|
||||
("cover", ColType::StringNull),
|
||||
],
|
||||
&[],
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
drop_table(m, "reviews").await
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
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> {
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Alias::new("comments"))
|
||||
.add_column_if_not_exists(
|
||||
ColumnDef::new(Alias::new("post_slug")).string().null(),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Alias::new("comments"))
|
||||
.drop_column(Alias::new("post_slug"))
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
use loco_rs::schema::*;
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
create_table(
|
||||
m,
|
||||
"site_settings",
|
||||
&[
|
||||
("id", ColType::PkAuto),
|
||||
("site_name", ColType::StringNull),
|
||||
("site_short_name", ColType::StringNull),
|
||||
("site_url", ColType::StringNull),
|
||||
("site_title", ColType::StringNull),
|
||||
("site_description", ColType::StringNull),
|
||||
("hero_title", ColType::StringNull),
|
||||
("hero_subtitle", ColType::StringNull),
|
||||
("owner_name", ColType::StringNull),
|
||||
("owner_title", ColType::StringNull),
|
||||
("owner_bio", ColType::TextNull),
|
||||
("owner_avatar_url", ColType::StringNull),
|
||||
("social_github", ColType::StringNull),
|
||||
("social_twitter", ColType::StringNull),
|
||||
("social_email", ColType::StringNull),
|
||||
("location", ColType::StringNull),
|
||||
("tech_stack", ColType::JsonBinaryNull),
|
||||
],
|
||||
&[],
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
drop_table(m, "site_settings").await
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
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> {
|
||||
if manager.has_column("site_settings", "site_url").await? {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Alias::new("site_settings"))
|
||||
.add_column(ColumnDef::new(Alias::new("site_url")).string().null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
if !manager.has_column("site_settings", "site_url").await? {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Alias::new("site_settings"))
|
||||
.drop_column(Alias::new("site_url"))
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
use sea_orm_migration::prelude::*;
|
||||
use sea_orm_migration::sea_orm::DbBackend;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
if manager.get_database_backend() != DbBackend::Postgres {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
manager
|
||||
.get_connection()
|
||||
.execute_unprepared(
|
||||
r#"
|
||||
CREATE INDEX IF NOT EXISTS idx_posts_search_fts
|
||||
ON posts
|
||||
USING GIN (
|
||||
(
|
||||
setweight(to_tsvector('simple', coalesce(title, '')), 'A') ||
|
||||
setweight(to_tsvector('simple', coalesce(description, '')), 'B') ||
|
||||
setweight(to_tsvector('simple', coalesce(category, '')), 'C') ||
|
||||
setweight(to_tsvector('simple', coalesce(tags::text, '')), 'C') ||
|
||||
setweight(to_tsvector('simple', coalesce(content, '')), 'D')
|
||||
)
|
||||
);
|
||||
"#,
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
if manager.get_database_backend() != DbBackend::Postgres {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
manager
|
||||
.get_connection()
|
||||
.execute_unprepared("DROP INDEX IF EXISTS idx_posts_search_fts;")
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
26
backend/migration/src/m20260328_000005_categories.rs
Normal file
26
backend/migration/src/m20260328_000005_categories.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use loco_rs::schema::*;
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
create_table(
|
||||
m,
|
||||
"categories",
|
||||
&[
|
||||
("id", ColType::PkAuto),
|
||||
("name", ColType::StringNull),
|
||||
("slug", ColType::String),
|
||||
],
|
||||
&[],
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
drop_table(m, "categories").await
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user