64b051264f32_init.py 47 KB

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