summaryrefslogtreecommitdiff
path: root/f1elo
diff options
context:
space:
mode:
Diffstat (limited to 'f1elo')
-rw-r--r--f1elo/db.py1
-rw-r--r--f1elo/interface.py8
-rw-r--r--f1elo/model.py16
3 files changed, 16 insertions, 9 deletions
diff --git a/f1elo/db.py b/f1elo/db.py
index bf106a6..cd7c4ac 100644
--- a/f1elo/db.py
+++ b/f1elo/db.py
@@ -10,7 +10,6 @@ config = json.load(open(path.join(path.dirname(__main__.__file__), 'config', 'db
engine = create_engine("mysql://{0[user]}:{0[pass]}@{0[host]}/{0[db]}?charset=utf8".format(config))
Session = sessionmaker(bind=engine)
-
def find_driver(name, country, session):
driver = session.query(Driver).filter(Driver.driver==name).first()
if driver:
diff --git a/f1elo/interface.py b/f1elo/interface.py
index 2065160..4b938ae 100644
--- a/f1elo/interface.py
+++ b/f1elo/interface.py
@@ -1,6 +1,8 @@
import datetime
import dateutil.relativedelta
+from sqlalchemy import MetaData
+
from f1elo.db import Session
from f1elo.elo import Elo
from f1elo.model import *
@@ -10,6 +12,12 @@ class Interface:
self.session = Session()
self.date = date
+ def init_db(self, force=False):
+ from f1elo.model import Base
+ if force:
+ Base.metadata.drop_all(self.session.get_bind())
+ Base.metadata.create_all(self.session.get_bind())
+
def reset(self, date=None, _debug=False):
if date is None:
date = self.date
diff --git a/f1elo/model.py b/f1elo/model.py
index 7b340fa..b60ff85 100644
--- a/f1elo/model.py
+++ b/f1elo/model.py
@@ -9,8 +9,8 @@ class Driver(Base):
__tablename__ = 'drivers'
id = Column(Integer, primary_key=True)
- driver = Column(String)
- country = Column(String)
+ driver = Column(String(1024))
+ country = Column(String(255))
rankings = relationship('Ranking', order_by='Ranking.rank_date', back_populates='driver')
@@ -34,8 +34,8 @@ class Entry(Base):
__tablename__ = 'entries'
id = Column(Integer, primary_key=True)
- result = Column(String)
- car_no = Column(String)
+ result = Column(String(255))
+ car_no = Column(String(255))
result_group = Column(Integer)
_race = Column(Integer, ForeignKey('races.id'))
@@ -49,7 +49,7 @@ class Race(Base):
__tablename__ = 'races'
id = Column(Integer, primary_key=True)
- race = Column(String)
+ race = Column(String(1024))
date = Column(Date)
ranked = Column(Boolean)
@@ -62,10 +62,10 @@ class Race(Base):
class RaceType(Base):
__tablename__ = 'race_types'
-
+
id = Column(Integer, primary_key=True)
- code = Column(String)
- description = Column(String)
+ code = Column(String(255))
+ description = Column(String(1024))
races = relationship('Race', back_populates='type')