Browse code

Applied path for correcting syntax from MySQL to Postgres: - moved INDEX creation out of CREATE table statement into CREATE INDEX (usr_preferences, trusted) - auto_increment isn't valid in Postgres, replaced with local AUTO_INCREMENT - datetime isn't valid in Postgres, replaced with local DATETIME - split GRANTs for SERWeb tables so that it is only executed if SERWeb tables are created - added GRANTs for re_grp table - added CREATE pd_multidomain table (from PDT module) - corrected comments to indicate Postgres as opposed to MySQL - made last_modified/created stamps consistent to now() using local TIMESTAMP

Credits go to Norman Brandinger <norm@goes.com>
Closes 1522180, 1522182, 1522303


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

Bogdan-Andrei Iancu authored on 14/07/2006 17:28:57
Showing 1 changed files
... ...
@@ -30,6 +30,21 @@
30 30
 #             separated the serweb from openser tables (bogdan)
31 31
 # 2006-05-16  added ability to specify MD5 from a configuration file
32 32
 #             FreeBSD does not have the md5sum function (norm)
33
+# 2006-07-14  Corrected syntax from MySQL to Postgres (norm)
34
+#             moved INDEX creation out of CREATE table statement into 
35
+#                  CREATE INDEX (usr_preferences, trusted)
36
+#             auto_increment isn't valid in Postgres, replaced with 
37
+#                  local AUTO_INCREMENT
38
+#             datetime isn't valid in Postgres, replaced with local DATETIME 
39
+#             split GRANTs for SERWeb tables so that it is only executed 
40
+#                  if SERWeb tables are created
41
+#             added GRANTs for re_grp table
42
+#             added CREATE pd_multidomain table (from PDT module)
43
+#             corrected comments to indicate Postgres as opposed to MySQL
44
+#             made last_modified/created stamps consistent to now() using 
45
+#                  local TIMESTAMP
46
+#
47
+
33 48
 
34 49
 PATH=$PATH:/usr/local/sbin
35 50
 
... ...
@@ -51,7 +66,7 @@ fi
51 51
 if [ -z "$DBNAME" ]; then
52 52
 	DBNAME="openser"
53 53
 fi
54
-# address of MySQL server
54
+# address of Postgres server
55 55
 if [ -z "$DBHOST" ]; then
56 56
 	DBHOST="localhost"
57 57
 fi
... ...
@@ -71,7 +86,7 @@ fi
71 71
 if [ -z "$RO_PW" ]; then
72 72
 	RO_PW="openserro"
73 73
 fi
74
-# full privileges MySQL user
74
+# full privileges Postgres user
75 75
 if [ -z "$SQL_USER" ]; then
76 76
 	SQL_USER="postgres"
77 77
 	if [ ! -r ~/.pgpass ]; then
... ...
@@ -242,7 +257,6 @@ credentials()
242 242
 	#PHPLIB_ID of users should be difficulty to guess for security reasons
243 243
 	NOW=`date`;
244 244
 	PHPLIB_ID=`echo -n "$RANDOM:$NOW:$SIP_DOMAIN" | $MD5 | awk '{ print $1 }'`
245
-	PHPLIB_ID=`$GENHA1 "$RANDOM" "$NOW" $SIP_DOMAIN`
246 245
 	if [ $? -ne 0 ] ; then
247 246
 		echo "PHPLIB_ID calculation failed"
248 247
 		exit 1
... ...
@@ -265,13 +279,8 @@ if [ $# -eq 1 ] ; then
265 265
 		'root@localhost', '2002-09-04 19:37:45', '$DUMMY_DATE',
266 266
 		'57DaSIPuCm52UNe54LF545750cfdL48OMZfroM53', 'o', '', '',
267 267
 		'$HA1', '$SIP_DOMAIN', '$HA1B',
268
-		'$PHPLIB_ID' );
269
-
270
-		INSERT INTO admin_privileges ($USERCOL, domain, priv_name, priv_value)
271
-		VALUES ('admin', '$SIP_DOMAIN', 'is_admin', '1');
268
+		'$PHPLIB_ID' );"
272 269
 
