Skip to content

Commit

Permalink
feat: DBマイグレーションにユーザー情報を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
rito528 committed Oct 8, 2023
1 parent d3a5bf1 commit 06a7935
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ pub struct Migrator;
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![
Box::new(m20231008_135425_create_user_table::Migration),
Box::new(m20220101_000001_create_table::Migration),
Box::new(m20221211_211233_form_questions::Migration),
Box::new(m20230219_143118_create_form_choices::Migration),
Box::new(m20230614_083950_crate_form_response_period_table::Migration),
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),
]
}
}
31 changes: 31 additions & 0 deletions server/migration/src/m20220101_000001_create_table.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::m20231008_135425_create_user_table::UsersTable;
use sea_orm_migration::prelude::*;

#[derive(DeriveMigrationName)]
Expand Down Expand Up @@ -26,12 +27,40 @@ impl MigrationTrait for Migration {
.not_null()
.extra("DEFAULT CURRENT_TIMESTAMP".to_string()),
)
.col(
ColumnDef::new(FormMetaDataTable::CreatedBy)
.integer()
.not_null(),
)
.foreign_key(
ForeignKey::create()
.name("fk-created-user-id")
.from(
FormMetaDataTable::FormMetaData,
FormMetaDataTable::CreatedBy,
)
.to(UsersTable::Users, UsersTable::Id),
)
.col(
ColumnDef::new(FormMetaDataTable::UpdatedAt)
.timestamp()
.not_null()
.extra("DEFAULT CURRENT_TIMESTAMP".to_string()),
)
.col(
ColumnDef::new(FormMetaDataTable::UpdatedBy)
.integer()
.not_null(),
)
.foreign_key(
ForeignKey::create()
.name("fk-updated-user-id")
.from(
FormMetaDataTable::FormMetaData,
FormMetaDataTable::UpdatedBy,
)
.to(UsersTable::Users, UsersTable::Id),
)
.to_owned(),
)
.await
Expand All @@ -55,5 +84,7 @@ pub enum FormMetaDataTable {
Title,
Description,
CreatedAt,
CreatedBy,
UpdatedAt,
UpdatedBy,
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use sea_orm_migration::prelude::*;

use crate::m20231008_135425_create_user_table::UsersTable;
use crate::{
m20220101_000001_create_table::FormMetaDataTable,
m20221211_211233_form_questions::FormQuestionsTable,
Expand Down Expand Up @@ -30,7 +31,13 @@ impl MigrationTrait for Migration {
.from(AnswersTable::Answers, AnswersTable::FormId)
.to(FormMetaDataTable::FormMetaData, FormMetaDataTable::Id),
)
.col(ColumnDef::new(AnswersTable::User).uuid().not_null())
.col(ColumnDef::new(AnswersTable::User).integer().not_null())
.foreign_key(
ForeignKey::create()
.name("fk-answer-user-id")
.from(AnswersTable::Answers, AnswersTable::User)
.to(UsersTable::Users, UsersTable::Id),
)
.col(
ColumnDef::new(AnswersTable::Title)
.string()
Expand Down
4 changes: 2 additions & 2 deletions server/migration/src/m20231008_135425_create_user_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl MigrationTrait for Migration {
.if_not_exists()
.col(
ColumnDef::new(UsersTable::Id)
.uuid()
.integer()
.not_null()
.auto_increment()
.primary_key(),
Expand All @@ -33,7 +33,7 @@ impl MigrationTrait for Migration {
}

#[derive(DeriveIden)]
enum UsersTable {
pub enum UsersTable {
Users,
Id,
Uuid,
Expand Down

0 comments on commit 06a7935

Please sign in to comment.