public function testSimple() { $xml = <<<XML <schema name="public" owner="NOBODY"> <table name="test" primaryKey="id" owner="NOBODY" description="test desc'ription"> <column name="id" type="int"/> <column name="foo" type="int"/> </table> </schema> XML; $schema = new SimpleXMLElement($xml); $expected = <<<SQL CREATE TABLE `test` ( `id` int, `foo` int ) COMMENT 'test desc\\'ription'; SQL; $this->assertEquals($expected, mysql5_table::get_creation_sql($schema, $schema->table)); $this->assertEquals("DROP TABLE `test`;", mysql5_table::get_drop_sql($schema, $schema->table)); }
/** * Drop tables in old_schema no longer defined in new_schema * * @param type $ofs * @param type $old_schema * @param type $new_schema * @param type $old_table * @param type $new_table */ public static function drop_tables($ofs, $old_schema, $new_schema, $old_table = null, $new_table = null) { if ($old_schema != null) { if ($old_table != null) { $tables = array($old_table); } else { $tables = dbx::get_tables($old_schema); } foreach ($tables as $table) { // does the new schema contain the old table? if (!mysql5_schema::contains_table($new_schema, $table['name'])) { // if the table was renamed, don't drop it if (!dbsteward::$ignore_oldnames && mysql5_schema::table_formerly_known_as(dbsteward::$new_database, $old_schema, $table, $reformed_schema, $reformed_table)) { $old_table_name = mysql5::get_fully_qualified_table_name($old_schema['name'], $table['name']); $reformed_table_name = mysql5::get_fully_qualified_table_name($reformed_schema['name'], $reformed_table['name']); $ofs->write("-- DROP TABLE {$old_table_name} omitted: new table {$reformed_table_name} indicates it is her replacement\n"); } else { $ofs->write(mysql5_table::get_drop_sql($old_schema, $table) . "\n"); } } } } }