diff --git a/config/config.php b/config/config.php index daa0991d..9c6a8484 100644 --- a/config/config.php +++ b/config/config.php @@ -8,7 +8,7 @@ $c->pg_connect[] = 'dbname=caldav port=5433 user=general'; $c->pg_connect[] = 'dbname=caldav port=5432 user=general'; - $c->dbg['ALL'] = 1; +// $c->dbg['ALL'] = 1; $c->dbg['propfind'] = 1; $c->dbg['report'] = 1; // $c->dbg['get'] = 1; @@ -17,6 +17,7 @@ // $c->dbg['icalendar'] = 1; $c->dbg['vevent'] = 1; $c->dbg['caldav'] = 1; +// $c->dbg['user'] = 1; $c->collections_always_exist = false; diff --git a/dba/base-data.sql b/dba/base-data.sql new file mode 100644 index 00000000..67b1b318 --- /dev/null +++ b/dba/base-data.sql @@ -0,0 +1,16 @@ +-- Some sample data to prime the database... + +-- FIXME: Only insert the rows if they are not there already. +INSERT INTO roles ( role_no, role_name ) VALUES( 1, 'Admin'); +INSERT INTO roles ( role_no, role_name ) VALUES(2, 'Group Target'); + +-- Set the insert sequence to the next number, with a minimum of 10 +SELECT setval('roles_role_no_seq', (SELECT 10 UNION SELECT role_no FROM roles ORDER BY 1 DESC LIMIT 1) ); + +INSERT INTO usr ( user_no, active, email_ok, updated, username, password, fullname, email ) + VALUES ( 1, TRUE, current_date, current_date, 'admin', '**nimda', 'Calendar Administrator', 'calendars@example.net' ); + +INSERT INTO role_member (user_no, role_no) VALUES(1, 1); + +-- Set the insert sequence to the next number, with a minimum of 1000 +SELECT setval('usr_user_no_seq', (SELECT 1000 UNION SELECT user_no FROM usr ORDER BY 1 DESC LIMIT 1) ); diff --git a/dba/create-database.sh b/dba/create-database.sh index 92e008c3..3315d429 100755 --- a/dba/create-database.sh +++ b/dba/create-database.sh @@ -21,4 +21,5 @@ psql -q -f "${DBADIR}/rscds.sql" "${DBNAME}" 2>&1 | egrep -v "(^CREATE |^GRANT|^ psql -q -f "${DBADIR}/caldav_functions.sql" "${DBNAME}" +psql -q -f "${DBADIR}/base-data.sql" "${DBNAME}" psql -q -f "${DBADIR}/sample-data.sql" "${DBNAME}" diff --git a/dba/sample-data.sql b/dba/sample-data.sql index 7c454572..be541863 100644 --- a/dba/sample-data.sql +++ b/dba/sample-data.sql @@ -1,11 +1,5 @@ -- Some sample data to prime the database... - -INSERT INTO roles ( role_no, role_name ) VALUES( 1, 'Admin'); -SELECT setval('roles_role_no_seq', 1); - -INSERT INTO usr ( user_no, active, email_ok, updated, username, password, fullname, email ) - VALUES( 1, TRUE, current_date, current_date, 'admin', '**nimda', 'Calendar Administrator', 'calendars@example.net' ); -INSERT INTO role_member (user_no, role_no) VALUES( 1, 1); +-- base-data.sql should be processed before this INSERT INTO usr ( user_no, active, email_ok, updated, username, password, fullname, email ) VALUES( 2, TRUE, current_date, current_date, 'andrew', '**x', 'Andrew McMillan', 'andrew@catalyst.net.nz' ); @@ -30,31 +24,30 @@ INSERT INTO usr ( user_no, active, email_ok, updated, username, password, fullna INSERT INTO usr ( user_no, active, email_ok, updated, username, password, fullname, email ) VALUES( 200, TRUE, current_date, current_date, 'resmgr1', '*salt*unpossible', 'Resource Managers', 'resource-managers@example.net' ); +INSERT INTO role_member (user_no, role_no) VALUES( 200, 2); INSERT INTO usr ( user_no, active, email_ok, updated, username, password, fullname, email ) VALUES( 300, TRUE, current_date, current_date, 'teamclient1', '*salt*unpossible', 'Team for Client1', 'team-client1@example.net' ); +INSERT INTO role_member (user_no, role_no) VALUES( 300, 2); SELECT setval('usr_user_no_seq', 1000); -INSERT INTO relationship_type ( rt_id, rt_name, rt_isgroup, rt_inverse, confers, prefix_match ) - VALUES( 1, 'Meeting Admin', TRUE, NULL, 'RW', '' ); +INSERT INTO relationship_type ( rt_id, rt_name, rt_isgroup, confers, prefix_match ) + VALUES( 1, 'Administers Group', TRUE, 'RW', '' ); -INSERT INTO relationship_type ( rt_id, rt_name, rt_isgroup, rt_inverse, confers, prefix_match ) - VALUES( 2, 'Assisted by', FALSE, 3, 'RW', '' ); +INSERT INTO relationship_type ( rt_id, rt_name, rt_isgroup, confers, prefix_match ) + VALUES( 2, 'Is Assisted by', FALSE, 'RW', '' ); -INSERT INTO relationship_type ( rt_id, rt_name, rt_isgroup, rt_inverse, confers, prefix_match ) - VALUES( 3, 'Assistant to', FALSE, 2, 'RW', '' ); +INSERT INTO relationship_type ( rt_id, rt_name, rt_isgroup, confers, prefix_match ) + VALUES( 3, 'Is a member of group', FALSE, 'R', '' ); -INSERT INTO relationship_type ( rt_id, rt_name, rt_isgroup, rt_inverse, confers, prefix_match ) - VALUES( 4, 'Member of team', FALSE, 4, 'R', '' ); - -INSERT INTO relationship_type ( rt_id, rt_name, rt_isgroup, rt_inverse, confers, prefix_match ) - VALUES( 5, 'Meeting Resource', TRUE, NULL, 'RW', '' ); +INSERT INTO relationship_type ( rt_id, rt_name, rt_isgroup, confers, prefix_match ) + VALUES( 4, 'Administers Resource', FALSE, 'RW', '' ); -- The resources for meetings -INSERT INTO relationship ( from_user, to_user, rt_id ) VALUES( 200, 100, 5 ); -INSERT INTO relationship ( from_user, to_user, rt_id ) VALUES( 200, 101, 5 ); +INSERT INTO relationship ( from_user, to_user, rt_id ) VALUES( 200, 100, 4 ); +INSERT INTO relationship ( from_user, to_user, rt_id ) VALUES( 200, 101, 4 ); -- The people who administer meetings INSERT INTO relationship ( from_user, to_user, rt_id ) VALUES( 10, 200, 1 ); @@ -65,6 +58,6 @@ INSERT INTO relationship ( from_user, to_user, rt_id ) VALUES( 30, 200, 1 ); INSERT INTO relationship ( from_user, to_user, rt_id ) VALUES( 20, 30, 2 ); -- Between a team -INSERT INTO relationship ( from_user, to_user, rt_id ) VALUES( 20, 300, 4 ); -INSERT INTO relationship ( from_user, to_user, rt_id ) VALUES( 10, 300, 4 ); -INSERT INTO relationship ( from_user, to_user, rt_id ) VALUES( 30, 300, 4 ); +INSERT INTO relationship ( from_user, to_user, rt_id ) VALUES( 20, 300, 3 ); +INSERT INTO relationship ( from_user, to_user, rt_id ) VALUES( 10, 300, 3 ); +INSERT INTO relationship ( from_user, to_user, rt_id ) VALUES( 30, 300, 3 ); diff --git a/dba/update-database.sh b/dba/update-database.sh new file mode 100644 index 00000000..fbf99652 --- /dev/null +++ b/dba/update-database.sh @@ -0,0 +1,19 @@ +#!/bin/sh +# +# Update the RSCDS database to the latest schema version and base data +# + +DBNAME="${1:-rscds}" + +DBADIR="`dirname \"$0\"`" + +# Apply any patches. +# FIXME: We shouldn't really apply patches we already have installed, although +# it should be safe enough since any patch which is not idempotent should be +# denied multiple application through the AWL schema management functions. +for PATCHFILE in "${DBADIR}/patches/patch-*.sql"; do + psql -q -f "${PATCHFILE}" "${DBNAME}" +done + +# Update the base data +psql -q -f "${DBADIR}/base-data.sql" "${DBNAME}"