本文整理汇总了PHP中Illuminate\Database\Migrations\Migrator类的典型用法代码示例。如果您正苦于以下问题:PHP Migrator类的具体用法?PHP Migrator怎么用?PHP Migrator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Migrator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$capsule = app('capsule');
$connectionResolver = $capsule->getDatabaseManager();
$repository = new DatabaseMigrationRepository($connectionResolver, 'migrations');
if (!$repository->repositoryExists()) {
$repository->createRepository();
}
$migrator = new Migrator($repository, $connectionResolver, new Filesystem());
return $migrator->run(__DIR__ . '/../database/migrations');
}
示例2: resolve
public function resolve($file)
{
/* @var $class \Consolet\Migrator\Migration */
$class = parent::resolve($file);
$class::setSchemaOnce($this->resolveConnection(null)->getSchemaBuilder());
return $class;
}
示例3: __construct
/**
* Returns a new TenantMigrator instance.
*
* @param MigrationRepositoryInterface $repository
* @param Resolver $resolver
* @param Filesystem $files
* @param TenantManager $manager
*/
public function __construct(MigrationRepositoryInterface $repository, Resolver $resolver, Filesystem $files, TenantManager $manager)
{
$this->manager = $manager;
// There is nothing special about the TenantMigrationResolver class, so let's just new up one.
$this->tenantMigrationResolver = new TenantMigrationResolver();
parent::__construct($repository, $resolver, $files);
}
示例4: setUpBeforeClass
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
$config = (require __DIR__ . '/../config.php');
$capsule = new Manager();
$capsule->addConnection($config);
$capsule->bootEloquent();
Schema::setConnection($capsule->getConnection('default'));
DB::setConnection($capsule->getConnection('default'));
// run the migrations
$migration_repo = new DatabaseMigrationRepository(Model::getConnectionResolver(), 'migrations');
if (!$migration_repo->repositoryExists()) {
$migration_repo->createRepository();
}
$migrator = new Migrator($migration_repo, Model::getConnectionResolver(), new Filesystem());
$migrator->rollback();
$migrator->run(__DIR__ . '/../../src/migrations');
static::loadFixtures();
}
示例5: execute
public function execute(InputInterface $input, OutputInterface $output)
{
$migrationsPath = APP_ROOT . 'db/migrations/';
$c = $this->app->container();
$migrationsTableName = 'migrations';
$dbResolver = $c['database.manager']->getDatabaseManager();
$filesystem = new Filesystem();
// Get the database migrations repository (create if not existant)
$repository = new MigrationRepo($dbResolver, $migrationsTableName);
if (!$repository->repositoryExists()) {
$repository->createRepository();
}
// Run!
$migrator = new Migrator($repository, $dbResolver, $filesystem);
$migrator->run($migrationsPath);
// Show notes
foreach ($migrator->getNotes() as $note) {
$output->writeln(preg_replace('(<[a-zA-Z/]+>)', '', $note));
}
$output->writeln('');
$output->writeln('Migrated!');
}
示例6: fire
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$this->migrator->setConnection($this->input->getOption('database'));
$pretend = $this->input->getOption('pretend');
while ($this->migrator->rollback($this->output, $pretend)) {
}
}
示例7: prepareDatabase
/**
* Prepare the migration database for running.
*
* @return void
*/
protected function prepareDatabase()
{
$this->migrator->setConnection($this->input->getOption('database'));
if (!$this->migrator->repositoryExists()) {
$options = ['--database' => $this->input->getOption('database')];
$this->call('migrate:install', $options);
}
}
示例8: fire
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$this->migrator->setConnection($this->input->getOption('database'));
$package = $this->input->getOption('package') ?: 'application';
// The pretend option can be used for "simulating" the migration and grabbing
// the SQL queries that would fire if the migration were to be run against
// a database for real, which is helpful for double checking migrations.
$pretend = $this->input->getOption('pretend');
$path = $this->getMigrationPath();
$this->migrator->run($this->output, $package, $path, $pretend);
}
示例9: fire
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$this->migrator->setConnection($this->input->getOption('database'));
$pretend = $this->input->getOption('pretend');
$this->migrator->rollback($pretend);
// Once the migrator has run we will grab the note output and send it out to
// the console screen, since the migrator itself functions without having
// any instances of the OutputInterface contract passed into the class.
foreach ($this->migrator->getNotes() as $note) {
$this->output->writeln($note);
}
}
示例10: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
if (!$this->confirmToProceed()) {
return;
}
$this->migrator->setConnection($this->option('database'));
$paths = $this->getMigrationPaths();
$this->migrator->rollback($paths, ['pretend' => $this->option('pretend'), 'step' => (int) $this->option('step')]);
foreach ($this->migrator->getNotes() as $note) {
$this->output->writeln($note);
}
}
示例11: fire
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
if (!$this->confirmToProceed()) {
return;
}
$this->migrator->setConnection($this->option('database'));
$this->migrator->rollback($this->getMigrationPaths(), ['pretend' => $this->option('pretend'), 'step' => (int) $this->option('step')]);
// Once the migrator has run we will grab the note output and send it out to
// the console screen, since the migrator itself functions without having
// any instances of the OutputInterface contract passed into the class.
foreach ($this->migrator->getNotes() as $note) {
$this->output->writeln($note);
}
}
示例12: runDown
/**
* Run "down" a migration instance. (Overridden)
*
* @param object $migration
* @param bool $pretend
* @return void
*/
protected function runDown($migration, $pretend)
{
$migrations = [$migration->migration];
// Retrieve migration path and throw exception if it doesn't exist
$path = $this->getMigrationPath(true);
$this->requireFiles($path, $migrations);
parent::runDown($migration, $pretend);
}
示例13: prepareDatabase
/**
* Prepare the migration database for running.
*/
private function prepareDatabase()
{
if ($database = $this->getStringOption('database')) {
$this->migrator->setConnection($database);
}
if (!$this->migrator->repositoryExists()) {
$this->call('migrate:install', ['--database' => $database]);
}
}
示例14: reset
/**
* Run the migration reset for the specified module.
*
* @param string $slug
* @return mixed
*/
protected function reset($slug)
{
$this->migrator->setconnection($this->input->getOption('database'));
$pretend = $this->input->getOption('pretend');
$migrationPath = $this->getMigrationPath($slug);
$migrations = $this->migrator->getMigrationFiles($migrationPath);
if (count($migrations) == 0) {
return $this->error('Nothing to rollback.');
}
// We need to reverse these migrations so that they are "downed" in reverse
// to what they run on "up". It lets us backtrack through the migrations
// and properly reverse the entire database schema operation that originally
// ran.
foreach ($migrations as $migration) {
$this->info('Migration: ' . $migration);
$this->runDown($slug, $migration, $pretend);
}
}
示例15: run
public function run($path, $pretend = false)
{
parent::run($path, $pretend);
$key = Config::get('database.default');
$database = Config::get('database.connections.' . $key . '.database');
$this->note('<info>Generating schema for: ' . $database . '</info>');
$builder = new Builder();
$builder->convert($database);
$builder->write();
}