Convert SamplePlugin to new-style table defs, tweak some stuff to test basic checkschema
This commit is contained in:
parent
8b0ba03a2e
commit
3b6f738ab7
@ -254,6 +254,9 @@ class Schema
|
||||
*/
|
||||
function appendForeignKeyDef(array &$sql, $name, array $def)
|
||||
{
|
||||
if (count($def) != 2) {
|
||||
throw new Exception("Invalid foreign key def for $name: " . var_export($def, true));
|
||||
}
|
||||
list($refTable, $map) = $def;
|
||||
$srcCols = array_keys($map);
|
||||
$refCols = array_values($map);
|
||||
@ -884,7 +887,7 @@ class Schema
|
||||
if (!$cd->nullable) {
|
||||
$column['not null'] = true;
|
||||
}
|
||||
if ($cd->autoincrement) {
|
||||
if ($cd->auto_increment) {
|
||||
$column['type'] = 'serial';
|
||||
}
|
||||
if ($cd->default) {
|
||||
@ -942,13 +945,13 @@ class Schema
|
||||
*/
|
||||
function validateDef($tableName, array $def)
|
||||
{
|
||||
if (count($defs) && $defs[0] instanceof ColumnDef) {
|
||||
$def = $this->oldToNew($tableName, $defs);
|
||||
if (count($def) && $def[0] instanceof ColumnDef) {
|
||||
$def = $this->oldToNew($tableName, $def);
|
||||
}
|
||||
|
||||
// A few quick checks :D
|
||||
if (!isset($def['fields'])) {
|
||||
throw new Exceptioni("Invalid table definition for $tableName: no fields.");
|
||||
throw new Exception("Invalid table definition for $tableName: no fields.");
|
||||
}
|
||||
|
||||
return $def;
|
||||
|
@ -73,8 +73,8 @@ class Ostatus_profile extends Managed_DataObject
|
||||
'ostatus_profile_feeduri_idx' => array('feeduri'),
|
||||
),
|
||||
'foreign keys' => array(
|
||||
'profile_id' => array('profile' => 'id'),
|
||||
'group_id' => array('user_group' => 'id'),
|
||||
'ostatus_profile_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
|
||||
'ostatus_profile_group_id_fkey' => array('user_group', array('group_id' => 'id')),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -172,9 +172,20 @@ class SamplePlugin extends Plugin
|
||||
// For storing user-submitted flags on profiles
|
||||
|
||||
$schema->ensureTable('user_greeting_count',
|
||||
array(new ColumnDef('user_id', 'integer', null,
|
||||
true, 'PRI'),
|
||||
new ColumnDef('greeting_count', 'integer')));
|
||||
array(
|
||||
'fields' => array(
|
||||
'user_id' => array('type' => 'int', 'not null' => true),
|
||||
'greeting_count' => array('type' => 'int'),
|
||||
),
|
||||
'primary key' => array('user_id'),
|
||||
'foreign keys' => array(
|
||||
// Not all databases will support foreign keys, but even
|
||||
// when not enforced it's helpful to include these definitions
|
||||
// as documentation.
|
||||
'user_greeting_count_user_id_fkey' => array('user', array('user_id' => 'id')),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user