273
-		INSERT INTO admin_privileges ($USERCOL, domain, priv_name, priv_value)
274
-		VALUES ('admin', '$SIP_DOMAIN', 'change_privileges', '1');"
275 270
 elif [ $# -eq 2 ] ; then
276 271
 	# if 3rd param set, don't create any initial user
277 272
 	INITIAL_USER=""
... ...
@@ -284,14 +293,14 @@ fi
284 284
 USE_CMD='\connect'
285 285
 GRANT_CMD="CREATE USER $DBRWUSER WITH PASSWORD '$DEFAULT_PW';
286 286
 	CREATE USER $DBROUSER WITH PASSWORD '$RO_PW';
287
-	GRANT ALL PRIVILEGES ON TABLE version, acc, active_sessions, aliases, dbaliases, grp,
288
-		location, missed_calls, pending, phonebook, phonebook_id_seq, subscriber, silo, silo_mid_seq, domain,
289
-		uri, server_monitoring, usr_preferences, usr_preferences_types, trusted, server_monitoring_agg,
290
-		admin_privileges, speed_dial, gw, gw_grp, gw_grp_grp_id_seq, lcr, sip_trace TO $DBRWUSER;
291
-	GRANT SELECT ON TABLE version, acc, active_sessions, aliases, dbaliases, grp,
292
-		location, missed_calls, pending, phonebook, phonebook_id_seq, subscriber, silo, silo_mid_seq, domain,
293
-		uri, server_monitoring, usr_preferences, usr_preferences_types, trusted, server_monitoring_agg,
294
-		admin_privileges, speed_dial, gw, gw_grp, gw_grp_grp_id_seq, lcr, sip_trace TO $DBROUSER;"
287
+	GRANT ALL PRIVILEGES ON TABLE version, acc, aliases, dbaliases, grp,
288
+		location, missed_calls, subscriber, silo, silo_mid_seq, domain,
289
+		uri, usr_preferences, trusted, re_grp, pd_multidomain,
290
+		speed_dial, gw, gw_grp, gw_grp_grp_id_seq, lcr, sip_trace TO $DBRWUSER;
291
+	GRANT SELECT ON TABLE version, acc, aliases, dbaliases, grp,
292
+		location, missed_calls, subscriber, silo, silo_mid_seq, domain,
293
+		uri, usr_preferences, trusted, re_grp, pd_multidomain,
294
+		speed_dial, gw, gw_grp, gw_grp_grp_id_seq, lcr, sip_trace TO $DBROUSER;"
295 295
 TIMESTAMP="timestamp NOT NULL DEFAULT NOW()"
296 296
 DATETIME="TIMESTAMP WITHOUT TIME ZONE NOT NULL default '$DUMMY_DATE'"
297 297
 DATETIMEALIAS="TIMESTAMP WITHOUT TIME ZONE NOT NULL default '$DEFAULT_ALIASES_EXPIRES'"
... ...
@@ -351,8 +360,8 @@ CREATE TABLE subscriber (
351 351
   last_name varchar(45) NOT NULL default '',
352 352
   phone varchar(15) NOT NULL default '',
353 353
   email_address varchar(50) NOT NULL default '',
354
-  datetime_created $DATETIME,
355
-  datetime_modified $DATETIME,
354
+  datetime_created $TIMESTAMP,
355
+  datetime_modified $TIMESTAMP,
356 356
   confirmation varchar(64) NOT NULL default '',
357 357
   flag char(1) NOT NULL default 'o',
358 358
   sendnotification varchar(50) NOT NULL default '',
... ...
@@ -435,7 +444,7 @@ CREATE TABLE location (
435 435
   q $FLOAT NOT NULL default '$DEFAULT_Q',
436 436
   callid varchar(255) NOT NULL default '$DEFAULT_CALLID',
437 437
   cseq int NOT NULL default '$DEFAULT_CSEQ',
438
-  last_modified $DATETIMELOCATION,
438
+  last_modified $TIMESTAMP,
439 439
   flags int NOT NULL default '0',
440 440
   user_agent varchar(255) NOT NULL default '',
441 441
   socket varchar(128) default NULL,
... ...
@@ -458,7 +467,7 @@ CREATE TABLE aliases (
458 458
   q $FLOAT NOT NULL default '$DEFAULT_Q',
459 459
   callid varchar(255) NOT NULL default '$DEFAULT_CALLID',
460 460
   cseq int NOT NULL default '$DEFAULT_CSEQ',
461
-  last_modified $DATETIMEALIAS,
461
+  last_modified $TIMESTAMP,
462 462
   flags int NOT NULL default '0',
463 463
   user_agent varchar(255) NOT NULL default '',
464 464
   socket varchar(128) default NULL,
... ...
@@ -489,7 +498,7 @@ CREATE TABLE grp (
489 489
   $USERCOL varchar(64) NOT NULL default '',
490 490
   domain varchar(128) NOT NULL default '',
491 491
   grp varchar(50) NOT NULL default '',
492
-  last_modified $DATETIME,
492
+  last_modified $TIMESTAMP,
493 493
   PRIMARY KEY($USERCOL, domain, grp)
494 494
 ) $TABLE_TYPE;
495 495
 
... ...
@@ -510,15 +519,15 @@ CREATE TABLE re_grp (
510 510
  */
511 511
 CREATE TABLE silo(
512 512
     mid $AUTO_INCREMENT,
513
-    src_addr VARCHAR(255) NOT NULL DEFAULT '',
514
-    dst_addr VARCHAR(255) NOT NULL DEFAULT '',
515
-    r_uri VARCHAR(255) NOT NULL DEFAULT '',
516
-    $USERCOL VARCHAR(64) NOT NULL DEFAULT '',
517
-    domain VARCHAR(128) NOT NULL DEFAULT '',
513
+    src_addr varchar(255) NOT NULL DEFAULT '',
514
+    dst_addr varchar(255) NOT NULL DEFAULT '',
515
+    r_uri varchar(255) NOT NULL DEFAULT '',
516
+    $USERCOL varchar(64) NOT NULL DEFAULT '',
517
+    domain varchar(128) NOT NULL DEFAULT '',
518 518
     inc_time INTEGER NOT NULL DEFAULT 0,
519 519
     exp_time INTEGER NOT NULL DEFAULT 0,
520 520
     snd_time INTEGER NOT NULL DEFAULT 0,
521
-    ctype VARCHAR(32) NOT NULL DEFAULT 'text/plain',
521
+    ctype varchar(32) NOT NULL DEFAULT 'text/plain',
522 522
     body TEXT NOT NULL DEFAULT ''
523 523
 ) $TABLE_TYPE;
524 524
 
... ...
@@ -528,7 +537,7 @@ CREATE TABLE silo(
528 528
  */
529 529
 CREATE TABLE domain (
530 530
   domain varchar(128) NOT NULL default '',
531
-  last_modified $DATETIME,
531
+  last_modified $TIMESTAMP,
532 532
   PRIMARY KEY  (domain)
533 533
 ) $TABLE_TYPE;
534 534
 
... ...
@@ -540,7 +549,7 @@ CREATE TABLE uri (
540 540
   $USERCOL varchar(64) NOT NULL default '',
541 541
   domain varchar(128) NOT NULL default '',
542 542
   uri_user varchar(50) NOT NULL default '',
543
-  last_modified $DATETIME,
543
+  last_modified $TIMESTAMP,
544 544
   PRIMARY KEY ($USERCOL, domain, uri_user)
545 545
 ) $TABLE_TYPE;
546 546
 
... ...
@@ -549,19 +558,18 @@ CREATE TABLE uri (
549 549
  * Table structure for table 'usr_preferences'
550 550
  */
551 551
 CREATE TABLE usr_preferences (
552
-  id bigint(20) NOT NULL auto_increment,
552
+  id $AUTO_INCREMENT,
553 553
   uuid varchar(64) NOT NULL default '',
554 554
   $USERCOL varchar(100) NOT NULL default '0',
555 555
   domain varchar(128) NOT NULL default '',
556 556
   attribute varchar(32) NOT NULL default '',
557 557
   value varchar(128) NOT NULL default '',
558 558
   type int NOT NULL default '0',
559
-  modified $TIMESTAMP,
560
-  PRIMARY KEY (id),
561
-  INDEX ua_idx  (uuid,attribute),
562
-  INDEX uda_idx ($USERCOL,domain,attribute)
559
+  modified $TIMESTAMP
563 560
 ) $TABLE_TYPE;
564 561
 
562
+CREATE INDEX ua_idx ON usr_preferences(uuid,attribute);
563
+CREATE INDEX uda_idx ON usr_preferences($USERCOL,domain,attribute);
565 564
 
566 565
 /*
567 566
  * Table structure for table trusted
... ...
@@ -570,10 +578,10 @@ CREATE TABLE trusted (
570 570
   src_ip varchar(39) NOT NULL,
571 571
   proto varchar(4) NOT NULL,
572 572
   from_pattern varchar(64) default NULL,
573
-  tag varchar(32) default NULL,
574
-  INDEX ip_addr (src_ip)
573
+  tag varchar(32) default NULL
575 574
 ) $TABLE_TYPE;
576 575
 
576
+CREATE INDEX ip_addr ON trusted(src_ip);
577 577
 
578 578
 /*
579 579
  * Table structure for table 'speed_dial'
... ...
@@ -596,7 +604,7 @@ CREATE TABLE speed_dial (
596 596
  * Table structure for table 'gw' (lcr module)
597 597
  */
598 598
 CREATE TABLE gw (
599
-  gw_name VARCHAR(128) NOT NULL,
599
+  gw_name varchar(128) NOT NULL,
600 600
   grp_id INT CHECK (grp_id > 0) NOT NULL,
601 601
   ip_addr BIGINT CHECK (ip_addr > 0 AND ip_addr < 4294967296) NOT NULL,
602 602
   port INT CHECK (port > 0 AND port < 65536),
... ...
@@ -614,7 +622,7 @@ CREATE INDEX gw_grp_id_indx ON gw (grp_id);
614 614
  */
615 615
 CREATE TABLE gw_grp (
616 616
   grp_id SERIAL PRIMARY KEY,
617
-  grp_name VARCHAR(64) NOT NULL
617
+  grp_name varchar(64) NOT NULL
618 618
 );
619 619
 
620 620
 
... ...
@@ -645,8 +653,8 @@ CREATE FUNCTION "rand" () RETURNS double precision AS 'SELECT random();' LANGUAG
645 645
  * Table structure for table 'siptrace'
646 646
  */
647 647
 CREATE TABLE sip_trace (
648
-  id bigint(20) NOT NULL auto_increment,
649
-  date datetime NOT NULL default '0000-00-00 00:00:00',
648
+  id $AUTO_INCREMENT,
649
+  date $TIMESTAMP,
650 650
   callid varchar(254) NOT NULL default '',
651 651
   traced_user varchar(128) NOT NULL default '',
652 652
   msg text NOT NULL,
... ...
@@ -655,14 +663,23 @@ CREATE TABLE sip_trace (
655 655
   fromip varchar(50) NOT NULL default '',
656 656
   toip varchar(50) NOT NULL default '',
657 657
   fromtag varchar(64) NOT NULL default '',
658
-  direction varchar(4) NOT NULL default '',
659
-  PRIMARY KEY  (id)
658
+  direction varchar(4) NOT NULL default ''
660 659
 ) $TABLE_TYPE;
661 660
 CREATE INDEX user_idx ON sip_trace (traced_user);
662 661
 CREATE INDEX date_idx ON sip_trace (date);
663 662
 CREATE INDEX fromip_idx ON sip_trace (fromip);
664 663
 CREATE INDEX callid_idx ON sip_trace (callid);
665 664
 
665
+/*
666
+ * Table structure for table 'pdt'
667
+ */
668
+CREATE TABLE pd_multidomain (
669
+        sdomain varchar(255) NOT NULL,
670
+        prefix varchar(32) NOT NULL,
671
+        domain varchar(255) NOT NULL DEFAULT '',
672
+        PRIMARY KEY (sdomain, prefix)
673
+);
674
+
666 675
 
667 676
 /* add an admin user "admin" with password==$DEFAULT_PW,
668 677
  * so that one can try it out on quick start
... ...
@@ -690,6 +707,13 @@ fi
690 690
 
691 691
 serweb_create () # pars: <database name>
692 692
 {
693
+
694
+GRANT_SERWEB_CMD="
695
+        GRANT ALL PRIVILEGES ON TABLE phonebook, pending, active_sessions, server_monitoring, server_monitoring_agg,
696
+                usr_preferences_types, admin_privileges to $DBRWUSER; 
697
+        GRANT ALL PRIVILEGES ON TABLE phonebook, pending, active_sessions, server_monitoring, server_monitoring_agg,
698
+                usr_preferences_types, admin_privileges to $DBROUSER;" 
699
+
693 700
 if [ $# -eq 1 ] ; then
694 701
 	if [ -z "$SIP_DOMAIN" ] ; then
695 702
 		prompt_realm
... ...
@@ -748,8 +772,8 @@ CREATE TABLE pending (
748 748
   last_name varchar(45) NOT NULL default '',
749 749
   phone varchar(15) NOT NULL default '',
750 750
   email_address varchar(50) NOT NULL default '',
751
-  datetime_created $DATETIME,
752
-  datetime_modified $DATETIME,
751
+  datetime_created $TIMESTAMP,
752
+  datetime_modified $TIMESTAMP,
753 753
   confirmation varchar(64) NOT NULL default '',
754 754
   flag char(1) NOT NULL default 'o',
755 755
   sendnotification varchar(50) NOT NULL default '',
... ...
@@ -784,7 +808,7 @@ CREATE TABLE phonebook (
784 784
  * Table structure for table 'server_monitoring'
785 785
  */
786 786
 CREATE TABLE server_monitoring (
787
-  time $DATETIME,
787
+  time $TIMESTAMP,
788 788
   id bigint NOT NULL default '0',
789 789
   param varchar(32) NOT NULL default '',
790 790
   value int NOT NULL default '0',
... ...
@@ -823,7 +847,7 @@ CREATE TABLE server_monitoring_agg (
823 823
   max_val int NOT NULL default '0',
824 824
   min_inc int NOT NULL default '0',
825 825
   max_inc int NOT NULL default '0',
826
-  lastupdate $DATETIME,
826
+  lastupdate $TIMESTAMP,
827 827
   PRIMARY KEY  (param)
828 828
 ) $TABLE_TYPE;
829 829
 
... ...
@@ -850,6 +874,9 @@ CREATE FUNCTION "truncate" (numeric,int) RETURNS numeric AS 'SELECT trunc(\$1,\$
850 850
 create function unix_timestamp(timestamp) returns integer as 'select date_part(''epoch'', \$1)::int4 as result' language 'sql';
851 851
 
852 852
 $INITIAL_INSERT
853
+
854
+$GRANT_SERWEB_CMD
855
+
853 856
 EOF
854 857
 
855 858
 }  # end serweb_create