Skip to content

Commit

Permalink
add migration name length limit
Browse files Browse the repository at this point in the history
  • Loading branch information
sakuraovq committed Jul 12, 2019
1 parent f9e7e39 commit 58314b8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/devtool/src/Annotation/Parser/MigrationParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public function parse(int $type, $annotationObject): array
throw new InvalidArgumentException(get_class($annotationObject) . ' time params must exists');
}

if (StringHelper::length($migrationName) > 255) {
throw new InvalidArgumentException(get_class($annotationObject) .
' this class name too long, please reduce the length');
}

MigrationRegister::registerMigration($migrationName, $time, $annotationObject->getPool());

return [$migrationName, $className, Bean::PROTOTYPE, ''];
Expand Down
2 changes: 1 addition & 1 deletion src/devtool/src/Command/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function create(): void
$isConfirm = input()->getOpt('y', false);

if (empty($name)) {
throw new MigrationException("name param can't be empty", $name);
throw new MigrationException("name param can't be empty");
}
$this->logic->create($name, (bool)$isConfirm);
} catch (Throwable $e) {
Expand Down
15 changes: 10 additions & 5 deletions src/devtool/src/Model/Logic/MigrateLogic.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Swoft\Devtool\Model\Logic;

use InvalidArgumentException;
use Leuffen\TextTemplate\TemplateParsingException;
use ReflectionException;
use Swoft;
Expand Down Expand Up @@ -70,6 +71,11 @@ public function create($name, bool $notConfirm = true): void
throw new MigrationException(sprintf("%s migration exists, please check migration !", $name));
}

if (StringHelper::length($mappingClass) > 255) {
throw new InvalidArgumentException($mappingClass .
' this class name too long, please reduce the length');
}

$tplDir = $migrate->getTemplateDir();
$config = [
'tplFilename' => $migrate->getTemplateFile(),
Expand Down Expand Up @@ -572,10 +578,8 @@ private function runMigration(Builder $schema, string $migrateName, string $meth
}
};

$schema->grammar->supportsSchemaTransactions() ?
$schema->getConnection()->transaction($callback) :
$callback();

$schema->grammar->supportsSchemaTransactions() ? $schema->getConnection()->transaction($callback) : $callback();

return true;
}

Expand Down Expand Up @@ -620,9 +624,10 @@ private function createMigrationIfNotExists(Builder $schema): void
{
$schema->createIfNotExists(MigrateDao::tableName(), function (Blueprint $blueprint) {
$blueprint->increments('id');
$blueprint->string('name', 60);
$blueprint->string('name');
$blueprint->bigInteger('time');
$blueprint->tinyInteger('is_rollback');
$blueprint->renameColumn('name', 'name', 'varchar', 255);
});
}

Expand Down

0 comments on commit 58314b8

Please sign in to comment.