MOON
Server: Apache
System: Linux res.emeff.ca 3.10.0-962.3.2.lve1.5.24.10.el7.x86_64 #1 SMP Wed Mar 20 07:36:02 EDT 2019 x86_64
User: accemeff (1004)
PHP: 7.0.33
Disabled: NONE
Upload Files
File: /home/accemeff/vendor/craftcms/cms/src/migrations/m170706_183216_rename_sequences.php
<?php

namespace craft\migrations;

use craft\db\Migration;

/**
 * m170706_183216_rename_sequences migration.
 */
class m170706_183216_rename_sequences extends Migration
{
    /**
     * @inheritdoc
     */
    public function safeUp()
    {
        if (!$this->db->getIsPgsql()) {
            return;
        }

        // Make sure any old sequences have been renamed to match the new table names
        // (see https://www.postgresql.org/message-id/200308211224.06775.jgardner%40jonathangardner.net)
        $sequences = [
            'emailmessages' => 'systemmessages',
            'categorygroups_i18n' => 'categorygroups_sites',
            'elements_i18n' => 'elements_sites',
            'sections_i18n' => 'sections_sites',
        ];

        foreach ($sequences as $oldName => $newName) {
            $oldName = $this->db->tablePrefix . $oldName . '_id_seq';
            $newName = $this->db->tablePrefix . $newName . '_id_seq';

            $transaction = $this->db->beginTransaction();
            try {
                $this->renameSequence($oldName, $newName);
                $transaction->commit();
            } catch (\Throwable $e) {
                // Silently fail. The sequence probably doesn't exist
                $transaction->rollBack();
            }
        }
    }

    /**
     * @inheritdoc
     */
    public function safeDown()
    {
        echo "m170706_183216_rename_sequences cannot be reverted.\n";
        return false;
    }
}