From f67337d5144317602e023284ce86b41d62bff74b Mon Sep 17 00:00:00 2001 From: miteruzo Date: Wed, 27 Nov 2024 01:37:56 +0900 Subject: [PATCH] =?UTF-8?q?#3=20=E5=88=B6=E7=B4=84=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- migration.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/migration.py b/migration.py index df8d14c..e861199 100644 --- a/migration.py +++ b/migration.py @@ -35,6 +35,7 @@ def create_queries ( table.integer ('model').comment ('GPT のモデル') table.datetime ('sent_at').comment ('送信日時') table.boolean ('answered').default (False).comment ('回答済') + table.foreign ('user_id').references ('user_id').on ('users').on_update ('cascade').on_delete ('restrict') def create_answers ( @@ -47,6 +48,7 @@ def create_answers ( table.integer ('answer_type').comment ('回答区分') table.datetime ('sent_at').comment ('送信日時') table.boolean ('answered').default (False).comment ('回答済') + table.foreign ('query_id').references ('query_id').on ('queries').on_update ('cascade').on_delete ('restrict') def create_users ( @@ -57,6 +59,7 @@ def create_users ( table.string ('code').comment ('ユーザ・コード(プラットフォーム依存)') table.string ('name').comment ('ユーザ名(プラットフォーム内)') table.binary ('icon').nullable ().comment ('アイコン') + table.unique (['platform', 'code']) def create_query_answer_histories ( @@ -65,6 +68,9 @@ def create_query_answer_histories ( table.big_increments ('id') table.big_integer ('query_id') table.big_integer ('answer_id') + table.unique (['query_id', 'answer_id']) + table.foreign ('query_id').references ('query_id').on ('queries').on_update ('cascade').on_delete ('cascade') + table.foreign ('answer_id').references ('answer_id').on ('answers').on_update ('cascade').on_delete ('cascade') class DbConfig (TypedDict):