Database README for Portal 0.4.00

Created by James Pattie, (james@pcxperience.com)
11/14/2000.  Last Updated 03/18/2005.
Copyright (c) 2000-2005 Xperience, Inc.
(http://www.pcxperience.com/)

The setupDB.pl script in /usr/lib/pcx_portal is the ONLY SUPPORTED mechanism
for doing database upgrades and new database installs.  If you find any bugs
please let me know.  Include any output that the script generated (you can
edit out any sensitive data) so I can try and track down the issue.

*****************

NOTE:  When upgrading from 0.2.xx to 0.3.xx the app_tb, app_servers_tb and
company_app_tb tables had the db_host field added and it defaults to 127.0.0.1.
If this is wrong, you will need to manually fix the entries in the database.

*****************

This document details how to manually create the databases needed by the Portal.

First make sure you have PostgreSQL 7.3 or later installed or 
MySQL 3.23.24 or later installed.

Note:  If using MySQL and times are being set in GMT then add TZ="timezone"
to the /etc/profile and restart mysqld.  This will convert all dates/times to
be relative to your timezone.  (Use this if you want to see log entries based
upon your local time.)

** All .psql and .mysql scripts are located in the install/Portal directory of
   the webserver directory.
   Upgrade db script files are in the install/Portal/upgrade directory.

Your database system must be configured to accept TCP connections.
If using PostgreSQL, the preferred way to configure this is by editing:
  /var/lib/pgsql/data/postgresql.conf
  on Debian this is /etc/postgresql/postgresql.conf

  uncomment the following line by removing the #.
  #tcpip_socket = false
  and change the false to true.

  Restart PostgreSQL and you can now accept TCP connections.


On the machine that you are going to configure the Portal to point to for the
Portal Database:
	Create the 'portal' user (or whatever you want to name it).
	PostgreSQL: createuser -U postgres -A -d portal
		substitute portal with the name you chose if different.

	MySQL: mysql -p mysql
               INSERT INTO user VALUES ('hostname', 'portal', PASSWORD('password'), 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'N', 'N', 'N', 'N', 'Y', 'Y', 'Y', 'Y');
               replace hostname with the name of the server, portal with the
               name of the user you want, and password with the password to
               use for that user.  If you change the username to be other than
               portal, you need to modify the portal_db.mysql and
               billing_db.mysql files to use that user name in the GRANT
               statement at the bottom of those files.
               Do this statement multiple times changing the hostname value for
               each possible server that may need to connect to the database.
               When done, issue the FLUSH PRIVILEGES command to make the changes
               go into affect.


	Create the 'portal_db' database (or whatever you want to call it).
	PostgreSQL: createdb -U portal portal_db
		substitute portal and portal_db for the correct values.

	MySQL: mysqladmin -p create portal_db

	Create the tables for the 'portal_db' database.
	PostgreSQL: psql -U portal portal_db < portal_db.psql
		substitue portal and portal_db (left of < only) for the values
		you defined.

	MySQL: mysql -p -u portal portal_db
               source portal_db.mysql

On the machine that you are going to configure the Portal to point to for the
Billing Database:
        (Only do this step if not on the same machine as the Portal Database)
	Create the 'portal' user (or whatever you want to name it).
	PostgreSQL: createuser -U postgres -A -d portal
		substitute portal with the name you chose if different.

	MySQL: mysql -p mysql
               INSERT INTO user VALUES ('hostname', 'portal', PASSWORD('password'), 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'N', 'N', 'N', 'N', 'Y', 'Y', 'Y', 'Y');
               replace hostname with the name of the server, portal with the
               name of the user you want, and password with the password to
               use for that user.  If you change the username to be other than
               portal, you need to modify the portal_db.mysql and
               billing_db.mysql files to use that user name in the GRANT
               statement at the bottom of those files.
               Do this statement multiple times changing the hostname value for
               each possible server that may need to connect to the database.
               When done, issue the FLUSH PRIVILEGES command to make the changes
               go into affect.


	Create the 'billing_db' database (or whatever you want to call it).
	PostgreSQL: createdb -U portal billing_db
		substitute portal and billing_db for the correct values.

	MySQL: mysqladmin -p create billing_db

	Create the tables for the 'billing_db' database.
	PostgreSQL: psql -U portal billing_db < portal_db.psql
		substitue portal and billing_db (left of < only) for the values
		you defined.

	MySQL: mysql -p -u portal billing_db
               source billing_db.mysql

If using PostgreSQL:
Now on each database machine, make the following entry in
  /var/lib/pgsql/data/pg_hba.conf:
  
  7.3+ installs:
      host  all  SERVER IP 255.255.255.255 md5

replace SERVER IP with the IP Address of the server.

7.2+ installs:
  psql -U postgres template1
  
  template1# ALTER USER portal WITH ENCRYPTED PASSWORD '<password>';
  ALTER USER
  template1# \q

  substitute <password> with the password you are using.

Final Notes:
Now you can make and configure the Portal using the information just used to
create the portal and billing databases.

The updateDBSettings.pl script is now used to add entries for config settings,
etc. to the Portal Database that are not schema changes.
