summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--migrations/versions/c2ca1cc5b130_add_author_to_comment.py38
-rw-r--r--src/database/models/comment.py3
2 files changed, 40 insertions, 1 deletions
diff --git a/migrations/versions/c2ca1cc5b130_add_author_to_comment.py b/migrations/versions/c2ca1cc5b130_add_author_to_comment.py
new file mode 100644
index 0000000..f1360b5
--- /dev/null
+++ b/migrations/versions/c2ca1cc5b130_add_author_to_comment.py
@@ -0,0 +1,38 @@
+"""Add author to comment
+
+Revision ID: c2ca1cc5b130
+Revises: 742bdc6e0718
+Create Date: 2024-02-03 16:47:06.111596
+
+"""
+from alembic import op
+import sqlalchemy as sa
+from sqlalchemy.dialects import mysql
+
+# revision identifiers, used by Alembic.
+revision = 'c2ca1cc5b130'
+down_revision = '742bdc6e0718'
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ with op.batch_alter_table('comments', schema=None) as batch_op:
+ batch_op.add_column(sa.Column('author', sa.String(length=128), nullable=True))
+ batch_op.alter_column('email',
+ existing_type=mysql.VARCHAR(length=256),
+ nullable=True)
+
+ # ### end Alembic commands ###
+
+
+def downgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ with op.batch_alter_table('comments', schema=None) as batch_op:
+ batch_op.alter_column('email',
+ existing_type=mysql.VARCHAR(length=256),
+ nullable=False)
+ batch_op.drop_column('author')
+
+ # ### end Alembic commands ###
diff --git a/src/database/models/comment.py b/src/database/models/comment.py
index 0110e75..9501bba 100644
--- a/src/database/models/comment.py
+++ b/src/database/models/comment.py
@@ -9,7 +9,8 @@ class Comment(db.Model):
id = mapped_column(BigInteger, primary_key=True)
content: Mapped[str] = mapped_column(Text)
language: Mapped[str] = mapped_column(String(16), nullable=False)
- email: Mapped[str] = mapped_column(String(256))
+ email: Mapped[str] = mapped_column(String(256), nullable=True)
+ author: Mapped[str] = mapped_column(String(128), nullable=True)
post: Mapped[str] = mapped_column(String(1024), nullable=False)
blog_id: Mapped[int] = mapped_column(ForeignKey('blogs.id'), index=True)
blog = relationship('Blog', back_populates='comments')