Browse code

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

Daniel-Constantin Mierla authored on 27/08/2013 12:00:17
Showing 3 changed files
... ...
@@ -444,6 +444,23 @@ case $1 in
444 444
 		kamailio_db_revoke $DBNAME
445 445
 		exit $?
446 446
 		;;
447
+	add-tables)
448
+		if [ "$USED_DBENGINE" != "mysql" ] ; then
449
+			merr "$USED_DBENGINE don't support add-tables operation"
450
+			exit 1
451
+		fi
452
+		if [ $# -ne 2 ] ; then
453
+			merr "add-tables requires 1 parameter: group id of tables"
454
+			exit 1
455
+		fi
456
+		if [ -z "$DBNAME" ] ; then
457
+			merr "DBNAME is not set"
458
+			exit 1
459
+		fi
460
+
461
+		kamailio_add_tables $DBNAME $2
462
+		exit $?
463
+		;;
447 464
 	bdb|db_berkeley)
448 465
 		shift
449 466
 		kamailio_berkeley "$@"
... ...
@@ -107,6 +107,7 @@ usage: $COMMAND create <db name or db_path, optional> ...(creates a new database
107 107
        $COMMAND dbonly ..................................(creates empty database)
108 108
        $COMMAND grant ...................................(grant privileges to database)
109 109
        $COMMAND revoke ..................................(revoke privileges to database)
110
+       $COMMAND add-tables <gid> ........................(creates only tables groupped in gid)
110 111
 
111 112
        if you want to manipulate database as other database user than
112 113
        root, want to change database name from default value "$DBNAME",
... ...
@@ -345,6 +345,28 @@ dbuid_create () # pars: <database name>
345 345
 }  # end uid_create
346 346
 
347 347
 
348
+kamailio_add_tables () # params: <database name> <tables group name>
349
+{
350
+	if [ $# -ne 2 ] ; then
351
+		merr "kamailio_add_tables function takes two params"
352
+		exit 1
353
+	fi
354
+
355
+	minfo "creating group of tables [$2] into database [$1] ..."
356
+
357
+	if [ -e $DB_SCHEMA/$2-create.sql ]
358
+	then
359
+		sql_query $1 < $DB_SCHEMA/$2-create.sql
360
+		if [ $? -ne 0 ] ; then
361
+			merr "Creating group of tables [$2] failed"
362
+			exit 1
363
+		fi
364
+	else
365
+		merr "Script for creating group of tables [$2] not found"
366
+		exit 1
367
+	fi
368
+}  # end kamailio_add_tables
369
+
348 370
 migrate_table () # 4 paremeters (dst_table, dst_cols, src_table, src_cols)
349 371
 {
350 372
 	if [ $# -ne 4 ] ; then