-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase_setup.py
65 lines (52 loc) · 1.92 KB
/
database_setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#shebang line for python 2
#!/usr/bin/env python
# nessary modules
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy import Column, String, Integer, ForeignKey
engine = create_engine("sqlite:///catogrey.db")
Base = declarative_base()
# table to save every user data
class User(Base):
__tablename__ = "user"
id = Column(Integer, primary_key=True)
name = Column(String(250), nullable=False)
email = Column(String(250), nullable=False)
picture = Column(String(250), nullable=False)
# catogries used in this app
class Catogrey(Base):
__tablename__ = "catogrey"
id = Column(Integer, primary_key=True)
name = Column(String(250), nullable=False)
@property
def serialize(self):
return {"id": self.id, "name": self.name}
# this branche table is containg the default branches and displayed for
# unregisteded user
class Branche(Base):
__tablename__ = "branche"
id = Column(Integer, primary_key=True)
name = Column(String(250), nullable=False)
description = Column(String(250), nullable=False)
catogrey_id = Column(Integer, ForeignKey("catogrey.id"))
relathion = relationship(Catogrey)
@property
def serialize(self):
return {
"id": self.id,
"name": self.name,
"description": self.description,
"catogrey_id": self.catogrey_id
}
# this table contain the user specfic branches or branches created by user
class UserBranche(Base):
__tablename__ = "userbranche"
id = Column(Integer, primary_key=True)
name = Column(String(250), nullable=False)
description = Column(String(250), nullable=False)
catogrey_id = Column(Integer, ForeignKey("catogrey.id"))
catogrey = relationship(Catogrey)
user_id = Column(Integer, ForeignKey("user.id"))
user = relationship(User)
Base.metadata.create_all(engine)