#!/usr/bin/perl # # ***** BEGIN LICENSE BLOCK ***** # # Zimbra Collaboration Suite Server # Copyright (C) 2007 Zimbra, Inc. # # The contents of this file are subject to the Yahoo! Public License # Version 1.0 ("License"); you may not use this file except in # compliance with the License. You may obtain a copy of the License at # http://www.zimbra.com/license. # # Software distributed under the License is distributed on an "AS IS" # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. # # ***** END LICENSE BLOCK ***** # use strict; use Migrate; my $version = Migrate::getSchemaVersion(); if ($version < 50) { print(STDERR "Detected schema version $version. This script requires schema version 50 or greater.\n"); exit(1); } foreach my $group (Migrate::getMailboxGroups()) { fixImapFlagsColumn($group); } if ($version == 50) { Migrate::updateSchemaVersion(50, 51); } exit(0); ##################### sub fixImapFlagsColumn($) { my ($group) = @_; # Add flags column if it's not already there my $numColumns = (Migrate::runSql( "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS " . "WHERE table_schema = '$group' AND table_name = 'imap_message' " . "AND column_name = 'flags'"))[0]; if ($numColumns == 0) { Migrate::log("Adding flags column to $group.imap_message."); Migrate::runSql("ALTER TABLE $group.imap_message ADD COLUMN flags INTEGER NOT NULL DEFAULT 0"); } else { Migrate::log("Found existing column $group.imap_message.flags."); } # Initialize values for flag column Migrate::log("Fixing flags column values in $group.imap_message."); my $sql = <