Skip to content
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

Add the exclude-stripped-tables put option #75

Open
wants to merge 3 commits into
base: release/5.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ There are some advanced configuration options that you may be interested in, suc

### Upload a database backup

magedbm2 put [--strip="@development"] [--clean=NUM|--no-clean] <project>
magedbm2 put [--strip="@development"] [--exclude-stripped-tables] [--clean=NUM|--no-clean] <project>

The `put` command will create a database backup and upload it to S3. If no database parameters are passed through on the command line, Magento will be assumed, and the database details will attempted to be loaded from the current working directory, or the directory specified by `--root-dir`.

By default, the tables defined in the `@development` table group (which can be seen by running `magedbm2 put --help`) will be stripped. Additional tables or table groups can be added to the `--strip` option, separated by spaces, e.g. `--strip="@log @sessions customtable customprefix*"`.

By default, the `--strip` option creates empty tables with no data for the stripped tables, to exclude those tables entirely use the option `--exclude-stripped-tables`

The `put` command also automatically cleans up old database backups once a new one has been uploaded, keeping only the 5 most recent backup files. You can customise the number of retained backups with the `--clean` option, or disable it completely with `--no-clean`.

### List available backup files
Expand Down
1 change: 1 addition & 0 deletions src/Application/Config/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ final class Option
const FORCE = 'force';
const DOWNLOAD_ONLY = 'download-only';
const STRIP = 'strip';
const EXCLUDE_STRIPPED_TABLES = 'exclude-stripped-tables';

const CLEAN_COUNT = 'clean';
const NO_CLEAN = 'no-clean';
Expand Down
9 changes: 8 additions & 1 deletion src/Command/PutCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ protected function configure()
"customer data is stripped.",
"@development"
)
->addOption(
Option::EXCLUDE_STRIPPED_TABLES,
"S",
InputOption::VALUE_NONE,
"Do not include structure for the stripped tables."
)
->addOption(
Option::CLEAN_COUNT,
"c",
Expand Down Expand Up @@ -123,6 +129,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$project = $input->getArgument(self::ARG_PROJECT);
$strip_tables = $input->getOption(Option::STRIP) ?? '@development';
$exclude_stripped_tables = $input->getOption(Option::EXCLUDE_STRIPPED_TABLES);

$output->writeln(
"<info>Creating a backup file of the database...</info>",
Expand All @@ -132,7 +139,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
try {
$this->database->setLogger($this->getLogger());

$local_file = $this->database->dump($project, $this->tableExpander->expand($strip_tables));
$local_file = $this->database->dump($project, $this->tableExpander->expand($strip_tables), $exclude_stripped_tables);

if (!file_exists($local_file)) {
throw new ServiceException(sprintf(
Expand Down
5 changes: 3 additions & 2 deletions src/Service/Database/Shell.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,13 @@ public function import($file)
*
* @param string $identifier An identifier for the dump file.
* @param string $strip_tables_patterns List of table patterns to dump with no data.
* @param bool $exclude_stripped_tables If strip tables is set, define if empty tables are excluded from the dump
*
* @return string Path to the database dump.
* @throws \Symfony\Component\Process\Exception\LogicException
* @throws \Symfony\Component\Process\Exception\RuntimeException
*/
public function dump($identifier, $strip_tables_patterns = '')
public function dump($identifier, $strip_tables_patterns = '', $exclude_stripped_tables = false)
{
$stripTables = array_filter($this->getStripTables($strip_tables_patterns));

Expand All @@ -118,7 +119,7 @@ public function dump($identifier, $strip_tables_patterns = '')
/** @var Process[] $commands */
$commands = [];

if (count($stripTables) > 0) {
if (count($stripTables) > 0 && !$exclude_stripped_tables) {
// Create the structure-only dump for tables that we don't want the data from.
$commands[] = $this->createDumpProcess()
->argument('--no-data')
Expand Down