public function testNoTableSequencesBuilds() { // the base pgsql8 class keeps track of sequence columns linked to tables // (i.e. as primary keys, etc.) // during schema extraction so as to avoid creating duplicates; however, // if no tables link sequences, then the WHERE clause will contain an // empty string. this test should prove that this is no longer an issue. $xml = <<<XML <dbsteward> <database> <role> <application>deployment</application> <owner>deployment</owner> <replication/> <readonly/> </role> </database> <schema name="public" owner="ROLE_OWNER"> <!-- this sequence is just hanging around, not keyed to the table at all, so as to trigger an empty WHERE clause which should be handled properly now --> <sequence name="test_seq" start="1" inc="1" max="15" cycle="false" cache="1" owner="ROLE_OWNER"> <grant operation="USAGE,SELECT,UPDATE" role="ROLE_APPLICATION"/> </sequence> <table name="user" owner="ROLE_OWNER" description="user logins" primaryKey="user_name"> <column name="user_name" type="varchar(100)" null="false"/> <column name="user_role" type="varchar(100)" null="false"/> <column name="user_create_date" type="timestamp with time zone" null="false" default="NOW()"/> <grant role="ROLE_APPLICATION" operation="SELECT, INSERT, UPDATE"/> <rows columns="user_name, user_role"> <tabrow>toor\tsuper_admin</tabrow> </rows> </table> </schema> </dbsteward> XML; // $this->xml_file_a = __DIR__ . '/../testdata/unit_test_xml_a.xml'; file_put_contents($this->xml_file_a, $xml); $this->build_db_pgsql8(); $extracted_xml = pgsql8::extract_schema($this->pgsql8->get_dbhost(), $this->pgsql8->get_dbport(), $this->pgsql8->get_dbname(), $this->pgsql8->get_dbuser(), $this->pgsql8->get_dbpass()); // no errors thrown by this point? we should be fine, but let's do some // checks to prove DDL integrtiry $rebuilt_db = simplexml_load_string($extracted_xml); $schema_node = $rebuilt_db->xpath("schema[@name='public']"); $table_node = $schema_node[0]->xpath("table"); // just make sure the table was built for now, the other tests do more // advanced checking $this->assertEquals('user', (string) $table_node[0]['name']); // test the sequence to make sure it built properly $sequence_node = $schema_node[0]->xpath("sequence"); $expected_seq = $sequence_node[0]; $this->assertEquals('test_seq', (string) $expected_seq['name']); $this->assertEquals(1, (string) $expected_seq['min']); $this->assertEquals(15, (string) $expected_seq['max']); $this->assertEquals(1, (string) $expected_seq['cache']); }
protected function extract($sql, $in_schema = TRUE) { $schemaname = __CLASS__; $sql = rtrim($sql, ';'); $sql = "SET search_path TO \"{$schemaname}\",public;\nBEGIN;\n{$sql};\nCOMMIT;"; $this->query($sql); $xml = pgsql8::extract_schema($this->conn->get_dbhost(), $this->conn->get_dbport(), $this->conn->get_dbname(), $this->conn->get_dbuser(), $this->conn->get_dbpass()); $dbdoc = simplexml_load_string($xml); foreach ($dbdoc->schema as $schema) { if (strcmp($schema['name'], $schemaname) == 0) { echo "Got schema:\n" . $schema->asXML() . "\n"; return $schema; } } echo $dbdoc->asXML() . "\n"; throw new exception("No schema named {$schemaname} was found!?"); }