Skip to content

Commit

Permalink
Add MySQL configurations for Travis CI
Browse files Browse the repository at this point in the history
  • Loading branch information
mertyildiran committed Aug 19, 2018
1 parent 98ff6f1 commit 978365f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
16 changes: 10 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ dist: xenial
sudo: required
language: python
virtualenv:
system_site_packages: true
system_site_packages: true
services:
- mysql
addons:
apt:
packages:
- xvfb
apt:
packages:
- xvfb
cache:
directories:
- /usr/share/dragonfire
directories:
- /usr/share/dragonfire
before_install:
- mysql -u root -e "CREATE DATABASE dragonfire;"
install:
- sudo ./install-dev.sh --no-model
- sudo pip3 install pytest-faulthandler
Expand Down
1 change: 1 addition & 0 deletions dragonfire/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def start(args, userin):
engine = create_engine('sqlite:///dragonfire.db', connect_args={'check_same_thread': False}, echo=True)
else:
engine = create_engine('mysql://' + Config.MYSQL_USER + ':' + Config.MYSQL_PASS + '@' + Config.MYSQL_HOST + '/' + Config.MYSQL_DB)
Base.metadata.create_all(engine)
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
db_session = DBSession()
Expand Down
19 changes: 15 additions & 4 deletions dragonfire/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
.. moduleauthor:: Mehmet Mert Yıldıran <mert.yildiran@bil.omu.edu.tr>
"""

import os


is_travis = 'TRAVIS' in os.environ


class Config():
"""Class that stores the Twitter API and MySQL database connection credentials in class variables.
Expand All @@ -21,10 +26,16 @@ class Config():
TWITTER_ACCESS_SECRET = 'ACCESS_SECRET'

# MySQL Credentials
MYSQL_HOST = 'MYSQL_HOST'
MYSQL_DB = 'MYSQL_DB'
MYSQL_USER = 'MYSQL_USER'
MYSQL_PASS = 'MYSQL_PASS'
if is_travis:
MYSQL_HOST = '127.0.0.1'
MYSQL_DB = 'dragonfire'
MYSQL_USER = 'root'
MYSQL_PASS = ''
else:
MYSQL_HOST = 'MYSQL_HOST'
MYSQL_DB = 'MYSQL_DB'
MYSQL_USER = 'MYSQL_USER'
MYSQL_PASS = 'MYSQL_PASS'

# SECRET KEY FOR JWT ENCODE/DECODE
SUPER_SECRET_KEY = 'SUPER_SECRET_KEY'
10 changes: 3 additions & 7 deletions dragonfire/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class User(Base):
"""

__tablename__ = 'users'
__table_args__ = {'useexisting': True}
id = Column(Integer, primary_key=True)
name = Column(String(255), nullable=False)
gender = Column(String(1), nullable=False)
Expand All @@ -36,6 +37,7 @@ class Fact(Base):
"""

__tablename__ = 'facts'
__table_args__ = {'useexisting': True}
id = Column(Integer, primary_key=True)
subject = Column(String(255), nullable=False)
verbtense = Column(String(255), nullable=False)
Expand All @@ -51,17 +53,11 @@ class Notification(Base):
"""

__tablename__ = 'notifications'
__table_args__ = {'useexisting': True}
id = Column(Integer, primary_key=True)
url = Column(String(255), nullable=False)
title = Column(String(63), nullable=False)
message = Column(String(255), nullable=False)
created_at = Column(DateTime(timezone=True), server_default=func.now())
is_active = Column(Boolean, default=True)
capitalize = Column(Boolean, default=False)


# Create an engine that stores data in the local directory's dragonfire.db file.
engine = create_engine('sqlite:///dragonfire.db')

# Create all tables in the engine. This is equivalent to "Create Table" statements in raw SQL.
Base.metadata.create_all(engine)

0 comments on commit 978365f

Please sign in to comment.