-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
90 lines (62 loc) · 3.13 KB
/
Copy pathmodel.py
File metadata and controls
90 lines (62 loc) · 3.13 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import os
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class User(db.Model):
__tablename__ = "users"
id = db.Column(db.Integer, primary_key = True, autoincrement = True)
username = db.Column(db.String(255) , nullable = False)
password = db.Column(db.String(255) , nullable = False)
owned_poke = db.relationship("OwnPoke", backref = "move", lazy = True)
class Move(db.Model):
__tablename__ = "moves"
id = db.Column(db.Integer, primary_key = True, autoincrement = True)
name = db.Column(db.String , nullable = False)
power = db.Column(db.Integer , nullable = True)
accuracy = db.Column(db.Integer , nullable = True)
pp = db.Column(db.Integer , nullable = False)
class Poke(db.Model):
__tablename__ = "pokemon"
id = db.Column(db.Integer, primary_key = True, autoincrement = True)
name = db.Column(db.String(255), nullable = False)
poketype1 = db.Column(db.Integer, db.ForeignKey("types.id"), nullable = False)
poketype2 = db.Column(db.Integer, db.ForeignKey("types.id"), nullable = True)
class PokeMove(db.Model):
__tablename__ = "pokemon_moves"
id = db.Column(db.Integer, primary_key = True, autoincrement = True)
pokemon_id = db.Column(db.Integer, db.ForeignKey("pokemon.id"), nullable = False)
move_id = db.Column(db.Integer, db.ForeignKey("moves.id"), nullable = False)
class OwnPoke(db.Model):
__tablename__ = "owned_pokes"
id = db.Column(db.Integer, primary_key = True, autoincrement = True)
pokemon_id = db.Column(db.Integer, db.ForeignKey("pokemon.id"), nullable = False)
user_id = db.Column(db.Integer, db.ForeignKey("users.id"), nullable = False)
sprite = db.Column(db.String(255), nullable = False)
move_1_id = db.Column(db.Integer, db.ForeignKey("moves.id"), nullable = False)
move_2_id = db.Column(db.Integer, db.ForeignKey("moves.id"), nullable = False)
move_3_id = db.Column(db.Integer, db.ForeignKey("moves.id"), nullable = False)
move_4_id = db.Column(db.Integer, db.ForeignKey("moves.id"), nullable = False)
name = db.Column(db.String(255))
poketype1 = db.Column(db.String(255))
poketype2 = db.Column(db.String(255), nullable = True)
class PokeType(db.Model):
__tablename__ = "types"
id = db.Column(db.Integer, primary_key = True, autoincrement = True)
poketype = db.Column(db.String(255), nullable = False)
class Region(db.Model):
__tablename__ = "regions"
id = db.Column(db.Integer, primary_key = True, autoincrement = True)
name = db.Column(db.String(255), nullable = False)
poketype = db.Column(db.String(255), nullable = False)
def connect_to_db(flask_app, echo=True):
flask_app.config["SQLALCHEMY_DATABASE_URI"] = os.environ["POSTGRES_URI"]
flask_app.config["SQLALCHEMY_ECHO"] = echo
flask_app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db.app = flask_app
db.init_app(flask_app)
print("Connected to the db!")
if __name__ == "__main__":
from server import app
# Call connect_to_db(app, echo=False) if your program output gets
# too annoying; this will tell SQLAlchemy not to print out every
# query it executes.
connect_to_db(app, echo=False)