skipAssertion(function (Schema $schema) { $sql = sprintf("select id from %s where properties like '%s' limit 1", $this->getPrefixedTableName(), '%'.self::OLD_STRING.'%'); $recordCount = $this->connection->executeQuery($sql)->fetchAllAssociative(); return !$recordCount; }, 'Migration is not required.'); } public function up(Schema $schema): void { $sql = sprintf("select id, properties from %s where properties like '%s'", $this->getPrefixedTableName(), '%'.self::OLD_STRING.'%'); $results = $this->connection->executeQuery($sql)->fetchAllAssociative(); $updatedRecords = 0; foreach ($results as $row) { $propertiesArray = unserialize($row['properties']); $propertiesArray['settings']['description'] = str_replace(self::OLD_STRING, self::NEW_STRING, $propertiesArray['settings']['description']); $propertiesString = serialize($propertiesArray); $sql = sprintf('UPDATE %s SET properties = :properties where id = :id', $this->getPrefixedTableName()); $stmt = $this->connection->prepare($sql); $stmt->bindValue('properties', $propertiesString, \PDO::PARAM_STR); $stmt->bindValue('id', $row['id'], \PDO::PARAM_INT); $updatedRecords += $stmt->executeStatement(); } $this->write(sprintf('%s record(s) have been updated successfully.', $updatedRecords)); } private function getPrefixedTableName(): string { return $this->prefix.self::$tableName; } }