From 939d9790c0f76697d776a4079c9ec10c5d1e4929 Mon Sep 17 00:00:00 2001 From: miteruzo Date: Mon, 2 Dec 2024 02:45:00 +0900 Subject: [PATCH] =?UTF-8?q?#3=20answers.answered=20=E7=A7=BB=E8=BB=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __init__.py | 0 .../2024_12_02_005300_create_tables.py | 2 +- ...2024_12_02_005500_create_answered_flags.py | 34 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 __init__.py rename migration.py => migrations/2024_12_02_005300_create_tables.py (99%) create mode 100644 migrations/2024_12_02_005500_create_answered_flags.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/migration.py b/migrations/2024_12_02_005300_create_tables.py similarity index 99% rename from migration.py rename to migrations/2024_12_02_005300_create_tables.py index f0661f1..504f57e 100644 --- a/migration.py +++ b/migrations/2024_12_02_005300_create_tables.py @@ -1,6 +1,6 @@ from __future__ import annotations -from config import CONFIG +from ..config import CONFIG from eloquent import DatabaseManager, Schema DB = DatabaseManager (CONFIG) diff --git a/migrations/2024_12_02_005500_create_answered_flags.py b/migrations/2024_12_02_005500_create_answered_flags.py new file mode 100644 index 0000000..98c4791 --- /dev/null +++ b/migrations/2024_12_02_005500_create_answered_flags.py @@ -0,0 +1,34 @@ +from __future__ import annotations + +from ..config import CONFIG +from eloquent import DatabaseManager, Schema + +DB = DatabaseManager (CONFIG) +SCHEMA = Schema (DB) + + +def main ( +) -> None: + create_answered_flags () + drop_answered_column_in_answers () + + +def create_answered_flags ( +) -> None: + with SCHEMA.create ('answered_flags') as table: + table.big_increments ('id') + table.unsigned_big_integer ('answer_id').comment ('回答') + table.integer ('platform').comment ('プラットフォーム区分') + table.boolean ('answered').default (False).comment ('回答済') + table.unique (['answered_id', 'platform']) + table.foreign ('answered_id').references ('id').on ('answers').on_update ('cascade').on_delete ('cascade') + + +def drop_answered_column_in_answers ( +) -> None: + with SCHEMA.table ('answers') as table: + table.drop_column ('answered') + + +if __name__ == '__main__': + main ()