public function migrate($model) { /* Initialise the schema variables from the connection */ $platform = $model->db->getDatabasePlatform(); $sm = $model->db->getSchemaManager(); $original_schema = $sm->createSchema(); $schema = new Schema(); /* Now use the Schema object to create a table */ if (!$schema->hasTable($model->table)) { $table = $schema->createTable($model->table); } else { $table = $schema->getTable($model->table); } foreach ($model->columns as $name => $options) { $table->addColumn($name, $options["type"], $options["options"]); } $table->setPrimaryKey(array($model->primary_key)); /* We now have a current Schema object, which is compared against the original to create migration sql */ $queries = $schema->getMigrateFromSql($original_schema, $platform); /* It produces a series of queries, which we run in sequence. The database should be up to date now. */ foreach ($queries as $query) { $model->db->query($query); } }
/** * @param Configuration $configuration * @param Schema $from * @param Schema $to * * @return string */ public function down(Configuration $configuration, Schema $from, Schema $to) { return $this->build($configuration, $from->getMigrateFromSql($to, $configuration->getConnection()->getDatabasePlatform())); }
/** * Returns the array of changes that will take place if commit is run * * @return array An array with SQL queries that correspond to the changes */ public function getChanges() { return $this->coded_schema->getMigrateFromSql($this->database_schema, $this->connection->getSchemaManager()->getDatabasePlatform()); }