protected function determineModuleState($sModuleName, $sMigrationsPath): ?\stdClass
    {
        $oModule = (object) [
            'name'  => $sModuleName,
            'start' => null,
            'end'   => null,
        ];

        // --------------------------------------------------------------------------

        //  Work out if the module needs migrated and if so between what and what
        $aDirMap = $this->mapDir($sMigrationsPath);

        if (!empty($aDirMap)) {

            //  Work out all the files we have and get their index
            $aMigrations = [];
            foreach ($aDirMap as $dir) {
                $aMigrations[$dir['path']] = [
                    'index' => $dir['index'],
                ];
            }

            // --------------------------------------------------------------------------

            //  Work out the current version
            $sSql    = "SELECT `version` FROM `" . NAILS_DB_PREFIX . "migration` WHERE `module` = '$sModuleName';";
            $oResult = $this->oDb->query($sSql);

            if ($oResult->rowCount() === 0) {

                //  Add a row for the module
                $sSql = "INSERT INTO `" . NAILS_DB_PREFIX . "migration` (`module`, `version`) VALUES ('$sModuleName', NULL);";
                $this->oDb->query($sSql);

                $iCurrentVersion = null;

            } else {
                $iCurrentVersion = $oResult->fetch(\PDO::FETCH_OBJ)->version;
                $iCurrentVersion = is_null($iCurrentVersion) ? null : (int) $iCurrentVersion;
            }

            // --------------------------------------------------------------------------

            //  Define the variable
            $aLastMigration = end($aMigrations);
            $oModule->start = $iCurrentVersion;
            $oModule->end   = $aLastMigration['index'];
        }

        return $oModule->start === $oModule->end ? null : $oModule;
    }