コード例 #1
0
    public function testSlonikOutputIsCorrect()
    {
        $xml = <<<OUTXML
<?xml version="1.0" encoding="UTF-8"?>
<dbsteward>
  <database>
    <sqlformat>pgsql8</sqlformat>
    <role>
      <application>application</application>
      <owner>dba</owner>
      <replication>slony</replication>
      <readonly>readonly</readonly>
    </role>
    <slony clusterName="aim">
      <slonyNode id="1" comment="Master" dbPassword="******" dbUser="******" dbHost="db00" dbName="mrh"/>
      <slonyNode id="2" comment="Replica" dbPassword="******" dbUser="******" dbHost="db01" dbName="mrh"/>
      <slonyReplicaSet id="101" comment="only set" originNodeId="1" upgradeSetId="2">
        <slonyReplicaSetNode id="2" providerNodeId="1"/>
      </slonyReplicaSet>
      <slonyReplicaSet id="201" comment="only set" originNodeId="1" upgradeSetId="3">
        <slonyReplicaSetNode id="2" providerNodeId="1"/>
      </slonyReplicaSet>
    </slony>
  </database>
  <schema name="public" owner="ROLE_OWNER">
    <table name="log" owner="ROLE_OWNER" primaryKey="id" primaryKeyName="log_pkey" slonySetId="101" slonyId="101">
      <column name="id" type="bigserial" slonySetId="101" slonyId="101"/>
      <grant role="ROLE_APPLICATION" operation="INSERT, SELECT, UPDATE, DELETE"/>
    </table>
    <table name="log" owner="ROLE_OWNER" primaryKey="id" primaryKeyName="log_pkey" slonySetId="101" slonyId="102">
      <column name="id" type="bigserial" slonySetId="101" slonyId="102"/>
      <grant role="ROLE_APPLICATION" operation="INSERT, SELECT, UPDATE, DELETE"/>
    </table>
    <table name="log" owner="ROLE_OWNER" primaryKey="id" primaryKeyName="log_pkey" slonySetId="201" slonyId="105">
      <column name="id" type="bigserial" slonySetId="201" slonyId="105"/>
      <grant role="ROLE_APPLICATION" operation="INSERT, SELECT, UPDATE, DELETE"/>
    </table>
    <table name="log" owner="ROLE_OWNER" primaryKey="id" primaryKeyName="log_pkey" slonySetId="201" slonyId="106">
      <column name="id" type="bigserial" slonySetId="201" slonyId="106"/>
      <grant role="ROLE_APPLICATION" operation="INSERT, SELECT, UPDATE, DELETE"/>
    </table>
    <table name="log" owner="ROLE_OWNER" primaryKey="id" primaryKeyName="log_pkey" slonyId="1098">
      <column name="id" type="bigserial" slonyId="1098"/>
      <grant role="ROLE_APPLICATION" operation="INSERT, SELECT, UPDATE, DELETE"/>
    </table>
    <!-- here for additional changes -->
  </schema>
</dbsteward>
OUTXML;
        $old_db_doc = simplexml_load_string($xml);
        dbsteward::$generate_slonik = TRUE;
        $output_prefix_path = dirname(__FILE__) . '/../testdata/' . 'slony_id_output';
        pgsql8::build($output_prefix_path, $old_db_doc);
        $this->assertLogged(Monolog\Logger::NOTICE, '/101:\\s101-102/');
        // before 1098 wasn't getting put into first natural order, now it should be
        $this->assertLogged(Monolog\Logger::NOTICE, '/101:\\s[\\d\\-]+,\\s*1098/', "SlonyIds without slonySetIds are not put into first natural order slonySet");
        $this->assertLogged(Monolog\Logger::NOTICE, '/201:\\s105-106/');
    }
