add events and rooms migrations
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-07-24 23:08:02 +02:00
parent 9510d9c765
commit d98e9ea9e3
17 changed files with 324 additions and 315 deletions

View File

@@ -5,5 +5,6 @@ edition = "2021"
publish = false
[dependencies]
sea-orm-migration = "^0.8"
sea-orm-migration = "^0.9"
neo-entity = { path = "../neo-entity" }
automod = "1"

View File

@@ -1,8 +1,6 @@
pub use sea_orm_migration::prelude::*;
mod m20220707_092851_create_users;
mod m20220707_112339_create_devices;
mod m20220707_143304_create_sessions;
automod::dir!("src");
pub struct Migrator;
@@ -13,6 +11,8 @@ impl MigratorTrait for Migrator {
Box::new(m20220707_092851_create_users::Migration),
Box::new(m20220707_112339_create_devices::Migration),
Box::new(m20220707_143304_create_sessions::Migration),
Box::new(m20220724_223253_create_rooms::Migration),
Box::new(m20220724_223335_create_events::Migration),
]
}
}

View File

@@ -1,14 +1,9 @@
use neo_entity::users::{self, Entity as User};
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
impl MigrationName for Migration {
fn name(&self) -> &str {
"m20220707_092851_create_users"
}
}
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {

View File

@@ -1,14 +1,9 @@
use neo_entity::devices::{self, Entity as Device};
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
impl MigrationName for Migration {
fn name(&self) -> &str {
"m20220707_112339_create_devices.rs"
}
}
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {

View File

@@ -1,14 +1,9 @@
use neo_entity::sessions::{self, Entity as Session};
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
impl MigrationName for Migration {
fn name(&self) -> &str {
"m20220707_143304_create_sessions.rs"
}
}
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {

View File

@@ -0,0 +1,26 @@
use neo_entity::rooms::{self, Entity as Room};
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
.create_table(
Table::create()
.table(Room)
.if_not_exists()
.col(
ColumnDef::new(rooms::Column::Uuid)
.uuid()
.primary_key()
.not_null(),
)
.col(ColumnDef::new(rooms::Column::Name).string().not_null())
.to_owned(),
)
.await
}
}

View File

@@ -0,0 +1,72 @@
use neo_entity::events::{self, Entity as Event};
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
.create_table(
Table::create()
.table(Event)
.if_not_exists()
.col(
ColumnDef::new(events::Column::Uuid)
.uuid()
.primary_key()
.not_null(),
)
.col(ColumnDef::new(events::Column::RoomUuid).uuid().not_null())
.col(ColumnDef::new(events::Column::Type).string().not_null())
.col(ColumnDef::new(events::Column::StateKey).string())
.col(ColumnDef::new(events::Column::SenderUuid).uuid().not_null())
.col(
ColumnDef::new(events::Column::OriginServerTs)
.integer()
.not_null(),
)
.col(ColumnDef::new(events::Column::Content).json().not_null())
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("room_uuid_index")
.table(Event)
.col(events::Column::RoomUuid)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("type_index")
.table(Event)
.col(events::Column::Type)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("state_key_index")
.table(Event)
.col(events::Column::StateKey)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("type_state_key_index")
.table(Event)
.col(events::Column::Type)
.col(events::Column::StateKey)
.to_owned(),
)
.await
}
}