protected function setup_pgsql8()
    {
        $xml = <<<XML
<dbsteward>
  <database>
    <sqlformat>pgsql8</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" slonyId="0">
      <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" slonyId="0">
      <rows columns="id, description">
        <row>
          <col>2</col>
          <col>Action 2 Alternate Description</col>
        </row>
        <row>
          <col>4</col>
          <col>Action 4 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/pgsql8_unit_test_xml_a.xml';
        $this->xml_file_b = dirname(__FILE__) . '/../testdata/pgsql8_unit_test_xml_b.xml';
        $this->xml_file_c = dirname(__FILE__) . '/../testdata/pgsql8_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/pgsql8_test_identical';
        dbsteward::$single_stage_upgrade = TRUE;
        dbsteward::$generate_slonik = FALSE;
        $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));
        pgsql8::build_upgrade('', 'identical_diff_test_pgsql8_old', $old_db_doc_comp, array(), $this->output_prefix, 'identical_diff_test_pgsql8_new', $new_db_doc_comp, array());
    }
 /**
  * @group pgsql8
  */
 public function testUpgradeNewTablePgsql8()
 {
     $this->apply_options_pgsql8();
     $this->setup_pgsql8();
     // 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));
     pgsql8::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('ALTER COLUMN "description" SET NOT NULL', $text);
     // make sure NOT NULL is specified for resolution column
     $this->assertContains('ALTER COLUMN "resolution" SET NOT NULL', $text);
     // make sure NOT NULL is NOT specified for points column
     $this->assertNotContains('ALTER COLUMN "points" SET NOT NULL', $text);
 }
Exemplo n.º 3
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.");
         }
     }
 }
