This class manipulates the Archiveopteryx database schema. It knows all the schema revisions and can upgrade a database to the latest schema version automatically.
Creates a new Schema object to check that the existing schema is one that the running server understands. If upgrade is true (which it is not, by default) and the schema is too old, it will be upgraded. (If upgrade is false, a "please upgrade" message will be issued.)
If commit is false (which it also is not, by default), the SQL statements performed during the upgrade will not be COMMITted, but their success or failure will be reported.
This function is responsible for checking that the running server is compatible with the existing database schema, and to notify owner when the verification is complete.
If the schema is not compatible, a disaster is logged.
The function expects to be called from ::main(), and should be the first database transaction.
This private helper logs a description of the step currently being made.
Checks or upgrades the schema as required.
Given an error message s and, optionally, the query q that caused the error, this private helper function logs a suitable set of Disaster messages (including the Query::description()) and sets the error message for d->result to s.
Returns a Query object that can be used to track the progress of the Schema verification or upgradation. The Query's owner is set by the constructor when the Schema is created.
Uses a helper function to upgrade the schema from d->revision to d->revision+1. Returns false if the helper has not yet completed its work.
Add "on delete cascade" to the mailboxes.owner reference.
Delete the revisions sequence.
Reverse stepTo10(). We don't want to delete rows in mailboxes.
Create the annotation_names and annotations tables.
Add the tables required to support views.
Add "on delete cascade" to the subscriptions/annotations.owner references.
Add the aliases table.
Drop the aliases table from #16 (never released) and recreate it, with a reference to the address, and a link from users.
Add the scripts table.
Add the date_fields table.
Changes the type of users.login and users.secret to text to remove the made-up length restriction on the earlier varchar field.
Populate the date_fields table from header_fields.
Remove unnecessary stuff from annotations.
For any two flag names that differ only in case, moves all flags from one to the other and removes the unused one. Then adds an index to ensure uniqueness in the future.
Add the deleted_messages table.
Create threads/thread_members if they don't exist already.
Adds the modsequences table.
Alters deleted_messages.deleted_at to be a timestamp with time zone.
Add "on delete cascade" to the mailboxes.owner reference.
Create the deliveries table.
Replace views.suidnext with nextmodseq.
Merges the binary_parts table into bodyparts.
Create the access_keys table.
Add indexes on addresses and deleted_messages.
The address_fields table lacks many of the rows it should have had in revisions prior to 33. This upgrade removes all existing rows, adds a new column with data we need to keep, parses header_fields to generate the new rows, and kills the now unnecessary header_fields rows.
Well, actually it doesn't do the last step yet. The MessageHeaderFetcher is careful to disregard these rows, so the do no harm.
Add some indexes to speed up message deletion.
Add tried_at to deliveries.
Add sender to deliveries too.
Grant "update" on deliveries to aox, because although stepTo28() did that, schema/grant-privileges did not.
Create the unparsed_messages table if it doesn't exist already. After this revision, the table exists, but is unfilled; and the upgraded schema and schema.pg ought to be in sync.
Grant insert on unparsed_messages.
Add a unique constraint to scripts.
Move message flags from the messages table to the extra_flags table, now renamed just "flags".
Relax the deleted_messages.deleted_by constraint.
Insert modsequences for any messages that don't have them.
Make nextmodseq be per-mailbox.
Add some primary keys (the easy ones).
Add an index on users.login.
Remove duplicates from deleted_messages, and add a primary key.
Unconstrain annotations.owner and add a surrogate key.
Grant select,update on annotations_id_seq.
Grant privileges on threads and thread_members.
Add some indices on header_fields, address_fields, and flags.
Split delivery_recipients away from deliveries.
Add delivery_recipients.action and last_attempt.
We need permissions on the delivery_recipients sequence too.
Make (mailbox,uid) unique in deliveries.
Convert mUTF-7 mailbox names to UTF-8.
Create the vacation_responses table.
Rename vacation_responses to autoresponses. (We do this by dropping the old table and creating a new one, so that the sequence is also renamed.)
Add a missing "on delete cascade" clause to scripts.
Delete duplicate addresses: By mistake the unique index used a case-sensitive domain. We keep the oldest version seen.
Move bodyparts.bytes/lines to the part_numbers table.
Split messages into two, and clean up the resulting mess.
Grant select,update on messages_id_seq.
Create a trigger on deleted_messages to remove the message.
Make deleted_messages.message cascade on delete.
Grant "update" on threads to aox, so that the threader can lock the table in exclusive mode.
Change the unique constraint on threads to include "mailbox".
Create a couple of new indexes to make "aox vacuum" faster, and help to look for specific message-ids.
Add a table to log connections.
Make subscriptions:(owner,mailbox) unique.
Add a table to refer to mailboxes that sieve scripts depend on.
Grant some missing privileges. Sigh.
Fix incorrect 2.09 EXPUNGEs.
Split connections.client into address/port.
Make bodyparts.hash non-unique.
...but don't make it non-indexed.
Add an index on d_m(mailbox,modseq) plus a couple of cleanups.
Add an ldapdn column to users (if it doesn't already exist).
3.0.3/schema.pg was mistakenly released with mailstore.revision=76, but with all the changes from schema #77. So fresh installations of 3.0.3 will later try to execute stepTo77(), and we need to silently succeed if there's nothing to do.
Move mailbox_messages.idate to messages.idate.
Make address_fields refer to header_fields.
Add "on delete cascade" to thread_indexes.message.
Fixes mailbox ownership and installs a trigger to keep it right.
aoximport and perhaps other code could create mailboxes such as /users/foo/stuff without knowing that /users/foo is someone's home, and therefore the new mailbox should be owned by foo.
Installs a trigger to prevent deleting mailboxes that have to be there for one reason or another.
What we really want is to delete the mail in the mailbox when the mailbox is deleted, but to do that we need (at a minimum) the responsible user. So what we must do is prevent the deletion, and in the application code we must delete the messages before deleting the mailbox.
However, if any bad mailboxes already exist (as they do, not sure why) then aox upgrade schema can delete any mail them. aox upgrade schema knows who ran it.
Move the Seen and Deleted flags into mailbox_messages, where we can test them much faster.
Add a retention_policies table for use by "aox set/show retention".
Starting with schema 80, we want aox upgrade schema to be able to downgrade. We do that by storing downgrade functions in the database. This schema adds the first few.
We want to cache retention_policies rows. For that to work we have to clear the cache when a new row is added or one is deleted.
Materialise internal nodes in the mailbox tree.
Make users.alias nullable to help "aox delete user".
Change connections.userid to username to help "aox delete user".
Remove the recent_messages table altogether.
Add a deliveries column so we can deliver mail later, not now.
Nothing. Needed so that the right downgrade_to_ functions are written (they were bad in schema 90).
Reintroduce connections.userid, for logging (only).
Add users.quota, and set it to the 31-bit int_max. A bigger value might tickle some clients, and a smaller value should really not be the default.
Rename group_members.groupname to groupid
Create and link to thread_roots for THREAD=REFS support.
This web page based on source code belonging to The Archiveopteryx Developers. All rights reserved.