[rhmessaging-commits] rhmessaging commits: r1794 - in mgmt: mint/python/mint and 1 other directories.
rhmessaging-commits at lists.jboss.org
rhmessaging-commits at lists.jboss.org
Tue Mar 25 15:32:12 EDT 2008
Author: justi9
Date: 2008-03-25 15:32:12 -0400 (Tue, 25 Mar 2008)
New Revision: 1794
Added:
mgmt/cumin/bin/cumin-database-destroy
Modified:
mgmt/cumin/bin/cumin-admin
mgmt/cumin/bin/cumin-database-init
mgmt/mint/python/mint/__init__.py
mgmt/mint/sql/schema.sql
Log:
Changes to the way databases are initially configured. This is in
preparation for a more secure default database config.
* Adds a cli tool cumin-database-destroy for getting rid of all
database state associated with cumin.
* Adds a mint_info table with a version and a db.checkSchema method.
* Makes cumin-database-init use the cumin-admin schema commands.
Modified: mgmt/cumin/bin/cumin-admin
===================================================================
--- mgmt/cumin/bin/cumin-admin 2008-03-25 18:47:35 UTC (rev 1793)
+++ mgmt/cumin/bin/cumin-admin 2008-03-25 19:32:12 UTC (rev 1794)
@@ -76,6 +76,8 @@
print "Error: command create-schema requires --force yes"
print_usage(config)
sys.exit(1)
+ elif command == "check-schema":
+ database.checkSchema()
elif command == "add-user":
if len(args) != 2:
print "Error: no user name given"
Added: mgmt/cumin/bin/cumin-database-destroy
===================================================================
--- mgmt/cumin/bin/cumin-database-destroy (rev 0)
+++ mgmt/cumin/bin/cumin-database-destroy 2008-03-25 19:32:12 UTC (rev 1794)
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+# This script assumes that postgresql is configured and running
+
+if [ "$EUID" -ne "0" ]; then
+ echo "This script must be run as root"
+ exit 2
+fi
+
+su - postgres -c "dropdb cumin"
+su - postgres -c "dropuser cumin"
Property changes on: mgmt/cumin/bin/cumin-database-destroy
___________________________________________________________________
Name: svn:executable
+ *
Modified: mgmt/cumin/bin/cumin-database-init
===================================================================
--- mgmt/cumin/bin/cumin-database-init 2008-03-25 18:47:35 UTC (rev 1793)
+++ mgmt/cumin/bin/cumin-database-init 2008-03-25 19:32:12 UTC (rev 1794)
@@ -2,43 +2,18 @@
# This script assumes that postgresql is configured and running
-if [ "$1" = "-h" -o "$1" = "--help" ]; then
- echo "Usage: cumin-database-init [USER-NAME] [DATABASE-NAME] [SCHEMA-FILE]"
- exit 2
-fi
-
if [ "$EUID" -ne "0" ]; then
echo "This script must be run as root"
exit 2
fi
-user="$1"
+su - postgres -c "createuser --superuser cumin"
+su - postgres -c "createdb --owner=cumin cumin"
-if [ -z "$user" -o "$user" = "-" ]; then
- user="cumin"
-fi
+cumin-admin check-schema | grep -e '^OK '
-db="$2"
-
-if [ -z "$db" -o "$db" = "-" ]; then
- db="cumin"
+if [ "$?" = 0 ]; then
+ echo "Not creating schema; it already exists"
+else
+ cumin-admin --force 1 create-schema
fi
-
-schema="$3"
-
-if [ -z "$schema" -o "$schema" = "-" ]; then
- if [ -z "$CUMIN_HOME" ]; then
- CUMIN_HOME=/usr/share/cumin
- fi
-
- schema="${CUMIN_HOME}/sql/schema.sql"
-fi
-
-if [ ! -f "$schema" ]; then
- echo "Schema file '$schema' not found"
- exit 2
-fi
-
-su postgres -c "createuser --superuser ${user}"
-su postgres -c "createdb --owner=${user} ${db}"
-psql -U "$user" -d "$db" -f "$schema"
Modified: mgmt/mint/python/mint/__init__.py
===================================================================
--- mgmt/mint/python/mint/__init__.py 2008-03-25 18:47:35 UTC (rev 1793)
+++ mgmt/mint/python/mint/__init__.py 2008-03-25 19:32:12 UTC (rev 1794)
@@ -23,6 +23,12 @@
Broker.sqlmeta.addJoin(SQLMultipleJoin("BrokerRegistration",
joinMethodName="registrations"))
+class MintInfo(SQLObject):
+ class sqlmeta:
+ lazyUpdate = True
+
+ version = StringCol(length=1000, default="0.1", notNone=True)
+
class BrokerRegistration(SQLObject):
class sqlmeta:
lazyUpdate = True
@@ -407,6 +413,7 @@
conn = self.getConnection()
try:
cursor = conn.cursor()
+
cursor.execute("drop schema public cascade")
conn.commit()
@@ -428,7 +435,10 @@
try:
cursor = conn.cursor()
- cursor.execute("create schema public")
+ try:
+ cursor.execute("create schema public");
+ except:
+ pass
for path, text in scripts:
stmts = text.split(";")
@@ -450,6 +460,24 @@
print "Executed %i statements from file '%s'" % (count, path)
+ cursor.execute("insert into mint_info (version) values ('0.1')")
+
conn.commit()
finally:
conn.close()
+
+ def checkSchema(self):
+ conn = self.getConnection()
+
+ try:
+ cursor = conn.cursor()
+ cursor.execute("select version from mint_info");
+
+ for rec in cursor:
+ print "OK (version %s)" % rec[0]
+ return;
+
+ print "No schema present"
+
+ finally:
+ conn.close()
Modified: mgmt/mint/sql/schema.sql
===================================================================
--- mgmt/mint/sql/schema.sql 2008-03-25 18:47:35 UTC (rev 1793)
+++ mgmt/mint/sql/schema.sql 2008-03-25 19:32:12 UTC (rev 1794)
@@ -45,6 +45,11 @@
last_logged_out TIMESTAMP
);
+CREATE TABLE mint_info (
+ id SERIAL PRIMARY KEY,
+ version VARCHAR(1000) NOT NULL
+);
+
CREATE TABLE binding (
id SERIAL PRIMARY KEY,
id_original BIGINT,
More information about the rhmessaging-commits
mailing list