From 6cd6566a06199d3f36040ebd54593a3b171b7fe9 Mon Sep 17 00:00:00 2001 From: winet Date: Thu, 7 Mar 2024 02:22:24 +1000 Subject: [PATCH] added names to collections --- app/models/collection.py | 1 + ...6529ad5_added_name_field_to_collections.py | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 migrations/versions/d573f6529ad5_added_name_field_to_collections.py diff --git a/app/models/collection.py b/app/models/collection.py index d5aa42a..077fa99 100644 --- a/app/models/collection.py +++ b/app/models/collection.py @@ -6,6 +6,7 @@ from app.extensions import db class Collection(db.Model): 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") users: Mapped[List['User']] = relationship("User", cascade="all, delete-orphan", back_populates="collection") \ No newline at end of file diff --git a/migrations/versions/d573f6529ad5_added_name_field_to_collections.py b/migrations/versions/d573f6529ad5_added_name_field_to_collections.py new file mode 100644 index 0000000..74adf75 --- /dev/null +++ b/migrations/versions/d573f6529ad5_added_name_field_to_collections.py @@ -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 ###