Skip to content

Commit

Permalink
Fix text type and timestamps precision
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarafdev committed Aug 29, 2020
1 parent 0ef87e8 commit b087636
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ protected function getFields($columns, IndexGenerator $indexGenerator)
$type = 'softDeletes';
$name = '';
} elseif ($name == 'created_at' and isset($fields['updated_at'])) {
$fields['updated_at'] = ['field' => '', 'type' => 'timestamps'];
$fields['updated_at'] = ['field' => '', 'type' => 'timestamps', 'args' => $column->getPrecision()];
continue;
} elseif ($name == 'updated_at' and isset($fields['created_at'])) {
$fields['created_at'] = ['field' => '', 'type' => 'timestamps'];
$fields['created_at'] = ['field' => '', 'type' => 'timestamps', 'args' => $column->getPrecision()];
continue;
}
} elseif (in_array($type, ['decimal', 'float', 'double'])) {
Expand Down
26 changes: 18 additions & 8 deletions src/OscarAFDev/MigrationsGenerator/Syntax/AddToTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,24 @@ protected function getItem(array $field)

// If we have args, then it needs
// to be formatted a bit differently
if (isset($field['args'])) {
$output = sprintf(
"\$table->%s(%s, %s)",
$type,
$property,
$field['args']
);
}
if (isset($field['args']) && $type !== 'text')
{
if ($property == '' || $property == null) {
$output = sprintf(
"\$table->%s(%s)",
$type,
$field['args']
);
}
else {
$output = sprintf(
"\$table->%s('%s', %s)",
$type,
$property,
$field['args']
);
}
}
if (isset($field['decorators'])) {
$output .= $this->addDecorators( $field['decorators'] );
}
Expand Down

0 comments on commit b087636

Please sign in to comment.