AI ニジカ綜合
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.7 KiB

  1. from __future__ import annotations
  2. import os
  3. from typing import TypedDict
  4. from eloquent import DatabaseManager, Schema
  5. CONFIG: dict[str, DbConfig] = { 'mysql': { 'driver': 'mysql',
  6. 'host': 'localhost',
  7. 'database': 'nizika_ai',
  8. 'user': os.environ['MYSQL_USER'],
  9. 'password': os.environ['MYSQL_PASS'],
  10. 'prefix': '' } }
  11. DB = DatabaseManager (CONFIG)
  12. SCHEMA = Schema (DB)
  13. def main (
  14. ) -> None:
  15. create_queries ()
  16. create_answers ()
  17. create_users ()
  18. def create_queries (
  19. ) -> None:
  20. with SCHEMA.create ('queries') as table:
  21. table.big_increments ('id')
  22. table.big_integer ('user_id').nullable ().comment ('クエリ主')
  23. table.integer ('target_character').comment ('クエリ先キャラクタ')
  24. table.text ('content').comment ('クエリ内容')
  25. table.string ('image_url').nullable ().default (None).comment ('添附画像 URL')
  26. table.integer ('query_type').comment ('クエリ区分')
  27. table.integer ('model').comment ('GPT のモデル')
  28. table.datetime ('sent_at').comment ('送信日時')
  29. table.boolean ('answered').default (False).comment ('回答済')
  30. def create_answers (
  31. ) -> None:
  32. with SCHEMA.create ('answers') as table:
  33. table.big_increments ('id')
  34. table.big_integer ('query_id').nullable ().comment ('クエリ')
  35. table.integer ('character').comment ('キャラクタ区分')
  36. table.text ('content').comment ('回答内容')
  37. table.integer ('answer_type').comment ('回答区分')
  38. table.datetime ('sent_at').comment ('送信日時')
  39. table.boolean ('answered').default (False).comment ('回答済')
  40. def create_users (
  41. ) -> None:
  42. with SCHEMA.create ('users') as table:
  43. table.big_increments ('id')
  44. table.integet ('platform').comment ('プラットフォーム区分')
  45. table.string ('code').comment ('ユーザ・コード(プラットフォーム依存)')
  46. table.string ('name').comment ('ユーザ名(プラットフォーム内)')
  47. table.binary ('icon').nullable ().comment ('アイコン')
  48. def create_query_answer_histories (
  49. ) -> None:
  50. with SCHEMA.create ('query_answer_histories') as table:
  51. table.big_increments ('id')
  52. table.big_integer ('query_id')
  53. table.big_integer ('answer_id')
  54. class DbConfig (TypedDict):
  55. driver: str
  56. host: str
  57. database: str
  58. user: str
  59. password: str
  60. prefix: str
  61. if __name__ == '__main__':
  62. main ()