-
Notifications
You must be signed in to change notification settings - Fork 3
/
db_tool
executable file
·37 lines (25 loc) · 917 Bytes
/
db_tool
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
#!/usr/bin/env python
# create the sourcy database (from the sqlalchemy definition in models.py)
from optparse import OptionParser
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from pprint import pprint
from unsourced.config import settings
from unsourced.models import Base
def main():
# parser = OptionParser()
# (opts, args) = parser.parse_args()
# if len(args) != 2:
# parser.error("requires 2 args: <kind> <infile>")
eng_url = "mysql+mysqldb://%(user)s:%(password)s@%(host)s/%(db)s?charset=utf8" % {
'user': settings.mysql_user,
'password': settings.mysql_password,
'host': settings.mysql_host,
'db': settings.mysql_database
}
engine = create_engine(eng_url, echo=True)
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
session = Session()
if __name__ == "__main__":
main()