Browse code

- change postgresqldb.sh script to use the generated SQL from the xml schema - database creation tested with postgresql 8.2 - move one error handler in mysqldb.sh inside the if case

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

Henning Westerholt authored on 30/05/2007 12:56:10
Showing 2 changed files
... ...
@@ -457,13 +457,14 @@ if [ -z "$NO_USER_INIT" ] ; then
457 457
 	VALUES ('admin', '$SIP_DOMAIN', 'is_admin', '1');
458 458
 	INSERT INTO admin_privileges ($USERCOL, domain, priv_name, priv_value)
459 459
 	VALUES ('admin', '$SIP_DOMAIN', 'change_privileges', '1');"
460
-fi
461 460
 
462
-if [ $? -ne 0 ] ; then
463
-	echo "Failed to create serweb credentials tables!"
464
-	exit 1
461
+	if [ $? -ne 0 ] ; then
462
+		echo "Failed to create serweb credentials tables!"
463
+		exit 1
464
+	fi
465 465
 fi
466 466
 
467
+
467 468
 echo "SERWEB tables succesfully created."
468 469
 
469 470
 echo ""
... ...
@@ -48,6 +48,8 @@
48 48
 #             serweb is installed (bogdan)
49 49
 # 2007-01-26  added seperate installation routine for presence related tables
50 50
 #             and fix permissions for the SERIAL sequences.
51
+#
52
+# 2007-05-21  Move SQL database definitions out of this script (henning)
51 53
 
52 54
 
53 55
 
... ...
@@ -64,6 +66,14 @@ if [ -f ~/.openserpostgresqlrc ]; then
64 64
 	. ~/.openserpostgresqlrc
65 65
 fi
66 66
 
67
+# path to the database schemas
68
+DATA_DIR="/usr/local/share/openser"
69
+if [ -d "$DATA_DIR/postgres" ] ; then
70
+	DB_SCHEMA="$DATA_DIR/postgres"
71
+else
72
+	DB_SCHEMA="./postgres"
73
+fi
74
+
67 75
 #################################################################
68 76
 # config vars
69 77
 #################################################################
... ...
@@ -101,7 +111,7 @@ if [ -z "$DBROOTUSER" ]; then
101 101
 	fi
102 102
 fi
103 103
 
104
-CMD="psql -h $DBHOST -d template1 -U $DBROOTUSER "
104
+CMD="psql -h $DBHOST -U $DBROOTUSER "
105 105
 # the following commands are untested:
106 106
 #   DUMP_CMD="pg_dump -h $DBHOST -u$DBROOTUSER -c -t "
107 107
 #   BACKUP_CMD="mysqldump -h $DBHOST -u$DBROOTUSER -c "
... ...
@@ -123,6 +133,9 @@ if [ -z "$AWK" ]; then
123 123
 	AWK="awk"
124 124
 fi
125 125
 
126
+# if you change this definitions here, then you must change them 
127
+# in db/schema/entities.xml too.
128
+# FIXME
126 129
 DUMMY_DATE="1900-01-01 00:00:01"
127 130
 FOREVER="2020-05-28 21:32:15"
128 131
 
... ...
@@ -161,24 +174,23 @@ EOF
161 161
 } #usage
162 162
 
163 163
 
164
-# noot needed for postgresql
165
-## read password
166
-#prompt_pw()
167
-#{
168
-#	savetty=`stty -g`
169
-#	printf "Postgres password for $DBROOTUSER: "
170
-#	stty -echo
171
-#	read PW
172
-#	stty $savetty
173
-#	echo
174
-#}
175
-
176
-# execute sql command
164
+# execute sql command with optional db name
177 165
 sql_query()
