示例#1
0
 public function getSchema()
 {
     if ($this->_schema) {
         return $this->_schema;
     }
     return $this->_schema = SchemaLoader::load('ProductBundle\\Model\\ProductFileSchemaProxy');
 }
示例#2
0
 public function getSchema()
 {
     if ($this->_schema) {
         return $this->_schema;
     }
     return $this->_schema = SchemaLoader::load('User\\Model\\UserSchemaProxy');
 }
示例#3
0
 public function getSchema()
 {
     if ($this->_schema) {
         return $this->_schema;
     }
     return $this->_schema = SchemaLoader::load('LazyRecord\\Model\\MetadataSchemaProxy');
 }
示例#4
0
 public function getSchema()
 {
     if ($this->_schema) {
         return $this->_schema;
     }
     return $this->_schema = SchemaLoader::load('OrderBundle\\Model\\OrderItemSchemaProxy');
 }
示例#5
0
 public function getSchema()
 {
     if ($this->_schema) {
         return $this->_schema;
     } elseif (@constant('static::SCHEMA_PROXY_CLASS')) {
         return $this->_schema = SchemaLoader::load(static::SCHEMA_PROXY_CLASS);
     }
     throw new RuntimeException('schema is not defined in ' . get_class($this));
 }
示例#6
0
 public function testSchemaFinder()
 {
     $finder = new SchemaFinder();
     $finder->findByPaths(['src', 'tests']);
     $schemas = SchemaLoader::loadDeclaredSchemas();
     $this->assertNotEmpty($schemas);
     foreach ($schemas as $schema) {
         $this->assertInstanceOf('LazyRecord\\Schema\\DeclareSchema', $schema);
     }
 }
 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}");
 }
示例#8
0
 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');
     }
 }
示例#9
0
 /**
  * Returns schema objects.
  *
  * @return array schema objects
  */
 public static function findSchemasByArguments(ConfigLoader $loader, $args, $logger = null)
 {
     if (count($args) && !file_exists($args[0])) {
         $classes = array();
         // it's classnames
         foreach ($args as $class) {
             // call class loader to load
             if (class_exists($class, true)) {
                 $classes[] = $class;
             } else {
                 if ($logger) {
                     $logger->warn("{$class} not found.");
                 } else {
                     echo ">>> {$class} not found.\n";
                 }
             }
         }
         return ClassUtils::schema_classes_to_objects($classes);
     } else {
         $finder = new SchemaFinder();
         if (count($args) && file_exists($args[0])) {
             $finder->paths = $args;
             foreach ($args as $file) {
                 if (is_file($file)) {
                     require_once $file;
                 }
             }
         } elseif ($paths = $loader->getSchemaPaths()) {
             $finder->setPaths($paths);
         }
         $finder->find();
         // load class from class map
         if ($classMap = $loader->getClassMap()) {
             foreach ($classMap as $file => $class) {
                 if (!is_numeric($file) && is_string($file)) {
                     require $file;
                 }
             }
         }
         return SchemaLoader::loadDeclaredSchemas();
     }
 }
 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.');
 }
示例#11
0
<?php

use LazyRecord\Schema\SchemaLoader;
$finder = new LazyRecord\Schema\SchemaFinder();
if ($app = kernel()->getApp()) {
    $finder->in($app->locate() . DIRECTORY_SEPARATOR . 'Model');
}
if ($bundles = kernel()->bundles) {
    foreach ($bundles as $bundle) {
        $finder->in($bundle->locate() . DIRECTORY_SEPARATOR . 'Model');
    }
}
$finder->find();
if (method_exists($finder, "getSchemas")) {
    return $finder->getSchemas();
}
return $finder;
return SchemaLoader::loadDeclaredSchemas();
示例#12
0
 public function getSchema()
 {
     if ($this->_schema) {
         return $this->_schema;
     } elseif (@constant('static::SCHEMA_PROXY_CLASS')) {
         // the SCHEMA_PROXY_CLASS is from the *Base.php file.
         if ($this->_schema = SchemaLoader::load(static::SCHEMA_PROXY_CLASS)) {
             return $this->_schema;
         }
         throw new Exception("Can not load " . static::SCHEMA_PROXY_CLASS);
     }
     throw new RuntimeException("schema is not defined in " . get_class($this));
 }
示例#13
0
 public function getSchema()
 {
     if ($this->_schema) {
         return $this->_schema;
     } elseif (@constant('static::schema_proxy_class')) {
         return $this->_schema = SchemaLoader::load(static::schema_proxy_class);
     }
     throw new RuntimeException("schema is not defined in " . get_class($this));
 }
示例#14
0
 /**
  * Returns schema objects.
  *
  * @return array schema objects
  */
 public static function findSchemasByArguments(ConfigLoader $loader, array $args, Logger $logger = null)
 {
     $classes = array_filter($args, function ($class) {
         return class_exists($class, true);
     });
     if (!empty($classes)) {
         return ClassUtils::schema_classes_to_objects(array_unique($classes));
     }
     $paths = array_filter($args, 'file_exists');
     if (empty($paths)) {
         $paths = $loader->getSchemaPaths();
     }
     if (!empty($paths)) {
         $finder = new SchemaFinder($paths);
         $finder->find();
     }
     // load class from class map
     if ($classMap = $loader->getClassMap()) {
         foreach ($classMap as $file => $class) {
             if (is_numeric($file)) {
                 continue;
             }
             require_once $file;
         }
     }
     return SchemaLoader::loadDeclaredSchemas();
 }