title: Symfony - Best practice to reset the database
body: <p>I'm working on a Symfony 4.2 project and I'm looking for the best practice to achieve a reset of the database when the admin needs to do it via a button in backoffice.</p>
  
  <p><strong>Explanation :</strong> </p>
  
  <p>The project is a <strong>temporary event</strong> website. 
  This means that, people will visit the website only for a day / a week and then the website is off. Per example, a website for spectators into a stadium during a basketball tournament.</p>
  
  <p>When the tournament is over, the administrator would like to reset all datas sent during it via a button.</p>
  
  <p>Right now I did it like this but I don't know if it's the better way in production environment.</p>
  
  <p>I created a service which get the KernelInterface in constructor :</p>
  
  <pre><code>public function resetDB() {
  
      $application = new Application($this-&gt;kernel);
      $application-&gt;setAutoExit(false);
  
      $input = new ArrayInput([
          'command'   =&gt; 'doctrine:schema:drop',
          '--force' =&gt; true
      ]);
  
      $output = new BufferedOutput();
      $application-&gt;run($input, $output);
  
      $responseDrop = $output-&gt;fetch();
  
      if (strpos($responseDrop, 'successfully') !== false) {
          $input = new ArrayInput([
              'command'   =&gt; 'doctrine:schema:create',
          ]);
  
          $application-&gt;run($input, $output);
  
          $responseCreate = $output-&gt;fetch();
  
          if (strpos($responseCreate, 'successfully') !== false)
              return new Response();
      }
  
      return new \ErrorException();
  }
  </code></pre>
  
  <p>Firstly, is it good to do it like this in a production environment ? (Nobody else the administrator will use the website when doing this operation)</p>
  
  <p>Secondly, I'm not really satisfied with the method I used to check if the operation has been successfully done (<code>strpos($responseCreate, 'successfully') !== false</code>). Does someone know a better way ?</p>
  
  <p>Thanks a lot for your help</p>