178 166
 {
179
-	$CMD "$@"
167
+	if [ $# -gt 1 ] ; then
168
+		if [ -n "$1" ]; then
169
+			DB="$1"
170
+		else
171
+			DB=""
172
+		fi
173
+		shift
174
+		$CMD -d $DB -c "$@"
175
+	else
176
+		$CMD "$@"
177
+	fi
180 178
 }
181 179
 
180
+
182 181
 # dump all rows
183 182
 openser_dump()  # pars: <database name>
184 183
 {
... ...
@@ -280,420 +292,59 @@ if [ $# -ne 1 ] ; then
280 280
 	exit 1
281 281
 fi
282 282
 
283
-# define constants for database definition
284
-USE_CMD='\connect'
285
-GRANT_CMD="CREATE USER $DBRWUSER WITH PASSWORD '$DBRWPW';
286
-	CREATE USER $DBROUSER WITH PASSWORD '$DBROPW';
287
-	GRANT ALL PRIVILEGES ON TABLE 
288
-		version, 
289
-		acc, acc_id_seq, 
290
-		address, address_id_seq, 
291
-		aliases, aliases_id_seq,
292
-		dbaliases, dbaliases_id_seq, 
293
-		domain, domain_id_seq, 
294
-		grp, grp_id_seq,
295
-		gw, gw_id_seq, 
296
-		gw_grp, gw_grp_grp_id_seq, 
297
-		lcr, lcr_id_seq, 
298
-		location, location_id_seq, 
299
-		missed_calls, missed_calls_id_seq, 
300
-		pdt, pdt_id_seq, 
301
-		re_grp, re_grp_id_seq, 
302
-		silo, silo_id_seq, 
303
-		speed_dial, speed_dial_id_seq, 
304
-		subscriber, subscriber_id_seq, 
305
-		trusted, trusted_id_seq, 
306
-		uri, uri_id_seq, 
307
-		usr_preferences, usr_preferences_id_seq
308
-		TO $DBRWUSER;
309
-	GRANT SELECT ON TABLE 
310
-		version, 
311
-		acc, 
312
-		address, 
313
-		aliases, 
314
-		dbaliases, 
315
-		domain, 
316
-		grp, 
317
-		gw, 
318
-		gw_grp, 
319
-		lcr, 
320
-		location, 
321
-		missed_calls, 
322
-		pdt, 
323
-		re_grp, 
324
-		silo, 
325
-		speed_dial, 
326
-		subscriber, 
327
-		trusted, 
328
-		uri, 
329
-		usr_preferences
330
-		TO $DBROUSER;"
331
-TIMESTAMP="timestamp NOT NULL DEFAULT NOW()"
332
-DATETIME="TIMESTAMP WITHOUT TIME ZONE NOT NULL default '$DUMMY_DATE'"
333
-DATETIMEALIAS="TIMESTAMP WITHOUT TIME ZONE NOT NULL default '$DEFAULT_ALIASES_EXPIRES'"
334
-DATETIMELOCATION="TIMESTAMP WITHOUT TIME ZONE NOT NULL default '$DEFAULT_LOCATION_EXPIRES'"
335
-FLOAT="NUMERIC(10,2)"
336
-TINYINT="NUMERIC(4,0)"
337
-AUTO_INCREMENT="SERIAL PRIMARY KEY"
283
+# define what modules should be installed
284
+# openser standard modules
285
+STANDARD_MODULES="standard acc lcr domain group permissions
286
+                  registrar usrloc msilo alias_db uri_db
287
+                  speeddial avpops auth_db pdt"
288
+
289
+# openser extra modules
290
+EXTRA_MODULES="imc cpl siptrace domainpolicy"
338 291
 
339 292
 echo "creating database $1 ..."
340 293
 
341
-#cat <<EOF
342
-sql_query <<EOF
343
-create database $1;
344
-$USE_CMD $1;
345
-
346
-/*
347
- * Table structure versions
348
- */
349
-
350
-CREATE TABLE version (
351
-   table_name varchar(64) NOT NULL primary key,
352
-   table_version smallint DEFAULT '0' NOT NULL
353
-) $TABLE_TYPE;
354
-
355
-/*
356
- * Dumping data for table 'version'
357
- */
358
-
359
-INSERT INTO version VALUES ( 'subscriber', '6');
360
-INSERT INTO version VALUES ( 'missed_calls', '3');
361
-INSERT INTO version VALUES ( 'location', '1004');
362
-INSERT INTO version VALUES ( 'aliases', '1004');
363
-INSERT INTO version VALUES ( 'grp', '2');
364
-INSERT INTO version VALUES ( 're_grp', '1');
365
-INSERT INTO version VALUES ( 'acc', '4');
366
-INSERT INTO version VALUES ( 'silo', '5');
367
-INSERT INTO version VALUES ( 'domain', '1');
368
-INSERT INTO version VALUES ( 'uri', '1');
369
-INSERT INTO version VALUES ( 'trusted', '4');
370
-INSERT INTO version VALUES ( 'usr_preferences', '2');
371
-INSERT INTO version VALUES ( 'speed_dial', '2');
372
-INSERT INTO version VALUES ( 'dbaliases', '1');
373
-INSERT INTO version VALUES ( 'gw', '4');
374
-INSERT INTO version VALUES ( 'gw_grp', '1');
375
-INSERT INTO version VALUES ( 'lcr', '2');
376
-INSERT INTO version VALUES ( 'address', '2');
377
-
378
-/*
379
- * Table structure for table 'subscriber' -- user database
380
- */
381
-CREATE TABLE subscriber (
382
-  id $AUTO_INCREMENT,
383
-  $USERCOL varchar(64) NOT NULL default '',
384
-  domain varchar(128) NOT NULL default '',
385
-  password varchar(25) NOT NULL default '',
386
-  first_name varchar(25) NOT NULL default '',
387
-  last_name varchar(45) NOT NULL default '',
388
-  email_address varchar(50) NOT NULL default '',
389
-  datetime_created $TIMESTAMP,
390
-  ha1 varchar(128) NOT NULL default '',
391
-  ha1b varchar(128) NOT NULL default '',
392
-  timezone varchar(128) default NULL,
393
-  rpid varchar(128) default NULL,
394
-  UNIQUE ($USERCOL, domain)
395
-) $TABLE_TYPE;
396
-CREATE INDEX username_subs_indx ON subscriber ($USERCOL);
397
-
398
-
399
-/*
400
- * Table structure for table 'acc' -- accounted calls
401
- */
402
-CREATE TABLE acc (
403
-  id $AUTO_INCREMENT,
404
-  method varchar(16) NOT NULL default '',
405
-  from_tag varchar(64) NOT NULL default '',
406
-  to_tag varchar(64) NOT NULL default '',
407
-  callid varchar(128) NOT NULL default '',
408
-  sip_code char(3) NOT NULL default '',
409
-  sip_reason varchar(32) NOT NULL default '',
410
-  time $DATETIME
411
-) $TABLE_TYPE;
412
-CREATE INDEX acc_callid_indx ON acc (callid);
413
-
414
-
415
-/* 
416
- * Table structure for table 'missed_calls' -- acc-like table
417
- * for keeping track of missed calls
418
- */ 
419
-CREATE TABLE missed_calls (
420
-  id $AUTO_INCREMENT,
421
-  method varchar(16) NOT NULL default '',
422
-  from_tag varchar(64) NOT NULL default '',
423
-  to_tag varchar(64) NOT NULL default '',
424
-  callid varchar(128) NOT NULL default '',
425
-  sip_code char(3) NOT NULL default '',
426
-  sip_reason varchar(32) NOT NULL default '',
427
-  time $DATETIME
428
-) $TABLE_TYPE;
429
-CREATE INDEX mc_callid_indx ON missed_calls (callid);
430
-
431
-
432
-
433
-/*
434
- * Table structure for table 'location' -- that is persistent UsrLoc
435
- */
436
-CREATE TABLE location (
437
-  id $AUTO_INCREMENT,
438
-  $USERCOL varchar(64) NOT NULL default '',
439
-  domain varchar(128) NOT NULL default '',
440
-  contact varchar(255) NOT NULL default '',
441
-  received varchar(255) default NULL,
442
-  path varchar(255) default NULL,
443
-  expires $DATETIMELOCATION,
444
-  q $FLOAT NOT NULL default '$DEFAULT_Q',
445
-  callid varchar(255) NOT NULL default '$DEFAULT_CALLID',
446
-  cseq int NOT NULL default '$DEFAULT_CSEQ',
447
-  last_modified $TIMESTAMP,
448
-  flags int NOT NULL default '0',
449
-  cflags int NOT NULL default '0',
450
-  user_agent varchar(255) NOT NULL default '',
451
-  socket varchar(128) default NULL,
452
-  methods int default NULL
453
-) $TABLE_TYPE;
454
-CREATE INDEX location_udc_indx ON location ($USERCOL, domain, contact);
455
-
456
-
457
-/*
458
- * Table structure for table 'aliases' -- location-like table
459
- * (aliases_contact index makes lookup of missed calls much faster)
460
- */
461
-CREATE TABLE aliases (
462
-  id $AUTO_INCREMENT,
463
-  $USERCOL varchar(64) NOT NULL default '',
464
-  domain varchar(128) NOT NULL default '',
465
-  contact varchar(255) NOT NULL default '',
466
-  received varchar(255) default NULL,
467
-  path varchar(255) default NULL,
468
-  expires $DATETIMEALIAS,
469
-  q $FLOAT NOT NULL default '$DEFAULT_Q',
470
-  callid varchar(255) NOT NULL default '$DEFAULT_CALLID',
471
-  cseq int NOT NULL default '$DEFAULT_CSEQ',
472
-  last_modified $TIMESTAMP,
473
-  flags int NOT NULL default '0',
474
-  cflags int NOT NULL default '0',
475
-  user_agent varchar(255) NOT NULL default '',
476
-  socket varchar(128) default NULL,
477
-  methods int default NULL
478
-) $TABLE_TYPE;
479
-CREATE INDEX aliases_udc_indx ON aliases ($USERCOL, domain, contact);
480
-
481
-
482
-/*
483
- * DB aliases
484
- */
485
-CREATE TABLE dbaliases (
486
-  id $AUTO_INCREMENT,
487
-  alias_username varchar(64) NOT NULL default '',
488
-  alias_domain varchar(128) NOT NULL default '',
489
-  $USERCOL varchar(64) NOT NULL default '',
490
-  domain varchar(128) NOT NULL default '',
491
-  UNIQUE (alias_username,alias_domain)
492
-) $TABLE_TYPE;
493
-CREATE INDEX alias_user_indx ON dbaliases ($USERCOL, domain);
494
-
495
-
496
-/*
497
- * Table structure for table 'grp' -- group membership
498
- * table; used primarily for ACLs
499
- */
500
-CREATE TABLE grp (
501
-  id $AUTO_INCREMENT,
502
-  $USERCOL varchar(64) NOT NULL default '',
503
-  domain varchar(128) NOT NULL default '',
504
-  grp varchar(50) NOT NULL default '',
505
-  last_modified $TIMESTAMP,
506
-  UNIQUE ($USERCOL, domain, grp)
507
-) $TABLE_TYPE;
508
-
509
-
510
-/*
511
- * Table structure for table 're_grp' -- group membership
512
- * based on regular expressions
513
- */
514
-CREATE TABLE re_grp (
515
-  id $AUTO_INCREMENT,
516
-  reg_exp varchar(128) NOT NULL default '',
517
-  group_id int NOT NULL default '0'
518
-) $TABLE_TYPE;
519
-CREATE INDEX gid_grp_indx ON re_grp (group_id);
520
-
521
-
522
-/*
523
- * "instant" message silo
524
- */
525
-CREATE TABLE silo(
526
-  id $AUTO_INCREMENT,
527
-  src_addr varchar(255) NOT NULL DEFAULT '',
528
-  dst_addr varchar(255) NOT NULL DEFAULT '',
529
-  $USERCOL varchar(64) NOT NULL DEFAULT '',
530
-  domain varchar(128) NOT NULL DEFAULT '',
531
-  inc_time int NOT NULL DEFAULT 0,
532
-  exp_time int NOT NULL DEFAULT 0,
533
-  snd_time int NOT NULL DEFAULT 0,
534
-  ctype varchar(32) NOT NULL DEFAULT 'text/plain',
535
-  body TEXT NOT NULL DEFAULT ''
536
-) $TABLE_TYPE;
537
-CREATE INDEX silo_idx ON silo($USERCOL, domain);
538
-
539
-/*
540
- * Table structure for table 'domain' -- domains proxy is responsible for
541
- */
542
-CREATE TABLE domain (
543
-  id $AUTO_INCREMENT,
544
-  domain varchar(128) NOT NULL default '',
545
-  last_modified $TIMESTAMP,
546
-  UNIQUE (domain)
547
-) $TABLE_TYPE;
548
-
549
-
550
-/*
551
- * Table structure for table 'uri' -- uri user parts users are allowed to use
552
- */
553
-CREATE TABLE uri (
554
-  id $AUTO_INCREMENT,
555
-  $USERCOL varchar(64) NOT NULL default '',
556
-  domain varchar(128) NOT NULL default '',
557
-  uri_user varchar(50) NOT NULL default '',
558
-  last_modified $TIMESTAMP,
559
-  UNIQUE ($USERCOL, domain, uri_user)
560
-) $TABLE_TYPE;
561
-
562
-
563
-/*
564
- * Table structure for table 'usr_preferences'
565
- */
566
-CREATE TABLE usr_preferences (
567
-  id $AUTO_INCREMENT,
568
-  uuid varchar(64) NOT NULL default '',
569
-  $USERCOL varchar(100) NOT NULL default '0',
570
-  domain varchar(128) NOT NULL default '',
571
-  attribute varchar(32) NOT NULL default '',
572
-  value varchar(128) NOT NULL default '',
573
-  type int NOT NULL default '0',
574
-  last_modified $TIMESTAMP
575
-) $TABLE_TYPE;
576
-CREATE INDEX ua_idx ON usr_preferences(uuid,attribute);
577
-CREATE INDEX uda_idx ON usr_preferences($USERCOL,domain,attribute);
578
-
579
-
580
-/*
581
- * Table structure for table trusted
582
- */
583
-CREATE TABLE trusted (
584
-  id $AUTO_INCREMENT,
585
-  src_ip varchar(39) NOT NULL,
586
-  proto varchar(4) NOT NULL,
587
-  from_pattern varchar(64) default NULL,
588
-  tag varchar(32) default NULL
589
-) $TABLE_TYPE;
590
-CREATE INDEX ip_addr ON trusted(src_ip);
591
-
592
-
593
-/*
594
- * Table structure for table 'speed_dial'
595
- */
596
-CREATE TABLE speed_dial (
597
-  id $AUTO_INCREMENT,
598
-  $USERCOL varchar(64) NOT NULL default '',
599
-  domain varchar(128) NOT NULL default '',
600
-  sd_username varchar(64) NOT NULL default '',
601
-  sd_domain varchar(128) NOT NULL default '',
602
-  new_uri varchar(192) NOT NULL default '',
603
-  fname varchar(128) NOT NULL default '',
604
-  lname varchar(128) NOT NULL default '',
605
-  description varchar(64) NOT NULL default '',
606
-  UNIQUE ($USERCOL,domain,sd_domain,sd_username)
607
-) $TABLE_TYPE;
608
-
609
-
610
-/*
611
- * Table structure for table 'gw' (lcr module)
612
- */
613
-CREATE TABLE gw (
614
-  id $AUTO_INCREMENT,
615
-  gw_name varchar(128) NOT NULL,
616
-  grp_id INT CHECK (grp_id > 0) NOT NULL,
617
-  ip_addr varchar(15) NOT NULL,
618
-  port INT CHECK (port > 0 AND port < 65536),
619
-  uri_scheme SMALLINT CHECK (uri_scheme >= 0 and uri_scheme < 256),
620
-  transport SMALLINT CHECK (transport >= 0 and transport < 256),
621
-  strip SMALLINT CHECK (strip >= 0),
622
-  prefix varchar(16) default NULL,
623
-  UNIQUE (gw_name)
624
-);
625
-CREATE INDEX gw_grp_id_indx ON gw (grp_id);
626
-
627
-
628
-/*
629
- * Table structure for table 'gw_grp' (lcr module)
630
- */
631
-CREATE TABLE gw_grp (
632
-  grp_id SERIAL PRIMARY KEY,
633
-  grp_name varchar(64) NOT NULL
634
-);
635
-
636
-
637
-/*
638
- * Table structure for table 'lcr' (lcr module)
639
- */
640
-CREATE TABLE lcr (
641
-  id $AUTO_INCREMENT,
642
-  prefix varchar(16) NOT NULL,
643
-  from_uri varchar(128) DEFAULT NULL,
644
-  grp_id INT CHECK (grp_id > 0) NOT NULL,
645
-  priority SMALLINT CHECK (priority >= 0 and priority < 256) NOT NULL
646
-);
647
-CREATE INDEX lcr_prefix_indx ON lcr (prefix);
648
-CREATE INDEX lcr_from_uri_indx ON lcr (from_uri);
649
-CREATE INDEX lcr_grp_id_indx ON lcr (grp_id);
650
-
651
-
652
-/*
653
- * emulate mysql proprietary functions used by the lcr module
654
- * in postgresql
655
- *
656
- */
657
-CREATE FUNCTION "concat" (text,text) RETURNS text AS 'SELECT \$1 || \$2;' LANGUAGE 'sql';
658
-CREATE FUNCTION "rand" () RETURNS double precision AS 'SELECT random();' LANGUAGE 'sql';
659
-
660
-
661
-/*
662
-* Table structure for table 'address'
663
-*/
664
-CREATE TABLE address (
665
-  id $AUTO_INCREMENT,
666
-  grp smallint NOT NULL default '0',
667
-  ip_addr varchar(15) NOT NULL default '',
668
-  mask $TINYINT NOT NULL default 32,
669
-  port smallint NOT NULL default '0'
670
-) $TABLE_TYPE; 
671
-
672
-
673
-/*
674
- * Table structure for table 'pdt'
675
- */
676
-CREATE TABLE pdt (
677
-  id $AUTO_INCREMENT,
678
-  sdomain varchar(255) NOT NULL,
679
-  prefix varchar(32) NOT NULL,
680
-  domain varchar(255) NOT NULL DEFAULT '',
681
-  UNIQUE (sdomain, prefix)
682
-) $TABLE_TYPE;
683
-
684
-
685
-/*
686
- * GRANT permissions
687
- */
688
-
689
-$GRANT_CMD
294
+sql_query "template1" "create database $1;"
295
+if [ $? -ne 0 ] ; then
296
+	echo "Creating database failed!"
297
+	exit 1
298
+fi
690 299
 
691
-EOF
300
+sql_query "$1" "CREATE FUNCTION "concat" (text,text) RETURNS text AS 'SELECT \$1 || \$2;' LANGUAGE 'sql';
301
+	        CREATE FUNCTION "rand" () RETURNS double precision AS 'SELECT random();' LANGUAGE 'sql';"
302
+# emulate mysql proprietary functions used by the lcr module in postgresql
692 303
 
693 304
 if [ $? -ne 0 ] ; then
305
+	echo "Creating mysql emulation functions failed!"
306
+	exit 1
307
+fi
308
+
309
+for TABLE in $STANDARD_MODULES; do
310
+    echo "Creating core table: $TABLE"
311
+    sql_query "$1" < $DB_SCHEMA/$TABLE-create.sql
312
+    if [ $? -ne 0 ] ; then
694 313
 	echo "Creating core tables failed!"
695
-	exit 1;
314
+	exit 1
315
+    fi
316
+done
317
+
318
+sql_query "$1" "CREATE USER $DBRWUSER WITH PASSWORD '$DBRWPW';
319
+		CREATE USER $DBROUSER WITH PASSWORD '$DBROPW';
320
+		GRANT ALL PRIVILEGES ON TABLE version, acc, acc_id_seq, address, address_id_seq, 
321
+		aliases, aliases_id_seq, dbaliases, dbaliases_id_seq, domain, domain_id_seq, 
322
+		grp, grp_id_seq, gw, gw_id_seq, gw_grp, gw_grp_grp_id_seq, lcr, lcr_id_seq, 
323
+		location, location_id_seq, missed_calls, missed_calls_id_seq, pdt, pdt_id_seq, 
324
+		re_grp, re_grp_id_seq, silo, silo_id_seq, speed_dial, speed_dial_id_seq, 
325
+		subscriber, subscriber_id_seq, trusted, trusted_id_seq, uri, uri_id_seq, 
326
+		usr_preferences, usr_preferences_id_seq TO $DBRWUSER;
327
+		GRANT SELECT ON TABLE version, acc, address, aliases, dbaliases, domain, grp, 
328
+		gw, gw_grp, lcr, location, missed_calls, pdt, re_grp, silo, speed_dial, 
329
+		subscriber, trusted, uri, usr_preferences TO $DBROUSER;"
330
+
331
+if [ $? -ne 0 ] ; then
332
+	echo "Grant privileges to database failed!"
333
+	exit 1
696 334
 fi
335
+
697 336
 echo "Core OpenSER tables succesfully created."
698 337
 
699 338
 echo -n "Install presence related tables ?(y/n):"
... ...
@@ -726,152 +377,26 @@ if [ $# -ne 1 ] ; then
726 726
 	exit 1
727 727
 fi
728 728
 
729
-GRANT_PRESENCE_CMD="
730
-	GRANT ALL PRIVILEGES ON TABLE 
731
-		active_watchers, active_watchers_id_seq, 
732
-		presentity, presentity_id_seq, 
733
-		watchers, watchers_id_seq, 
734
-		xcap_xml, xcap_xml_id_seq,
735
-		pua, pua_id_seq
736
-		TO $DBRWUSER;
737
-	GRANT SELECT ON TABLE 
738
-		active_watchers, 
739
-		presentity, 
740
-		watchers, 
741
-		xcap_xml,
742
-		pua
743
-		TO $DBROUSER;" 
744
-
745 729
 echo "creating presence tables into $1 ..."
746 730
 
747
-sql_query <<EOF
748
-$USE_CMD $1;
749
-
750
-INSERT INTO version VALUES ( 'presentity', '1');
751
-INSERT INTO version VALUES ( 'active_watchers', '4');
752
-INSERT INTO version VALUES ( 'watchers', '1');
753
-INSERT INTO version VALUES ( 'xcap_xml', '1');
754
-INSERT INTO version VALUES ( 'pua', '3');
755
-
756
-/*
757
- * Table structure for table 'presentity'
758
- * 
759
- * used by presence module
760
- */
761
-CREATE TABLE presentity (
762
-  id $AUTO_INCREMENT,
763
-  username varchar(64) NOT NULL,
764
-  domain varchar(124) NOT NULL,
765
-  event varchar(64) NOT NULL,
766
-  etag varchar(64) NOT NULL,
767
-  expires int NOT NULL,
768
-  received_time int NOT NULL,
769
-  body bytea NOT NULL,
770
-  UNIQUE (username, domain, event, etag)
771
-) $TABLE_TYPE;
772
-
773
-
774
-
775
-/*
776
- * Table structure for table 'active_watchers'
777
- * 
778
- * used by presence module
779
- */
780
-CREATE TABLE active_watchers (
781
-  id $AUTO_INCREMENT,
782
-  pres_user varchar(64) NOT NULL,
783
-  pres_domain varchar(128) NOT NULL,
784
-  to_user varchar(64) NOT NULL,
785
-  to_domain varchar(128) NOT NULL,
786
-  from_user varchar(64) NOT NULL,
787
-  from_domain varchar(128) NOT NULL,
788
-  event varchar(64) NOT NULL default 'presence',
789
-  event_id varchar(64) NOT NULL,
790
-  to_tag varchar(128) NOT NULL,
791
-  from_tag varchar(128) NOT NULL,
792
-  callid varchar(128) NOT NULL,
793
-  local_cseq int NOT NULL,
794
-  remote_cseq int NOT NULL,
795
-  contact varchar(128) NOT NULL,
796
-  record_route text NULL,
797
-  expires int NOT NULL,
798
-  status varchar(32) NOT NULL default 'pending',
799
-  version int NOT NULL default '0',
800
-  socket_info varchar(128) NOT NULL,
801
-  local_contact varchar(255) NOT NULL,
802
-  UNIQUE (to_tag)
803
-) $TABLE_TYPE;
804
-CREATE INDEX due_activewatchers ON active_watchers (to_domain,to_user,event);
805
-
806
-
807
-/*
808
- * Table structure for table 'watchers'
809
- * 
810
- * used by presence module
811
- */
812
-CREATE TABLE watchers (
813
-  id $AUTO_INCREMENT,
814
-  p_user varchar(64) NOT NULL,
815
-  p_domain varchar(128) NOT NULL,
816
-  w_user varchar(64) NOT NULL,
817
-  w_domain varchar(128) NOT NULL,
818
-  subs_status varchar(64) NOT NULL,
819
-  reason varchar(64) NULL,
820
-  inserted_time int NOT NULL,
821
-  UNIQUE (p_user, p_domain, w_user, w_domain)
822
-) $TABLE_TYPE;
823
-
824
-
825
-
826
-/*
827
- * Table structure for table 'xcap_xml'
828
- * 
829
- * used by presence module
830
- */
831
-CREATE TABLE xcap_xml (
832
-  id $AUTO_INCREMENT,
833
-  username varchar(66) NOT NULL,
834
-  domain varchar(128) NOT NULL,
835
-  xcap text NOT NULL,
836
-  doc_type int NOT NULL,
837
-  UNIQUE (username, domain, doc_type)
838
-) $TABLE_TYPE;
839
-
840
-
841
-/*
842
- * Table structure for table 'pua'
843
- * 
844
- * used by pua module
845
- */
846
-
847
-CREATE TABLE pua (
848
-  id $AUTO_INCREMENT,
849
-  pres_uri varchar(128) NOT NULL,
850
-  pres_id varchar(128) NOT NULL,
851
-  event int NOT NULL, 
852
-  expires int NOT NULL,
853
-  flag int NOT NULL,
854
-  etag varchar(128) NOT NULL,
855
-  tuple_id varchar(128) NOT NULL,
856
-  watcher_uri varchar(128) NOT NULL,
857
-  call_id varchar(128) NOT NULL,
858
-  to_tag varchar(128) NOT NULL,
859
-  from_tag varchar(128) NOT NULL,
860
-  cseq int NOT NULL
861
-  record_route text NULL,
862
-  version int NOT NULL,
863
-) $TABLE_TYPE;
864
-
865
-
866
-$GRANT_PRESENCE_CMD
867
-
868
-EOF
731
+sql_query "$1" < $DB_SCHEMA/presence-create.sql
869 732
 
870 733
 if [ $? -ne 0 ] ; then
871 734
 	echo "Failed to create presence tables!"
872 735
 	exit 1
873 736
 fi
874 737
 
738
+sql_query "$1" "GRANT ALL PRIVILEGES ON TABLE 	active_watchers, active_watchers_id_seq,
739
+		presentity, presentity_id_seq, watchers, watchers_id_seq, xcap_xml,
740
+		xcap_xml_id_seq, pua, pua_id_seq TO $DBRWUSER;
741
+		GRANT SELECT ON TABLE active_watchers, presentity, watchers, xcap_xml,
742
+		pua TO $DBROUSER;"
743
+
744
+if [ $? -ne 0 ] ; then
745
+	echo "Grant privileges to presences tables failed!"
746
+	exit 1
747
+fi
748
+
875 749
 echo "Presence tables succesfully created."
876 750
 }  # end presence_create
877 751
 
... ...
@@ -883,116 +408,30 @@ if [ $# -ne 1 ] ; then
883 883
 	exit 1
884 884
 fi
885 885
 
886
-GRANT_EXTRA_CMD="
887
-	GRANT ALL PRIVILEGES ON TABLE 
888
-		cpl, cpl_id_seq,
889
-		imc_members, imc_members_id_seq,
890
-		imc_rooms, imc_rooms_id_seq,
891
-		sip_trace, sip_trace_id_seq,
892
-		domainpolicy, domainpolicy_id_seq
886
+for TABLE in $EXTRA_MODULES; do
887
+    echo "Creating extra table: $TABLE"
888
+    sql_query "$1" < $DB_SCHEMA/$TABLE-create.sql
889
+    if [ $? -ne 0 ] ; then
890
+	echo "Creating extra tables failed!"
891
+	exit 1
892
+    fi
893
+done
894
+
895
+sql_query "$1" "GRANT ALL PRIVILEGES ON TABLE cpl, cpl_id_seq, imc_members,
896
+		imc_members_id_seq, imc_rooms, imc_rooms_id_seq, sip_trace, 
897
+		sip_trace_id_seq, domainpolicy, domainpolicy_id_seq
893 898
 		TO $DBRWUSER;
894
-	GRANT SELECT ON TABLE 
895
-		cpl,
896
-		imc_members,
897
-		imc_rooms,
898
-		sip_trace,
899
-		domainpolicy
900
-		TO $DBROUSER;"
899
+		GRANT SELECT ON TABLE cpl, imc_members, imc_rooms, sip_trace,
900
+		domainpolicy TO $DBROUSER;"
901 901
 
902
-echo "creating extra tables into $1 ..."
902
+if [ $? -ne 0 ] ; then
903
+	echo "Grant privileges to extra tables failed!"
904
+	exit 1
905
+fi
903 906
 
904
-sql_query <<EOF
905
-$USE_CMD $1;
906
-
907
-INSERT INTO version VALUES ( 'cpl', '1');
908
-INSERT INTO version VALUES ( 'imc_members', '1');
909
-INSERT INTO version VALUES ( 'imc_rooms', '1');
910
-INSERT INTO version VALUES ( 'sip_trace', '1');
911
-INSERT INTO version VALUES ( 'domainpolicy', '2');
912
-
913
-/*
914
- * Table structure for table 'cpl'
915
- * 
916
- * used by cpl-c module
917
- */
918
-CREATE TABLE cpl (
919
-  id $AUTO_INCREMENT,
920
-  username varchar(64) NOT NULL,
921
-  domain varchar(64) NOT NULL default '',
922
-  cpl_xml text,
923
-  cpl_bin text,
924
-  UNIQUE (username, domain)
925
-) $TABLE_TYPE;
926
-
927
-
928
-/*
929
- * Table structure for table 'imc_members'
930
- * 
931
- * used by imc module
932
- */
933
-CREATE TABLE imc_members (
934
-  id $AUTO_INCREMENT,
935
-  username varchar(128) NOT NULL,
936
-  domain varchar(128) NOT NULL,
937
-  room varchar(64) NOT NULL,
938
-  flag int NOT NULL,
939
-  UNIQUE (username,domain,room)
940
-) $TABLE_TYPE;
941
-
942
-
943
-/*
944
- * Table structure for table 'imc_rooms'
945
- * 
946
- * used by imc module
947
- */
948
-CREATE TABLE imc_rooms (
949
-  id $AUTO_INCREMENT,
950
-  name varchar(128) NOT NULL,
951
-  domain varchar(128) NOT NULL,
952
-  flag int NOT NULL,
953
-  UNIQUE (name,domain)
954
-) $TABLE_TYPE;
955
-
956
-
957
-/*
958
- * Table structure for table 'siptrace'
959
- */
960
-CREATE TABLE sip_trace (
961
-  id $AUTO_INCREMENT,
962
-  date $TIMESTAMP,
963
-  callid varchar(254) NOT NULL default '',
964
-  traced_user varchar(128) NOT NULL default '',
965
-  msg text NOT NULL,
966
-  method varchar(50) NOT NULL default '',
967
-  status varchar(254) NOT NULL default '',
968
-  fromip varchar(50) NOT NULL default '',
969
-  toip varchar(50) NOT NULL default '',
970
-  fromtag varchar(64) NOT NULL default '',
971
-  direction varchar(4) NOT NULL default ''
972
-) $TABLE_TYPE;
973
-CREATE INDEX user_idx ON sip_trace (traced_user);
974
-CREATE INDEX date_idx ON sip_trace (date);
975
-CREATE INDEX fromip_idx ON sip_trace (fromip);
976
-CREATE INDEX callid_idx ON sip_trace (callid);
977
-
978
-
979
-/*
980
- * domainpolicy table (see README domainpolicy module)
981
- */
982
-CREATE TABLE domainpolicy (
983
-  id $AUTO_INCREMENT,
984
-  rule VARCHAR(255) NOT NULL,
985
-  type VARCHAR(255) NOT NULL,
986
-  att VARCHAR(255),
987
-  val VARCHAR(255),
988
-  comment VARCHAR(255),
989
-  UNIQUE ( rule, att, val )
990
-);
991
-CREATE INDEX domainpolicy_rule_idx ON domainpolicy(rule);
992
-
993
-$GRANT_EXTRA_CMD
994 907
 
995
-EOF
908
+echo "creating extra tables into $1 ..."
909
+
996 910
 
997 911
 if [ $? -ne 0 ] ; then
998 912
 	echo "Failed to create extra tables!"
... ...
@@ -1010,224 +449,98 @@ if [ $# -ne 1 ] ; then
1010 1010
 	exit 1
1011 1011
 fi
1012 1012
 
1013
-GRANT_SERWEB_CMD="
1014
-	GRANT ALL PRIVILEGES ON TABLE phonebook, phonebook_id_seq, 
1015
-		pending, pending_id_seq, active_sessions,
1016
-		server_monitoring, server_monitoring_agg,
1013
+echo "creating serweb tables into $1 ..."
1014
+
1015
+# Extend table 'subscriber' with serweb specific columns
1016
+# It would be easier to drop the table and create a new one,
1017
+# but in case someone want to add serweb and has already
1018
+# a populated subscriber table, we show here how this
1019
+# can be done without deleting the existing data.
1020
+# Tested with postgres 7.4.7
1021
+
1022
+sql_query "$1" "ALTER TABLE subscriber ADD COLUMN phplib_id varchar(32);
1023
+		ALTER TABLE subscriber ADD COLUMN phone varchar(15);
1024
+		ALTER TABLE subscriber ADD COLUMN datetime_modified timestamp;
1025
+		ALTER TABLE subscriber ADD COLUMN confirmation varchar(64);
1026
+		ALTER TABLE subscriber ADD COLUMN flag char(1);
1027
+		ALTER TABLE subscriber ADD COLUMN sendnotification varchar(50);
1028
+		ALTER TABLE subscriber ADD COLUMN greeting varchar(50);
1029
+		ALTER TABLE subscriber ADD COLUMN allow_find char(1);
1030
+		ALTER TABLE subscriber ADD CONSTRAINT phplib_id_key unique (phplib_id);
1031
+
1032
+		ALTER TABLE subscriber ALTER phplib_id SET NOT NULL;
1033
+		ALTER TABLE subscriber ALTER phplib_id SET DEFAULT '';
1034
+		ALTER TABLE subscriber ALTER phone SET NOT NULL;
1035
+		ALTER TABLE subscriber ALTER phone SET DEFAULT '';
1036
+		ALTER TABLE subscriber ALTER datetime_modified SET NOT NULL;
1037
+		ALTER TABLE subscriber ALTER datetime_modified SET DEFAULT NOW();
1038
+		ALTER TABLE subscriber ALTER confirmation SET NOT NULL;
1039
+		ALTER TABLE subscriber ALTER confirmation SET DEFAULT '';
1040
+		ALTER TABLE subscriber ALTER flag SET NOT NULL;
1041
+		ALTER TABLE subscriber ALTER flag SET DEFAULT 'o';
1042
+		ALTER TABLE subscriber ALTER sendnotification SET NOT NULL;
1043
+		ALTER TABLE subscriber ALTER sendnotification SET DEFAULT '';
1044
+		ALTER TABLE subscriber ALTER greeting SET NOT NULL;
1045
+		ALTER TABLE subscriber ALTER greeting SET DEFAULT '';
1046
+		ALTER TABLE subscriber ALTER allow_find SET NOT NULL;
1047
+		ALTER TABLE subscriber ALTER allow_find SET DEFAULT '0';
1048
+
1049
+		UPDATE subscriber SET phplib_id = DEFAULT, phone = DEFAULT, datetime_modified = DEFAULT,
1050
+		confirmation = DEFAULT, flag = DEFAULT, sendnotification = DEFAULT, 
1051
+		greeting = DEFAULT, allow_find = DEFAULT;"
1052
+
1053
+if [ $? -ne 0 ] ; then
1054
+	echo "Failed to alter subscriber table for serweb!"
1055
+	exit 1
1056
+fi
1057
+
1058
+sql_query "$1" < $DB_SCHEMA/serweb-create.sql
1059
+
1060
+if [ $? -ne 0 ] ; then
1061
+	echo "Failed to create presence tables!"
1062
+	exit 1
1063
+fi
1064
+
1065
+sql_query "$1" "GRANT ALL PRIVILEGES ON TABLE phonebook, phonebook_id_seq, pending,
1066
+		pending_id_seq, active_sessions, server_monitoring, server_monitoring_agg,
1017 1067
 		usr_preferences_types, admin_privileges to $DBRWUSER; 
1018
-	GRANT SELECT ON TABLE phonebook, pending, active_sessions,
1019
-		server_monitoring, server_monitoring_agg,
1020
-		usr_preferences_types, admin_privileges to $DBROUSER;" 
1068
+		GRANT SELECT ON TABLE phonebook, pending, active_sessions, server_monitoring,
1069
+		server_monitoring_agg, usr_preferences_types, admin_privileges to $DBROUSER;" 
1070
+
1071
+if [ $? -ne 0 ] ; then
1072
+	echo "Grant privileges to serweb tables failed!"
1073
+	exit 1
1074
+fi
1021 1075
 
1022 1076
 if [ -z "$NO_USER_INIT" ] ; then
1023 1077
 	if [ -z "$SIP_DOMAIN" ] ; then
1024 1078
 		prompt_realm
1025 1079
 	fi
1026 1080
 	credentials
1027
-	INITIAL_INSERT="
1028
-		INSERT INTO subscriber
1029
-			($USERCOL, password, first_name, last_name, phone,
1030
-			email_address, datetime_created, datetime_modified, confirmation,
1081
+	sql_query "$1" "INSERT INTO subscriber ($USERCOL, password, first_name, last_name,
1082
+			phone, email_address, datetime_created, datetime_modified, confirmation,
1031 1083
 			flag, sendnotification, greeting, ha1, domain, ha1b, phplib_id )
1032
-			VALUES ( 'admin', '$DBRWPW', 'Initial', 'Admin', '123',
1033
-			'root@localhost', '2002-09-04 19:37:45', '$DUMMY_DATE',
1034
-			'57DaSIPuCm52UNe54LF545750cfdL48OMZfroM53', 'o', '', '',
1035
-			'$HA1', '$SIP_DOMAIN', '$HA1B',
1036
-			'$PHPLIB_ID' );
1037
-		INSERT INTO admin_privileges ($USERCOL, domain, priv_name, priv_value)
1038
-		VALUES ('admin', '$SIP_DOMAIN', 'is_admin', '1');
1039
-		INSERT INTO admin_privileges ($USERCOL, domain, priv_name, priv_value)
1040
-		VALUES ('admin', '$SIP_DOMAIN', 'change_privileges', '1');"
1041
-else
1042
-	INITIAL_INSERT=""
1043
-fi
1044
-
1045
-echo "creating serweb tables into $1 ..."
1084
+			VALUES ( 'admin', '$DBRWPW', 'Initial', 'Admin', '123', 'root@localhost', 
1085
+			'2002-09-04 19:37:45', '$DUMMY_DATE', '57DaSIPuCm52UNe54LF545750cfdL48OMZfroM53',
1086
+			'o', '', '', '$HA1', '$SIP_DOMAIN', '$HA1B', '$PHPLIB_ID' );
1087
+			INSERT INTO admin_privileges ($USERCOL, domain, priv_name, priv_value)
1088
+			VALUES ('admin', '$SIP_DOMAIN', 'is_admin', '1');
1089
+			INSERT INTO admin_privileges ($USERCOL, domain, priv_name, priv_value)
1090
+			VALUES ('admin', '$SIP_DOMAIN', 'change_privileges', '1');"
1046 1091
 
1047
-sql_query <<EOF
1048
-$USE_CMD $1;
1049
-
1050
-INSERT INTO version VALUES ( 'phonebook', '1');
1051
-INSERT INTO version VALUES ( 'pending', '6');
1052
-INSERT INTO version VALUES ( 'active_sessions', '1');
1053
-INSERT INTO version VALUES ( 'server_monitoring', '1');
1054
-INSERT INTO version VALUES ( 'server_monitoring_agg', '1');
1055
-INSERT INTO version VALUES ( 'usr_preferences_types', '1');
1056
-INSERT INTO version VALUES ( 'admin_privileges', '1');
1057
-
1058
-/*
1059
- * Extend table 'subscriber' with serweb specific columns
1060
- * It would be easier to drop the table and create a new one,
1061
- * but in case someone want to add serweb and has already
1062
- * a populated subscriber table, we show here how this
1063
- * can be done without deleting the existing data.
1064
- * Tested with postgres 7.4.7
1065
- */
1066
-ALTER TABLE subscriber ADD COLUMN phplib_id varchar(32);
1067
-ALTER TABLE subscriber ADD COLUMN phone varchar(15);
1068
-ALTER TABLE subscriber ADD COLUMN datetime_modified timestamp;
1069
-ALTER TABLE subscriber ADD COLUMN confirmation varchar(64);
1070
-ALTER TABLE subscriber ADD COLUMN flag char(1);
1071
-ALTER TABLE subscriber ADD COLUMN sendnotification varchar(50);
1072
-ALTER TABLE subscriber ADD COLUMN greeting varchar(50);
1073
-ALTER TABLE subscriber ADD COLUMN allow_find char(1);
1074
-ALTER TABLE subscriber ADD CONSTRAINT phplib_id_key unique (phplib_id);
1075
-
1076
-ALTER TABLE subscriber ALTER phplib_id SET NOT NULL;
1077
-ALTER TABLE subscriber ALTER phplib_id SET DEFAULT '';
1078
-ALTER TABLE subscriber ALTER phone SET NOT NULL;
1079
-ALTER TABLE subscriber ALTER phone SET DEFAULT '';
1080
-ALTER TABLE subscriber ALTER datetime_modified SET NOT NULL;
1081
-ALTER TABLE subscriber ALTER datetime_modified SET DEFAULT NOW();
1082
-ALTER TABLE subscriber ALTER confirmation SET NOT NULL;
1083
-ALTER TABLE subscriber ALTER confirmation SET DEFAULT '';
1084
-ALTER TABLE subscriber ALTER flag SET NOT NULL;
1085
-ALTER TABLE subscriber ALTER flag SET DEFAULT 'o';
1086
-ALTER TABLE subscriber ALTER sendnotification SET NOT NULL;
1087
-ALTER TABLE subscriber ALTER sendnotification SET DEFAULT '';
1088
-ALTER TABLE subscriber ALTER greeting SET NOT NULL;
1089
-ALTER TABLE subscriber ALTER greeting SET DEFAULT '';
1090
-ALTER TABLE subscriber ALTER allow_find SET NOT NULL;
1091
-ALTER TABLE subscriber ALTER allow_find SET DEFAULT '0';
1092
-
1093
-UPDATE subscriber SET phplib_id = DEFAULT, phone = DEFAULT, datetime_modified = DEFAULT, 
1094
-                      confirmation = DEFAULT, flag = DEFAULT, sendnotification = DEFAULT, 
1095
-                      greeting = DEFAULT, allow_find = DEFAULT ;
1096
-
1097
-/*
1098
- * Table structure for table 'active_sessions' -- web stuff
1099
- */
1100
-CREATE TABLE active_sessions (
1101
-  sid varchar(32) NOT NULL default '',
1102
-  name varchar(32) NOT NULL default '',
1103
-  val text,
1104
-  changed varchar(14) NOT NULL default '',
1105
-  PRIMARY KEY  (name,sid)
1106
-) $TABLE_TYPE;
1107
-CREATE INDEX ch_active_sess_indx ON active_sessions (changed);
1108
-
1109
-
1110
-/*
1111
- * Table structure for table 'pending' -- unconfirmed subscribtion
1112
- * requests
1113
- */
1114
-CREATE TABLE pending (
1115
-  id $AUTO_INCREMENT,
1116
-  phplib_id varchar(32) NOT NULL default '',
1117
-  $USERCOL varchar(64) NOT NULL default '',
1118
-  domain varchar(128) NOT NULL default '',
1119
-  password varchar(25) NOT NULL default '',
1120
-  first_name varchar(25) NOT NULL default '',
1121
-  last_name varchar(45) NOT NULL default '',
1122
-  phone varchar(15) NOT NULL default '',
1123
-  email_address varchar(50) NOT NULL default '',
1124
-  datetime_created $TIMESTAMP,
1125
-  datetime_modified $TIMESTAMP,
1126
-  confirmation varchar(64) NOT NULL default '',
1127
-  flag char(1) NOT NULL default 'o',
1128
-  sendnotification varchar(50) NOT NULL default '',
1129
-  greeting varchar(50) NOT NULL default '',
1130
-  ha1 varchar(128) NOT NULL default '',
1131
-  ha1b varchar(128) NOT NULL default '',
1132
-  allow_find char(1) NOT NULL default '0',
1133
-  timezone varchar(128) default NULL,
1134
-  rpid varchar(128) default NULL,
1135
-  UNIQUE ($USERCOL, domain),
1136
-  UNIQUE (phplib_id)
1137
-) $TABLE_TYPE;
1138
-CREATE INDEX username_pend_indx ON pending ($USERCOL);
1139
-
1140
-
1141
-/*
1142
- * Table structure for table 'phonebook' -- user's phonebook
1143
- */
1144
-CREATE TABLE phonebook (
1145
-  id $AUTO_INCREMENT,
1146
-  $USERCOL varchar(64) NOT NULL default '',
1147
-  domain varchar(128) NOT NULL default '',
1148
-  fname varchar(32) NOT NULL default '',
1149
-  lname varchar(32) NOT NULL default '',
1150
-  sip_uri varchar(128) NOT NULL default ''
1151
-) $TABLE_TYPE;
1152
-
1153
-
1154
-/*
1155
- * Table structure for table 'server_monitoring'
1156
- */
1157
-CREATE TABLE server_monitoring (
1158
-  time $TIMESTAMP,
1159
-  id bigint NOT NULL default '0',
1160
-  param varchar(32) NOT NULL default '',
1161
-  value int NOT NULL default '0',
1162
-  increment int NOT NULL default '0',
1163
-  PRIMARY KEY  (id,param)
1164
-) $TABLE_TYPE;
1165
-
1166
-
1167
-/*
1168
- * Table structure for table 'usr_preferences_types' -- types of atributes 
1169
- * in preferences
1170
- */
1171
-CREATE TABLE usr_preferences_types (
1172
-  att_name varchar(32) NOT NULL default '',
1173
-  att_rich_type varchar(32) NOT NULL default 'string',
1174
-  att_raw_type int NOT NULL default '2',
1175
-  att_type_spec text,
1176
-  default_value varchar(100) NOT NULL default '',
1177
-  PRIMARY KEY  (att_name)
1178
-) $TABLE_TYPE;
1179
-
1180
-
1181
-/*
1182
- * Table structure for table 'server_monitoring_agg'
1183
- */
1184
-CREATE TABLE server_monitoring_agg (
1185
-  param varchar(32) NOT NULL default '',
1186
-  s_value int NOT NULL default '0',
1187
-  s_increment int NOT NULL default '0',
1188
-  last_aggregated_increment int NOT NULL default '0',
1189
-  av real NOT NULL default '0',
1190
-  mv int NOT NULL default '0',
1191
-  ad real NOT NULL default '0',
1192
-  lv int NOT NULL default '0',
1193
-  min_val int NOT NULL default '0',
1194
-  max_val int NOT NULL default '0',
1195
-  min_inc int NOT NULL default '0',
1196
-  max_inc int NOT NULL default '0',
1197
-  lastupdate $TIMESTAMP,
1198
-  PRIMARY KEY  (param)
1199
-) $TABLE_TYPE;
1200
-
1201
-
1202
-/*
1203
- * Table structure for table 'admin_privileges' -- multidomain serweb
1204
- * ACL control
1205
- */
1206
-
1207
-CREATE TABLE admin_privileges (
1208
-  $USERCOL varchar(64) NOT NULL default '',
1209
-  domain varchar(128) NOT NULL default '',
1210
-  priv_name varchar(64) NOT NULL default '',
1211
-  priv_value varchar(64) NOT NULL default '',
1212
-  PRIMARY KEY  ($USERCOL,priv_name,priv_value,domain)
1213
-) $TABLE_TYPE;
1214
-
1215
-
1216
-/*
1217
- * emulate mysql proprietary functions used by the serweb
1218
- * in postgresql
1219
- */
1220
-CREATE FUNCTION "truncate" (numeric,int) RETURNS numeric AS 'SELECT trunc(\$1,\$2);' LANGUAGE 'sql';
1221
-create function unix_timestamp(timestamp) returns integer as 'select date_part(''epoch'', \$1)::int4 as result' language 'sql';
1222
-
1223
-$INITIAL_INSERT
1224
-
1225
-$GRANT_SERWEB_CMD
1092
+	if [ $? -ne 0 ] ; then
1093
+		echo "Failed to create serweb credentials tables!"
1094
+		exit 1
1095
+	fi
1096
+fi
1226 1097
 
1227
-EOF
1098
+# emulate mysql proprietary functions used by the serweb in postgresql
1099
+sql_query "$1" "CREATE FUNCTION "truncate" (numeric,int) RETURNS numeric AS 'SELECT trunc(\$1,\$2);' LANGUAGE 'sql';
1100
+		create function unix_timestamp(timestamp) returns integer as 'select date_part(''epoch'', \$1)::int4 
1101
+		as result' language 'sql';"
1228 1102
 
1229 1103
 if [ $? -ne 0 ] ; then
1230
-	echo "Failed to create serweb tables!"
1104
+	echo "Failed to create mysql emulation functions for serweb!"
1231 1105
 	exit 1
1232 1106
 fi
1233 1107