Skip to content
Permalink
Browse files

[#14] 스키마 정의

  • Loading branch information...
JoMingyu committed Mar 7, 2019
1 parent eb3bff1 commit d3e78ddb23ad51b0b14deb61fc5b3f12a22fe260
Showing with 59 additions and 0 deletions.
  1. +15 −0 app/models/category.py
  2. +16 −0 app/models/comment.py
  3. +17 −0 app/models/post.py
  4. +11 −0 app/models/user.py
@@ -0,0 +1,15 @@
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.orm import relationship

from app.models import Base


class TblCategories(Base):
__tablename__ = 'tbl_categories'

id = Column(Integer, primary_key=True)
# SQLAlchemy가 첫 integer 타입의 PK에 auto increment 속성을 알아서 부여함
name = Column(String(32), unique=True)
author_id = Column(String(256), ForeignKey('tbl_users.id'))

author = relationship('TblUsers')
@@ -0,0 +1,16 @@
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.orm import relationship

from app.models import Base


class TblComments(Base):
__tablename__ = 'tbl_comments'

id = Column(Integer, primary_key=True)
content = Column(String(500))
owner_id = Column(String(256), ForeignKey('tbl_users.id'))
post_id = Column(Integer, ForeignKey('tbl_posts.id'))

owner = relationship('TblUsers')
post = relationship('TblPosts')
@@ -0,0 +1,17 @@
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.orm import relationship

from app.models import Base


class TblPosts(Base):
__tablename__ = 'tbl_posts'

id = Column(Integer, primary_key=True)
title = Column(String(100))
content = Column(String(5000))
owner_id = Column(String(256), ForeignKey('tbl_users.id'))
category_id = Column(Integer, ForeignKey('tbl_categories.id'))

owner = relationship('TblUsers')
category = relationship('TblCategories')
@@ -0,0 +1,11 @@
from sqlalchemy import Column, String, CHAR

from app.models import Base


class TblUsers(Base):
__tablename__ = 'tbl_users'

id = Column(String(64), primary_key=True)
password = Column(CHAR(93)) # len(werkzeug.security.generate_password_hash())
nickname = Column(String(32))

0 comments on commit d3e78dd

Please sign in to comment.
You can’t perform that action at this time.