aboutsummaryrefslogtreecommitdiff
path: root/cli/Commands/Migrate/Migrate.php
blob: f5acff89dac9e0bc8ae07e7ba87de4feea407e5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php

namespace Studip\Cli\Commands\Migrate;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class Migrate extends Command
{
    protected static $defaultName = 'migrate';

    protected function configure(): void
    {
        $this->setDescription('Run the database migrations.');
        $this->setHelp('This command runs all pending database migrations.');

        $this->addOption('branch', 'b', InputOption::VALUE_OPTIONAL, 'the branch of the migrations', '0');

        $this->addOption('domain', 'd', InputOption::VALUE_OPTIONAL, 'the domain of the migrations', 'studip');

        $defaultPath = $GLOBALS['STUDIP_BASE_PATH'] . '/db/migrations';
        $this->addOption('path', 'p', InputOption::VALUE_OPTIONAL, 'the id of the migration to list to', $defaultPath);

        $this->addOption('target', 't', InputOption::VALUE_OPTIONAL, 'the target version', null);
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $branch = $input->getOption('branch');
        $domain = $input->getOption('domain');
        $path = $input->getOption('path');
        $target = $input->getOption('target');
        $verbose = $input->getOption('verbose');

        $version = new \DBSchemaVersion($domain, $branch);
        $migrator = new \Migrator($path, $version, $verbose);
        $migrator->migrateTo($target);

        return Command::SUCCESS;
    }
}