Exemplo n.º 4
0
    /** Generates DDL for a build or upgrade given dbxml fragments **/
    private function common($old, $new = FALSE, $generate_slonik = TRUE)
    {
        pgsql8::$table_slony_ids = array();
        pgsql8::$sequence_slony_ids = array();
        pgsql8::$known_pg_identifiers = array();
        if (is_string($old) && empty($old)) {
            //      $old = <<<XML
            //<table name="foo" owner="ROLE_OWNER" primaryKey="id" slonyId="1">
            //  <column name="id" type="int"/>
            //</table>
            //<sequence name="seq" owner="ROLE_OWNER" slonyId="4"/>
            //XML;
        }
        $xml_a = <<<XML
<dbsteward>
  <database>
    <host>db-host</host>
    <name>dbsteward</name>
    <role>
      <application>dbsteward_phpunit_app</application>
      <owner>deployment</owner>
      <replication/>
      <readonly/>
    </role>
    <slony clusterName="duplicate_slony_ids_testsuite">
      <slonyNode id="1" comment="DSI - Local Primary"  dbName="test" dbHost="db-dev1" dbUser="******" dbPassword="******"/>
      <slonyNode id="2" comment="DSI - Local Backup"   dbName="test" dbHost="db-dev1" dbUser="******" dbPassword="******"/>
      <slonyNode id="3" comment="DSI - Local Backup"   dbName="test" dbHost="db-dev1" dbUser="******" dbPassword="******"/>
      <slonyReplicaSet id="100" originNodeId="1" upgradeSetId="101" comment="common duplicate testing database definition">
        <slonyReplicaSetNode id="2" providerNodeId="1"/>
        <slonyReplicaSetNode id="3" providerNodeId="2"/>
      </slonyReplicaSet>
    </slony>
    <configurationParameter name="TIME ZONE" value="America/New_York"/>
  </database>
  <schema name="dbsteward" owner="ROLE_OWNER">
    {$old}
  </schema>
</dbsteward>
XML;
        $this->set_xml_content_a($xml_a);
        if ($new) {
            $xml_b = <<<XML
<dbsteward>
  <database>
    <host>db-host</host>
    <name>dbsteward</name>
    <role>
      <application>dbsteward_phpunit_app</application>
      <owner>deployment</owner>
      <replication/>
      <readonly/>
    </role>
    <slony clusterName="duplicate_slony_ids_testsuite">
      <slonyNode id="1" comment="DSI - Local Primary"  dbName="test" dbHost="db-dev1" dbUser="******" dbPassword="******"/>
      <slonyNode id="2" comment="DSI - Local Backup"   dbName="test" dbHost="db-dev1" dbUser="******" dbPassword="******"/>
      <slonyNode id="3" comment="DSI - Local Backup"   dbName="test" dbHost="db-dev1" dbUser="******" dbPassword="******"/>
      <slonyReplicaSet id="100" originNodeId="1" upgradeSetId="101" comment="common duplicate testing database definition">
        <slonyReplicaSetNode id="2" providerNodeId="1"/>
        <slonyReplicaSetNode id="3" providerNodeId="2"/>
      </slonyReplicaSet>
    </slony>
    <configurationParameter name="TIME ZONE" value="America/New_York"/>
  </database>
  <schema name="dbsteward" owner="ROLE_OWNER">
    {$new}
  </schema>
</dbsteward>
XML;
            $this->set_xml_content_b($xml_b);
            ob_start();
            try {
                // new parameters for function:
                // $old_output_prefix, $old_composite_file, $old_db_doc, $old_files, $new_output_prefix, $new_composite_file, $new_db_doc, $new_files
                $old_db_doc = simplexml_load_file($this->xml_file_a);
                $new_db_doc = simplexml_load_file($this->xml_file_b);
                dbsteward::$generate_slonik = $generate_slonik;
                pgsql8::build_upgrade('', $old_db_doc, $old_db_doc, array(), $this->output_prefix, $new_db_doc, $new_db_doc, array());
                ob_end_clean();
            } catch (Exception $ex) {
                ob_end_clean();
                throw $ex;
            }
        } else {
            ob_start();
            try {
                $db_doc = simplexml_load_file($this->xml_file_a);
                dbsteward::$generate_slonik = $generate_slonik;
                pgsql8::build($this->output_prefix, $db_doc);
                ob_end_clean();
            } catch (Exception $ex) {
                ob_end_clean();
                throw $ex;
            }
        }
    }
 protected function upgrade_db_pgsql8()
 {
     $this->apply_options_pgsql8();
     // make sure we clear these in case we ran something else before this
     pgsql8::$table_slony_ids = array();
     pgsql8::$sequence_slony_ids = array();
     pgsql8::$known_pg_identifiers = array();
     // 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));
     pgsql8::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->assertStringNotEqualsFile($this->output_prefix . '_upgrade_stage1_schema1.sql', '');
     $this->pgsql8->run_file($this->output_prefix . '_upgrade_stage1_schema1.sql');
     $this->pgsql8->run_file($this->output_prefix . '_upgrade_stage2_data1.sql');
     $this->pgsql8->run_file($this->output_prefix . '_upgrade_stage3_schema1.sql');
     $this->pgsql8->run_file($this->output_prefix . '_upgrade_stage4_data1.sql');
     //@TODO: confirm tables defined in B are present
 }
 protected function diff_definitions($output_prefix)
 {
     dbsteward::$old_database = new SimpleXMLElement($this->oldxml);
     dbsteward::$new_database = new SimpleXMLElement($this->newxml);
     pgsql8_diff::$new_table_dependency = xml_parser::table_dependency_order(dbsteward::$new_database);
     pgsql8_diff::$old_table_dependency = xml_parser::table_dependency_order(dbsteward::$old_database);
     $output_prefix_path = dirname(__FILE__) . '/../testdata/' . $output_prefix;
     pgsql8::build_upgrade('', 'old_SlonyStageTransactionalityTest', dbsteward::$old_database, array(), $output_prefix_path, 'new_SlonyStageTransactionalityTest', dbsteward::$new_database, array());
     return $output_prefix_path;
 }