/** * @param Configuration $configuration * @param bool $create * @param bool $update * @param null $up * @param null $down * * @return string */ public function generate(Configuration $configuration, $create = false, $update = false, $up = null, $down = null) { $stub = $this->getStub($create, $update); $contents = $this->locator->locate($stub)->get(); $contents = $this->replacer->replace($contents, $this->variables, [$configuration->getMigrationsNamespace(), $configuration->getNamingStrategy()->getClassName(), $this->getTableName($create, $update), $up ? $this->tabbedNewLine($up) : null, $down ? $this->tabbedNewLine($down) : null]); $filename = $configuration->getNamingStrategy()->getFilename(); $this->writer->write($contents, $filename, $configuration->getMigrationsDirectory()); return $filename; }
/** * @param $versionName * @param bool|false $all * * @throws MigrationException */ protected function mark($versionName, $all = false) { if (!$this->configuration->hasVersion($versionName)) { throw MigrationException::unknownMigrationVersion($versionName); } $version = $this->configuration->getVersion($versionName); if ($this->markMigrated && $this->configuration->hasVersionMigrated($version)) { $marked = true; if (!$all) { throw new InvalidArgumentException(sprintf('The version "%s" already exists in the version table.', $version)); } } if (!$this->markMigrated && !$this->configuration->hasVersionMigrated($version)) { $marked = false; if (!$all) { throw new InvalidArgumentException(sprintf('The version "%s" does not exists in the version table.', $version)); } } if (!isset($marked)) { $filename = $this->configuration->getNamingStrategy()->getFilename($versionName); if ($this->markMigrated) { $version->markMigrated(); $this->info('<info>Added version to table:</info> ' . $filename); } else { $version->markNotMigrated(); $this->info('<info>Removed version from table:</info> ' . $filename); } } }
/** * @param Connection $connection * * @return Configuration */ public function make(Connection $connection) { $configuration = new Configuration($connection); $configuration->setName($this->config->get('migrations.name', 'Doctrine Migrations')); $configuration->setMigrationsNamespace($this->config->get('migrations.namespace', 'Database\\Migrations')); $configuration->setMigrationsTableName($this->config->get('migrations.table', 'migrations')); $configuration->getConnection()->getConfiguration()->setFilterSchemaAssetsExpression($this->config->get('migrations.schema.filter', '/^(?).*$/')); $configuration->setNamingStrategy($this->container->make($this->config->get('migrations.naming_strategy', DefaultNamingStrategy::class))); $configuration->setMigrationFinder($configuration->getNamingStrategy()->getFinder()); $directory = $this->config->get('migrations.directory', database_path('migrations')); $configuration->setMigrationsDirectory($directory); $configuration->registerMigrationsFromDirectory($directory); return $configuration; }