added names to collections

This commit is contained in:
Анатолий Богомолов 2024-03-07 02:22:24 +10:00
parent e9cf18d0e6
commit 6cd6566a06
2 changed files with 35 additions and 0 deletions

View File

@ -6,6 +6,7 @@ from app.extensions import db
class Collection(db.Model): class Collection(db.Model):
id: Mapped[int] = mapped_column(primary_key=True) id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(unique=True, nullable=False)
tasks: Mapped[List['Task']] = relationship("Task", back_populates="collection") tasks: Mapped[List['Task']] = relationship("Task", back_populates="collection")
users: Mapped[List['User']] = relationship("User", cascade="all, delete-orphan", back_populates="collection") users: Mapped[List['User']] = relationship("User", cascade="all, delete-orphan", back_populates="collection")

View File

@ -0,0 +1,34 @@
"""Added name field to collections
Revision ID: d573f6529ad5
Revises: 21750f5bbab1
Create Date: 2024-03-06 01:45:54.772732
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'd573f6529ad5'
down_revision = '21750f5bbab1'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('collection', schema=None) as batch_op:
batch_op.add_column(sa.Column('name', sa.String(), nullable=False))
batch_op.create_unique_constraint(None, ['name'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('collection', schema=None) as batch_op:
batch_op.drop_constraint(None, type_='unique')
batch_op.drop_column('name')
# ### end Alembic commands ###