feat: add feedback database model and migration
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
42
backend/alembic/versions/e65b9f8fd458_add_feedback_table.py
Normal file
42
backend/alembic/versions/e65b9f8fd458_add_feedback_table.py
Normal file
@@ -0,0 +1,42 @@
|
||||
"""add feedback table
|
||||
|
||||
Revision ID: e65b9f8fd458
|
||||
Revises: 0fd2a90a9c2c
|
||||
Create Date: 2026-02-18 17:39:16.939185
|
||||
|
||||
"""
|
||||
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 = 'e65b9f8fd458'
|
||||
down_revision: Union[str, None] = '0fd2a90a9c2c'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
'feedback',
|
||||
sa.Column('id', postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column('account_id', postgresql.UUID(as_uuid=True), sa.ForeignKey('accounts.id', ondelete='SET NULL'), nullable=True),
|
||||
sa.Column('user_id', postgresql.UUID(as_uuid=True), sa.ForeignKey('users.id', ondelete='SET NULL'), nullable=False),
|
||||
sa.Column('email', sa.String(255), nullable=False),
|
||||
sa.Column('feedback_type', sa.String(50), nullable=False),
|
||||
sa.Column('message', sa.Text(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.func.now()),
|
||||
)
|
||||
op.create_index('ix_feedback_account_id', 'feedback', ['account_id'])
|
||||
op.create_index('ix_feedback_user_id', 'feedback', ['user_id'])
|
||||
op.create_index('ix_feedback_created_at', 'feedback', ['created_at'])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index('ix_feedback_created_at', table_name='feedback')
|
||||
op.drop_index('ix_feedback_user_id', table_name='feedback')
|
||||
op.drop_index('ix_feedback_account_id', table_name='feedback')
|
||||
op.drop_table('feedback')
|
||||
@@ -25,6 +25,7 @@ from .platform_setting import PlatformSetting
|
||||
from .user_pinned_tree import UserPinnedTree
|
||||
from .target_list import TargetList
|
||||
from .maintenance_schedule import MaintenanceSchedule
|
||||
from .feedback import Feedback
|
||||
|
||||
__all__ = [
|
||||
"User",
|
||||
@@ -61,4 +62,5 @@ __all__ = [
|
||||
"UserPinnedTree",
|
||||
"TargetList",
|
||||
"MaintenanceSchedule",
|
||||
"Feedback",
|
||||
]
|
||||
|
||||
19
backend/app/models/feedback.py
Normal file
19
backend/app/models/feedback.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import uuid
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
from sqlalchemy import String, Text, DateTime, ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class Feedback(Base):
|
||||
__tablename__ = "feedback"
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
account_id: Mapped[Optional[uuid.UUID]] = mapped_column(UUID(as_uuid=True), ForeignKey("accounts.id", ondelete="SET NULL"), nullable=True)
|
||||
user_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), ForeignKey("users.id", ondelete="SET NULL"), nullable=False)
|
||||
email: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
feedback_type: Mapped[str] = mapped_column(String(50), nullable=False)
|
||||
message: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=lambda: datetime.now(timezone.utc))
|
||||
Reference in New Issue
Block a user