Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #135 : add option when created_at and updated_at are the other co… #138

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/Xethron/MigrationsGenerator/Generators/FieldGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/Xethron/MigrationsGenerator/MigrateGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public function fire()
}
$this->schemaGenerator = new SchemaGenerator(
$this->option('connection'),
$this->option('unusedTimestamps'),
$this->option('defaultIndexNames'),
$this->option('defaultFKNames')
);
Expand Down Expand Up @@ -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'],
Expand Down