예제 #1
0
 public function testSanity()
 {
     $reader = new SchemaReader(self::$currentDatabase);
     $schemas = $reader->load();
     $this->assertCount(4, $schemas);
     // test tables
     $this->assertCount(0, array_diff(array('p1', 'p2'), array_keys($schemas['public']->getRelations())));
     $this->assertCount(0, array_diff(array('s1', 's2', 's3'), array_keys($schemas['schema1']->getRelations())));
     $this->assertCount(0, array_diff(array('s1', 's2', 's3', 's4'), array_keys($schemas['schema2']->getRelations())));
     $rels = $schemas['public']->getRelations();
     $this->assertCount(0, array_diff(array('col1'), array_keys($rels['p1']->getColumns())));
     $this->assertCount(0, array_diff(array('col1', 'col2'), array_keys($rels['p2']->getColumns())));
     $rels = $schemas['schema1']->getRelations();
     $this->assertCount(0, array_diff(array('col1'), array_keys($rels['s1']->getColumns())));
     $this->assertCount(0, array_diff(array('col1', 'col2'), array_keys($rels['s2']->getColumns())));
     $this->assertCount(0, array_diff(array('col1', 'col2', 'col3'), array_keys($rels['s3']->getColumns())));
     $keysSchema = $schemas['k'];
     $keySchemaRelations = $keysSchema->getRelations();
     $table_with_pk = $keySchemaRelations['table_with_pk'];
     $keys = $table_with_pk->getUniqueKeys();
     $this->assertArrayHasKey('PRIMARY KEY', $keys);
     $this->assertCount(1, $keys['PRIMARY KEY']);
     $table_with_two_pk = $keySchemaRelations['table_with_two_pk'];
     $keys = $table_with_two_pk->getUniqueKeys();
     $this->assertArrayHasKey('PRIMARY KEY', $keys);
     $this->assertCount(2, $keys['PRIMARY KEY']);
     $table_with_unique_key = $keySchemaRelations['table_with_unique_key'];
     $keys = $table_with_unique_key->getUniqueKeys();
     $this->assertCount(1, $keys);
 }
예제 #2
0
 /**
  * Load the Schema information from the database that is configured in the
  * config.json
  * @return boolean
  */
 protected function loadDatabaseSchema()
 {
     $database = $this->createDatabaseInstance();
     $schemaReader = new SchemaReader($database);
     $schemas = $schemaReader->load();
     if (is_null($this->config->getSchemaListToGenerate())) {
         $this->schemas = $schemas;
     } else {
         foreach ($this->config->getSchemaListToGenerate() as $name) {
             if (isset($schemas[$name])) {
                 $this->schemas[$name] = $schemas[$name];
             } else {
                 $this->output->writeln("<error>There is no [{$name}] schema in this database.</error>");
             }
         }
     }
     if (!isset($this->schemas['public'])) {
         $this->output->writeln("<warn>WARNING: The [public] schema from your database was not selected!</warn>");
     }
     return true;
 }