<gh_stars>0
from sqlalchemy import Boolean, Column, Integer, String
from sqlalchemy.orm import relationship
from sqlalchemy.sql.expression import text
from sqlalchemy.sql.schema import ForeignKey
from sqlalchemy.sql.sqltypes import TIMESTAMP
from database import Base


class Posts(Base):
    """This is an ORM Model which is used to create a table in a PostgreSQL DB."""

    __tablename__ = "posts"

    id = Column(Integer, primary_key=True, index=True)
    title = Column(String, nullable=False, index=True)
    content = Column(String, nullable=False)
    is_published = Column(Boolean, nullable=False, server_default="False")
    created_at = Column(
        TIMESTAMP(timezone=True), nullable=False, server_default=text("now()")
    )
    owner_id = Column(
        Integer, ForeignKey("users.id", ondelete="cascade"), nullable=False
    )
    owner = relationship("Users")  # fetches the owner_id details from the Users table


class Users(Base):
    """This class is used to create the Users table in the PostgreSQL DB. It
    stores the user information."""

    __tablename__ = "users"
    id = Column(Integer, primary_key=True, index=True)
    email = Column(String, nullable=False, unique=True)
    password = Column(String, nullable=False)
    created_at = Column(
        TIMESTAMP(timezone=True), nullable=False, server_default=text("now()")
    )


class Votes(Base):
    """This class is used to create the Votes table in the PostgreSQL DB."""

    __tablename__ = "votes"
    post_id = Column(
        Integer, ForeignKey("posts.id", ondelete="CASCADE"), primary_key=True
    )
    user_id = Column(
        Integer, ForeignKey("users.id", ondelete="CASCADE"), primary_key=True
    )
    post = relationship("Posts")
    owner = relationship("Users")

from sqlalchemy import Boolean, Column, Integer, String
from sqlalchemy.orm import relationship
from sqlalchemy.sql.expression import text
from sqlalchemy.sql.schema import ForeignKey
from sqlalchemy.sql.sqltypes import TIMESTAMP
from database import Base


class Posts(Base):
    """This is an ORM Model which is used to create a table in a PostgreSQL DB."""

    __tablename__ = "posts"

    id = Column(Integer, primary_key=True, index=True)
    title = Column(String, nullable=False, index=True)
    content = Column(String, nullable=False)
    is_published = Column(Boolean, nullable=False, server_default="False")
    created_at = Column(
        TIMESTAMP(timezone=True), nullable=False, server_default=text("now()")
    )
    owner_id = Column(
        Integer, ForeignKey("users.id", ondelete="cascade"), nullable=False
    )
    owner = relationship("Users")  # fetches the owner_id details from the Users table


class Users(Base):
    """This class is used to create the Users table in the PostgreSQL DB. It
    stores the user information."""

    __tablename__ = "users"
    id = Column(Integer, primary_key=True, index=True)
    email = Column(String, nullable=False, unique=True)
    password = Column(String, nullable=False)
    created_at = Column(
        TIMESTAMP(timezone=True), nullable=False, server_default=text("now()")
    )


class Votes(Base):
    """This class is used to create the Votes table in the PostgreSQL DB."""

    __tablename__ = "votes"
    post_id = Column(
        Integer, ForeignKey("posts.id", ondelete="CASCADE"), primary_key=True
    )
    user_id = Column(
        Integer, ForeignKey("users.id", ondelete="CASCADE"), primary_key=True
    )
    post = relationship("Posts")
    owner = relationship("Users")
This is an ORM Model which is used to create a table in a PostgreSQL DB. # fetches the owner_id details from the Users table This class is used to create the Users table in the PostgreSQL DB. It     stores the user information. This class is used to create the Votes table in the PostgreSQL DB.