diff --git a/src/Xethron/MigrationsGenerator/Generators/FieldGenerator.php b/src/Xethron/MigrationsGenerator/Generators/FieldGenerator.php index 0ac0220..53c5069 100644 --- a/src/Xethron/MigrationsGenerator/Generators/FieldGenerator.php +++ b/src/Xethron/MigrationsGenerator/Generators/FieldGenerator.php @@ -21,6 +21,19 @@ class FieldGenerator { */ protected $database; + /** + * @var bool + */ + private $unusedTimestamps; + + /** + * @param bool $unusedTimestamps + */ + public function __construct($unusedTimestamps) + { + $this->unusedTimestamps = $unusedTimestamps; + } + /** * Create array of all the fields for a table * @@ -124,10 +137,10 @@ protected function getFields($columns, IndexGenerator $indexGenerator) $nullable = false; $type = 'softDeletes'; $name = ''; - } elseif ($name == 'created_at' and isset($fields['updated_at'])) { + } elseif (($name == 'created_at' and isset($fields['updated_at'])) and !$this->unusedTimestamps) { $fields['updated_at'] = ['field' => '', 'type' => 'timestamps']; continue; - } elseif ($name == 'updated_at' and isset($fields['created_at'])) { + } elseif (($name == 'updated_at' and isset($fields['created_at'])) and !$this->unusedTimestamps) { $fields['created_at'] = ['field' => '', 'type' => 'timestamps']; continue; } diff --git a/src/Xethron/MigrationsGenerator/Generators/SchemaGenerator.php b/src/Xethron/MigrationsGenerator/Generators/SchemaGenerator.php index 89b0a11..8b21196 100644 --- a/src/Xethron/MigrationsGenerator/Generators/SchemaGenerator.php +++ b/src/Xethron/MigrationsGenerator/Generators/SchemaGenerator.php @@ -34,10 +34,11 @@ class SchemaGenerator { /** * @param string $database + * @param bool $unusedTimestamps * @param bool $ignoreIndexNames * @param bool $ignoreForeignKeyNames */ - public function __construct($database, $ignoreIndexNames, $ignoreForeignKeyNames) + public function __construct($database, $unusedTimestamps, $ignoreIndexNames, $ignoreForeignKeyNames) { $connection = DB::connection($database)->getDoctrineConnection(); $connection->getDatabasePlatform()->registerDoctrineTypeMapping('json', 'text'); @@ -48,7 +49,7 @@ public function __construct($database, $ignoreIndexNames, $ignoreForeignKeyNames $this->database = $connection->getDatabase(); $this->schema = $connection->getSchemaManager(); - $this->fieldGenerator = new FieldGenerator(); + $this->fieldGenerator = new FieldGenerator($unusedTimestamps); $this->foreignKeyGenerator = new ForeignKeyGenerator(); $this->ignoreIndexNames = $ignoreIndexNames; diff --git a/src/Xethron/MigrationsGenerator/MigrateGenerateCommand.php b/src/Xethron/MigrationsGenerator/MigrateGenerateCommand.php index 9585b07..2573102 100644 --- a/src/Xethron/MigrationsGenerator/MigrateGenerateCommand.php +++ b/src/Xethron/MigrationsGenerator/MigrateGenerateCommand.php @@ -141,6 +141,7 @@ public function fire() } $this->schemaGenerator = new SchemaGenerator( $this->option('connection'), + $this->option('unusedTimestamps'), $this->option('defaultIndexNames'), $this->option('defaultFKNames') ); @@ -353,6 +354,7 @@ protected function getOptions() ['connection', 'c', InputOption::VALUE_OPTIONAL, 'The database connection to use.', $this->config->get( 'database.default' )], ['tables', 't', InputOption::VALUE_OPTIONAL, 'A list of Tables you wish to Generate Migrations for separated by a comma: users,posts,comments'], ['ignore', 'i', InputOption::VALUE_OPTIONAL, 'A list of Tables you wish to ignore, separated by a comma: users,posts,comments' ], + ['unusedTimestamps', 'u', InputOption::VALUE_OPTIONAL, 'Unused to timestamps(), so field of created_at and updated_at' ], ['path', 'p', InputOption::VALUE_OPTIONAL, 'Where should the file be created?'], ['templatePath', 'tp', InputOption::VALUE_OPTIONAL, 'The location of the template for this generator'], ['defaultIndexNames', null, InputOption::VALUE_NONE, 'Don\'t use db index names for migrations'],