Index: openacs-4/packages/acs-core-docs/www/tutorial-database.html =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-core-docs/www/tutorial-database.html,v diff -u -r1.44.2.12 -r1.44.2.13 --- openacs-4/packages/acs-core-docs/www/tutorial-database.html 19 Nov 2016 09:21:55 -0000 1.44.2.12 +++ openacs-4/packages/acs-core-docs/www/tutorial-database.html 6 Jan 2017 09:18:42 -0000 1.44.2.13 @@ -2,7 +2,7 @@ Setting Up Database Objects

Setting Up Database Objects

by Joel Aufrecht

OpenACS docs are written by the named authors, and may be edited by OpenACS documentation staff. -

Code the data model

We create all database objects with scripts in the +

Code the data model

We create all database objects with scripts in the myfirstpackage/sql/ directory. All database scripts are database-specific and are thus in either the myfirstpackage/sql/oracle or @@ -32,13 +32,13 @@ repository functions to simplify our database creation. (More information about ACS Objects. More information about the Content Repository.) -

Figure 9.2. Tutorial Data Model

Tutorial Data Model

The top of each sql file has some +

Figure 9.2. Tutorial Data Model

Tutorial Data Model

The top of each sql file has some standard comments, including doc tags such as @author which will be picked up by the API browser. The string $Id$ will automatically be expanded when the file is checked in to cvs.

[$OPENACS_SERVICE_NAME ~]$ cd /var/lib/aolserver/$OPENACS_SERVICE_NAME/packages/myfirstpackage/sql/postgresql
-[$OPENACS_SERVICE_NAME postgresql]$ emacs myfirstpackage-create.sql

Paste the text below into the file, save, and close.

Figure 9.3. The Database Creation Script

-- creation script
+[$OPENACS_SERVICE_NAME postgresql]$ emacs myfirstpackage-create.sql

Paste the text below into the file, save, and close.

Figure 9.3. The Database Creation Script

-- creation script
 --
 -- @author joel@aufrecht.org
 -- @cvs-id &Id:$
@@ -62,7 +62,7 @@
     object.  Notice the use of "mfp."  This is derived from "My
     First Package" and ensures that our object is unlikely to conflict
     with objects from other packages.

Create a database file to drop everything if the package is uninstalled.

-[$OPENACS_SERVICE_NAME postgresql]$ emacs myfirstpackage-drop.sql

Figure 9.4. Database Deletion Script

-- drop script
+[$OPENACS_SERVICE_NAME postgresql]$ emacs myfirstpackage-drop.sql

Figure 9.4. Database Deletion Script

-- drop script
 --
 -- @author joel@aufrecht.org
 -- @cvs-id &Id:$
@@ -82,7 +82,7 @@
                          0
 (1 row)
 
-[$OPENACS_SERVICE_NAME postgresql]$

If there are errors, use them to debug the sql file and try again. If there are errors in the database table creation, you may need to run the drop script to drop the table so that you can recreate it. The drop script will probably have errors since some of the things it's trying to drop may be missing. They can be ignored.

Once you get the same output as shown above, test the drop script:

[$OPENACS_SERVICE_NAME postgresql]$ psql service0 -f myfirstpackage-drop.sql
+[$OPENACS_SERVICE_NAME postgresql]$

If there are errors, use them to debug the sql file and try again. If there are errors in the database table creation, you may need to run the drop script to drop the table so that you can recreate it. The drop script will probably have errors since some of the things it's trying to drop may be missing. They can be ignored.

Once you get the same output as shown above, test the drop script:

[$OPENACS_SERVICE_NAME postgresql]$ psql service0 -f myfirstpackage-drop.sql
 
  content_type__drop_type
 -------------------------