businesstrips/tools/dbinit.py

52 lines
1.6 KiB
Python
Raw Normal View History

2014-04-18 23:43:54 +04:00
#!/usr/bin/env python
'''
Created on 15.09.2010
@author: Sergey Morozov
'''
import MySQLdb, os, sys
toolsdir = os.path.dirname(__file__)
if toolsdir == '':
toolsdir = '.'
serverdir = toolsdir + os.sep + '..'
sys.path.append(serverdir + os.sep + 'include')
import functions
config = functions.readConfig()
if __name__ == '__main__':
db = MySQLdb.connect(
host = config.mysql_server,
user = config.mysql_user,
passwd = config.mysql_password,
db = config.mysql_database,
port = int(config.mysql_port)
)
cursor = db.cursor()
q = "CREATE TABLE IF NOT EXISTS `journal` ("\
"`key` bigint(20) NOT NULL AUTO_INCREMENT,"\
"`name` varchar(128) NOT NULL,"\
"`position` varchar(128) NOT NULL,"\
"`department` varchar(128) NOT NULL,"\
"`date` date NOT NULL,"\
"`start_time` time NOT NULL,"\
"`end_time` time NOT NULL,"\
"`description` text NOT NULL,"\
"`chief` varchar(128) DEFAULT NULL,"\
"`username` varchar(128) NOT NULL,"\
"PRIMARY KEY (`key`)"\
") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"
cursor.execute(q)
db.commit()
q = "CREATE TABLE IF NOT EXISTS `user_settings` ("\
"`key` bigint(20) NOT NULL AUTO_INCREMENT,"\
"`username` varchar(128) NOT NULL,"\
"`setting` varchar(128) NOT NULL,"\
"`value` text,"\
"PRIMARY KEY (`key`)"\
") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1"
cursor.execute(q)
db.commit()
cursor.close()
db.close()