Skip to content

Instantly share code, notes, and snippets.

@gabbyprecious
Last active May 23, 2020 21:44
Show Gist options
  • Save gabbyprecious/33c9d3a9c22b064895e954ab3be293f6 to your computer and use it in GitHub Desktop.
Save gabbyprecious/33c9d3a9c22b064895e954ab3be293f6 to your computer and use it in GitHub Desktop.
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
from datetime import datetime
Base = declarative_base()
class User(Base):
"""
This table records the users of the site
"""
__tablename__ = "users"
id = Column(Integer, primary_key=True, index=True)
first_name = Column(String(150))
last_name = Column(String(150))
username = Column(String(150))
email = Column(String(150))
password = Column(String(150))
class Post(Base):
"""
A table to record all posts made by all users of the minitwitter
"""
__tablename__ = "posts"
id = Column(Integer, primary_key=True, index=True)
userId = Column(Integer, ForeignKey("users.id"))
post = Column(String(150))
created = Column(DateTime, default=datetime.utcnow)
class Follower(Base):
"""
This table records the following of each user,
UserId refers to the user been followed
And FollowerId refers to the follower
"""
__tablename__ = "followers"
id = Column(Integer, primary_key=True, index=True)
userId = Column(Integer, ForeignKey("users.id"))
FollowerId = Column(Integer, ForeignKey("users.id"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment