-
-
Notifications
You must be signed in to change notification settings - Fork 842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Squash core migrations #2842
Merged
Merged
Squash core migrations #2842
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c67e526
Squash core migrations into SQL dump
askvortsov1 92f6197
Put prefixed dump into temp file instead of overriding current
askvortsov1 e685980
Try making schema with prefix file in tmp dir
askvortsov1 37878a5
Apply fixes from StyleCI
askvortsov1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* For detailed copyright and license information, please view the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Flarum\Database\Console; | ||
|
||
use Flarum\Console\AbstractCommand; | ||
use Flarum\Foundation\Paths; | ||
use Illuminate\Database\Connection; | ||
|
||
class GenerateDumpCommand extends AbstractCommand | ||
{ | ||
/** | ||
* @var Connection | ||
*/ | ||
protected $connection; | ||
|
||
/** | ||
* @var Paths | ||
*/ | ||
protected $paths; | ||
|
||
/** | ||
* @param Connection $connection | ||
* @param Paths $paths | ||
*/ | ||
public function __construct(Connection $connection, Paths $paths) | ||
{ | ||
$this->connection = $connection; | ||
$this->paths = $paths; | ||
|
||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('schema:dump') | ||
->setDescription('Dump DB schema'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function fire() | ||
{ | ||
$dumpPath = __DIR__.'/../../../migrations/install.dump'; | ||
/** @var Connection */ | ||
askvortsov1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$connection = resolve('db.connection'); | ||
|
||
$connection | ||
->getSchemaState() | ||
->withMigrationTable($connection->getTablePrefix().'migrations') | ||
->handleOutputUsing(function ($type, $buffer) { | ||
$this->output->write($buffer); | ||
}) | ||
->dump($connection, $dumpPath); | ||
|
||
// We need to remove any data migrations, as those won't be captured | ||
// in the schema dump, and must be run separately. | ||
$coreDataMigrations = [ | ||
'2018_07_21_000000_seed_default_groups', | ||
'2018_07_21_000100_seed_default_group_permissions', | ||
]; | ||
|
||
$newDump = []; | ||
$dump = file($dumpPath); | ||
foreach ($dump as $line) { | ||
foreach ($coreDataMigrations as $excludeMigrationId) { | ||
if (strpos($line, $excludeMigrationId) !== false) { | ||
continue 2; | ||
} | ||
} | ||
$newDump[] = $line; | ||
} | ||
|
||
file_put_contents($dumpPath, implode($newDump)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to put this command inside of the source code?
We likely won't need it before a while, and it might end up broken without us even realizing it in the meantime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which is why I commented it out. I wanted to keep it so that we could debug how the dump was created if we run into issues with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just don't really like the idea of having that code lying around unused for 1,2,5 years? in the repo. I feel like it would be best inside of an issue, or a dedicated branch so we can find it again later but don't ship it / maintain it as part of the whole 1.x release cycle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to put it in the Flarum CLI, but didn't have time to rewrite it so that it worked for this.