7e5b5dc7342b_init.py 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. """init
  2. Revision ID: 7e5b5dc7342b
  3. Revises:
  4. Create Date: 2024-06-24 13:15:33.808998
  5. """
  6. from typing import Sequence, Union
  7. import sqlalchemy as sa
  8. from alembic import op
  9. import open_webui.apps.webui.internal.db
  10. from open_webui.migrations.util import get_existing_tables
  11. # revision identifiers, used by Alembic.
  12. revision: str = "7e5b5dc7342b"
  13. down_revision: Union[str, None] = None
  14. branch_labels: Union[str, Sequence[str], None] = None
  15. depends_on: Union[str, Sequence[str], None] = None
  16. def upgrade() -> None:
  17. existing_tables = set(get_existing_tables())
  18. # ### commands auto generated by Alembic - please adjust! ###
  19. if "auth" not in existing_tables:
  20. op.create_table(
  21. "auth",
  22. sa.Column("id", sa.String(), nullable=False),
  23. sa.Column("email", sa.String(), nullable=True),
  24. sa.Column("password", sa.Text(), nullable=True),
  25. sa.Column("active", sa.Boolean(), nullable=True),
  26. sa.PrimaryKeyConstraint("id"),
  27. )
  28. if "chat" not in existing_tables:
  29. op.create_table(
  30. "chat",
  31. sa.Column("id", sa.String(), nullable=False),
  32. sa.Column("user_id", sa.String(), nullable=True),
  33. sa.Column("title", sa.Text(), nullable=True),
  34. sa.Column("chat", sa.Text(), nullable=True),
  35. sa.Column("created_at", sa.BigInteger(), nullable=True),
  36. sa.Column("updated_at", sa.BigInteger(), nullable=True),
  37. sa.Column("share_id", sa.Text(), nullable=True),
  38. sa.Column("archived", sa.Boolean(), nullable=True),
  39. sa.PrimaryKeyConstraint("id"),
  40. sa.UniqueConstraint("share_id"),
  41. )
  42. if "chatidtag" not in existing_tables:
  43. op.create_table(
  44. "chatidtag",
  45. sa.Column("id", sa.String(), nullable=False),
  46. sa.Column("tag_name", sa.String(), nullable=True),
  47. sa.Column("chat_id", sa.String(), nullable=True),
  48. sa.Column("user_id", sa.String(), nullable=True),
  49. sa.Column("timestamp", sa.BigInteger(), nullable=True),
  50. sa.PrimaryKeyConstraint("id"),
  51. )
  52. if "document" not in existing_tables:
  53. op.create_table(
  54. "document",
  55. sa.Column("collection_name", sa.String(), nullable=False),
  56. sa.Column("name", sa.String(), nullable=True),
  57. sa.Column("title", sa.Text(), nullable=True),
  58. sa.Column("filename", sa.Text(), nullable=True),
  59. sa.Column("content", sa.Text(), nullable=True),
  60. sa.Column("user_id", sa.String(), nullable=True),
  61. sa.Column("timestamp", sa.BigInteger(), nullable=True),
  62. sa.PrimaryKeyConstraint("collection_name"),
  63. sa.UniqueConstraint("name"),
  64. )
  65. if "file" not in existing_tables:
  66. op.create_table(
  67. "file",
  68. sa.Column("id", sa.String(), nullable=False),
  69. sa.Column("user_id", sa.String(), nullable=True),
  70. sa.Column("filename", sa.Text(), nullable=True),
  71. sa.Column("meta", apps.webui.internal.db.JSONField(), nullable=True),
  72. sa.Column("created_at", sa.BigInteger(), nullable=True),
  73. sa.PrimaryKeyConstraint("id"),
  74. )
  75. if "function" not in existing_tables:
  76. op.create_table(
  77. "function",
  78. sa.Column("id", sa.String(), nullable=False),
  79. sa.Column("user_id", sa.String(), nullable=True),
  80. sa.Column("name", sa.Text(), nullable=True),
  81. sa.Column("type", sa.Text(), nullable=True),
  82. sa.Column("content", sa.Text(), nullable=True),
  83. sa.Column("meta", apps.webui.internal.db.JSONField(), nullable=True),
  84. sa.Column("valves", apps.webui.internal.db.JSONField(), nullable=True),
  85. sa.Column("is_active", sa.Boolean(), nullable=True),
  86. sa.Column("is_global", sa.Boolean(), nullable=True),
  87. sa.Column("updated_at", sa.BigInteger(), nullable=True),
  88. sa.Column("created_at", sa.BigInteger(), nullable=True),
  89. sa.PrimaryKeyConstraint("id"),
  90. )
  91. if "memory" not in existing_tables:
  92. op.create_table(
  93. "memory",
  94. sa.Column("id", sa.String(), nullable=False),
  95. sa.Column("user_id", sa.String(), nullable=True),
  96. sa.Column("content", sa.Text(), nullable=True),
  97. sa.Column("updated_at", sa.BigInteger(), nullable=True),
  98. sa.Column("created_at", sa.BigInteger(), nullable=True),
  99. sa.PrimaryKeyConstraint("id"),
  100. )
  101. if "model" not in existing_tables:
  102. op.create_table(
  103. "model",
  104. sa.Column("id", sa.Text(), nullable=False),
  105. sa.Column("user_id", sa.Text(), nullable=True),
  106. sa.Column("base_model_id", sa.Text(), nullable=True),
  107. sa.Column("name", sa.Text(), nullable=True),
  108. sa.Column("params", apps.webui.internal.db.JSONField(), nullable=True),
  109. sa.Column("meta", apps.webui.internal.db.JSONField(), nullable=True),
  110. sa.Column("updated_at", sa.BigInteger(), nullable=True),
  111. sa.Column("created_at", sa.BigInteger(), nullable=True),
  112. sa.PrimaryKeyConstraint("id"),
  113. )
  114. if "prompt" not in existing_tables:
  115. op.create_table(
  116. "prompt",
  117. sa.Column("command", sa.String(), nullable=False),
  118. sa.Column("user_id", sa.String(), nullable=True),
  119. sa.Column("title", sa.Text(), nullable=True),
  120. sa.Column("content", sa.Text(), nullable=True),
  121. sa.Column("timestamp", sa.BigInteger(), nullable=True),
  122. sa.PrimaryKeyConstraint("command"),
  123. )
  124. if "tag" not in existing_tables:
  125. op.create_table(
  126. "tag",
  127. sa.Column("id", sa.String(), nullable=False),
  128. sa.Column("name", sa.String(), nullable=True),
  129. sa.Column("user_id", sa.String(), nullable=True),
  130. sa.Column("data", sa.Text(), nullable=True),
  131. sa.PrimaryKeyConstraint("id"),
  132. )
  133. if "tool" not in existing_tables:
  134. op.create_table(
  135. "tool",
  136. sa.Column("id", sa.String(), nullable=False),
  137. sa.Column("user_id", sa.String(), nullable=True),
  138. sa.Column("name", sa.Text(), nullable=True),
  139. sa.Column("content", sa.Text(), nullable=True),
  140. sa.Column("specs", apps.webui.internal.db.JSONField(), nullable=True),
  141. sa.Column("meta", apps.webui.internal.db.JSONField(), nullable=True),
  142. sa.Column("valves", apps.webui.internal.db.JSONField(), nullable=True),
  143. sa.Column("updated_at", sa.BigInteger(), nullable=True),
  144. sa.Column("created_at", sa.BigInteger(), nullable=True),
  145. sa.PrimaryKeyConstraint("id"),
  146. )
  147. if "user" not in existing_tables:
  148. op.create_table(
  149. "user",
  150. sa.Column("id", sa.String(), nullable=False),
  151. sa.Column("name", sa.String(), nullable=True),
  152. sa.Column("email", sa.String(), nullable=True),
  153. sa.Column("role", sa.String(), nullable=True),
  154. sa.Column("profile_image_url", sa.Text(), nullable=True),
  155. sa.Column("last_active_at", sa.BigInteger(), nullable=True),
  156. sa.Column("updated_at", sa.BigInteger(), nullable=True),
  157. sa.Column("created_at", sa.BigInteger(), nullable=True),
  158. sa.Column("api_key", sa.String(), nullable=True),
  159. sa.Column("settings", apps.webui.internal.db.JSONField(), nullable=True),
  160. sa.Column("info", apps.webui.internal.db.JSONField(), nullable=True),
  161. sa.Column("oauth_sub", sa.Text(), nullable=True),
  162. sa.PrimaryKeyConstraint("id"),
  163. sa.UniqueConstraint("api_key"),
  164. sa.UniqueConstraint("oauth_sub"),
  165. )
  166. # ### end Alembic commands ###
  167. def downgrade() -> None:
  168. # ### commands auto generated by Alembic - please adjust! ###
  169. op.drop_table("user")
  170. op.drop_table("tool")
  171. op.drop_table("tag")
  172. op.drop_table("prompt")
  173. op.drop_table("model")
  174. op.drop_table("memory")
  175. op.drop_table("function")
  176. op.drop_table("file")
  177. op.drop_table("document")
  178. op.drop_table("chatidtag")
  179. op.drop_table("chat")
  180. op.drop_table("auth")
  181. # ### end Alembic commands ###