Skip to content

Commit

Permalink
Revert "Squash core migrations (#2842)"
Browse files Browse the repository at this point in the history
This reverts commit 6ecca95.
  • Loading branch information
luceos committed May 29, 2021
1 parent a976a21 commit 16f3ae9
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 510 deletions.
367 changes: 0 additions & 367 deletions migrations/install.dump

This file was deleted.

2 changes: 0 additions & 2 deletions src/Console/ConsoleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ public function register()
ResetCommand::class,
ScheduleListCommand::class,
ScheduleRunCommand::class
// Used internally to create DB dumps before major releases.
// \Flarum\Database\Console\GenerateDumpCommand::class
];
});

Expand Down
87 changes: 0 additions & 87 deletions src/Database/Console/GenerateDumpCommand.php

This file was deleted.

16 changes: 16 additions & 0 deletions src/Database/DatabaseMigrationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ public function delete($file, $extension = null)
$query->delete();
}

/**
* Create the migration repository data store.
*
* @return void
*/
public function createRepository()
{
$schema = $this->connection->getSchemaBuilder();

$schema->create($this->table, function ($table) {
$table->increments('id');
$table->string('migration');
$table->string('extension')->nullable();
});
}

/**
* Determine if the migration repository exists.
*
Expand Down
7 changes: 7 additions & 0 deletions src/Database/MigrationRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public function log($file, $extension = null);
*/
public function delete($file, $extension = null);

/**
* Create the migration repository data store.
*
* @return void
*/
public function createRepository();

/**
* Determine if the migration repository exists.
*
Expand Down
73 changes: 20 additions & 53 deletions src/Database/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@
use Exception;
use Flarum\Extension\Extension;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Database\MySqlConnection;
use Illuminate\Database\Schema\Builder;
use Illuminate\Database\Schema\SchemaState;
use Illuminate\Filesystem\Filesystem;
use InvalidArgumentException;
use Symfony\Component\Console\Output\OutputInterface;

/**
Expand Down Expand Up @@ -45,18 +42,6 @@ class Migrator
*/
protected $schemaBuilder;

/**
* The DB table prefix.
*/
protected $tablePrefix;

/**
* The database schema builder instance.
*
* @var SchemaState
*/
protected $schemaState;

/**
* The output interface implementation.
*
Expand All @@ -79,13 +64,7 @@ public function __construct(
$this->files = $files;
$this->repository = $repository;

if (! ($connection instanceof MySqlConnection)) {
throw new InvalidArgumentException('Only MySQL connections are supported');
}

$this->tablePrefix = $connection->getTablePrefix();
$this->schemaBuilder = $connection->getSchemaBuilder();
$this->schemaState = $connection->getSchemaState();

// Workaround for https://github.com/laravel/framework/issues/1186
$connection->getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
Expand Down Expand Up @@ -266,38 +245,6 @@ public function resolve($path, $file)
}
}

/**
* Initialize the Flarum database from a schema dump.
*
* @param string $path to the directory containing the dump.
*/
public function installFromSchema(string $path)
{
$schemaPath = "$path/install.dump";

// If we can't create a tmp file, fall back to the vendor directory.
$schemaWithPrefixes = tempnam(sys_get_temp_dir(), 'install');
if (! $schemaWithPrefixes) {
$schemaWithPrefixes = "$path/install_dump.dump.tmp";
}

$currDumpFile = file_get_contents($schemaPath);

file_put_contents($schemaWithPrefixes, str_replace('db_prefix_', $this->tablePrefix, $currDumpFile));

$this->note('<info>Loading stored database schema:</info>');
$startTime = microtime(true);

$this->schemaState->handleOutputUsing(function ($type, $buffer) {
$this->output->write($buffer);
})->load($schemaWithPrefixes);

$runTime = number_format((microtime(true) - $startTime) * 1000, 2);
$this->note('<info>Loaded stored database schema.</info> ('.$runTime.'ms)');

unlink($schemaWithPrefixes);
}

/**
* Set the output implementation that should be used by the console.
*
Expand All @@ -324,6 +271,16 @@ protected function note($message)
}
}

/**
* Get the migration repository instance.
*
* @return MigrationRepositoryInterface
*/
public function getRepository()
{
return $this->repository;
}

/**
* Determine if the migration repository exists.
*
Expand All @@ -333,4 +290,14 @@ public function repositoryExists()
{
return $this->repository->repositoryExists();
}

/**
* Get the file system instance.
*
* @return \Illuminate\Filesystem\Filesystem
*/
public function getFilesystem()
{
return $this->files;
}
}
2 changes: 1 addition & 1 deletion src/Install/Steps/RunMigrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function run()
{
$migrator = $this->getMigrator();

$migrator->installFromSchema($this->path);
$migrator->getRepository()->createRepository();
$migrator->run($this->path);
}

Expand Down

0 comments on commit 16f3ae9

Please sign in to comment.