-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdatabase_setup.py
More file actions
45 lines (36 loc) · 1.29 KB
/
database_setup.py
File metadata and controls
45 lines (36 loc) · 1.29 KB
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
import os
import sys
import datetime
# include sqlalchemy
from sqlalchemy import Column, ForeignKey, Integer, String, DateTime
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy import create_engine
Base = declarative_base()
"""User class"""
class User(Base):
__tablename__ = 'Users'
id = Column(Integer, primary_key=True)
name = Column(String(255), nullable=False)
github_access_token = Column(String(255))
avatar = Column(String(255))
"""Category class"""
class Category(Base):
__tablename__ = 'Categories'
name = Column(String(255), nullable = False)
id = Column(Integer, primary_key = True)
"""Item class"""
class Item(Base):
__tablename__ = 'Items'
name = Column(String(255), nullable = False)
id = Column(Integer, primary_key = True)
category_id = Column(Integer,ForeignKey('Categories.id'))
category = relationship(Category)
owner_id = Column(Integer,ForeignKey('Users.id'))
owner = relationship(User)
description = Column(String(255))
image = Column(String(255))
created = Column(DateTime, default=datetime.datetime.utcnow)
# engine = create_engine("postgresql://vagrant@localhost/catalog")
engine = create_engine('sqlite:///catalog.db')
Base.metadata.create_all(engine)