Version20171022064541.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. declare(strict_types=1);
  3. namespace ShlinkMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\DBAL\Schema\SchemaException;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\Migrations\AbstractMigration;
  8. /**
  9. * Auto-generated Migration: Please modify to your needs!
  10. */
  11. class Version20171022064541 extends AbstractMigration
  12. {
  13. /**
  14. * @throws SchemaException
  15. */
  16. public function up(Schema $schema): void
  17. {
  18. $shortUrls = $schema->getTable('short_urls');
  19. if ($shortUrls->hasColumn('max_visits')) {
  20. return;
  21. }
  22. $shortUrls->addColumn('max_visits', Types::INTEGER, [
  23. 'unsigned' => true,
  24. 'notnull' => false,
  25. ]);
  26. }
  27. /**
  28. * @throws SchemaException
  29. */
  30. public function down(Schema $schema): void
  31. {
  32. $shortUrls = $schema->getTable('short_urls');
  33. if (! $shortUrls->hasColumn('max_visits')) {
  34. return;
  35. }
  36. $shortUrls->dropColumn('max_visits');
  37. }
  38. /**
  39. * @fixme Workaround for https://github.com/doctrine/migrations/issues/1104
  40. */
  41. public function isTransactional(): bool
  42. {
  43. return false;
  44. }
  45. }