public function execute() { $options = $this->options; $logger = $this->logger; $id = $this->getCurrentDataSourceId(); $logger->debug("Finding schema classes..."); $schemas = $this->findSchemasByArguments(func_get_args()); $logger->debug("Initialize schema builder..."); $connectionManager = ConnectionManager::getInstance(); $conn = $connectionManager->getConnection($id); $driver = $connectionManager->getQueryDriver($id); $sqlBuilder = SqlBuilder::create($driver, array('rebuild' => $options->rebuild, 'clean' => $options->clean)); $builder = new DatabaseBuilder($conn, $sqlBuilder, $this->logger); $sqls = $builder->build($schemas); $sqlOutput = join("\n", $sqls); if ($file = $this->options->file) { $fp = fopen($file, 'w'); fwrite($fp, $sqlOutput); fclose($fp); } if ($this->options->basedata) { $collection = new SchemaCollection($schemas); $collection = $collection->evaluate(); $seedBuilder = new SeedBuilder($this->getConfigLoader(), $this->logger); $seedBuilder->build($collection); } $time = time(); $logger->info("Setting migration timestamp to {$time}"); $metadata = new Metadata($driver, $conn); // update migration timestamp $metadata['migration'] = $time; $logger->info($logger->formatter->format('Done. ' . count($schemas) . " schema tables were generated into data source '{$id}'.", 'green')); }
public function seed(array $schemas, ConfigLoader $config = null) { $seedBuilder = new SeedBuilder($this->logger); $seedBuilder->build(new SchemaCollection($schemas)); if ($config) { $seedBuilder->buildConfigSeeds($config); } }
public function execute() { $options = $this->options; $logger = $this->logger; $classes = $this->findSchemasByArguments(func_get_args()); SchemaUtils::printSchemaClasses($classes, $this->logger); $collection = new SchemaCollection($classes); $collection = $collection->evaluate(); $seedBuilder = new SeedBuilder($this->getConfigLoader(), $this->logger); $seedBuilder->build($collection); $this->logger->info('Done'); }
public function setUp() { if ($this->onlyDriver !== null && $this->getDataSource() != $this->onlyDriver) { return $this->markTestSkipped("{$this->onlyDriver} only"); } $this->prepareConnection(); // Ensure that we use the correct default data source ID $this->assertEquals($this->getDataSource(), $this->config->getDefaultDataSourceId()); $this->assertInstanceOf('SQLBuilder\\Driver\\BaseDriver', $this->queryDriver, 'QueryDriver object OK'); // Rebuild means rebuild the database for new tests $annnotations = $this->getAnnotations(); $rebuild = true; $basedata = true; if (isset($annnotations['method']['rebuild'][0]) && $annnotations['method']['rebuild'][0] == 'false') { $rebuild = false; } if (isset($annnotations['method']['basedata'][0]) && $annnotations['method']['basedata'][0] == 'false') { $basedata = false; } $schemas = ClassUtils::schema_classes_to_objects($this->getModels()); if (false === $this->schemaHasBeenBuilt) { $g = new SchemaGenerator($this->config); $g->setForceUpdate(true); $g->generate($schemas); $this->schemaHasBeenBuilt = true; } if ($rebuild === false) { $tableParser = TableParser::create($this->conn, $this->queryDriver, $this->config); $tables = $tableParser->getTables(); $schemas = array_filter($schemas, function ($schema) use($tables) { return !in_array($schema->getTable(), $tables); }); } $this->sqlBuilder = SqlBuilder::create($this->queryDriver, array('rebuild' => $rebuild)); $this->bootstrap = new Bootstrap($this->conn, $this->sqlBuilder, $this->logger); $this->bootstrap->build($schemas); if ($rebuild && $basedata) { $seeder = new SeedBuilder($this->logger); $seeder->build(new SchemaCollection($schemas)); $seeder->buildConfigSeeds($this->config); } }