function createDb($connection) { //Drop all tables $sql1 = 'DROP TABLE IF EXISTS story;'; $sql2 = 'DROP TABLE IF EXISTS tasks;'; $sql3 = 'DROP TABLE IF EXISTS comments;'; $sql4 = 'DROP TABLE IF EXISTS history;'; $sql5 = 'DROP TABLE IF EXISTS epics;'; $sql6 = 'DROP TABLE IF EXISTS labels;'; $sql7 = 'DROP TABLE IF EXISTS attachments;'; $connection->query($sql1); $connection->query($sql2); $connection->query($sql3); $connection->query($sql4); $connection->query($sql5); $connection->query($sql6); $connection->query($sql7); //Create tables createTableStory($connection); createTableTasks($connection); createTableComments($connection); createTableHistory($connection); createTableEpics($connection); createTableLabels($connection); createTableAttachments($connection); return true; }
$column = $table->GetColumn('task_status'); $column->setType(Type::GetType('integer')); } try { $table->addColumn('task_handle', 'string', ['notnull' => false, 'length' => 20, 'default' => '']); } catch (\Exception $e) { $column = $table->GetColumn('task_handle'); $column->setType(Type::GetType('string')); } $table->setPrimaryKey([0 => 'task_id']); $table->addIndex([0 => 'task_handle', 1 => 'task_status']); $table->addIndex([0 => 'task_handle', 1 => 'task_type']); } $config = new Configuration(); $connectionParams = array('pdo' => $pdo); $conn = DriverManager::getConnection($connectionParams, $config); $sm = $conn->getSchemaManager(); $schema = $sm->createSchema(); $tables = array('task' => 'tasks'); foreach ($schema->GetTables() as $table) { if (!in_array($table->GetName(), $tables)) { $schema->dropTable($table->getName()); } } createTableTasks($schema); $sqls = $sm->createSchema()->getMigrateToSql($schema, $conn->getDatabasePlatform()); $conn->beginTransaction(); foreach ($sqls as $sql) { $conn->executequery($sql); } $conn->commit();