Skip to content

Commit

Permalink
Show a nice message if triggers, indexes, columns, etc are not setup …
Browse files Browse the repository at this point in the history
…on a table
  • Loading branch information
zacharymarshal committed Mar 7, 2014
1 parent 589cde4 commit c29bd8a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 12 deletions.
7 changes: 6 additions & 1 deletion Controller/SchemaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ public function tableDescribe()

$description = new \SQLBoss\Describe\Table($schema, $table, $table_queries);
$this->set('table_name', $this->params['pass'][0]);
$this->set('description', $description);
$this->set('columns', $description->getFields());
$this->set('indexes', $description->getIndexes());
$this->set('foreign_keys', $description->getForeignKeys());
$this->set('triggers', $description->getTriggers());
$this->set('references', $description->getReferences());
$this->set('checks', $description->getChecks());
}

public function tableDefinition()
Expand Down
64 changes: 53 additions & 11 deletions View/Schema/table_describe.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,23 @@ $this->Html->css('/media/sqlboss/schema/css/tableDescribe', null, array('inline'
</tr>
</thead>
<tbody>
<?php foreach ($description->getFields() as $field): ?>
<?php if (!$columns): ?>
<tr>
<td><?php echo $field['column'] ?></td>
<td><pre data-language="generic" class="nowrap"><?php echo $field['type'] ?></pre></td>
<td colspan="3">
<em>No columns</em>
</td>
</tr>
<?php endif ?>
<?php foreach ($columns as $column): ?>
<tr>
<td><?php echo $column['column'] ?></td>
<td><pre data-language="generic" class="nowrap"><?php echo $column['type'] ?></pre></td>
<td>
<pre data-language="generic" class="nowrap"><?php echo ($field['not_null'] ? "not null" : '') ?> <?php echo $field['default'] ?></pre>
<pre data-language="generic" class="nowrap"><?php echo ($column['not_null'] ? "not null" : '') ?> <?php echo $column['default'] ?></pre>
</td>
<td><?php echo $field['comment'] ?></td>
<td><?php echo $column['comment'] ?></td>
</tr>
<?php endforeach ?>
<?php endforeach ?>
</tbody>
</table>
<h3>Indexes</h3>
Expand All @@ -57,7 +64,14 @@ $this->Html->css('/media/sqlboss/schema/css/tableDescribe', null, array('inline'
</tr>
</thead>
<tbody>
<?php foreach ($description->getIndexes() as $index): ?>
<?php if (!$indexes): ?>
<tr>
<td colspan="3">
<em>No indexes</em>
</td>
</tr>
<?php endif ?>
<?php foreach ($indexes as $index): ?>
<tr>
<td><?php echo $index['relname'] ?></td>
<td><pre data-language="generic"><?php echo $index['definition'] ?></pre></td>
Expand All @@ -74,7 +88,14 @@ $this->Html->css('/media/sqlboss/schema/css/tableDescribe', null, array('inline'
</tr>
</thead>
<tbody>
<?php foreach ($description->getChecks() as $check): ?>
<?php if (!$checks): ?>
<tr>
<td colspan="3">
<em>No check constraints</em>
</td>
</tr>
<?php endif ?>
<?php foreach ($checks as $check): ?>
<tr>
<td><?php echo $check['conname'] ?></td>
<td><pre data-language="generic"><?php echo $check['condef'] ?></pre></td>
Expand All @@ -91,7 +112,14 @@ $this->Html->css('/media/sqlboss/schema/css/tableDescribe', null, array('inline'
</tr>
</thead>
<tbody>
<?php foreach ($description->getForeignKeys() as $fk): ?>
<?php if (!$foreign_keys): ?>
<tr>
<td colspan="3">
<em>No foreign-key contraints</em>
</td>
</tr>
<?php endif ?>
<?php foreach ($foreign_keys as $fk): ?>
<tr>
<td><?php echo $fk['conname'] ?></td>
<td><pre data-language="generic"><?php echo $fk['condef'] ?></pre></td>
Expand All @@ -109,7 +137,14 @@ $this->Html->css('/media/sqlboss/schema/css/tableDescribe', null, array('inline'
</tr>
</thead>
<tbody>
<?php foreach ($description->getTriggers() as $trigger): ?>
<?php if (!$triggers): ?>
<tr>
<td colspan="3">
<em>No triggers</em>
</td>
</tr>
<?php endif ?>
<?php foreach ($triggers as $trigger): ?>
<tr>
<td>
<?php if ($trigger['tgenabled'] == 'D'): ?>
Expand All @@ -134,7 +169,14 @@ $this->Html->css('/media/sqlboss/schema/css/tableDescribe', null, array('inline'
</tr>
</thead>
<tbody>
<?php foreach ($description->getReferences() as $ref): ?>
<?php if (!$references): ?>
<tr>
<td colspan="3">
<em>Not referenced</em>
</td>
</tr>
<?php endif ?>
<?php foreach ($references as $ref): ?>
<tr>
<td><?php echo $ref['ref_table'] ?></td>
<td><?php echo $ref['conname'] ?></td>
Expand Down

0 comments on commit c29bd8a

Please sign in to comment.