64b051264f32_init.py 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. """init
  2. Revision ID: 64b051264f32
  3. Revises:
  4. Create Date: 2023-05-13 14:26:59.085018
  5. """
  6. from alembic import op
  7. import sqlalchemy as sa
  8. from sqlalchemy.dialects import postgresql
  9. # revision identifiers, used by Alembic.
  10. revision = '64b051264f32'
  11. down_revision = None
  12. branch_labels = None
  13. depends_on = None
  14. def upgrade():
  15. # ### commands auto generated by Alembic - please adjust! ###
  16. op.create_table('account_integrates',
  17. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  18. sa.Column('account_id', postgresql.UUID(), nullable=False),
  19. sa.Column('provider', sa.String(length=16), nullable=False),
  20. sa.Column('open_id', sa.String(length=255), nullable=False),
  21. sa.Column('encrypted_token', sa.String(length=255), nullable=False),
  22. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  23. sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  24. sa.PrimaryKeyConstraint('id', name='account_integrate_pkey'),
  25. sa.UniqueConstraint('account_id', 'provider', name='unique_account_provider'),
  26. sa.UniqueConstraint('provider', 'open_id', name='unique_provider_open_id')
  27. )
  28. op.create_table('accounts',
  29. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  30. sa.Column('name', sa.String(length=255), nullable=False),
  31. sa.Column('email', sa.String(length=255), nullable=False),
  32. sa.Column('password', sa.String(length=255), nullable=True),
  33. sa.Column('password_salt', sa.String(length=255), nullable=True),
  34. sa.Column('avatar', sa.String(length=255), nullable=True),
  35. sa.Column('interface_language', sa.String(length=255), nullable=True),
  36. sa.Column('interface_theme', sa.String(length=255), nullable=True),
  37. sa.Column('timezone', sa.String(length=255), nullable=True),
  38. sa.Column('last_login_at', sa.DateTime(), nullable=True),
  39. sa.Column('last_login_ip', sa.String(length=255), nullable=True),
  40. sa.Column('status', sa.String(length=16), server_default=sa.text("'active'::character varying"), nullable=False),
  41. sa.Column('initialized_at', sa.DateTime(), nullable=True),
  42. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  43. sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  44. sa.PrimaryKeyConstraint('id', name='account_pkey')
  45. )
  46. with op.batch_alter_table('accounts', schema=None) as batch_op:
  47. batch_op.create_index('account_email_idx', ['email'], unique=False)
  48. op.create_table('api_requests',
  49. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  50. sa.Column('tenant_id', postgresql.UUID(), nullable=False),
  51. sa.Column('api_token_id', postgresql.UUID(), nullable=False),
  52. sa.Column('path', sa.String(length=255), nullable=False),
  53. sa.Column('request', sa.Text(), nullable=True),
  54. sa.Column('response', sa.Text(), nullable=True),
  55. sa.Column('ip', sa.String(length=255), nullable=False),
  56. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  57. sa.PrimaryKeyConstraint('id', name='api_request_pkey')
  58. )
  59. with op.batch_alter_table('api_requests', schema=None) as batch_op:
  60. batch_op.create_index('api_request_token_idx', ['tenant_id', 'api_token_id'], unique=False)
  61. op.create_table('api_tokens',
  62. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  63. sa.Column('app_id', postgresql.UUID(), nullable=True),
  64. sa.Column('dataset_id', postgresql.UUID(), nullable=True),
  65. sa.Column('type', sa.String(length=16), nullable=False),
  66. sa.Column('token', sa.String(length=255), nullable=False),
  67. sa.Column('last_used_at', sa.DateTime(), nullable=True),
  68. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  69. sa.PrimaryKeyConstraint('id', name='api_token_pkey')
  70. )
  71. with op.batch_alter_table('api_tokens', schema=None) as batch_op:
  72. batch_op.create_index('api_token_app_id_type_idx', ['app_id', 'type'], unique=False)
  73. batch_op.create_index('api_token_token_idx', ['token', 'type'], unique=False)
  74. op.create_table('app_dataset_joins',
  75. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  76. sa.Column('app_id', postgresql.UUID(), nullable=False),
  77. sa.Column('dataset_id', postgresql.UUID(), nullable=False),
  78. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
  79. sa.PrimaryKeyConstraint('id', name='app_dataset_join_pkey')
  80. )
  81. with op.batch_alter_table('app_dataset_joins', schema=None) as batch_op:
  82. batch_op.create_index('app_dataset_join_app_dataset_idx', ['dataset_id', 'app_id'], unique=False)
  83. op.create_table('app_model_configs',
  84. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  85. sa.Column('app_id', postgresql.UUID(), nullable=False),
  86. sa.Column('provider', sa.String(length=255), nullable=False),
  87. sa.Column('model_id', sa.String(length=255), nullable=False),
  88. sa.Column('configs', sa.JSON(), nullable=False),
  89. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  90. sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  91. sa.Column('opening_statement', sa.Text(), nullable=True),
  92. sa.Column('suggested_questions', sa.Text(), nullable=True),
  93. sa.Column('suggested_questions_after_answer', sa.Text(), nullable=True),
  94. sa.Column('more_like_this', sa.Text(), nullable=True),
  95. sa.Column('model', sa.Text(), nullable=True),
  96. sa.Column('user_input_form', sa.Text(), nullable=True),
  97. sa.Column('pre_prompt', sa.Text(), nullable=True),
  98. sa.Column('agent_mode', sa.Text(), nullable=True),
  99. sa.PrimaryKeyConstraint('id', name='app_model_config_pkey')
  100. )
  101. with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
  102. batch_op.create_index('app_app_id_idx', ['app_id'], unique=False)
  103. op.create_table('apps',
  104. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  105. sa.Column('tenant_id', postgresql.UUID(), nullable=False),
  106. sa.Column('name', sa.String(length=255), nullable=False),
  107. sa.Column('mode', sa.String(length=255), nullable=False),
  108. sa.Column('icon', sa.String(length=255), nullable=True),
  109. sa.Column('icon_background', sa.String(length=255), nullable=True),
  110. sa.Column('app_model_config_id', postgresql.UUID(), nullable=True),
  111. sa.Column('status', sa.String(length=255), server_default=sa.text("'normal'::character varying"), nullable=False),
  112. sa.Column('enable_site', sa.Boolean(), nullable=False),
  113. sa.Column('enable_api', sa.Boolean(), nullable=False),
  114. sa.Column('api_rpm', sa.Integer(), nullable=False),
  115. sa.Column('api_rph', sa.Integer(), nullable=False),
  116. sa.Column('is_demo', sa.Boolean(), server_default=sa.text('false'), nullable=False),
  117. sa.Column('is_public', sa.Boolean(), server_default=sa.text('false'), nullable=False),
  118. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  119. sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  120. sa.PrimaryKeyConstraint('id', name='app_pkey')
  121. )
  122. with op.batch_alter_table('apps', schema=None) as batch_op:
  123. batch_op.create_index('app_tenant_id_idx', ['tenant_id'], unique=False)
  124. op.execute('CREATE SEQUENCE task_id_sequence;')
  125. op.execute('CREATE SEQUENCE taskset_id_sequence;')
  126. op.create_table('celery_taskmeta',
  127. sa.Column('id', sa.Integer(), nullable=False,
  128. server_default=sa.text('nextval(\'task_id_sequence\')')),
  129. sa.Column('task_id', sa.String(length=155), nullable=True),
  130. sa.Column('status', sa.String(length=50), nullable=True),
  131. sa.Column('result', sa.PickleType(), nullable=True),
  132. sa.Column('date_done', sa.DateTime(), nullable=True),
  133. sa.Column('traceback', sa.Text(), nullable=True),
  134. sa.Column('name', sa.String(length=155), nullable=True),
  135. sa.Column('args', sa.LargeBinary(), nullable=True),
  136. sa.Column('kwargs', sa.LargeBinary(), nullable=True),
  137. sa.Column('worker', sa.String(length=155), nullable=True),
  138. sa.Column('retries', sa.Integer(), nullable=True),
  139. sa.Column('queue', sa.String(length=155), nullable=True),
  140. sa.PrimaryKeyConstraint('id'),
  141. sa.UniqueConstraint('task_id')
  142. )
  143. op.create_table('celery_tasksetmeta',
  144. sa.Column('id', sa.Integer(), nullable=False,
  145. server_default=sa.text('nextval(\'taskset_id_sequence\')')),
  146. sa.Column('taskset_id', sa.String(length=155), nullable=True),
  147. sa.Column('result', sa.PickleType(), nullable=True),
  148. sa.Column('date_done', sa.DateTime(), nullable=True),
  149. sa.PrimaryKeyConstraint('id'),
  150. sa.UniqueConstraint('taskset_id')
  151. )
  152. op.create_table('conversations',
  153. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  154. sa.Column('app_id', postgresql.UUID(), nullable=False),
  155. sa.Column('app_model_config_id', postgresql.UUID(), nullable=False),
  156. sa.Column('model_provider', sa.String(length=255), nullable=False),
  157. sa.Column('override_model_configs', sa.Text(), nullable=True),
  158. sa.Column('model_id', sa.String(length=255), nullable=False),
  159. sa.Column('mode', sa.String(length=255), nullable=False),
  160. sa.Column('name', sa.String(length=255), nullable=False),
  161. sa.Column('summary', sa.Text(), nullable=True),
  162. sa.Column('inputs', sa.JSON(), nullable=True),
  163. sa.Column('introduction', sa.Text(), nullable=True),
  164. sa.Column('system_instruction', sa.Text(), nullable=True),
  165. sa.Column('system_instruction_tokens', sa.Integer(), server_default=sa.text('0'), nullable=False),
  166. sa.Column('status', sa.String(length=255), nullable=False),
  167. sa.Column('from_source', sa.String(length=255), nullable=False),
  168. sa.Column('from_end_user_id', postgresql.UUID(), nullable=True),
  169. sa.Column('from_account_id', postgresql.UUID(), nullable=True),
  170. sa.Column('read_at', sa.DateTime(), nullable=True),
  171. sa.Column('read_account_id', postgresql.UUID(), nullable=True),
  172. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  173. sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  174. sa.PrimaryKeyConstraint('id', name='conversation_pkey')
  175. )
  176. with op.batch_alter_table('conversations', schema=None) as batch_op:
  177. batch_op.create_index('conversation_app_from_user_idx', ['app_id', 'from_source', 'from_end_user_id'], unique=False)
  178. op.create_table('dataset_keyword_tables',
  179. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  180. sa.Column('dataset_id', postgresql.UUID(), nullable=False),
  181. sa.Column('keyword_table', sa.Text(), nullable=False),
  182. sa.PrimaryKeyConstraint('id', name='dataset_keyword_table_pkey'),
  183. sa.UniqueConstraint('dataset_id')
  184. )
  185. with op.batch_alter_table('dataset_keyword_tables', schema=None) as batch_op:
  186. batch_op.create_index('dataset_keyword_table_dataset_id_idx', ['dataset_id'], unique=False)
  187. op.create_table('dataset_process_rules',
  188. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  189. sa.Column('dataset_id', postgresql.UUID(), nullable=False),
  190. sa.Column('mode', sa.String(length=255), server_default=sa.text("'automatic'::character varying"), nullable=False),
  191. sa.Column('rules', sa.Text(), nullable=True),
  192. sa.Column('created_by', postgresql.UUID(), nullable=False),
  193. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  194. sa.PrimaryKeyConstraint('id', name='dataset_process_rule_pkey')
  195. )
  196. with op.batch_alter_table('dataset_process_rules', schema=None) as batch_op:
  197. batch_op.create_index('dataset_process_rule_dataset_id_idx', ['dataset_id'], unique=False)
  198. op.create_table('dataset_queries',
  199. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  200. sa.Column('dataset_id', postgresql.UUID(), nullable=False),
  201. sa.Column('content', sa.Text(), nullable=False),
  202. sa.Column('source', sa.String(length=255), nullable=False),
  203. sa.Column('source_app_id', postgresql.UUID(), nullable=True),
  204. sa.Column('created_by_role', sa.String(), nullable=False),
  205. sa.Column('created_by', postgresql.UUID(), nullable=False),
  206. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
  207. sa.PrimaryKeyConstraint('id', name='dataset_query_pkey')
  208. )
  209. with op.batch_alter_table('dataset_queries', schema=None) as batch_op:
  210. batch_op.create_index('dataset_query_dataset_id_idx', ['dataset_id'], unique=False)
  211. op.create_table('datasets',
  212. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  213. sa.Column('tenant_id', postgresql.UUID(), nullable=False),
  214. sa.Column('name', sa.String(length=255), nullable=False),
  215. sa.Column('description', sa.Text(), nullable=True),
  216. sa.Column('provider', sa.String(length=255), server_default=sa.text("'vendor'::character varying"), nullable=False),
  217. sa.Column('permission', sa.String(length=255), server_default=sa.text("'only_me'::character varying"), nullable=False),
  218. sa.Column('data_source_type', sa.String(length=255), nullable=True),
  219. sa.Column('indexing_technique', sa.String(length=255), nullable=True),
  220. sa.Column('index_struct', sa.Text(), nullable=True),
  221. sa.Column('created_by', postgresql.UUID(), nullable=False),
  222. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  223. sa.Column('updated_by', postgresql.UUID(), nullable=True),
  224. sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  225. sa.PrimaryKeyConstraint('id', name='dataset_pkey')
  226. )
  227. with op.batch_alter_table('datasets', schema=None) as batch_op:
  228. batch_op.create_index('dataset_tenant_idx', ['tenant_id'], unique=False)
  229. op.create_table('dify_setups',
  230. sa.Column('version', sa.String(length=255), nullable=False),
  231. sa.Column('setup_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  232. sa.PrimaryKeyConstraint('version', name='dify_setup_pkey')
  233. )
  234. op.create_table('document_segments',
  235. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  236. sa.Column('tenant_id', postgresql.UUID(), nullable=False),
  237. sa.Column('dataset_id', postgresql.UUID(), nullable=False),
  238. sa.Column('document_id', postgresql.UUID(), nullable=False),
  239. sa.Column('position', sa.Integer(), nullable=False),
  240. sa.Column('content', sa.Text(), nullable=False),
  241. sa.Column('word_count', sa.Integer(), nullable=False),
  242. sa.Column('tokens', sa.Integer(), nullable=False),
  243. sa.Column('keywords', sa.JSON(), nullable=True),
  244. sa.Column('index_node_id', sa.String(length=255), nullable=True),
  245. sa.Column('index_node_hash', sa.String(length=255), nullable=True),
  246. sa.Column('hit_count', sa.Integer(), nullable=False),
  247. sa.Column('enabled', sa.Boolean(), server_default=sa.text('true'), nullable=False),
  248. sa.Column('disabled_at', sa.DateTime(), nullable=True),
  249. sa.Column('disabled_by', postgresql.UUID(), nullable=True),
  250. sa.Column('status', sa.String(length=255), server_default=sa.text("'waiting'::character varying"), nullable=False),
  251. sa.Column('created_by', postgresql.UUID(), nullable=False),
  252. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  253. sa.Column('indexing_at', sa.DateTime(), nullable=True),
  254. sa.Column('completed_at', sa.DateTime(), nullable=True),
  255. sa.Column('error', sa.Text(), nullable=True),
  256. sa.Column('stopped_at', sa.DateTime(), nullable=True),
  257. sa.PrimaryKeyConstraint('id', name='document_segment_pkey')
  258. )
  259. with op.batch_alter_table('document_segments', schema=None) as batch_op:
  260. batch_op.create_index('document_segment_dataset_id_idx', ['dataset_id'], unique=False)
  261. batch_op.create_index('document_segment_dataset_node_idx', ['dataset_id', 'index_node_id'], unique=False)
  262. batch_op.create_index('document_segment_document_id_idx', ['document_id'], unique=False)
  263. batch_op.create_index('document_segment_tenant_dataset_idx', ['dataset_id', 'tenant_id'], unique=False)
  264. batch_op.create_index('document_segment_tenant_document_idx', ['document_id', 'tenant_id'], unique=False)
  265. op.create_table('documents',
  266. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  267. sa.Column('tenant_id', postgresql.UUID(), nullable=False),
  268. sa.Column('dataset_id', postgresql.UUID(), nullable=False),
  269. sa.Column('position', sa.Integer(), nullable=False),
  270. sa.Column('data_source_type', sa.String(length=255), nullable=False),
  271. sa.Column('data_source_info', sa.Text(), nullable=True),
  272. sa.Column('dataset_process_rule_id', postgresql.UUID(), nullable=True),
  273. sa.Column('batch', sa.String(length=255), nullable=False),
  274. sa.Column('name', sa.String(length=255), nullable=False),
  275. sa.Column('created_from', sa.String(length=255), nullable=False),
  276. sa.Column('created_by', postgresql.UUID(), nullable=False),
  277. sa.Column('created_api_request_id', postgresql.UUID(), nullable=True),
  278. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  279. sa.Column('processing_started_at', sa.DateTime(), nullable=True),
  280. sa.Column('file_id', sa.Text(), nullable=True),
  281. sa.Column('word_count', sa.Integer(), nullable=True),
  282. sa.Column('parsing_completed_at', sa.DateTime(), nullable=True),
  283. sa.Column('cleaning_completed_at', sa.DateTime(), nullable=True),
  284. sa.Column('splitting_completed_at', sa.DateTime(), nullable=True),
  285. sa.Column('tokens', sa.Integer(), nullable=True),
  286. sa.Column('indexing_latency', sa.Float(), nullable=True),
  287. sa.Column('completed_at', sa.DateTime(), nullable=True),
  288. sa.Column('is_paused', sa.Boolean(), server_default=sa.text('false'), nullable=True),
  289. sa.Column('paused_by', postgresql.UUID(), nullable=True),
  290. sa.Column('paused_at', sa.DateTime(), nullable=True),
  291. sa.Column('error', sa.Text(), nullable=True),
  292. sa.Column('stopped_at', sa.DateTime(), nullable=True),
  293. sa.Column('indexing_status', sa.String(length=255), server_default=sa.text("'waiting'::character varying"), nullable=False),
  294. sa.Column('enabled', sa.Boolean(), server_default=sa.text('true'), nullable=False),
  295. sa.Column('disabled_at', sa.DateTime(), nullable=True),
  296. sa.Column('disabled_by', postgresql.UUID(), nullable=True),
  297. sa.Column('archived', sa.Boolean(), server_default=sa.text('false'), nullable=False),
  298. sa.Column('archived_reason', sa.String(length=255), nullable=True),
  299. sa.Column('archived_by', postgresql.UUID(), nullable=True),
  300. sa.Column('archived_at', sa.DateTime(), nullable=True),
  301. sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  302. sa.Column('doc_type', sa.String(length=40), nullable=True),
  303. sa.Column('doc_metadata', sa.JSON(), nullable=True),
  304. sa.PrimaryKeyConstraint('id', name='document_pkey')
  305. )
  306. with op.batch_alter_table('documents', schema=None) as batch_op:
  307. batch_op.create_index('document_dataset_id_idx', ['dataset_id'], unique=False)
  308. batch_op.create_index('document_is_paused_idx', ['is_paused'], unique=False)
  309. op.create_table('embeddings',
  310. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  311. sa.Column('hash', sa.String(length=64), nullable=False),
  312. sa.Column('embedding', sa.LargeBinary(), nullable=False),
  313. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  314. sa.PrimaryKeyConstraint('id', name='embedding_pkey'),
  315. sa.UniqueConstraint('hash', name='embedding_hash_idx')
  316. )
  317. op.create_table('end_users',
  318. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  319. sa.Column('tenant_id', postgresql.UUID(), nullable=False),
  320. sa.Column('app_id', postgresql.UUID(), nullable=True),
  321. sa.Column('type', sa.String(length=255), nullable=False),
  322. sa.Column('external_user_id', sa.String(length=255), nullable=True),
  323. sa.Column('name', sa.String(length=255), nullable=True),
  324. sa.Column('is_anonymous', sa.Boolean(), server_default=sa.text('true'), nullable=False),
  325. sa.Column('session_id', sa.String(length=255), nullable=False),
  326. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  327. sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  328. sa.PrimaryKeyConstraint('id', name='end_user_pkey')
  329. )
  330. with op.batch_alter_table('end_users', schema=None) as batch_op:
  331. batch_op.create_index('end_user_session_id_idx', ['session_id', 'type'], unique=False)
  332. batch_op.create_index('end_user_tenant_session_id_idx', ['tenant_id', 'session_id', 'type'], unique=False)
  333. op.create_table('installed_apps',
  334. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  335. sa.Column('tenant_id', postgresql.UUID(), nullable=False),
  336. sa.Column('app_id', postgresql.UUID(), nullable=False),
  337. sa.Column('app_owner_tenant_id', postgresql.UUID(), nullable=False),
  338. sa.Column('position', sa.Integer(), nullable=False),
  339. sa.Column('is_pinned', sa.Boolean(), server_default=sa.text('false'), nullable=False),
  340. sa.Column('last_used_at', sa.DateTime(), nullable=True),
  341. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  342. sa.PrimaryKeyConstraint('id', name='installed_app_pkey'),
  343. sa.UniqueConstraint('tenant_id', 'app_id', name='unique_tenant_app')
  344. )
  345. with op.batch_alter_table('installed_apps', schema=None) as batch_op:
  346. batch_op.create_index('installed_app_app_id_idx', ['app_id'], unique=False)
  347. batch_op.create_index('installed_app_tenant_id_idx', ['tenant_id'], unique=False)
  348. op.create_table('invitation_codes',
  349. sa.Column('id', sa.Integer(), nullable=False),
  350. sa.Column('batch', sa.String(length=255), nullable=False),
  351. sa.Column('code', sa.String(length=32), nullable=False),
  352. sa.Column('status', sa.String(length=16), server_default=sa.text("'unused'::character varying"), nullable=False),
  353. sa.Column('used_at', sa.DateTime(), nullable=True),
  354. sa.Column('used_by_tenant_id', postgresql.UUID(), nullable=True),
  355. sa.Column('used_by_account_id', postgresql.UUID(), nullable=True),
  356. sa.Column('deprecated_at', sa.DateTime(), nullable=True),
  357. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  358. sa.PrimaryKeyConstraint('id', name='invitation_code_pkey')
  359. )
  360. with op.batch_alter_table('invitation_codes', schema=None) as batch_op:
  361. batch_op.create_index('invitation_codes_batch_idx', ['batch'], unique=False)
  362. batch_op.create_index('invitation_codes_code_idx', ['code', 'status'], unique=False)
  363. op.create_table('message_agent_thoughts',
  364. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  365. sa.Column('message_id', postgresql.UUID(), nullable=False),
  366. sa.Column('message_chain_id', postgresql.UUID(), nullable=False),
  367. sa.Column('position', sa.Integer(), nullable=False),
  368. sa.Column('thought', sa.Text(), nullable=True),
  369. sa.Column('tool', sa.Text(), nullable=True),
  370. sa.Column('tool_input', sa.Text(), nullable=True),
  371. sa.Column('observation', sa.Text(), nullable=True),
  372. sa.Column('tool_process_data', sa.Text(), nullable=True),
  373. sa.Column('message', sa.Text(), nullable=True),
  374. sa.Column('message_token', sa.Integer(), nullable=True),
  375. sa.Column('message_unit_price', sa.Numeric(), nullable=True),
  376. sa.Column('answer', sa.Text(), nullable=True),
  377. sa.Column('answer_token', sa.Integer(), nullable=True),
  378. sa.Column('answer_unit_price', sa.Numeric(), nullable=True),
  379. sa.Column('tokens', sa.Integer(), nullable=True),
  380. sa.Column('total_price', sa.Numeric(), nullable=True),
  381. sa.Column('currency', sa.String(), nullable=True),
  382. sa.Column('latency', sa.Float(), nullable=True),
  383. sa.Column('created_by_role', sa.String(), nullable=False),
  384. sa.Column('created_by', postgresql.UUID(), nullable=False),
  385. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
  386. sa.PrimaryKeyConstraint('id', name='message_agent_thought_pkey')
  387. )
  388. with op.batch_alter_table('message_agent_thoughts', schema=None) as batch_op:
  389. batch_op.create_index('message_agent_thought_message_chain_id_idx', ['message_chain_id'], unique=False)
  390. batch_op.create_index('message_agent_thought_message_id_idx', ['message_id'], unique=False)
  391. op.create_table('message_chains',
  392. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  393. sa.Column('message_id', postgresql.UUID(), nullable=False),
  394. sa.Column('type', sa.String(length=255), nullable=False),
  395. sa.Column('input', sa.Text(), nullable=True),
  396. sa.Column('output', sa.Text(), nullable=True),
  397. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
  398. sa.PrimaryKeyConstraint('id', name='message_chain_pkey')
  399. )
  400. with op.batch_alter_table('message_chains', schema=None) as batch_op:
  401. batch_op.create_index('message_chain_message_id_idx', ['message_id'], unique=False)
  402. op.create_table('message_feedbacks',
  403. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  404. sa.Column('app_id', postgresql.UUID(), nullable=False),
  405. sa.Column('conversation_id', postgresql.UUID(), nullable=False),
  406. sa.Column('message_id', postgresql.UUID(), nullable=False),
  407. sa.Column('rating', sa.String(length=255), nullable=False),
  408. sa.Column('content', sa.Text(), nullable=True),
  409. sa.Column('from_source', sa.String(length=255), nullable=False),
  410. sa.Column('from_end_user_id', postgresql.UUID(), nullable=True),
  411. sa.Column('from_account_id', postgresql.UUID(), nullable=True),
  412. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  413. sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  414. sa.PrimaryKeyConstraint('id', name='message_feedback_pkey')
  415. )
  416. with op.batch_alter_table('message_feedbacks', schema=None) as batch_op:
  417. batch_op.create_index('message_feedback_app_idx', ['app_id'], unique=False)
  418. batch_op.create_index('message_feedback_conversation_idx', ['conversation_id', 'from_source', 'rating'], unique=False)
  419. batch_op.create_index('message_feedback_message_idx', ['message_id', 'from_source'], unique=False)
  420. op.create_table('operation_logs',
  421. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  422. sa.Column('tenant_id', postgresql.UUID(), nullable=False),
  423. sa.Column('account_id', postgresql.UUID(), nullable=False),
  424. sa.Column('action', sa.String(length=255), nullable=False),
  425. sa.Column('content', sa.JSON(), nullable=True),
  426. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  427. sa.Column('created_ip', sa.String(length=255), nullable=False),
  428. sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  429. sa.PrimaryKeyConstraint('id', name='operation_log_pkey')
  430. )
  431. with op.batch_alter_table('operation_logs', schema=None) as batch_op:
  432. batch_op.create_index('operation_log_account_action_idx', ['tenant_id', 'account_id', 'action'], unique=False)
  433. op.create_table('pinned_conversations',
  434. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  435. sa.Column('app_id', postgresql.UUID(), nullable=False),
  436. sa.Column('conversation_id', postgresql.UUID(), nullable=False),
  437. sa.Column('created_by', postgresql.UUID(), nullable=False),
  438. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  439. sa.PrimaryKeyConstraint('id', name='pinned_conversation_pkey')
  440. )
  441. with op.batch_alter_table('pinned_conversations', schema=None) as batch_op:
  442. batch_op.create_index('pinned_conversation_conversation_idx', ['app_id', 'conversation_id', 'created_by'], unique=False)
  443. op.create_table('providers',
  444. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  445. sa.Column('tenant_id', postgresql.UUID(), nullable=False),
  446. sa.Column('provider_name', sa.String(length=40), nullable=False),
  447. sa.Column('provider_type', sa.String(length=40), nullable=False, server_default=sa.text("'custom'::character varying")),
  448. sa.Column('encrypted_config', sa.Text(), nullable=True),
  449. sa.Column('is_valid', sa.Boolean(), server_default=sa.text('false'), nullable=False),
  450. sa.Column('last_used', sa.DateTime(), nullable=True),
  451. sa.Column('quota_type', sa.String(length=40), nullable=True, server_default=sa.text("''::character varying")),
  452. sa.Column('quota_limit', sa.Integer(), nullable=True),
  453. sa.Column('quota_used', sa.Integer(), nullable=True),
  454. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  455. sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  456. sa.PrimaryKeyConstraint('id', name='provider_pkey'),
  457. sa.UniqueConstraint('tenant_id', 'provider_name', 'provider_type', 'quota_type', name='unique_provider_name_type_quota')
  458. )
  459. with op.batch_alter_table('providers', schema=None) as batch_op:
  460. batch_op.create_index('provider_tenant_id_provider_idx', ['tenant_id', 'provider_name'], unique=False)
  461. op.create_table('recommended_apps',
  462. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  463. sa.Column('app_id', postgresql.UUID(), nullable=False),
  464. sa.Column('description', sa.JSON(), nullable=False),
  465. sa.Column('copyright', sa.String(length=255), nullable=False),
  466. sa.Column('privacy_policy', sa.String(length=255), nullable=False),
  467. sa.Column('category', sa.String(length=255), nullable=False),
  468. sa.Column('position', sa.Integer(), nullable=False),
  469. sa.Column('is_listed', sa.Boolean(), nullable=False),
  470. sa.Column('install_count', sa.Integer(), nullable=False),
  471. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  472. sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  473. sa.PrimaryKeyConstraint('id', name='recommended_app_pkey')
  474. )
  475. with op.batch_alter_table('recommended_apps', schema=None) as batch_op:
  476. batch_op.create_index('recommended_app_app_id_idx', ['app_id'], unique=False)
  477. batch_op.create_index('recommended_app_is_listed_idx', ['is_listed'], unique=False)
  478. op.create_table('saved_messages',
  479. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  480. sa.Column('app_id', postgresql.UUID(), nullable=False),
  481. sa.Column('message_id', postgresql.UUID(), nullable=False),
  482. sa.Column('created_by', postgresql.UUID(), nullable=False),
  483. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  484. sa.PrimaryKeyConstraint('id', name='saved_message_pkey')
  485. )
  486. with op.batch_alter_table('saved_messages', schema=None) as batch_op:
  487. batch_op.create_index('saved_message_message_idx', ['app_id', 'message_id', 'created_by'], unique=False)
  488. op.create_table('sessions',
  489. sa.Column('id', sa.Integer(), nullable=False),
  490. sa.Column('session_id', sa.String(length=255), nullable=True),
  491. sa.Column('data', sa.LargeBinary(), nullable=True),
  492. sa.Column('expiry', sa.DateTime(), nullable=True),
  493. sa.PrimaryKeyConstraint('id'),
  494. sa.UniqueConstraint('session_id')
  495. )
  496. op.create_table('sites',
  497. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  498. sa.Column('app_id', postgresql.UUID(), nullable=False),
  499. sa.Column('title', sa.String(length=255), nullable=False),
  500. sa.Column('icon', sa.String(length=255), nullable=True),
  501. sa.Column('icon_background', sa.String(length=255), nullable=True),
  502. sa.Column('description', sa.String(length=255), nullable=True),
  503. sa.Column('default_language', sa.String(length=255), nullable=False),
  504. sa.Column('copyright', sa.String(length=255), nullable=True),
  505. sa.Column('privacy_policy', sa.String(length=255), nullable=True),
  506. sa.Column('customize_domain', sa.String(length=255), nullable=True),
  507. sa.Column('customize_token_strategy', sa.String(length=255), nullable=False),
  508. sa.Column('prompt_public', sa.Boolean(), server_default=sa.text('false'), nullable=False),
  509. sa.Column('status', sa.String(length=255), server_default=sa.text("'normal'::character varying"), nullable=False),
  510. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  511. sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  512. sa.Column('code', sa.String(length=255), nullable=True),
  513. sa.PrimaryKeyConstraint('id', name='site_pkey')
  514. )
  515. with op.batch_alter_table('sites', schema=None) as batch_op:
  516. batch_op.create_index('site_app_id_idx', ['app_id'], unique=False)
  517. batch_op.create_index('site_code_idx', ['code', 'status'], unique=False)
  518. op.create_table('tenant_account_joins',
  519. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  520. sa.Column('tenant_id', postgresql.UUID(), nullable=False),
  521. sa.Column('account_id', postgresql.UUID(), nullable=False),
  522. sa.Column('role', sa.String(length=16), server_default='normal', nullable=False),
  523. sa.Column('invited_by', postgresql.UUID(), nullable=True),
  524. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  525. sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  526. sa.PrimaryKeyConstraint('id', name='tenant_account_join_pkey'),
  527. sa.UniqueConstraint('tenant_id', 'account_id', name='unique_tenant_account_join')
  528. )
  529. with op.batch_alter_table('tenant_account_joins', schema=None) as batch_op:
  530. batch_op.create_index('tenant_account_join_account_id_idx', ['account_id'], unique=False)
  531. batch_op.create_index('tenant_account_join_tenant_id_idx', ['tenant_id'], unique=False)
  532. op.create_table('tenants',
  533. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  534. sa.Column('name', sa.String(length=255), nullable=False),
  535. sa.Column('encrypt_public_key', sa.Text(), nullable=True),
  536. sa.Column('plan', sa.String(length=255), server_default=sa.text("'basic'::character varying"), nullable=False),
  537. sa.Column('status', sa.String(length=255), server_default=sa.text("'normal'::character varying"), nullable=False),
  538. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  539. sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  540. sa.PrimaryKeyConstraint('id', name='tenant_pkey')
  541. )
  542. op.create_table('upload_files',
  543. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  544. sa.Column('tenant_id', postgresql.UUID(), nullable=False),
  545. sa.Column('storage_type', sa.String(length=255), nullable=False),
  546. sa.Column('key', sa.String(length=255), nullable=False),
  547. sa.Column('name', sa.String(length=255), nullable=False),
  548. sa.Column('size', sa.Integer(), nullable=False),
  549. sa.Column('extension', sa.String(length=255), nullable=False),
  550. sa.Column('mime_type', sa.String(length=255), nullable=True),
  551. sa.Column('created_by', postgresql.UUID(), nullable=False),
  552. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  553. sa.Column('used', sa.Boolean(), server_default=sa.text('false'), nullable=False),
  554. sa.Column('used_by', postgresql.UUID(), nullable=True),
  555. sa.Column('used_at', sa.DateTime(), nullable=True),
  556. sa.Column('hash', sa.String(length=255), nullable=True),
  557. sa.PrimaryKeyConstraint('id', name='upload_file_pkey')
  558. )
  559. with op.batch_alter_table('upload_files', schema=None) as batch_op:
  560. batch_op.create_index('upload_file_tenant_idx', ['tenant_id'], unique=False)
  561. op.create_table('message_annotations',
  562. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  563. sa.Column('app_id', postgresql.UUID(), nullable=False),
  564. sa.Column('conversation_id', postgresql.UUID(), nullable=False),
  565. sa.Column('message_id', postgresql.UUID(), nullable=False),
  566. sa.Column('content', sa.Text(), nullable=False),
  567. sa.Column('account_id', postgresql.UUID(), nullable=False),
  568. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  569. sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  570. sa.PrimaryKeyConstraint('id', name='message_annotation_pkey')
  571. )
  572. with op.batch_alter_table('message_annotations', schema=None) as batch_op:
  573. batch_op.create_index('message_annotation_app_idx', ['app_id'], unique=False)
  574. batch_op.create_index('message_annotation_conversation_idx', ['conversation_id'], unique=False)
  575. batch_op.create_index('message_annotation_message_idx', ['message_id'], unique=False)
  576. op.create_table('messages',
  577. sa.Column('id', postgresql.UUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
  578. sa.Column('app_id', postgresql.UUID(), nullable=False),
  579. sa.Column('model_provider', sa.String(length=255), nullable=False),
  580. sa.Column('model_id', sa.String(length=255), nullable=False),
  581. sa.Column('override_model_configs', sa.Text(), nullable=True),
  582. sa.Column('conversation_id', postgresql.UUID(), nullable=False),
  583. sa.Column('inputs', sa.JSON(), nullable=True),
  584. sa.Column('query', sa.Text(), nullable=False),
  585. sa.Column('message', sa.JSON(), nullable=False),
  586. sa.Column('message_tokens', sa.Integer(), server_default=sa.text('0'), nullable=False),
  587. sa.Column('message_unit_price', sa.Numeric(precision=10, scale=4), nullable=False),
  588. sa.Column('answer', sa.Text(), nullable=False),
  589. sa.Column('answer_tokens', sa.Integer(), server_default=sa.text('0'), nullable=False),
  590. sa.Column('answer_unit_price', sa.Numeric(precision=10, scale=4), nullable=False),
  591. sa.Column('provider_response_latency', sa.Float(), server_default=sa.text('0'), nullable=False),
  592. sa.Column('total_price', sa.Numeric(precision=10, scale=7), nullable=True),
  593. sa.Column('currency', sa.String(length=255), nullable=False),
  594. sa.Column('from_source', sa.String(length=255), nullable=False),
  595. sa.Column('from_end_user_id', postgresql.UUID(), nullable=True),
  596. sa.Column('from_account_id', postgresql.UUID(), nullable=True),
  597. sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  598. sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
  599. sa.Column('agent_based', sa.Boolean(), server_default=sa.text('false'), nullable=False),
  600. sa.PrimaryKeyConstraint('id', name='message_pkey')
  601. )
  602. with op.batch_alter_table('messages', schema=None) as batch_op:
  603. batch_op.create_index('message_account_idx', ['app_id', 'from_source', 'from_account_id'], unique=False)
  604. batch_op.create_index('message_app_id_idx', ['app_id', 'created_at'], unique=False)
  605. batch_op.create_index('message_conversation_id_idx', ['conversation_id'], unique=False)
  606. batch_op.create_index('message_end_user_idx', ['app_id', 'from_source', 'from_end_user_id'], unique=False)
  607. # ### end Alembic commands ###
  608. def downgrade():
  609. # ### commands auto generated by Alembic - please adjust! ###
  610. with op.batch_alter_table('messages', schema=None) as batch_op:
  611. batch_op.drop_index('message_end_user_idx')
  612. batch_op.drop_index('message_conversation_id_idx')
  613. batch_op.drop_index('message_app_id_idx')
  614. batch_op.drop_index('message_account_idx')
  615. op.drop_table('messages')
  616. with op.batch_alter_table('message_annotations', schema=None) as batch_op:
  617. batch_op.drop_index('message_annotation_message_idx')
  618. batch_op.drop_index('message_annotation_conversation_idx')
  619. batch_op.drop_index('message_annotation_app_idx')
  620. op.drop_table('message_annotations')
  621. with op.batch_alter_table('upload_files', schema=None) as batch_op:
  622. batch_op.drop_index('upload_file_tenant_idx')
  623. op.drop_table('upload_files')
  624. op.drop_table('tenants')
  625. with op.batch_alter_table('tenant_account_joins', schema=None) as batch_op:
  626. batch_op.drop_index('tenant_account_join_tenant_id_idx')
  627. batch_op.drop_index('tenant_account_join_account_id_idx')
  628. op.drop_table('tenant_account_joins')
  629. with op.batch_alter_table('sites', schema=None) as batch_op:
  630. batch_op.drop_index('site_code_idx')
  631. batch_op.drop_index('site_app_id_idx')
  632. op.drop_table('sites')
  633. op.drop_table('sessions')
  634. with op.batch_alter_table('saved_messages', schema=None) as batch_op:
  635. batch_op.drop_index('saved_message_message_idx')
  636. op.drop_table('saved_messages')
  637. with op.batch_alter_table('recommended_apps', schema=None) as batch_op:
  638. batch_op.drop_index('recommended_app_is_listed_idx')
  639. batch_op.drop_index('recommended_app_app_id_idx')
  640. op.drop_table('recommended_apps')
  641. with op.batch_alter_table('providers', schema=None) as batch_op:
  642. batch_op.drop_index('provider_tenant_id_provider_idx')
  643. op.drop_table('providers')
  644. with op.batch_alter_table('pinned_conversations', schema=None) as batch_op:
  645. batch_op.drop_index('pinned_conversation_conversation_idx')
  646. op.drop_table('pinned_conversations')
  647. with op.batch_alter_table('operation_logs', schema=None) as batch_op:
  648. batch_op.drop_index('operation_log_account_action_idx')
  649. op.drop_table('operation_logs')
  650. with op.batch_alter_table('message_feedbacks', schema=None) as batch_op:
  651. batch_op.drop_index('message_feedback_message_idx')
  652. batch_op.drop_index('message_feedback_conversation_idx')
  653. batch_op.drop_index('message_feedback_app_idx')
  654. op.drop_table('message_feedbacks')
  655. with op.batch_alter_table('message_chains', schema=None) as batch_op:
  656. batch_op.drop_index('message_chain_message_id_idx')
  657. op.drop_table('message_chains')
  658. with op.batch_alter_table('message_agent_thoughts', schema=None) as batch_op:
  659. batch_op.drop_index('message_agent_thought_message_id_idx')
  660. batch_op.drop_index('message_agent_thought_message_chain_id_idx')
  661. op.drop_table('message_agent_thoughts')
  662. with op.batch_alter_table('invitation_codes', schema=None) as batch_op:
  663. batch_op.drop_index('invitation_codes_code_idx')
  664. batch_op.drop_index('invitation_codes_batch_idx')
  665. op.drop_table('invitation_codes')
  666. with op.batch_alter_table('installed_apps', schema=None) as batch_op:
  667. batch_op.drop_index('installed_app_tenant_id_idx')
  668. batch_op.drop_index('installed_app_app_id_idx')
  669. op.drop_table('installed_apps')
  670. with op.batch_alter_table('end_users', schema=None) as batch_op:
  671. batch_op.drop_index('end_user_tenant_session_id_idx')
  672. batch_op.drop_index('end_user_session_id_idx')
  673. op.drop_table('end_users')
  674. op.drop_table('embeddings')
  675. with op.batch_alter_table('documents', schema=None) as batch_op:
  676. batch_op.drop_index('document_is_paused_idx')
  677. batch_op.drop_index('document_dataset_id_idx')
  678. op.drop_table('documents')
  679. with op.batch_alter_table('document_segments', schema=None) as batch_op:
  680. batch_op.drop_index('document_segment_tenant_document_idx')
  681. batch_op.drop_index('document_segment_tenant_dataset_idx')
  682. batch_op.drop_index('document_segment_document_id_idx')
  683. batch_op.drop_index('document_segment_dataset_node_idx')
  684. batch_op.drop_index('document_segment_dataset_id_idx')
  685. op.drop_table('document_segments')
  686. op.drop_table('dify_setups')
  687. with op.batch_alter_table('datasets', schema=None) as batch_op:
  688. batch_op.drop_index('dataset_tenant_idx')
  689. op.drop_table('datasets')
  690. with op.batch_alter_table('dataset_queries', schema=None) as batch_op:
  691. batch_op.drop_index('dataset_query_dataset_id_idx')
  692. op.drop_table('dataset_queries')
  693. with op.batch_alter_table('dataset_process_rules', schema=None) as batch_op:
  694. batch_op.drop_index('dataset_process_rule_dataset_id_idx')
  695. op.drop_table('dataset_process_rules')
  696. with op.batch_alter_table('dataset_keyword_tables', schema=None) as batch_op:
  697. batch_op.drop_index('dataset_keyword_table_dataset_id_idx')
  698. op.drop_table('dataset_keyword_tables')
  699. with op.batch_alter_table('conversations', schema=None) as batch_op:
  700. batch_op.drop_index('conversation_app_from_user_idx')
  701. op.drop_table('conversations')
  702. op.drop_table('celery_tasksetmeta')
  703. op.drop_table('celery_taskmeta')
  704. op.execute('DROP SEQUENCE taskset_id_sequence;')
  705. op.execute('DROP SEQUENCE task_id_sequence;')
  706. with op.batch_alter_table('apps', schema=None) as batch_op:
  707. batch_op.drop_index('app_tenant_id_idx')
  708. op.drop_table('apps')
  709. with op.batch_alter_table('app_model_configs', schema=None) as batch_op:
  710. batch_op.drop_index('app_app_id_idx')
  711. op.drop_table('app_model_configs')
  712. with op.batch_alter_table('app_dataset_joins', schema=None) as batch_op:
  713. batch_op.drop_index('app_dataset_join_app_dataset_idx')
  714. op.drop_table('app_dataset_joins')
  715. with op.batch_alter_table('api_tokens', schema=None) as batch_op:
  716. batch_op.drop_index('api_token_token_idx')
  717. batch_op.drop_index('api_token_app_id_type_idx')
  718. op.drop_table('api_tokens')
  719. with op.batch_alter_table('api_requests', schema=None) as batch_op:
  720. batch_op.drop_index('api_request_token_idx')
  721. op.drop_table('api_requests')
  722. with op.batch_alter_table('accounts', schema=None) as batch_op:
  723. batch_op.drop_index('account_email_idx')
  724. op.drop_table('accounts')
  725. op.drop_table('account_integrates')
  726. # ### end Alembic commands ###