title: Doctrine Migration Error - "relation does not exist"
body: <p>how do you create sql triggers with doctrine migrations?</p>
  
  <p>here is migration:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  namespace App\Migrations;
  
  use Doctrine\DBAL\Migrations\AbstractMigration;
  use Doctrine\DBAL\Schema\Schema;
  use Doctrine\DBAL\Schema\Table;
  
  /**
   * Auto-generated Migration: Please modify to your needs!
   */
  class Version20151211173441 extends AbstractMigration
  {
      /**
       * @param Schema $schema
       */
      public function up(Schema $schema)
      {
          $table = $schema-&gt;createTable('public.users');
          $table-&gt;addColumn('id', 'integer', [
              'autoincrement' =&gt; true
          ]);
          $table-&gt;addColumn('name', 'string');
          $table-&gt;setPrimaryKey(['id']);
  
          $this-&gt;addSql("
              CREATE OR REPLACE FUNCTION public.users_insert_trigger()
                  RETURNS TRIGGER AS $$
                  BEGIN
                      NEW.name := NEW.name || ' test';
                      RETURN NEW;
                  END;
                  $$
                  LANGUAGE plpgsql;
          ");
  
          $this-&gt;addSql("
              CREATE TRIGGER users_on_insert_trigger
                  BEFORE INSERT ON public.users
                  FOR EACH ROW EXECUTE PROCEDURE public.users_insert_trigger();
          ");
      }
  
      /**
       * @param Schema $schema
       */
      public function down(Schema $schema)
      {
          $this-&gt;addSql("DROP TRIGGER public.users_on_insert_trigger ON users");
          $this-&gt;addSql("DROP FUNCTION public.users_insert_trigger()");
          $schema-&gt;dropTable('users');
      }
  }
  </code></pre>
  
  <p>This produces the following error:</p>
  
  <blockquote>
    <p>SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "public.users"
    does not exist</p>
  </blockquote>
  
  <p>And produces the following sql:</p>
  
  <pre class="lang-sql prettyprint-override"><code>CREATE OR REPLACE FUNCTION public.users_insert_trigger()
      RETURNS TRIGGER AS $$
      BEGIN
          NEW.name := NEW.name || ' test';
          RETURN NEW;
      END;
      $$
      LANGUAGE plpgsql;
  
  CREATE TRIGGER users_on_insert_trigger
      BEFORE INSERT ON public.users
      FOR EACH ROW EXECUTE PROCEDURE public.users_insert_trigger();
  
  CREATE TABLE public.users (id SERIAL NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id));
  INSERT INTO common.migrations (version) VALUES ('20151211173441');
  </code></pre>
  
  <p>If I correctly understand, changes in schema is applied in the end of migration.
  But it doesn't suit me...</p>
  
  <p>So, how can i handle it?</p>