remove contact table

This commit is contained in:
2025-10-01 22:36:32 +03:00
parent 58185a11a9
commit 2c7522018f
2 changed files with 43 additions and 13 deletions

View File

@@ -0,0 +1,41 @@
"""remove contact table
Revision ID: 603af861b193
Revises: c151f5abb66d
Create Date: 2025-10-01 22:35:33.898996
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '603af861b193'
down_revision: Union[str, Sequence[str], None] = 'c151f5abb66d'
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_table('contact')
op.add_column('user', sa.Column('email', sa.String(), nullable=True))
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('user', 'email')
op.create_table('contact',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('user_id', sa.INTEGER(), autoincrement=False, nullable=False),
sa.Column('type', sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column('value', sa.VARCHAR(), autoincrement=False, nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], name=op.f('contact_user_id_fkey')),
sa.PrimaryKeyConstraint('id', name=op.f('contact_pkey'))
)
# ### end Alembic commands ###

View File

@@ -17,11 +17,10 @@ class User(Base):
fullname: Mapped[str] = mapped_column() fullname: Mapped[str] = mapped_column()
role: Mapped[str] = mapped_column(default=UserRole.USER.value) role: Mapped[str] = mapped_column(default=UserRole.USER.value)
phone: Mapped[str] = mapped_column(nullable=True) phone: Mapped[str] = mapped_column(nullable=True)
email: Mapped[str] = mapped_column(nullable=True)
events = relationship("UserEvent", back_populates="user_rel") events = relationship("UserEvent", back_populates="user_rel")
certificates = relationship("Certificate", back_populates="user_rel") certificates = relationship("Certificate", back_populates="user_rel")
addresses = relationship("Address", back_populates="user_rel") addresses = relationship("Address", back_populates="user_rel")
contacts = relationship("Contact", back_populates="user_rel")
class Event(Base): class Event(Base):
@@ -87,14 +86,4 @@ class Address(Base):
extended_address: Mapped[str] = mapped_column() extended_address: Mapped[str] = mapped_column()
postal_code: Mapped[str] = mapped_column() postal_code: Mapped[str] = mapped_column()
user_rel = relationship("User", back_populates="addresses") user_rel = relationship("User", back_populates="addresses")
class Contact(Base):
__tablename__ = "contact"
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
user_id: Mapped[int] = mapped_column(ForeignKey("user.id"))
type: Mapped[str] = mapped_column()
value: Mapped[str] = mapped_column()
user_rel = relationship("User", back_populates="contacts")