public function handle(InputInterface $input, OutputInterface $output) { $name = $input->getArgument('migration_name'); if ($input->getOption('fake')) { $fake = true; } else { $fake = false; } $connection = BaseOrm::getDbConnection(); $registry = BaseOrm::getRegistry(); $executor = Executor::createObject($connection); // target migrations to act on if (!empty($name)) { if ($name == 'zero') { $targets = [$name]; } else { $targets = $executor->loader->getMigrationByPrefix($name); } } else { $targets = $executor->loader->graph->getLeafNodes(); } // get migration plan $plan = $executor->getMigrationPlan($targets); BaseOrm::signalDispatch('powerorm.migration.pre_migrate', $this); $output->writeln('<comment>Running migrations:</comment>'); if (empty($plan)) { $output->writeln(' No migrations to apply.'); if ($input->getOption('no-interaction')) { $asker = NonInteractiveAsker::createObject($input, $output); } else { $asker = InteractiveAsker::createObject($input, $output); } //detect if we need to make migrations $auto_detector = new AutoDetector($executor->loader->getProjectState(), ProjectState::fromApps($registry), $asker); $changes = $auto_detector->getChanges($executor->loader->graph); if (!empty($changes)) { $output->writeln('<warning> Your models have changes that are not yet reflected ' . "in a migration, and so won't be applied.</warning>"); $output->writeln("<warning> Run 'php pmanager.php makemigrations' to make new " . "migrations, and then re-run 'php pmanager.php migrate' to apply them.</warning>"); } } else { // migrate $executor->migrate($targets, $plan, $fake); } BaseOrm::signalDispatch('powerorm.migration.post_migrate', $this); }
public function handle(InputInterface $input, OutputInterface $output) { $connection = BaseOrm::getDbConnection(); // get migrations list $loader = new Loader($connection, true); $leaves = $loader->graph->getLeafNodes(); foreach ($leaves as $leaf) { $list = $loader->graph->getAncestryTree($leaf); foreach ($list as $item) { $migrationName = array_pop(explode('\\', $item)); if (in_array($item, $loader->appliedMigrations)) { $indicator = '<info>(applied)</info>'; } else { $indicator = '(pending)'; } $output->writeln(sprintf('%1$s %2$s', $indicator, $migrationName)); } } }
/** * Do an INSERT. If update_pk is defined then this method should return the new pk for the model. * * @param Model $model * @param $fields * @param $returnId * * @return mixed * * @since 1.1.0 * * @author Eddilbert Macharia (http://eddmash.com) <*****@*****.**> */ private function doInsert(Model $model, $fields, $returnId) { $conn = BaseOrm::getDbConnection(); $qb = $conn->createQueryBuilder(); $qb->insert($model->meta->dbTable); /** @var $field Field */ foreach ($fields as $name => $field) { $qb->setValue($field->getColumnName(), $qb->createNamedParameter($field->preSave($model, true))); } $qb->execute(); if ($returnId) { return $conn->lastInsertId(); } return; }