src/SimpleUser/Migration/MigrateV1ToV2.php
public function sqlDownData()
    {
        // Map columns to custom fields.
        $colmap = array();
        foreach ($this->fieldmap as $field => $col) {
            $colmap[$col] = $field;
        }

        // Test that the v2 columns actually exist.
        $existingCols = $this->conn->getSchemaManager()->listTableColumns($this->usersTable);
        $existingColnames = array_map(function($col) { return $col->getName(); }, $existingCols);
        foreach ($this->fieldmap as $col) {
            if (!in_array($col, $existingColnames)) {
                throw new \RuntimeException('Cannot migrate down because current schema is not v2. (Missing column "' . $this->usersTable . '.' . $col . '").');
            }
        }

        // Get user columns to revert back to custom fields.
        $userData = $this->conn->fetchAll('SELECT id AS user_id, ' . implode(', ', $this->fieldmap) . ' FROM ' . $this->conn->quoteIdentifier($this->usersTable));

        $queries = array();
        foreach ($userData as $row) {
            foreach ($this->fieldmap as $col) {
                if ($row[$col] !== null) {
                    $queries[] = 'INSERT INTO ' . $this->conn->quoteIdentifier($this->userCustomFieldsTable)
                        . ' (user_id, attribute, value) VALUES'
                        . ' (' . $this->conn->quote($row['user_id'], Type::INTEGER)
                        . ', ' . $this->conn->quote($colmap[$col], Type::STRING)
                        . ', ' . $this->conn->quote($row[$col], Type::STRING)
                        . ')';
                }
            }

        }

        return $queries;
    }
public function sqlDownData()
    {
        // Map columns to custom fields.
        $colmap = array();
        foreach ($this->fieldmap as $field => $col) {
            $colmap[$col] = $field;
        }

        // Test that the v2 columns actually exist.
        $existingCols = $this->conn->getSchemaManager()->listTableColumns($this->usersTable);
        $existingColnames = array_map(function($col) { return $col->getName(); }, $existingCols);
        foreach ($this->fieldmap as $col) {
            if (!in_array($col, $existingColnames)) {
                throw new \RuntimeException('Cannot migrate down because current schema is not v2. (Missing column "' . $this->usersTable . '.' . $col . '").');
            }
        }

        // Get user columns to revert back to custom fields.
        $userData = $this->conn->fetchAll('SELECT id AS user_id, ' . implode(', ', $this->fieldmap) . ' FROM ' . $this->conn->quoteIdentifier($this->usersTable));

        $queries = array();
        foreach ($userData as $row) {
            foreach ($this->fieldmap as $col) {
                if ($row[$col] !== null) {
                    $queries[] = 'INSERT INTO ' . $this->conn->quoteIdentifier($this->userCustomFieldsTable)
                        . ' (user_id, attribute, value) VALUES'
                        . ' (' . $this->conn->quote($row['user_id'], Type::INTEGER)
                        . ', ' . $this->conn->quote($colmap[$col], Type::STRING)
                        . ', ' . $this->conn->quote($row[$col], Type::STRING)
                        . ')';
                }
            }

        }

        return $queries;
    }
Revert data to the previous version.