lithium\data\source\Database::createSchema()
Create a database-native schema
Parameters
-
string
$source
A table name.
-
object
$schema
A
Schema
instance.
Returns
booleantrue
on success, true
otherwise
Source
public function createSchema($source, $schema) {
if (!$schema instanceof $this->_classes['schema']) {
throw new InvalidArgumentException("Passed schema is not a valid `{$class}` instance.");
}
$columns = [];
$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() + ['table' => [], 'constraints' => []];
$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));
}