lithium\data\source\Database::createSchema PHP Method

createSchema() public method

Create a database-native schema
public createSchema ( string $source, object $schema ) : boolean
$source string A table name.
$schema object A `Schema` instance.
return boolean `true` on success, `true` otherwise
    public function createSchema($source, $schema)
    {
        if (!$schema instanceof $this->_classes['schema']) {
            throw new InvalidArgumentException("Passed schema is not a valid `{$class}` instance.");
        }
        $columns = array();
        $primary = null;
        $source = $this->name($source);
        foreach ($schema->fields() as $name => $field) {
            $field['name'] = $name;
            if ($field['type'] === 'id') {
                $primary = $name;
            }
            $columns[] = $this->column($field);
        }
        $columns = join(",\n", array_filter($columns));
        $metas = $schema->meta() + array('table' => array(), 'constraints' => array());
        $constraints = $this->_buildConstraints($metas['constraints'], $schema, ",\n", $primary);
        $table = $this->_buildMetas('table', $metas['table']);
        $params = compact('source', 'columns', 'constraints', 'table');
        return $this->_execute($this->renderCommand('schema', $params));
    }