Browse code

- subscriber table cleanup: unused columns dropped (uuid and dom) added "id" column (autoincrement) as PRIMARY KEY serweb specific columns/keys are added only id serweb is installed - initial "admin" user creadted ONLY if serweb is installed.

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@1196 689a6050-402a-0410-94f2-e92a70836424

Bogdan-Andrei Iancu authored on 27/10/2006 13:21:54
Showing 2 changed files
... ...
@@ -26,6 +26,9 @@
26 26
 # 2006-05-16  added ability to specify MD5 from a configuration file
27 27
 #             FreeBSD does not have the md5sum function (norm)
28 28
 # 2006-09-02  Added address table (juhe)
29
+# 2006-10-27  subscriber table cleanup; some columns are created only if
30
+#             serweb is installed (bogdan)
31
+#
29 32
 
30 33
 PATH=$PATH:/usr/local/sbin
31 34
 
... ...
@@ -232,28 +235,10 @@ credentials()
232 232
 }
233 233
 
234 234
 
235
-openser_create () # pars: <database name> [<no_init_user>]
235
+openser_create () # pars: <database name>
236 236
 {
237
-if [ $# -eq 1 ] ; then
238
-	if [ -z "$SIP_DOMAIN" ] ; then
239
-		prompt_realm
240
-	fi
241
-	credentials
242
-	# by default we create initial user
243
-	INITIAL_USER="INSERT INTO subscriber
244
-		($USERCOL, password, first_name, last_name, phone,
245
-		email_address, datetime_created, datetime_modified, confirmation,
246
-		flag, sendnotification, greeting, ha1, domain, ha1b, phplib_id )
247
-		VALUES ( 'admin', '$DEFAULT_PW', 'Initial', 'Admin', '123',
248
-		'root@localhost', '2002-09-04 19:37:45', '0000-00-00 00:00:00',
249
-		'57DaSIPuCm52UNe54LF545750cfdL48OMZfroM53', 'o', '', '',
250
-		'$HA1', '$SIP_DOMAIN', '$HA1B',
251
-		'$PHPLIB_ID' );"
252
-elif [ $# -eq 2 ] ; then
253
-	# if 3rd param set, don't create any initial user
254
-	INITIAL_USER=""
255
-else
256
-	echo "openser_create function takes one or two params"
237
+if [ $# -ne 1 ] ; then
238
+	echo "openser_create function takes one param"
257 239
 	exit 1
258 240
 fi
259 241
 
... ...
@@ -283,7 +268,7 @@ CREATE TABLE version (
283 283
 # Dumping data for table 'version'
284 284
 #
285 285
 
286
-INSERT INTO version VALUES ( 'subscriber', '5');
286
+INSERT INTO version VALUES ( 'subscriber', '6');
287 287
 INSERT INTO version VALUES ( 'missed_calls', '3');
288 288
 INSERT INTO version VALUES ( 'location', '1003');
289 289
 INSERT INTO version VALUES ( 'aliases', '1003');
... ...
@@ -309,30 +294,21 @@ INSERT INTO version VALUES ( 'domainpolicy', '2');
309 309
 # Table structure for table 'subscriber' -- user database
310 310
 #
311 311
 CREATE TABLE subscriber (
312
-  phplib_id varchar(32) NOT NULL default '',
312
+  id int(10) unsigned NOT NULL auto_increment,
313 313
   $USERCOL varchar(64) NOT NULL default '',
314 314
   domain varchar(128) NOT NULL default '',
315 315
   password varchar(25) NOT NULL default '',
316 316
   first_name varchar(25) NOT NULL default '',
317 317
   last_name varchar(45) NOT NULL default '',
318
-  phone varchar(15) NOT NULL default '',
319 318
   email_address varchar(50) NOT NULL default '',
320 319
   datetime_created datetime NOT NULL default '0000-00-00 00:00:00',
321
-  datetime_modified datetime NOT NULL default '0000-00-00 00:00:00',
322
-  confirmation varchar(64) NOT NULL default '',
323
-  flag char(1) NOT NULL default 'o',
324
-  sendnotification varchar(50) NOT NULL default '',
325
-  greeting varchar(50) NOT NULL default '',
326 320
   ha1 varchar(128) NOT NULL default '',
327 321
   ha1b varchar(128) NOT NULL default '',
328
-  allow_find char(1) NOT NULL default '0',
329 322
   timezone varchar(128) default NULL,
330 323
   rpid varchar(128) default NULL,
331
-  domn int(10) default NULL,
332
-  uuid varchar(64) default NULL,
333
-  UNIQUE KEY phplib_id (phplib_id),
334
-  PRIMARY KEY ($USERCOL, domain),
335
-  KEY user_2 ($USERCOL)
324
+  PRIMARY KEY (id),
325
+  UNIQUE KEY user_id ($USERCOL, domain),
326
+  INDEX username_id ($USERCOL)
336 327
 ) $TABLE_TYPE;
337 328
 
338 329
 
... ...
@@ -641,39 +617,44 @@ CREATE TABLE domainpolicy (
641 641
  UNIQUE         (rule, att, val),
642 642
  INDEX          rule_idx (rule)
643 643
 ) $TABLE_TYPE;
644
-
645
-
646
-# add an admin user "admin" with password==$DEFAULT_PW,
647
-# so that one can try it out on quick start
648
-$INITIAL_USER
649 644
 EOF
650 645
 
651 646
 echo -n "Install SERWEB tables ?(y/n):"
652 647
 read INPUT
653 648
 if [ "$INPUT" = "y" ] || [ "$INPUT" = "Y" ]
654 649
 then
655
-	serweb_create $1 $2
650
+	serweb_create $1
656 651
 fi
657 652
 } # openser_create
658 653
 
659 654
 
660 655
 serweb_create () # pars: <database name>
661 656
 {
662
-if [ $# -eq 1 ] ; then
657
+if [ $# -ne 1 ] ; then
658
+	echo "serweb_create function takes one param"
659
+	exit 1
660
+fi
661
+
662
+if [ -z "$NO_USER_INIT" ] ; then
663 663
 	if [ -z "$SIP_DOMAIN" ] ; then
664 664
 		prompt_realm
665 665
 	fi
666 666
 	INITIAL_INSERT="
667
+		INSERT INTO subscriber
668
+			($USERCOL, password, first_name, last_name, phone,
669
+			email_address, datetime_created, datetime_modified, confirmation,
670
+			flag, sendnotification, greeting, ha1, domain, ha1b, phplib_id )
671
+			VALUES ( 'admin', '$DEFAULT_PW', 'Initial', 'Admin', '123',
672
+			'root@localhost', '2002-09-04 19:37:45', '0000-00-00 00:00:00',
673
+			'57DaSIPuCm52UNe54LF545750cfdL48OMZfroM53', 'o', '', '',
674
+			'$HA1', '$SIP_DOMAIN', '$HA1B',
675
+			'$PHPLIB_ID' );
667 676
 		INSERT INTO admin_privileges ($USERCOL, domain, priv_name, priv_value)
668 677
 		VALUES ('admin', '$SIP_DOMAIN', 'is_admin', '1');
669 678
 		INSERT INTO admin_privileges ($USERCOL, domain, priv_name, priv_value)
670 679
 		VALUES ('admin', '$SIP_DOMAIN', 'change_privileges', '1');"
671
-elif [ $# -eq 2 ] ; then
672
-	# if 3rd param set, don't do any initial insert
673
-	INITIAL_INSERT=""
674 680
 else
675
-	echo "serweb_create function takes one or two params"
676
-	exit 1
681
+	INITIAL_INSERT=""
677 682
 fi
678 683
 
679 684
 echo "creating serweb tables into $1 ..."
... ...
@@ -682,7 +663,7 @@ sql_query <<EOF
682 682
 use $1;
683 683
 
684 684
 INSERT INTO version VALUES ( 'phonebook', '1');
685
-INSERT INTO version VALUES ( 'pending', '4');
685
+INSERT INTO version VALUES ( 'pending', '6');
686 686
 INSERT INTO version VALUES ( 'active_sessions', '1');
687 687
 INSERT INTO version VALUES ( 'server_monitoring', '1');
688 688
 INSERT INTO version VALUES ( 'server_monitoring_agg', '1');
... ...
@@ -691,6 +672,24 @@ INSERT INTO version VALUES ( 'admin_privileges', '1');
691 691
 
692 692
 
693 693
 #
694
+# Extend table 'subscriber' with serweb specific columns
695
+#
696
+ALTER TABLE subscriber 
697
+  ADD COLUMN (
698
+    phplib_id varchar(32) NOT NULL default '',
699
+    phone varchar(15) NOT NULL default '',
700
+    datetime_modified datetime NOT NULL default '0000-00-00 00:00:00',
701
+    confirmation varchar(64) NOT NULL default '',
702
+    flag char(1) NOT NULL default 'o',
703
+    sendnotification varchar(50) NOT NULL default '',
704
+    greeting varchar(50) NOT NULL default '',
705
+    allow_find char(1) NOT NULL default '0'
706
+  ),
707
+  ADD UNIQUE KEY phplib_id (phplib_id)
708
+;
709
+
710
+
711
+#
694 712
 # Table structure for table 'active_sessions' -- web stuff
695 713
 #
696 714
 CREATE TABLE active_sessions (
... ...
@@ -708,6 +707,7 @@ CREATE TABLE active_sessions (
708 708
 # requests
709 709
 #
710 710
 CREATE TABLE pending (
711
+  id int(10) unsigned NOT NULL auto_increment,
711 712
   phplib_id varchar(32) NOT NULL default '',
712 713
   $USERCOL varchar(64) NOT NULL default '',
713 714
   domain varchar(128) NOT NULL default '',
... ...
@@ -727,11 +727,10 @@ CREATE TABLE pending (
727 727
   allow_find char(1) NOT NULL default '0',
728 728
   timezone varchar(128) default NULL,
729 729
   rpid varchar(128) default NULL,
730
-  domn int(10) default NULL,
731
-  uuid varchar(64) default NULL,
732
-  PRIMARY KEY ($USERCOL, domain),
733
-  KEY user_2 ($USERCOL),
734
-  UNIQUE KEY phplib_id (phplib_id)
730
+  PRIMARY KEY (id),
731
+  UNIQUE KEY user_id ($USERCOL, domain),
732
+  UNIQUE KEY phplib_id (phplib_id),
733
+  INDEX username_id ($USERCOL)
735 734
 ) $TABLE_TYPE;
736 735
 
737 736
 
... ...
@@ -849,7 +848,8 @@ case $1 in
849 849
 		fi
850 850
 		#4 change names in table definition and restore
851 851
 		echo "creating new structures"
852
-		openser_create $DBNAME no_init_user
852
+		NO_USER_INIT="yes"
853
+		openser_create $DBNAME
853 854
 		if [ "$?" -ne 0 ] ; then
854 855
 			echo "reinstall: creating new table failed"
855 856
 			rm $tmp_file*
... ...
@@ -882,7 +882,8 @@ case $1 in
882 882
 			rm $tmp_file
883 883
 			exit $ret
884 884
 		fi
885
-		openser_create $1 no_init_user
885
+		NO_USER_INIT="yes"
886
+		openser_create $1
886 887
 		ret=$?
887 888
 		if [ "$ret" -ne 0 ]; then
888 889
 			echo "copy: creating new db failed"
... ...
@@ -44,6 +44,8 @@
44 44
 #             made last_modified/created stamps consistent to now() using 
45 45
 #                  local TIMESTAMP
46 46
 # 2006-10-19  Added address table (bogdan)
47
+# 2006-10-27  subscriber table cleanup; some columns are created only if
48
+#             serweb is installed (bogdan)
47 49
 #
48 50
 
49 51
 
... ...
@@ -264,29 +266,10 @@ credentials()
264 264
 	fi
265 265
 }
266 266
 
267
-openser_create () # pars: <database name> [<no_init_user>]
267
+openser_create () # pars: <database name>
268 268
 {
269
-if [ $# -eq 1 ] ; then
270
-	if [ -z "$SIP_DOMAIN" ] ; then
271
-		prompt_realm
272
-	fi
273
-	credentials
274
-	# by default we create initial user
275
-	INITIAL_USER="INSERT INTO subscriber
276
-		($USERCOL, password, first_name, last_name, phone,
277
-		email_address, datetime_created, datetime_modified, confirmation,
278
-		flag, sendnotification, greeting, ha1, domain, ha1b, phplib_id )
279
-		VALUES ( 'admin', '$DEFAULT_PW', 'Initial', 'Admin', '123',
280
-		'root@localhost', '2002-09-04 19:37:45', '$DUMMY_DATE',
281
-		'57DaSIPuCm52UNe54LF545750cfdL48OMZfroM53', 'o', '', '',
282
-		'$HA1', '$SIP_DOMAIN', '$HA1B',
283
-		'$PHPLIB_ID' );"
284
-
285
-elif [ $# -eq 2 ] ; then
286
-	# if 3rd param set, don't create any initial user
287
-	INITIAL_USER=""
288
-else
289
-	echo "openser_create function takes one or two params"
269
+if [ $# -ne 1 ] ; then
270
+	echo "openser_create function takes one param"
290 271
 	exit 1
291 272
 fi
292 273
 
... ...
@@ -331,7 +314,7 @@ CREATE TABLE version (
331 331
  * Dumping data for table 'version'
332 332
  */
333 333
 
334
-INSERT INTO version VALUES ( 'subscriber', '5');
334
+INSERT INTO version VALUES ( 'subscriber', '6');
335 335
 INSERT INTO version VALUES ( 'missed_calls', '3');
336 336
 INSERT INTO version VALUES ( 'location', '1003');
337 337
 INSERT INTO version VALUES ( 'aliases', '1003');
... ...
@@ -356,31 +339,21 @@ INSERT INTO version VALUES ( 'domainpolicy', '2');
356 356
  * Table structure for table 'subscriber' -- user database
357 357
  */
358 358
 CREATE TABLE subscriber (
359
-  phplib_id varchar(32) NOT NULL default '',
359
+  id $AUTO_INCREMENT,
360 360
   $USERCOL varchar(64) NOT NULL default '',
361 361
   domain varchar(128) NOT NULL default '',
362 362
   password varchar(25) NOT NULL default '',
363 363
   first_name varchar(25) NOT NULL default '',
364 364
   last_name varchar(45) NOT NULL default '',
365
-  phone varchar(15) NOT NULL default '',
366 365
   email_address varchar(50) NOT NULL default '',
367 366
   datetime_created $TIMESTAMP,
368
-  datetime_modified $TIMESTAMP,
369
-  confirmation varchar(64) NOT NULL default '',
370
-  flag char(1) NOT NULL default 'o',
371
-  sendnotification varchar(50) NOT NULL default '',
372
-  greeting varchar(50) NOT NULL default '',
373 367
   ha1 varchar(128) NOT NULL default '',
374 368
   ha1b varchar(128) NOT NULL default '',
375
-  allow_find char(1) NOT NULL default '0',
376 369
   timezone varchar(128) default NULL,
377 370
   rpid varchar(128) default NULL,
378
-  domn int default NULL,
379
-  uuid varchar(64) default NULL,
380
-  UNIQUE (phplib_id),
381
-  PRIMARY KEY ($USERCOL, domain)
371
+  UNIQUE ($USERCOL, domain)
382 372
 ) $TABLE_TYPE;
383
-CREATE INDEX user_2_subs_indx ON subscriber ($USERCOL);
373
+CREATE INDEX username_subs_indx ON subscriber ($USERCOL);
384 374
 
385 375
 
386 376
 /*
... ...
@@ -694,12 +667,6 @@ CREATE TABLE domainpolicy (
694 694
 CREATE INDEX domainpolicy_rule_idx ON domainpolicy(rule);
695 695
 
696 696
 
697
-/* add an admin user "admin" with password==$DEFAULT_PW,
698
- * so that one can try it out on quick start
699
- */
700
-
701
-$INITIAL_USER
702
-
703 697
 /*
704 698
  * GRANT permissions
705 699
  */
... ...
@@ -712,7 +679,7 @@ echo -n "Install SERWEB tables ?(y/n):"
712 712
 read INPUT
713 713
 if [ "$INPUT" = "y" ] || [ "$INPUT" = "Y" ]
714 714
 then
715
-	serweb_create $1 $2
715
+	serweb_create $1
716 716
 fi
717 717
 
718 718
 } # openser_create
... ...
@@ -720,6 +687,10 @@ fi
720 720
 
721 721
 serweb_create () # pars: <database name>
722 722
 {
723
+if [ $# -ne 1 ] ; then
724
+	echo "serweb_create function takes one param"
725
+	exit 1
726
+fi
723 727
 
724 728
 GRANT_SERWEB_CMD="
725 729
 	GRANT ALL PRIVILEGES ON TABLE phonebook, pending, active_sessions,
... ...
@@ -729,21 +700,26 @@ GRANT_SERWEB_CMD="
729 729
 		server_monitoring, server_monitoring_agg,
730 730
 		usr_preferences_types, admin_privileges to $DBROUSER;" 
731 731
 
732
-if [ $# -eq 1 ] ; then
732
+if [ -z "$NO_USER_INIT" ] ; then
733 733
 	if [ -z "$SIP_DOMAIN" ] ; then
734 734
 		prompt_realm
735 735
 	fi
736 736
 	INITIAL_INSERT="
737
+		INSERT INTO subscriber
738
+			($USERCOL, password, first_name, last_name, phone,
739
+			email_address, datetime_created, datetime_modified, confirmation,
740
+			flag, sendnotification, greeting, ha1, domain, ha1b, phplib_id )
741
+			VALUES ( 'admin', '$DEFAULT_PW', 'Initial', 'Admin', '123',
742
+			'root@localhost', '2002-09-04 19:37:45', '$DUMMY_DATE',
743
+			'57DaSIPuCm52UNe54LF545750cfdL48OMZfroM53', 'o', '', '',
744
+			'$HA1', '$SIP_DOMAIN', '$HA1B',
745
+			'$PHPLIB_ID' );
737 746
 		INSERT INTO admin_privileges ($USERCOL, domain, priv_name, priv_value)
738 747
 		VALUES ('admin', '$SIP_DOMAIN', 'is_admin', '1');
739 748
 		INSERT INTO admin_privileges ($USERCOL, domain, priv_name, priv_value)
740 749
 		VALUES ('admin', '$SIP_DOMAIN', 'change_privileges', '1');"
741
-elif [ $# -eq 2 ] ; then
742
-	# if 3rd param set, don't do any initial insert
743
-	INITIAL_INSERT=""
744 750
 else
745
-	echo "serweb_create function takes one or two params"
746
-	exit 1
751
+	INITIAL_INSERT=""
747 752
 fi
748 753
 
749 754
 echo "creating serweb tables into $1 ..."
... ...
@@ -752,13 +728,31 @@ sql_query <<EOF
752 752
 $USE_CMD $1;
753 753
 
754 754
 INSERT INTO version VALUES ( 'phonebook', '1');
755
-INSERT INTO version VALUES ( 'pending', '4');
755
+INSERT INTO version VALUES ( 'pending', '6');
756 756
 INSERT INTO version VALUES ( 'active_sessions', '1');
757 757
 INSERT INTO version VALUES ( 'server_monitoring', '1');
758 758
 INSERT INTO version VALUES ( 'server_monitoring_agg', '1');
759 759
 INSERT INTO version VALUES ( 'usr_preferences_types', '1');
760 760
 INSERT INTO version VALUES ( 'admin_privileges', '1');
761 761
 
762
+#
763
+# Extend table 'subscriber' with serweb specific columns
764
+#
765
+ALTER TABLE subscriber 
766
+  ADD COLUMN (
767
+    phplib_id varchar(32) NOT NULL default '',
768
+    phone varchar(15) NOT NULL default '',
769
+    datetime_modified $TIMESTAMP,
770
+    confirmation varchar(64) NOT NULL default '',
771
+    flag char(1) NOT NULL default 'o',
772
+    sendnotification varchar(50) NOT NULL default '',
773
+    greeting varchar(50) NOT NULL default '',
774
+    allow_find char(1) NOT NULL default '0'
775
+  ),
776
+  ADD UNIQUE (phplib_id)
777
+;
778
+
779
+
762 780
 
763 781
 /*
764 782
  * Table structure for table 'active_sessions' -- web stuff
... ...
@@ -778,6 +772,7 @@ CREATE INDEX ch_active_sess_indx ON active_sessions (changed);
778 778
  * requests
779 779
  */
780 780
 CREATE TABLE pending (
781
+  id $AUTO_INCREMENT,
781 782
   phplib_id varchar(32) NOT NULL default '',
782 783
   $USERCOL varchar(64) NOT NULL default '',
783 784
   domain varchar(128) NOT NULL default '',
... ...
@@ -797,12 +792,10 @@ CREATE TABLE pending (
797 797
   allow_find char(1) NOT NULL default '0',
798 798
   timezone varchar(128) default NULL,
799 799
   rpid varchar(128) default NULL,
800
-  domn int default NULL,
801
-  uuid varchar(64) default NULL,
802
-  PRIMARY KEY ($USERCOL, domain),
800
+  UNIQUE ($USERCOL, domain),
803 801
   UNIQUE (phplib_id)
804 802
 ) $TABLE_TYPE;
805
-CREATE INDEX user_2_pend_indx ON pending ($USERCOL);
803
+CREATE INDEX username_pend_indx ON pending ($USERCOL);
806 804
 
807 805
 
808 806
 /*
... ...
@@ -933,7 +926,8 @@ case $1 in
933 933
 #		fi
934 934
 #		#4 change names in table definition and restore
935 935
 #		echo "creating new structures"
936
-#		openser_create $DBNAME no_init_user
936
+#		NO_USER_INIT="yes"
937
+#		openser_create $DBNAME
937 938
 #		if [ "$?" -ne 0 ] ; then
938 939
 #			echo "reinstall: creating new table failed"
939 940
 #			rm $tmp_file*
... ...
@@ -965,7 +959,8 @@ case $1 in
965 965
 #			rm $tmp_file
966 966
 #			exit $ret
967 967
 #		fi
968
-#		openser_create $1 no_init_user
968
+#		NO_USER_INIT="yes"
969
+#		openser_create $1
969 970
 #		ret=$?
970 971
 #		if [ "$ret" -ne 0 ]; then
971 972
 #			rm $tmp_file