Skip to content

Commit

Permalink
feat: usersテーブルのマイグレーションを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
rito528 committed Oct 8, 2023
1 parent b6ad764 commit d3a5bf1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions server/migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod m20230614_083950_crate_form_response_period_table;
mod m20230622_053919_create_form_webhook;
mod m20230811_062425_create_answer_tables;
mod m20230908_140907_create_default_answer_titles;
mod m20231008_135425_create_user_table;

pub struct Migrator;

Expand All @@ -21,6 +22,7 @@ impl MigratorTrait for Migrator {
Box::new(m20230622_053919_create_form_webhook::Migration),
Box::new(m20230811_062425_create_answer_tables::Migration),
Box::new(m20230908_140907_create_default_answer_titles::Migration),
Box::new(m20231008_135425_create_user_table::Migration),
]
}
}
41 changes: 41 additions & 0 deletions server/migration/src/m20231008_135425_create_user_table.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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(UsersTable::Users)
.if_not_exists()
.col(
ColumnDef::new(UsersTable::Id)
.uuid()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(UsersTable::Uuid).uuid().not_null())
.col(ColumnDef::new(UsersTable::Name).string().not_null())
.to_owned(),
)
.await
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(UsersTable::Users).to_owned())
.await
}
}

#[derive(DeriveIden)]
enum UsersTable {
Users,
Id,
Uuid,
Name,
}

0 comments on commit d3a5bf1

Please sign in to comment.