[sr-dev] git:master: kamdbctl: new command add-tables

Daniel-Constantin Mierla miconda at gmail.com
Tue Aug 27 14:03:53 CEST 2013


Module: sip-router
Branch: master
Commit: 727aa357d9ee8abcb8471733e22886d2cff386db
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=727aa357d9ee8abcb8471733e22886d2cff386db

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Tue Aug 27 14:00:17 2013 +0200

kamdbctl: new command add-tables

- creates only tables that are groupped under same id, thus have the sql
  script in a file
- syntax: kamdbctl add-tables <gid>
- there has to be a <gid>-create.sql script
- eg: kamdbctl add-tables lcr

---

 utils/kamctl/kamdbctl       |   17 +++++++++++++++++
 utils/kamctl/kamdbctl.base  |    1 +
 utils/kamctl/kamdbctl.mysql |   22 ++++++++++++++++++++++
 3 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/utils/kamctl/kamdbctl b/utils/kamctl/kamdbctl
index 935e106..e9249d8 100755
--- a/utils/kamctl/kamdbctl
+++ b/utils/kamctl/kamdbctl
@@ -444,6 +444,23 @@ case $1 in
 		kamailio_db_revoke $DBNAME
 		exit $?
 		;;
+	add-tables)
+		if [ "$USED_DBENGINE" != "mysql" ] ; then
+			merr "$USED_DBENGINE don't support add-tables operation"
+			exit 1
+		fi
+		if [ $# -ne 2 ] ; then
+			merr "add-tables requires 1 parameter: group id of tables"
+			exit 1
+		fi
+		if [ -z "$DBNAME" ] ; then
+			merr "DBNAME is not set"
+			exit 1
+		fi
+
+		kamailio_add_tables $DBNAME $2
+		exit $?
+		;;
 	bdb|db_berkeley)
 		shift
 		kamailio_berkeley "$@"
diff --git a/utils/kamctl/kamdbctl.base b/utils/kamctl/kamdbctl.base
index ab4dc87..364e4c2 100644
--- a/utils/kamctl/kamdbctl.base
+++ b/utils/kamctl/kamdbctl.base
@@ -107,6 +107,7 @@ usage: $COMMAND create <db name or db_path, optional> ...(creates a new database
        $COMMAND dbonly ..................................(creates empty database)
        $COMMAND grant ...................................(grant privileges to database)
        $COMMAND revoke ..................................(revoke privileges to database)
+       $COMMAND add-tables <gid> ........................(creates only tables groupped in gid)
 
        if you want to manipulate database as other database user than
        root, want to change database name from default value "$DBNAME",
diff --git a/utils/kamctl/kamdbctl.mysql b/utils/kamctl/kamdbctl.mysql
index e4825ab..0c6d5d3 100644
--- a/utils/kamctl/kamdbctl.mysql
+++ b/utils/kamctl/kamdbctl.mysql
@@ -345,6 +345,28 @@ dbuid_create () # pars: <database name>
 }  # end uid_create
 
 
+kamailio_add_tables () # params: <database name> <tables group name>
+{
+	if [ $# -ne 2 ] ; then
+		merr "kamailio_add_tables function takes two params"
+		exit 1
+	fi
+
+	minfo "creating group of tables [$2] into database [$1] ..."
+
+	if [ -e $DB_SCHEMA/$2-create.sql ]
+	then
+		sql_query $1 < $DB_SCHEMA/$2-create.sql
+		if [ $? -ne 0 ] ; then
+			merr "Creating group of tables [$2] failed"
+			exit 1
+		fi
+	else
+		merr "Script for creating group of tables [$2] not found"
+		exit 1
+	fi
+}  # end kamailio_add_tables
+
 migrate_table () # 4 paremeters (dst_table, dst_cols, src_table, src_cols)
 {
 	if [ $# -ne 4 ] ; then




More information about the sr-dev mailing list