OpenACS 4.0 Guidelines

by Don Baccus and Ben Adida.

Simple Issues

We faced most of these issues at some point during the process of developing OpenACS 3.x. It's now time to standardize these and do everything correctly in 4.x!

Sequences

Use Dan Wickstrom's sequence view hack. The idea is to structure a view around a sequence so that the foo_seq.nextval construct can work.

create sequence user_id_seq;
create view user_id_sequence as select nextval('user_id_seq') as nextval;

Empty Strings

Be stricter, not Oracle'ish. Default all varchars to empty string not null.

create table foo (
       some_text varchar(100) default '' not null
);

Sysdate

No using sysdate in the data model. This is pretty important given that we don't really want to have the basic data-model depend on a PL/SQL procedure. In general, avoid user-defined functions in the data model. Otherwise, the sysdate() function works fine.

Case/Decode, NVL/Coalesce

These issues are solved, but let's just remind everyone how they should be solved

In Oracle, a decode statement looks like this:

select sum(decode(available_p,'t', 1,0)) as n_available from foo;

In PG, this looks like this:

select sum(case when available_p='t' then 1 else 0 end) as n_available from foo;

In Oracle, an NVL statement looks like:

select user_id, nvl(screen_name, '(no screen name)') from users;

In PG, it looks like:

select user_id, coalesce(screen_name, '(no screen name)') from users;

Note that coalesce is more powerful than NVL in that you can list any number of arguments, and the first non-null one will be returned. With NVL, you have to nest a number of NVL statements to achieve the same effect.

Outer joins

conversion examples by Don.

Dispatching New Queries

This is a pretty involved topic which will be handled in a separate document. We note one important thing: we can easily identify which page we are in using [ns_conn url] and the Tcl procedure we are in using ns_info. This means that the unique tagging scheme used in ACS 4.0 will work perfectly fine to replace simple SQL queries using a different source.

Data Model Changes

We need to standardize ways in which a data model is modified from Oracle to Postgres (7.1 or later):

PL/pgSQL

Things for PG/GB to do

Questions for aD

Random Issues

Immediate Next Steps


dhogaza@pacifier.com / ben@mit.edu