public static loadSchemaTableMap ( ) : |
||
리턴 | Return declared schema object in associative array |
public function execute($taskName) { $dsId = $this->getCurrentDataSourceId(); $config = $this->getConfigLoader(true); $this->logger->info('Loading schema objects...'); $finder = new SchemaFinder(); $finder->setPaths($config->getSchemaPaths() ?: array()); $finder->find(); $generator = new MigrationGenerator($this->logger, 'db/migrations'); $this->logger->info('Creating migration script from diff'); $schemaMap = SchemaLoader::loadSchemaTableMap(); list($class, $path) = $generator->generateWithDiff($taskName, $dsId, $schemaMap); $this->logger->info("Migration script is generated: {$path}"); }
public function execute() { $formatter = new \CLIFramework\Formatter(); $options = $this->options; $logger = $this->logger; $dsId = $this->getCurrentDataSourceId(); $connectionManager = \LazyRecord\ConnectionManager::getInstance(); $conn = $connectionManager->getConnection($dsId); $driver = $connectionManager->getQueryDriver($dsId); $this->logger->info('Performing comparison...'); $parser = TableParser::create($conn, $driver); $existingTables = $parser->getTables(); $tableSchemas = SchemaLoader::loadSchemaTableMap(); $found = false; $comparator = new Comparator($driver); foreach ($tableSchemas as $table => $currentSchema) { $this->logger->debug("Checking table {$table}"); $ref = new ReflectionObject($currentSchema); $filepath = $ref->getFilename(); $filepath = substr($filepath, strlen(getcwd()) + 1); if (in_array($table, $existingTables)) { $before = $parser->reverseTableSchema($table, $currentSchema); $diffs = $comparator->compare($before, $currentSchema); if (count($diffs)) { $found = true; $printer = new ComparatorConsolePrinter($diffs); $printer->beforeName = $table . ":data source [{$dsId}]"; $printer->afterName = $table . ':' . $filepath; $printer->output(); } } else { $msg = sprintf('+ table %-20s %s', "'" . $table . "'", $filepath); echo $formatter->format($msg, 'green'), "\n"; $a = isset($tableSchemas[$table]) ? $tableSchemas[$table] : null; $diff = $comparator->compare(new DeclareSchema(), $currentSchema); foreach ($diff as $diffItem) { echo ' ', $diffItem->toColumnAttrsString(), "\n"; } $found = true; } } if (!$found) { $this->logger->info('No diff found'); } }
public function execute() { $dsId = $this->getCurrentDataSourceId(); $container = ServiceContainer::getInstance(); $conn = $this->getCurrentConnection(); $driver = $this->getCurrentQueryDriver(); if ($this->options->backup) { if (!$driver instanceof PDOMySQLDriver) { $this->logger->error('backup is only supported for MySQL'); return false; } $this->logger->info('Backing up database...'); $backup = new MySQLBackup(); if ($dbname = $backup->incrementalBackup($conn)) { $this->logger->info("Backup at {$dbname}"); } } $runner = new MigrationRunner($this->logger, $dsId); $this->logger->info("Performing automatic upgrade over data source: {$dsId}"); $tableSchemas = SchemaLoader::loadSchemaTableMap(); $runner->runUpgradeAutomatically($conn, $driver, $tableSchemas, $this->options); $this->logger->info('Done.'); }