protected function setup_mysql5()
    {
        $xml = <<<XML
<dbsteward>
  <database>
    <sqlformat>mysql5</sqlformat>
    <role>
      <application>app_application</application>
      <owner>postgres</owner>
      <replication>app_slony</replication>
      <readonly>app_readonly</readonly>
    </role>
  </database>
  <schema name="app" owner="ROLE_OWNER">
    <table name="my_table" owner="ROLE_OWNER" primaryKey="id" primaryKeyName="my_table_pk">
      <column name="id" type="character varying(32)" null="false"/>
      <column name="action" type="character varying(32)"/>
      <column name="description" type="character varying(200)"/>
      <rows columns="id, action, description">
        <row>
          <col>1</col>
          <col>Row 1</col>
          <col>Action 1 Description</col>
        </row>
        <row>
          <col>2</col>
          <col>Row 2</col>
          <col>Action 2 Description</col>
        </row>
        <row>
          <col>3</col>
          <col>Row 3</col>
          <col>Action 3 Description</col>
        </row>
        <row>
          <col>4</col>
          <col>Row 4</col>
          <col>Action 4 Description</col>
        </row>
        <row>
          <col>5</col>
          <col>Row 5</col>
          <col>Action 5 Description</col>
        </row>
      </rows>
    </table>
  </schema>
</dbsteward>
XML;
        $xml_data_overlay = <<<XML
<dbsteward>
  <database>
    <role>
      <application>client_app_application</application>
      <owner>postgres</owner>
      <replication>client_app_slony</replication>
      <readonly>client_app_readonly</readonly>
    </role>
  </database>
  <schema name="app" owner="ROLE_OWNER">
    <table name="my_table" owner="ROLE_OWNER" primaryKey="id" primaryKeyName="my_table_pk">
      <rows columns="id, description">
        <row>
          <col>2</col>
          <col>Action 2 Alternate Description</col>
        </row>
        <row>
          <col>3</col>
          <col>Action 3 Alternate Description</col>
        </row>
        <row>
          <col>5</col>
          <col>Action 5 Alternate Description</col>
        </row>          
      </rows>
    </table>
  </schema>
</dbsteward>
XML;
        $this->xml_file_a = dirname(__FILE__) . '/../testdata/mysql5_unit_test_xml_a.xml';
        $this->xml_file_b = dirname(__FILE__) . '/../testdata/mysql5_unit_test_xml_b.xml';
        $this->xml_file_c = dirname(__FILE__) . '/../testdata/mysql5_unit_test_xml_c.xml';
        $this->set_xml_content_a($xml);
        $this->set_xml_content_b($xml);
        $this->set_xml_content_c($xml_data_overlay);
        $this->output_prefix = dirname(__FILE__) . '/../testdata/mysql5_unit_test_identical';
        dbsteward::$single_stage_upgrade = TRUE;
        $old_db_doc_comp = xml_parser::xml_composite(array($this->xml_file_a, $this->xml_file_c));
        $new_db_doc_comp = xml_parser::xml_composite(array($this->xml_file_b, $this->xml_file_c));
        mysql5::build_upgrade('', 'identical_diff_test_mysql5_old', $old_db_doc_comp, array(), $this->output_prefix, 'identical_diff_test_mysql5_new', $new_db_doc_comp, array());
    }
示例#2
0
 protected function do_upgrade($sql_format)
 {
     $old_db_doc = simplexml_load_file($this->xml_file_a);
     $new_db_doc = simplexml_load_file($this->xml_file_b);
     $this->output_prefix = dirname(__FILE__) . '/testdata/' . $sql_format . '_unit_test_xml_a';
     // need to unfortunately do the one thing austin told me not to:
     // use more than one format type per run
     if (strcasecmp($sql_format, 'pgsql8') == 0) {
         pgsql8::build_upgrade('', $old_db_doc, $old_db_doc, array(), $this->output_prefix, $new_db_doc, $new_db_doc, array());
     } else {
         if (strcasecmp($sql_format, 'mysql5') == 0) {
             mysql5::build_upgrade('', $old_db_doc, $old_db_doc, array(), $this->output_prefix, $new_db_doc, $new_db_doc, array());
         } else {
             $this->fail("This test only uses pgsql8 and mysql5 formats, but can be expanded.");
         }
     }
 }
 /**
  * @group mysql5
  */
 public function testUpgradeNewTableMysql5()
 {
     $this->apply_options_mysql5();
     $this->setup_mysql5();
     // upgrade from base
     // to base + strict action table + new resolution table
     // check null specificity
     $base_db_doc = xml_parser::xml_composite(array($this->xml_file_a));
     $newtable_db_doc = xml_parser::xml_composite(array($this->xml_file_a, $this->xml_file_b, $this->xml_file_c));
     mysql5::build_upgrade('', 'newtable_upgrade_test_pgsql8_base', $base_db_doc, array(), $this->output_prefix, 'newtable_upgrade_test_pgsql8_newtable', $newtable_db_doc, array());
     $text = file_get_contents($this->output_prefix . '_upgrade_single_stage.sql');
     // make sure NOT NULL is specified for description column
     $this->assertContains('`description` character varying(200) NOT NULL', $text);
     // make sure NOT NULL is specified for resolution column
     $this->assertContains('`resolution` character varying(16) NOT NULL', $text);
     // make sure NOT NULL is NOT specified for points column
     $this->assertNotContains('`points` int NOT NULL', $text);
 }
 protected function upgrade_db_mysql5()
 {
     $this->apply_options_mysql5();
     // build the upgrade DDL first, incase dbsteward code wants to throw about something
     $old_db_doc = xml_parser::xml_composite(array($this->xml_file_a));
     $new_db_doc = xml_parser::xml_composite(array($this->xml_file_b));
     mysql5::build_upgrade('', $old_db_doc, $old_db_doc, array(), $this->output_prefix, $new_db_doc, $new_db_doc, array());
     // upgrade database to "B" with each stage file
     $this->mysql5->run_file($this->output_prefix . '_upgrade_stage1_schema1.sql');
     $this->mysql5->run_file($this->output_prefix . '_upgrade_stage2_data1.sql');
     $this->mysql5->run_file($this->output_prefix . '_upgrade_stage3_schema1.sql');
     $this->mysql5->run_file($this->output_prefix . '_upgrade_stage4_data1.sql');
     // build the upgrade DDL first, incase dbsteward code wants to throw about something
     mysql5::build_upgrade($this->xml_file_a, $this->xml_file_b);
     // upgrade database to "B" with each stage file
     $this->mysql5->run_file(__DIR__ . '/testdata/upgrade_stage1_schema1.sql');
     $this->mysql5->run_file(__DIR__ . '/testdata/upgrade_stage2_data1.sql');
     $this->mysql5->run_file(__DIR__ . '/testdata/upgrade_stage3_schema1.sql');
     $this->mysql5->run_file(__DIR__ . '/testdata/upgrade_stage4_data1.sql');
     //@TODO: confirm tables defined in B are present
 }