Read this first
---------------

As of version 2.2, Services no longer supports SQL databases. The 
documentation concern SQL is available below. To use Services 2.2, you 
will need to switch to the flatfile backend.


SQL Notes
---------

Atheme supports SQL databases. SQL is not "live" for a number of
reasons. Most significantly, better, more portable, and safer
functionality is provided by Atheme's XML-RPC interface.

To repeat, the SQL backends do not pick up any changes to the
database at run time and only write changes to the database every
5 minutes (or configurable time), and therefore they cannot (or only
to a very limited extent) be used to create web interfaces to services.

Additionally the SQL backends are less well tested than flatfile, and
may lack some recent features (nickname access lists (/ns access),
services ignores).

Schema files are available in the SQL/ directory.

Note that during 0.3 development, several columns changed from
VARCHAR to TEXT.


PostgreSQL
----------

To initialize the database, use:

	psql <database> < atheme_init.pgsql

Upgrade information:

Note that the several aspects of the schema have changed. Some
information was moved to metadata. The only major issue with this is
with the ENTRYMSG and URL columns in the CHANNELS table. Run
0.3beta2 against your database and the values will be automatically
converted to metadata. Then, it is safe to drop those columns.

Note also that the FAILNUM, LASTFAIL, and LASTFAILON columns in the
ACCOUNTS table have been removed.

The PostgreSQL FAQ has this to say on changing a column's data type:

	Changing the data type of a column can be done easily in 8.0
	and later with ALTER TABLE ALTER COLUMN TYPE.

	In earlier releases, do this:

	BEGIN;
	 ALTER TABLE tab ADD COLUMN new_col new_data_type;
	 UPDATE tab SET new_col = CAST(old_col AS new_data_type);
	 ALTER TABLE tab DROP COLUMN old_col;
	COMMIT;

	You might then want to do VACUUM FULL tab to reclaim
	the disk space used by the expired rows.

(http://www.postgresql.org/docs/faqs.FAQ.html#4.3)


Switching to a SQL backend
--------------------------

Switching to a SQL backend is relatively painless; just make sure
that your database {} block is configured properly.
  Hint: /msg operserv rehash

Once you have a properly configured database{} block, you can simply
load the replacement backend via:
  /msg operserv modload ../backend/<replacement backend>

After the backend is loaded, you can export your data by using
OperServ's UPDATE command.

Once you have loaded the replacement backend, you are now on
SQL. You will probably want to switch your backend module out in
the configuration file, as your flatfile database will no longer
be updated. You may want to restart Services to ensure that the
transition was successful after updating the config file.

Switching from a SQL backend to flatfile can be done similarly.
