#3 ガッチリしたマイグレはしなくていいかも
このコミットが含まれているのは:
+61
-42
@@ -1,48 +1,67 @@
|
||||
from eloquent.migrations import Migration
|
||||
from __future__ import annotations
|
||||
|
||||
from eloquent import DatabaseManager, Schema
|
||||
|
||||
CONFIG: dict[str, DbConfig] = { 'mysql': { 'driver': 'mysql',
|
||||
'host': 'localhost',
|
||||
'database': 'nizika_nico',
|
||||
'user': os.environ['MYSQL_USER'],
|
||||
'password': os.environ['MYSQL_PASS'],
|
||||
'prefix': '' } }
|
||||
DB = DatabaseManager (CONFIG)
|
||||
SCHEMA = Schema (DB)
|
||||
|
||||
|
||||
class CreateQueries (Migration):
|
||||
"""
|
||||
queries テーブルの作成
|
||||
"""
|
||||
|
||||
def up (
|
||||
self,
|
||||
) -> None:
|
||||
with self.schema.create ('queries') as table:
|
||||
table.big_increments ('id')
|
||||
table.big_integer ('user_id').nullable ().comment ('クエリ主')
|
||||
table.integer ('target_character').comment ('クエリ先キャラクタ')
|
||||
table.text ('content').comment ('クエリ内容')
|
||||
table.binary ('attachment').nullable ().default (None).comment ('添附')
|
||||
table.integer ('query_type').comment ('クエリ区分')
|
||||
table.datetime ('sent_at', 6).comment ('送信日時')
|
||||
table.boolean ('answered').default (False).comment ('回答済')
|
||||
|
||||
def down (
|
||||
self,
|
||||
) -> None:
|
||||
self.schema.drop ('queries')
|
||||
def main (
|
||||
) -> None:
|
||||
create_queries ()
|
||||
create_answers ()
|
||||
create_users ()
|
||||
|
||||
|
||||
class CreateAnswers (Migration):
|
||||
"""
|
||||
answers テーブルの作成
|
||||
"""
|
||||
def create_queries (
|
||||
) -> None:
|
||||
with SCHEMA.create ('queries') as table:
|
||||
table.big_increments ('id')
|
||||
table.big_integer ('user_id').nullable ().comment ('クエリ主')
|
||||
table.integer ('target_character').comment ('クエリ先キャラクタ')
|
||||
table.text ('content').comment ('クエリ内容')
|
||||
table.binary ('attachment').nullable ().default (None).comment ('添附')
|
||||
table.integer ('query_type').comment ('クエリ区分')
|
||||
table.datetime ('sent_at', 6).comment ('送信日時')
|
||||
table.boolean ('answered').default (False).comment ('回答済')
|
||||
|
||||
def up (
|
||||
self,
|
||||
) -> None:
|
||||
with self.schema.create ('answers') as table:
|
||||
table.big_increments ('id')
|
||||
table.big_integer ('query_id').nullable ().comment ('クエリ')
|
||||
table.integer ('character').comment ('キャラクタ区分')
|
||||
table.text ('content').comment ('回答内容')
|
||||
table.integer ('answer_type').comment ('回答区分')
|
||||
table.datetime ('sent_at', 6).comment ('送信日時')
|
||||
table.boolean ('answered').default (False).comment ('回答済')
|
||||
|
||||
def down (
|
||||
self,
|
||||
) -> None:
|
||||
self.schema.drop ('answers')
|
||||
def create_answers (
|
||||
) -> None:
|
||||
with SCHEMA.create ('answers') as table:
|
||||
table.big_increments ('id')
|
||||
table.big_integer ('query_id').nullable ().comment ('クエリ')
|
||||
table.integer ('character').comment ('キャラクタ区分')
|
||||
table.text ('content').comment ('回答内容')
|
||||
table.integer ('answer_type').comment ('回答区分')
|
||||
table.datetime ('sent_at', 6).comment ('送信日時')
|
||||
table.boolean ('answered').default (False).comment ('回答済')
|
||||
|
||||
|
||||
def create_users (
|
||||
) -> None:
|
||||
with SCHEMA.create ('users') as table:
|
||||
table.big_increments ('id')
|
||||
table.integet ('platform').comment ('プラットフォーム区分')
|
||||
table.string ('code').nullable ().comment ('ユーザ・コード(プラットフォーム依存)')
|
||||
table.string ('name').comment ('ユーザ名(プラットフォーム内)')
|
||||
table.binary ('icon').nullable ().comment ('アイコン')
|
||||
|
||||
|
||||
class DbConfig (TypedDict):
|
||||
driver: str
|
||||
host: str
|
||||
database: str
|
||||
user: str
|
||||
password: str
|
||||
prefix: str
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main ()
|
||||
|
||||
新しい課題から参照
ユーザをブロックする