# HG changeset patch # User Daniele Nicolodi # Date 1309201524 -7200 # Node ID 56e3649ff013b63fff051f452fe65ebc06b87645 # Parent d87ede392d4833358184b37ce0a7c0b521c79d0b Update administrative database creation code to schema version 2.7. diff -r d87ede392d48 -r 56e3649ff013 src/ltpdarepo/admin.py --- a/src/ltpdarepo/admin.py Mon Jun 27 21:05:18 2011 +0200 +++ b/src/ltpdarepo/admin.py Mon Jun 27 21:05:24 2011 +0200 @@ -281,7 +281,6 @@ """setup test environment""" install() - upgrade() useradd('u1', password='u1') grant('u1', '%', ['admin', ]) createdb('db1', description=u'Test database One') diff -r d87ede392d48 -r 56e3649ff013 src/ltpdarepo/install.py --- a/src/ltpdarepo/install.py Mon Jun 27 21:05:18 2011 +0200 +++ b/src/ltpdarepo/install.py Mon Jun 27 21:05:24 2011 +0200 @@ -1,82 +1,55 @@ -import MySQLdb as db +import MySQLdb as mysql -from config import HOSTNAME, DATABASE, USERNAME, PASSWORD +from .config import HOSTNAME, DATABASE, USERNAME, PASSWORD def install(): """create LTDA repository database tables""" - - conn = db.connect(host=HOSTNAME, db='', user=USERNAME, passwd=PASSWORD) + + conn = mysql.connect(host=HOSTNAME, db='', user=USERNAME, passwd=PASSWORD) curs = conn.cursor() - # curs.execute('DROP DATABASE IF EXISTS `%s`' % DATABASE) - curs.execute('CREATE DATABASE `%s`' % DATABASE) + + curs.execute("CREATE DATABASE `%s`" % DATABASE) conn.close() - conn = db.connect(host=HOSTNAME, db=DATABASE, user=USERNAME, passwd=PASSWORD) + conn = mysql.connect(host=HOSTNAME, db=DATABASE, user=USERNAME, passwd=PASSWORD) curs = conn.cursor() - curs.execute(''' - CREATE TABLE `available_dbs` ( - `id` int(10) NOT NULL auto_increment, - `db_name` varchar(50) NOT NULL, - `name` varchar(50) NOT NULL, - `description` text NOT NULL, - `version` INT DEFAULT 1, - PRIMARY KEY (`id`), - UNIQUE KEY `database` (`db_name`) - ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8''') - - curs.execute(''' - CREATE TABLE `user_access` ( - `user_id` int(10) NOT NULL, - `db_name` varchar(50) NOT NULL, - `select_priv` tinyint(1) NOT NULL, - `insert_priv` tinyint(1) NOT NULL, - `update_priv` tinyint(1) NOT NULL, - `delete_priv` tinyint(1) NOT NULL, - PRIMARY KEY (`user_id`, `db_name`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8''') - - curs.execute(''' - CREATE TABLE `user_hosts` ( - `user_id` int(10) NOT NULL, - `hostname` varchar(100) NOT NULL - ) ENGINE=MyISAM DEFAULT CHARSET=utf8''') - - curs.execute('''INSERT INTO user_hosts (user_id, hostname) - VALUES (0, "localhost")''') + curs.execute("""CREATE TABLE `available_dbs` ( + `id` int(10) NOT NULL AUTO_INCREMENT, + `db_name` varchar(50) NOT NULL, + `name` varchar(50) NOT NULL, + `description` text NOT NULL, + `version` int(11) DEFAULT '1', + PRIMARY KEY (`id`), + UNIQUE KEY `database` (`db_name`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8""") - curs.execute(''' - CREATE TABLE `users` ( - `id` int(11) NOT NULL auto_increment, - `username` varchar(50) NOT NULL, - `password` varchar(50) NOT NULL, - `family_name` varchar(50) NOT NULL, - `given_name` varchar(50) NOT NULL, - `email` varchar(80) NOT NULL, - `institution` varchar(150) NOT NULL, - `telephone` varchar(50) NOT NULL, - `is_admin` tinyint(1) NOT NULL, - PRIMARY KEY (`id`) - ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8''') + curs.execute("""CREATE TABLE `users` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `username` varchar(50) NOT NULL, + `family_name` varchar(50) NOT NULL, + `given_name` varchar(50) NOT NULL, + `email` varchar(80) NOT NULL, + `institution` varchar(150) NOT NULL, + `telephone` varchar(50) NOT NULL, + `is_admin` tinyint(1) NOT NULL, + PRIMARY KEY (`id`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8""") - curs.execute(''' - CREATE TABLE `options` ( - `name` varchar(50) NOT NULL, - `value` text NOT NULL, - PRIMARY KEY (`name`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8''') + curs.execute("""CREATE TABLE `queries` ( + `name` text, + `db` text, + `querystring` text + ) ENGINE=MyISAM DEFAULT CHARSET=utf8""") - # curs.execute(''' - # INSERT INTO `options` (`name`, `value`) - # VALUES ("plot_path", "/var/www/html/ltpdarepo/plots")''') + curs.execute("""CREATE TABLE `options` ( + `name` varchar(50) NOT NULL, + `value` text NOT NULL, + PRIMARY KEY (`name`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8""") - # curs.execute(''' - # INSERT INTO `options` (`name`, `value`) - # VALUES ("robot_path", "/var/www/html/ltpdarepo/ltpdareporobot.rb")''') - - curs.execute(''' - INSERT INTO `options` (`name`, `value`) VALUES ("version", "2.4")''') + curs.execute("""INSERT INTO `options` VALUES ('version','2.7')""") conn.commit() conn.close() diff -r d87ede392d48 -r 56e3649ff013 src/ltpdarepo/tests/__init__.py --- a/src/ltpdarepo/tests/__init__.py Mon Jun 27 21:05:18 2011 +0200 +++ b/src/ltpdarepo/tests/__init__.py Mon Jun 27 21:05:24 2011 +0200 @@ -21,10 +21,9 @@ def doctestSetUp(self): - from ltpdarepo.admin import wipe, install, upgrade, useradd, grant, createdb + from ltpdarepo.admin import wipe, install, useradd, grant, createdb wipe() install() - upgrade() useradd('u1', 'u1') grant('u1', '%', ['admin', ]) createdb('db1') diff -r d87ede392d48 -r 56e3649ff013 src/ltpdarepo/tests/test_users.py --- a/src/ltpdarepo/tests/test_users.py Mon Jun 27 21:05:18 2011 +0200 +++ b/src/ltpdarepo/tests/test_users.py Mon Jun 27 21:05:24 2011 +0200 @@ -34,10 +34,9 @@ class DatabaseTestCase(unittest.TestCase): def setUp(self): - from ltpdarepo.admin import wipe, install, upgrade, useradd + from ltpdarepo.admin import wipe, install, useradd wipe() install() - upgrade() useradd('u1', 'u1') from ltpdarepo import app