support articles
This commit is contained in:
56
migrations/versions/add_help_articles_table.py
Normal file
56
migrations/versions/add_help_articles_table.py
Normal file
@@ -0,0 +1,56 @@
|
||||
"""add help articles table
|
||||
|
||||
Revision ID: add_help_articles_table
|
||||
Revises: c94c2b2b9f2e
|
||||
Create Date: 2024-12-19 10:00:00.000000
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import text
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'add_help_articles_table'
|
||||
down_revision = 'c94c2b2b9f2e'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
conn = op.get_bind()
|
||||
result = conn.execute(text("""
|
||||
SELECT EXISTS (
|
||||
SELECT FROM information_schema.tables
|
||||
WHERE table_name = 'help_articles'
|
||||
);
|
||||
"""))
|
||||
exists = result.scalar()
|
||||
if not exists:
|
||||
op.create_table('help_articles',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('title', sa.String(length=200), nullable=False),
|
||||
sa.Column('category', sa.String(length=50), nullable=False),
|
||||
sa.Column('body', sa.Text(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('created_by', sa.Integer(), nullable=False),
|
||||
sa.Column('is_published', sa.Boolean(), nullable=True, server_default='true'),
|
||||
sa.Column('order_index', sa.Integer(), nullable=True, server_default='0'),
|
||||
sa.ForeignKeyConstraint(['created_by'], ['user.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
|
||||
# Create indexes for better performance
|
||||
op.create_index('idx_help_articles_category', 'help_articles', ['category'])
|
||||
op.create_index('idx_help_articles_published', 'help_articles', ['is_published'])
|
||||
op.create_index('idx_help_articles_order', 'help_articles', ['order_index'])
|
||||
op.create_index('idx_help_articles_created_at', 'help_articles', ['created_at'])
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_index('idx_help_articles_category', table_name='help_articles')
|
||||
op.drop_index('idx_help_articles_published', table_name='help_articles')
|
||||
op.drop_index('idx_help_articles_order', table_name='help_articles')
|
||||
op.drop_index('idx_help_articles_created_at', table_name='help_articles')
|
||||
op.drop_table('help_articles')
|
||||
Reference in New Issue
Block a user