Jul 9 - Chat - Add knowledge base for AI training
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
"""phase38 — support_knowledge (admin-curated AI chat knowledge base)
|
||||
|
||||
Admin-editable knowledge entries injected into the support chatbot's system
|
||||
prompt so staff can improve its app knowledge without code changes.
|
||||
|
||||
Uses table existence check — safe to re-run.
|
||||
"""
|
||||
|
||||
revision = 'phase38_support_knowledge'
|
||||
down_revision = 'phase37_support_chat'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def _table_exists(conn, table):
|
||||
return conn.execute(sa.text(
|
||||
"SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES "
|
||||
"WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = :t"
|
||||
), {"t": table}).scalar() > 0
|
||||
|
||||
|
||||
def upgrade():
|
||||
bind = op.get_bind()
|
||||
if _table_exists(bind, 'support_knowledge'):
|
||||
return
|
||||
op.create_table(
|
||||
'support_knowledge',
|
||||
sa.Column('id', sa.Integer, primary_key=True),
|
||||
sa.Column('title', sa.String(200), nullable=False),
|
||||
sa.Column('content', sa.Text, nullable=False),
|
||||
sa.Column('active', sa.Boolean, nullable=False, server_default='1'),
|
||||
sa.Column('sort_order', sa.Integer, nullable=False, server_default='0'),
|
||||
sa.Column('created_by', sa.Integer,
|
||||
sa.ForeignKey('users.id', ondelete='SET NULL'), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime, nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime, nullable=False),
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
bind = op.get_bind()
|
||||
if _table_exists(bind, 'support_knowledge'):
|
||||
op.drop_table('support_knowledge')
|
||||
Reference in New Issue
Block a user