Parent and child posts

This commit is contained in:
Bad Manners 2025-04-08 23:10:10 -03:00
parent 04f888c323
commit 54379b98e0
16 changed files with 334 additions and 58 deletions

View file

@ -32,6 +32,29 @@ impl MigrationTrait for Migration {
)
.await?;
manager
.create_table(
Table::create()
.table(SameyTag::Table)
.if_not_exists()
.col(pk_auto(SameyTag::Id))
.col(string_len(SameyTag::Name, 100))
.col(string_len_uniq(SameyTag::NormalizedName, 100))
.to_owned(),
)
.await?;
manager
.create_table(
Table::create()
.table(SameyPool::Table)
.if_not_exists()
.col(pk_auto(SameyPool::Id))
.col(string_len_uniq(SameyPool::Name, 100))
.to_owned(),
)
.await?;
manager
.create_table(
Table::create()
@ -98,18 +121,6 @@ impl MigrationTrait for Migration {
)
.await?;
manager
.create_table(
Table::create()
.table(SameyTag::Table)
.if_not_exists()
.col(pk_auto(SameyTag::Id))
.col(string_len(SameyTag::Name, 100))
.col(string_len_uniq(SameyTag::NormalizedName, 100))
.to_owned(),
)
.await?;
manager
.create_table(
Table::create()
@ -142,6 +153,39 @@ impl MigrationTrait for Migration {
)
.await?;
manager
.create_table(
Table::create()
.table(SameyPoolPost::Table)
.if_not_exists()
.col(pk_auto(SameyPoolPost::Id))
.col(integer(SameyPoolPost::PoolId))
.col(integer(SameyPoolPost::PostId))
.col(float(SameyPoolPost::Position))
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-samey_pool_post-samey_pool-pool_id")
.from(SameyPoolPost::Table, SameyPoolPost::PoolId)
.to(SameyPool::Table, SameyPool::Id)
.on_delete(ForeignKeyAction::Cascade),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-samey_pool_post-samey_post-post_id")
.from(SameyPoolPost::Table, SameyPoolPost::PostId)
.to(SameyPost::Table, SameyPost::Id)
.on_delete(ForeignKeyAction::Cascade),
)
.index(
Index::create()
.unique()
.col(SameyPoolPost::PoolId)
.col(SameyPoolPost::PostId),
)
.to_owned(),
)
.await?;
Ok(())
}
@ -149,11 +193,11 @@ impl MigrationTrait for Migration {
// Replace the sample below with your own migration scripts
manager
.drop_table(Table::drop().table(SameyTagPost::Table).to_owned())
.drop_table(Table::drop().table(SameyPoolPost::Table).to_owned())
.await?;
manager
.drop_table(Table::drop().table(SameyTag::Table).to_owned())
.drop_table(Table::drop().table(SameyTagPost::Table).to_owned())
.await?;
manager
@ -164,6 +208,14 @@ impl MigrationTrait for Migration {
.drop_table(Table::drop().table(SameyPost::Table).to_owned())
.await?;
manager
.drop_table(Table::drop().table(SameyPool::Table).to_owned())
.await?;
manager
.drop_table(Table::drop().table(SameyTag::Table).to_owned())
.await?;
manager
.drop_table(Table::drop().table(SameyUser::Table).to_owned())
.await?;
@ -255,3 +307,21 @@ enum SameyTagPost {
TagId,
PostId,
}
#[derive(DeriveIden)]
enum SameyPool {
#[sea_orm(iden = "samey_pool")]
Table,
Id,
Name,
}
#[derive(DeriveIden)]
enum SameyPoolPost {
#[sea_orm(iden = "samey_pool_post")]
Table,
Id,
PoolId,
PostId,
Position,
}