|
|
@@ -21,6 +21,9 @@ def main ( |
|
|
|
create_answers () |
|
|
|
create_users () |
|
|
|
create_query_answer_histories () |
|
|
|
add_constraints_to_queries () |
|
|
|
add_constraints_to_answers () |
|
|
|
add_constraints_to_query_answer_histories () |
|
|
|
|
|
|
|
|
|
|
|
def create_queries ( |
|
|
@@ -35,6 +38,11 @@ def create_queries ( |
|
|
|
table.integer ('model').comment ('GPT のモデル') |
|
|
|
table.datetime ('sent_at').comment ('送信日時') |
|
|
|
table.boolean ('answered').default (False).comment ('回答済') |
|
|
|
|
|
|
|
|
|
|
|
def add_constraints_to_queries ( |
|
|
|
) -> None: |
|
|
|
with SCHEMA.create ('queries') as table: |
|
|
|
table.foreign ('user_id').references ('user_id').on ('users').on_update ('cascade').on_delete ('restrict') |
|
|
|
|
|
|
|
|
|
|
@@ -48,6 +56,11 @@ def create_answers ( |
|
|
|
table.integer ('answer_type').comment ('回答区分') |
|
|
|
table.datetime ('sent_at').comment ('送信日時') |
|
|
|
table.boolean ('answered').default (False).comment ('回答済') |
|
|
|
|
|
|
|
|
|
|
|
def add_constraints_to_answers ( |
|
|
|
) -> None: |
|
|
|
with SCHEMA.create ('answers') as table: |
|
|
|
table.foreign ('query_id').references ('query_id').on ('queries').on_update ('cascade').on_delete ('restrict') |
|
|
|
|
|
|
|
|
|
|
@@ -69,6 +82,11 @@ def create_query_answer_histories ( |
|
|
|
table.big_integer ('query_id') |
|
|
|
table.big_integer ('answer_id') |
|
|
|
table.unique (['query_id', 'answer_id']) |
|
|
|
|
|
|
|
|
|
|
|
def add_constraints_to_query_answer_histories ( |
|
|
|
) -> None: |
|
|
|
with SCHEMA.create ('query_answer_histories') as table: |
|
|
|
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') |
|
|
|
|
|
|
|