public function endMigration(APIMigration $migration, $force = false)
    {
        if ($migration->status == APIMigration::STATUS_STARTED) {
            throw new \Exception($this->getEntityName($migration)." '{$migration->name}' can not be ended as its status is 'started'...");
        }

        $this->createTableIfNeeded();

        // select for update

        // annoyingly enough, neither Doctrine nor EZP provide built in support for 'FOR UPDATE' in their query builders...
        // at least the doctrine one allows us to still use parameter binding when we add our sql particle
        $conn = $this->getConnection();

        $qb = $conn->createQueryBuilder();
        $qb->select('*')
            ->from($this->tableName, 'm')
            ->where('migration = ?');
        $sql = $qb->getSQL() . ' FOR UPDATE';

        $conn->beginTransaction();

        $stmt = $conn->executeQuery($sql, array($migration->name));
        $existingMigrationData = $stmt->fetch(\PDO::FETCH_ASSOC);

        // fail if it was not executing

        if (!is_array($existingMigrationData)) {
            // commit to release the lock
            $conn->commit();
            throw new \Exception($this->getEntityName($migration)." '{$migration->name}' can not be ended as it is not found");
        }

        if (($existingMigrationData['status'] != APIMigration::STATUS_STARTED) && !$force) {
            // commit to release the lock
            $conn->commit();
            throw new \Exception($this->getEntityName($migration)." '{$migration->name}' can not be ended as it is not executing");
        }

        $conn->update(
            $this->tableName,
            array(
                'status' => $migration->status,
                /// @todo use mb_substr (if all dbs we support count col length not in bytes but in chars...)
                'execution_error' => substr($migration->executionError, 0, 4000),
                'execution_date' => $migration->executionDate
            ),
            array('migration' => $migration->name)
        );

        $conn->commit();
    }