Browse Source

#3 もしかして Nullable でも行ける?

main
みてるぞ 1 month ago
parent
commit
38bb0d3e95
1 changed files with 14 additions and 0 deletions
  1. +14
    -0
      migration.py

+ 14
- 0
migration.py View File

@@ -21,6 +21,8 @@ def main (
create_answers ()
create_users ()
create_query_answer_histories ()
add_constraints_to_queries ()
add_constraints_to_answers ()
add_constraints_to_query_answer_histories ()


@@ -38,6 +40,12 @@ def create_queries (
table.boolean ('answered').default (False).comment ('回答済')


def add_constraints_to_queries (
) -> None:
with SCHEMA.table ('queries') as table:
table.foreign ('user_id').references ('id').on ('users').on_update ('cascade').on_delete ('restrict')


def create_answers (
) -> None:
with SCHEMA.create ('answers') as table:
@@ -50,6 +58,12 @@ def create_answers (
table.boolean ('answered').default (False).comment ('回答済')


def add_constraints_to_answers (
) -> None:
with SCHEMA.table ('answers') as table:
table.foreign ('query_id').references ('id').on ('queries').on_update ('cascade').on_delete ('restrict')


def create_users (
) -> None:
with SCHEMA.create ('users') as table:


Loading…
Cancel
Save