Projekte pro Benutzer mit Name und Farbe, Clips optional einem Projekt zugeordnet. Löschen eines Projekts verschiebt seine Clips nach "ohne Projekt". Clip-Liste filtert nach Projekt und sucht Teiltexte in Titel und Inhalt, unabhängig von Groß-/Kleinschreibung (auch Umlaute). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
"""projects
|
|
|
|
Revision ID: 0004
|
|
Revises: 0003
|
|
Create Date: 2026-10-25 13:12:18.898120
|
|
|
|
"""
|
|
|
|
from collections.abc import Sequence
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
revision: str = "0004"
|
|
down_revision: str | None = "0003"
|
|
branch_labels: str | Sequence[str] | None = None
|
|
depends_on: str | Sequence[str] | None = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"projects",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("user_id", sa.Integer(), nullable=False),
|
|
sa.Column("name", sa.String(length=100), nullable=False),
|
|
sa.Column("name_key", sa.String(length=100), nullable=False),
|
|
sa.Column("color", sa.String(length=16), nullable=False),
|
|
sa.Column("created_at", sa.DateTime(), nullable=False),
|
|
sa.Column("updated_at", sa.DateTime(), nullable=False),
|
|
sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
sa.UniqueConstraint("user_id", "name_key", name="uq_projects_user_name"),
|
|
)
|
|
with op.batch_alter_table("clips", schema=None) as batch_op:
|
|
batch_op.add_column(sa.Column("project_id", sa.Integer(), nullable=True))
|
|
batch_op.create_index("ix_clips_user_project", ["user_id", "project_id"], unique=False)
|
|
batch_op.create_foreign_key(
|
|
"fk_clips_project_id", "projects", ["project_id"], ["id"], ondelete="SET NULL"
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
with op.batch_alter_table("clips", schema=None) as batch_op:
|
|
batch_op.drop_constraint("fk_clips_project_id", type_="foreignkey")
|
|
batch_op.drop_index("ix_clips_user_project")
|
|
batch_op.drop_column("project_id")
|
|
|
|
op.drop_table("projects")
|