with a migration generator of some sort (see TODO.txt).
}
/**
- * Returns a string of <tt>CREATE TABLE</tt> SQL statement(s) for recreating the
- * entire structure of the database.
- *
- * @param string $table
- * @return string
- */
- abstract public function structureDump($table = null);
-
- /**
* Recreate the given db
*
* @param string $name
}
/**
- * Dump entire schema structure or specific table
- *
- * @param string $table
- * @return string
- */
- public function structureDump($table=null)
- {
- foreach ($this->selectAll('SHOW TABLES') as $row) {
- if ($table && $table != current($row)) { continue; }
- $dump = $this->selectOne('SHOW CREATE TABLE ' . $this->quoteTableName(current($row)));
- $creates[] = $dump['Create Table'] . ';';
- }
- return isset($creates) ? implode("\n\n", $creates) : null;
- }
-
- /**
* Create the given db
*
* @param string $name
}
/**
- * Returns a string of <tt>CREATE TABLE</tt> SQL statement(s) for recreating the
- * entire structure of the database.
- *
- * @param string $table
- * @return string
- */
- public function structureDump($table=null)
- {
- }
-
- /**
* Create a new PostgreSQL database. Options include <tt>:owner</tt>, <tt>:template</tt>,
* <tt>:encoding</tt>, <tt>:tablespace</tt>, and <tt>:connection_limit</tt> (note that MySQL uses
* <tt>:charset</tt> while PostgreSQL uses <tt>:encoding</tt>).
}
/**
- * Dump entire schema structure or specific table
- *
- * @param string $table
- * @return string
- */
- public function structureDump($table=null)
- {
- if ($table) {
- return $this->selectValue('SELECT sql FROM (
- SELECT * FROM sqlite_master UNION ALL
- SELECT * FROM sqlite_temp_master) WHERE type != \'meta\' AND name = ' . $this->quote($table));
- } else {
- $dump = $this->selectValues('SELECT sql FROM (
- SELECT * FROM sqlite_master UNION ALL
- SELECT * FROM sqlite_temp_master) WHERE type != \'meta\' AND name != \'sqlite_sequence\'');
- return implode("\n\n", $dump);
- }
- }
-
- /**
* Create the given db
*
* @param string $name
$this->assertEquals('test', $name);
}
- public function testStructureDump()
- {
- $this->_createTestTable('sports');
- // Avoid AUTO_INCREMENT being a part of the dump
- $this->_conn->execute('TRUNCATE TABLE sports');
-
- // single table
- $structure = $this->_conn->structureDump('sports');
-
- $expected = "CREATE TABLE `sports` (\n".
- " `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n".
- " `name` varchar(255) DEFAULT NULL,\n".
- " `is_college` tinyint(1) DEFAULT NULL,\n".
- " PRIMARY KEY (`id`)\n".
- ") ENGINE=InnoDB DEFAULT CHARSET=utf8";
-
- // MySQL differs in how it dumps table structure between versions, so do
- // some normalization.
- $expected = strtolower(preg_replace('/\s+/', ' ', $expected));
- $structure = strtolower(preg_replace('/\s+/', ' ', $structure));
-
- $this->assertContains($expected, $structure);
-
- // entire structure
- $structure = $this->_conn->structureDump();
- $structure = strtolower(preg_replace('/\s+/', ' ', $structure));
-
- // contains, but doesn't match only sports table
- $this->assertContains($expected, $structure);
- $this->assertNotEquals($expected, $structure);
- }
-
public function testTypeToSqlTypePrimaryKey()
{
$result = $this->_conn->typeToSql('primaryKey');
$this->assertEquals('test', $name);
}
- public function testStructureDump()
- {
- $this->_createTestTable('sports');
- // Avoid AUTO_INCREMENT being a part of the dump
- $this->_conn->execute('TRUNCATE TABLE sports');
-
- // single table
- $structure = $this->_conn->structureDump('sports');
-
- $expected = "CREATE TABLE `sports` (\n".
- " `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n".
- " `name` varchar(255) DEFAULT NULL,\n".
- " `is_college` tinyint(1) DEFAULT NULL,\n".
- " PRIMARY KEY (`id`)\n".
- ") ENGINE=InnoDB DEFAULT CHARSET=utf8";
-
- // MySQL differs in how it dumps table structure between versions, so do
- // some normalization.
- $expected = strtolower(preg_replace('/\s+/', ' ', $expected));
- $structure = strtolower(preg_replace('/\s+/', ' ', $structure));
-
- $this->assertContains($expected, $structure);
-
- // entire structure
- $structure = $this->_conn->structureDump();
- $structure = strtolower(preg_replace('/\s+/', ' ', $structure));
-
- // contains, but doesn't match only sports table
- $this->assertContains($expected, $structure);
- $this->assertNotEquals($expected, $structure);
- }
-
public function testTypeToSqlTypePrimaryKey()
{
$result = $this->_conn->typeToSql('primaryKey');
$this->assertEquals('test', $name);
}
- public function testStructureDump()
- {
- $this->_createTestTable('sports');
-
- // single table
- $structure = $this->_conn->structureDump('sports');
-
- $expected = "CREATE TABLE \"sports\" (\n".
- " \"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, \n".
- " \"name\" varchar(255), \n".
- " \"is_college\" boolean\n".
- ")";
-
- $this->assertContains($expected, $structure);
-
- // entire structure
- $structure = $this->_conn->structureDump();
-
- // contains, but doesn't match only sports table
- $this->assertContains($expected, $structure);
- $this->assertNotEquals($expected, $structure);
- }
-
public function testTypeToSqlTypePrimaryKey()
{
$result = $this->_conn->typeToSql('primaryKey');