about page
This commit is contained in:
@@ -12,6 +12,7 @@ mod m20260517_000007_audio_tags;
|
||||
mod m20260517_000008_audio_track_tags;
|
||||
mod m20260517_000009_simple_constraints;
|
||||
mod m20260517_000010_drop_user_roles;
|
||||
mod m20260517_000011_site_pages;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
@@ -30,6 +31,7 @@ impl MigratorTrait for Migrator {
|
||||
Box::new(m20260517_000008_audio_track_tags::Migration),
|
||||
Box::new(m20260517_000009_simple_constraints::Migration),
|
||||
Box::new(m20260517_000010_drop_user_roles::Migration),
|
||||
Box::new(m20260517_000011_site_pages::Migration),
|
||||
// inject-above (do not remove this comment)
|
||||
]
|
||||
}
|
||||
|
||||
65
migration/src/m20260517_000011_site_pages.rs
Normal file
65
migration/src/m20260517_000011_site_pages.rs
Normal file
@@ -0,0 +1,65 @@
|
||||
use sea_orm_migration::{prelude::*, sea_orm::ConnectionTrait, sea_query::Expr};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum SitePages {
|
||||
Table,
|
||||
Id,
|
||||
Slug,
|
||||
Title,
|
||||
Content,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.create_table(
|
||||
Table::create()
|
||||
.table(SitePages::Table)
|
||||
.if_not_exists()
|
||||
.col(ColumnDef::new(SitePages::Id).uuid().not_null().primary_key())
|
||||
.col(
|
||||
ColumnDef::new(SitePages::Slug)
|
||||
.string_len(100)
|
||||
.not_null()
|
||||
.unique_key(),
|
||||
)
|
||||
.col(ColumnDef::new(SitePages::Title).string_len(500).not_null())
|
||||
.col(ColumnDef::new(SitePages::Content).text().not_null())
|
||||
.col(
|
||||
ColumnDef::new(SitePages::CreatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(SitePages::UpdatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
m.get_connection()
|
||||
.execute_unprepared(
|
||||
"INSERT INTO site_pages (id, slug, title, content, created_at, updated_at) \
|
||||
VALUES (gen_random_uuid(), 'about', 'About', '', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) \
|
||||
ON CONFLICT (slug) DO NOTHING",
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||
m.drop_table(Table::drop().table(SitePages::Table).to_owned())
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user