* [add]修改迁移文件新建空白表结构 * Add installation guide and environment setup Added installation instructions and environment requirements for MemoryBear. * [delete]删除api,web的readme.md。只保留唯一readme.md * Fix database connection example in README Update database connection configuration example in README.
86 lines
4.7 KiB
Python
86 lines
4.7 KiB
Python
"""20251117114804
|
|
|
|
Revision ID: fda52b5e7c38
|
|
Revises: 2a82ee37b707
|
|
Create Date: 2025-11-17 11:48:05.399402
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = 'fda52b5e7c38'
|
|
down_revision: Union[str, None] = '2a82ee37b707'
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
# 使用 IF EXISTS 避免表不存在时报错
|
|
op.execute('DROP TABLE IF EXISTS mappings_copy1')
|
|
op.execute('DROP TABLE IF EXISTS mappings')
|
|
op.add_column('agent_configs', sa.Column('knowledge_retrieval', postgresql.JSON(astext_type=sa.Text()), nullable=True, comment='知识库检索配置'))
|
|
op.add_column('agent_configs', sa.Column('memory', postgresql.JSON(astext_type=sa.Text()), nullable=True, comment='记忆配置'))
|
|
op.add_column('agent_configs', sa.Column('variables', postgresql.JSON(astext_type=sa.Text()), nullable=True, comment='变量配置'))
|
|
op.add_column('agent_configs', sa.Column('tools', postgresql.JSON(astext_type=sa.Text()), nullable=True, comment='工具配置'))
|
|
op.alter_column('agent_configs', 'system_prompt',
|
|
existing_type=sa.TEXT(),
|
|
comment='系统提示词',
|
|
existing_nullable=True)
|
|
op.alter_column('agent_configs', 'default_model_config_id',
|
|
existing_type=sa.UUID(),
|
|
comment='默认模型配置ID',
|
|
existing_nullable=True)
|
|
op.drop_column('agent_configs', 'conversation_prefs')
|
|
op.drop_column('agent_configs', 'memory_strategy')
|
|
op.drop_column('agent_configs', 'tools_config')
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade() -> None:
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.add_column('agent_configs', sa.Column('tools_config', postgresql.JSON(astext_type=sa.Text()), autoincrement=False, nullable=True))
|
|
op.add_column('agent_configs', sa.Column('memory_strategy', sa.VARCHAR(), autoincrement=False, nullable=True))
|
|
op.add_column('agent_configs', sa.Column('conversation_prefs', postgresql.JSON(astext_type=sa.Text()), autoincrement=False, nullable=True))
|
|
op.alter_column('agent_configs', 'default_model_config_id',
|
|
existing_type=sa.UUID(),
|
|
comment=None,
|
|
existing_comment='默认模型配置ID',
|
|
existing_nullable=True)
|
|
op.alter_column('agent_configs', 'system_prompt',
|
|
existing_type=sa.TEXT(),
|
|
comment=None,
|
|
existing_comment='系统提示词',
|
|
existing_nullable=True)
|
|
op.drop_column('agent_configs', 'tools')
|
|
op.drop_column('agent_configs', 'variables')
|
|
op.drop_column('agent_configs', 'memory')
|
|
op.drop_column('agent_configs', 'knowledge_retrieval')
|
|
op.create_table('mappings',
|
|
sa.Column('app_id', sa.UUID(), autoincrement=False, nullable=False),
|
|
sa.Column('host_id', sa.UUID(), autoincrement=False, nullable=False),
|
|
sa.Column('other_id', sa.UUID(), autoincrement=False, nullable=False),
|
|
sa.Column('other_name', sa.VARCHAR(length=255), autoincrement=False, nullable=True),
|
|
sa.Column('other_address', sa.VARCHAR(length=255), autoincrement=False, nullable=True),
|
|
sa.Column('created_at', postgresql.TIMESTAMP(precision=6), server_default=sa.text('CURRENT_TIMESTAMP'), autoincrement=False, nullable=True),
|
|
sa.Column('updated_at', postgresql.TIMESTAMP(precision=6), server_default=sa.text('CURRENT_TIMESTAMP'), autoincrement=False, nullable=True),
|
|
sa.ForeignKeyConstraint(['app_id'], ['apps.id'], name=op.f('app_id')),
|
|
sa.PrimaryKeyConstraint('app_id', 'host_id', 'other_id', name=op.f('mapping_pkey'))
|
|
)
|
|
op.create_table('mappings_copy1',
|
|
sa.Column('app_id', sa.UUID(), autoincrement=False, nullable=False),
|
|
sa.Column('host_id', sa.UUID(), autoincrement=False, nullable=False),
|
|
sa.Column('other_id', sa.UUID(), autoincrement=False, nullable=False),
|
|
sa.Column('other_name', sa.VARCHAR(length=255), autoincrement=False, nullable=True),
|
|
sa.Column('other_address', sa.VARCHAR(length=255), autoincrement=False, nullable=True),
|
|
sa.Column('created_at', postgresql.TIMESTAMP(precision=6), server_default=sa.text('CURRENT_TIMESTAMP'), autoincrement=False, nullable=True),
|
|
sa.Column('updated_at', postgresql.TIMESTAMP(precision=6), server_default=sa.text('CURRENT_TIMESTAMP'), autoincrement=False, nullable=True),
|
|
sa.ForeignKeyConstraint(['app_id'], ['apps.id'], name=op.f('mappings_copy1_app_id_fkey')),
|
|
sa.PrimaryKeyConstraint('app_id', 'host_id', 'other_id', name=op.f('mappings_copy1_pkey'))
|
|
)
|
|
# ### end Alembic commands ###
|