feat: show author name instead of user x
This commit was merged in pull request #7.
This commit is contained in:
@@ -5,6 +5,8 @@ from sqlalchemy import pool
|
||||
|
||||
from alembic import context
|
||||
|
||||
from app.database import Base
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
# access to the values within the .ini file in use.
|
||||
config = context.config
|
||||
@@ -17,8 +19,7 @@ if config.config_file_name is not None:
|
||||
# add your model's MetaData object here
|
||||
# for 'autogenerate' support
|
||||
# from myapp import mymodel
|
||||
# target_metadata = mymodel.Base.metadata
|
||||
target_metadata = None
|
||||
target_metadata = Base.metadata
|
||||
|
||||
# other values from the config, defined by the needs of env.py,
|
||||
# can be acquired:
|
||||
@@ -64,9 +65,7 @@ def run_migrations_online() -> None:
|
||||
)
|
||||
|
||||
with connectable.connect() as connection:
|
||||
context.configure(
|
||||
connection=connection, target_metadata=target_metadata
|
||||
)
|
||||
context.configure(connection=connection, target_metadata=target_metadata)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
"""Add author_name to blogs
|
||||
|
||||
Revision ID: c9b28e38d00c
|
||||
Revises:
|
||||
Create Date: 2025-06-24 20:51:56.034469
|
||||
|
||||
"""
|
||||
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 = 'c9b28e38d00c'
|
||||
down_revision: Union[str, None] = None
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_index(op.f('ix_users_email'), table_name='users')
|
||||
op.drop_index(op.f('ix_users_id'), table_name='users')
|
||||
op.drop_index(op.f('ix_users_username'), table_name='users')
|
||||
op.drop_table('users')
|
||||
op.drop_index(op.f('ix_blogs_author_id'), table_name='blogs')
|
||||
op.drop_index(op.f('ix_blogs_id'), table_name='blogs')
|
||||
op.drop_index(op.f('ix_blogs_title'), table_name='blogs')
|
||||
op.drop_table('blogs')
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('blogs',
|
||||
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
|
||||
sa.Column('title', sa.VARCHAR(), autoincrement=False, nullable=True),
|
||||
sa.Column('author_id', sa.INTEGER(), autoincrement=False, nullable=False),
|
||||
sa.Column('description', sa.VARCHAR(), autoincrement=False, nullable=True),
|
||||
sa.Column('body', sa.VARCHAR(), autoincrement=False, nullable=False),
|
||||
sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False),
|
||||
sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True),
|
||||
sa.Column('published_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True),
|
||||
sa.Column('word_count', sa.INTEGER(), autoincrement=False, nullable=True),
|
||||
sa.Column('version', sa.INTEGER(), autoincrement=False, nullable=True),
|
||||
sa.Column('read_time', sa.INTEGER(), autoincrement=False, nullable=True),
|
||||
sa.Column('language', sa.VARCHAR(), autoincrement=False, nullable=True),
|
||||
sa.Column('tags', postgresql.JSON(astext_type=sa.Text()), autoincrement=False, nullable=True),
|
||||
sa.Column('view_count', sa.INTEGER(), autoincrement=False, nullable=False),
|
||||
sa.Column('like_count', sa.INTEGER(), autoincrement=False, nullable=False),
|
||||
sa.PrimaryKeyConstraint('id', name=op.f('blogs_pkey'))
|
||||
)
|
||||
op.create_index(op.f('ix_blogs_title'), 'blogs', ['title'], unique=False)
|
||||
op.create_index(op.f('ix_blogs_id'), 'blogs', ['id'], unique=False)
|
||||
op.create_index(op.f('ix_blogs_author_id'), 'blogs', ['author_id'], unique=False)
|
||||
op.create_table('users',
|
||||
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
|
||||
sa.Column('username', sa.VARCHAR(), autoincrement=False, nullable=False),
|
||||
sa.Column('email', sa.VARCHAR(), autoincrement=False, nullable=False),
|
||||
sa.Column('hashed_password', sa.VARCHAR(), autoincrement=False, nullable=False),
|
||||
sa.Column('permissions', postgresql.JSON(astext_type=sa.Text()), autoincrement=False, nullable=False),
|
||||
sa.Column('subscriber', sa.BOOLEAN(), autoincrement=False, nullable=False),
|
||||
sa.PrimaryKeyConstraint('id', name=op.f('users_pkey'))
|
||||
)
|
||||
op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True)
|
||||
op.create_index(op.f('ix_users_id'), 'users', ['id'], unique=False)
|
||||
op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
|
||||
# ### end Alembic commands ###
|
||||
@@ -16,6 +16,7 @@ class Blog(Base):
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
title = Column(String, index=True)
|
||||
author_id = Column(Integer, nullable=False, index=True)
|
||||
author_name = Column(String, nullable=False, index=True)
|
||||
description = Column(String, nullable=True)
|
||||
body = Column(String, nullable=False)
|
||||
created_at = Column(
|
||||
|
||||
@@ -5,6 +5,7 @@ from pydantic import AwareDatetime, BaseModel, EmailStr
|
||||
class BlogBase(BaseModel):
|
||||
title: str
|
||||
author_id: int
|
||||
author_name: str
|
||||
description: Optional[str] = None
|
||||
body: str
|
||||
created_at: AwareDatetime
|
||||
@@ -30,6 +31,7 @@ class BlogUpdate(BaseModel):
|
||||
|
||||
title: Optional[str] = None
|
||||
description: Optional[str] = None
|
||||
author_name: Optional[str] = None
|
||||
body: Optional[str] = None
|
||||
created_at: Optional[str] = None
|
||||
updated_at: Optional[str] = None
|
||||
|
||||
Reference in New Issue
Block a user