コード例 #2
0
    /**
     * There was a bug in streaker where it wasn't counting the entire first streak, output used to be for below: 1, 5-6, 98-98
     */
    public function testSlonikStreakerIsGood()
    {
        $xml = <<<SLONXML
<?xml version="1.0" encoding="UTF-8"?>
<dbsteward>
  <database>
    <sqlformat>pgsql8</sqlformat>
    <role>
      <application>application</application>
      <owner>dba</owner>
      <replication>slony</replication>
      <readonly>readonly</readonly>
    </role>
    <slony clusterName="aim">
      <slonyNode id="1" comment="Master" dbPassword="******" dbUser="******" dbHost="db00" dbName="mrh"/>
      <slonyNode id="2" comment="Replica" dbPassword="******" dbUser="******" dbHost="db01" dbName="mrh"/>
      <slonyReplicaSet id="1" comment="only set" originNodeId="1" upgradeSetId="2">
        <slonyReplicaSetNode id="2" providerNodeId="1"/>
      </slonyReplicaSet>
    </slony>
  </database>
  <schema name="public" owner="ROLE_OWNER">
    <table name="log_sl" owner="ROLE_OWNER" primaryKey="id" primaryKeyName="log_pkey" slonyId="1">
      <column name="id" type="bigserial" slonyId="1"/>
      <grant role="ROLE_APPLICATION" operation="INSERT, SELECT, UPDATE, DELETE"/>
    </table>
    <table name="log_sl2" owner="ROLE_OWNER" primaryKey="id" primaryKeyName="log_pkey" slonyId="2">
      <column name="id" type="bigserial" slonyId="2"/>
      <grant role="ROLE_APPLICATION" operation="INSERT, SELECT, UPDATE, DELETE"/>
    </table>
    <table name="log_sl3" owner="ROLE_OWNER" primaryKey="id" primaryKeyName="log_pkey" slonyId="5">
      <column name="id" type="bigserial" slonyId="5"/>
      <grant role="ROLE_APPLICATION" operation="INSERT, SELECT, UPDATE, DELETE"/>
    </table>
    <table name="log_sl4" owner="ROLE_OWNER" primaryKey="id" primaryKeyName="log_pkey" slonyId="6">
      <column name="id" type="bigserial" slonyId="6"/>
      <grant role="ROLE_APPLICATION" operation="INSERT, SELECT, UPDATE, DELETE"/>
    </table>
    <table name="log_sl5" owner="ROLE_OWNER" primaryKey="id" primaryKeyName="log_pkey" slonyId="98">
      <column name="id" type="bigserial" slonyId="98"/>
      <grant role="ROLE_APPLICATION" operation="INSERT, SELECT, UPDATE, DELETE"/>
    </table>
    <!-- here for additional changes -->
  </schema>
</dbsteward>
SLONXML;
        $old_db_doc = simplexml_load_string($xml);
        dbsteward::$generate_slonik = TRUE;
        $output_prefix_path = dirname(__FILE__) . '/../testdata/' . 'slony_id_streak';
        pgsql8::build($output_prefix_path, $old_db_doc);
        $this->assertLogged(Monolog\Logger::NOTICE, '/sequence ID segments.*:\\s1-2, 5-6, 98/');
    }
コード例 #3
0
 /**
  * @group pgsql8
  */
 public function testFullBuildPgsql8()
 {
     $this->apply_options_pgsql8();
     $this->setup_pgsql8();
     // build base full, check contents
     $base_db_doc = xml_parser::xml_composite(array($this->xml_file_a, $this->xml_file_a));
     pgsql8::build($this->output_prefix, $base_db_doc);
     $text = file_get_contents($this->output_prefix . '_build.sql');
     // make sure SET NOT NULL is specified for action column
     $this->assertContains('ALTER COLUMN "action" SET NOT NULL', $text);
     // make sure SET NOT NULL is NOT specified for description column
     $this->assertNotContains('ALTER COLUMN "description" SET NOT NULL', $text);
     // build base + strict, check contents
     $strict_db_doc = xml_parser::xml_composite(array($this->xml_file_a, $this->xml_file_b));
     pgsql8::build($this->output_prefix, $strict_db_doc);
     $text = file_get_contents($this->output_prefix . '_build.sql');
     // make sure SET NOT NULL is specified for action column
     $this->assertContains('ALTER COLUMN "action" SET NOT NULL', $text);
     // make sure SET NOT NULL is specified for description column
     $this->assertContains('ALTER COLUMN "description" SET NOT NULL', $text);
     // build base + strict + new table, check contents
     $addtable_db_doc = xml_parser::xml_composite(array($this->xml_file_a, $this->xml_file_b, $this->xml_file_c));
     pgsql8::build($this->output_prefix, $addtable_db_doc);
     $text = file_get_contents($this->output_prefix . '_build.sql');
     // 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);
 }
コード例 #4
0
 /**
  * @group pgsql8
  */
 public function testGoodSerialIdPGSQL8()
 {
     // reset options
     $this->apply_options_pgsql8();
     dbsteward::$require_slony_id = TRUE;
     dbsteward::$generate_slonik = TRUE;
     $this->set_xml_content_a($this->pgsql8_xml_good_serial_id);
     // build the DDL first, incase dbsteward code wants to throw about something
     pgsql8::build($this->output_prefix, xml_parser::xml_composite(array($this->xml_file_a)));
     // if that worked, build a db with this definition
     $this->pgsql8->create_db();
     $this->assertStringNotEqualsFile($this->output_prefix . '_build.sql', '');
     $this->pgsql8->run_file($this->output_prefix . '_build.sql');
 }
コード例 #5
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;
            }
        }
    }
コード例 #6
0
 protected function build_db_pgsql8()
 {
     $this->apply_options_pgsql8();
     // build the DDL first, incase dbsteward code wants to throw about something
     pgsql8::build($this->output_prefix, xml_parser::xml_composite(array($this->xml_file_a)));
     $this->pgsql8->create_db();
     // build initial "A" database
     $this->assertStringNotEqualsFile($this->output_prefix . '_build.sql', '');
     $this->pgsql8->run_file($this->output_prefix . '_build.sql');
 }