Version20171021093246.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 Version20171021093246 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('valid_since')) {
  20. return;
  21. }
  22. $shortUrls->addColumn('valid_since', Types::DATETIME_MUTABLE, [
  23. 'notnull' => false,
  24. ]);
  25. $shortUrls->addColumn('valid_until', Types::DATETIME_MUTABLE, [
  26. 'notnull' => false,
  27. ]);
  28. }
  29. /**
  30. * @throws SchemaException
  31. */
  32. public function down(Schema $schema): void
  33. {
  34. $shortUrls = $schema->getTable('short_urls');
  35. if (! $shortUrls->hasColumn('valid_since')) {
  36. return;
  37. }
  38. $shortUrls->dropColumn('valid_since');
  39. $shortUrls->dropColumn('valid_until');
  40. }
  41. /**
  42. * @fixme Workaround for https://github.com/doctrine/migrations/issues/1104
  43. */
  44. public function isTransactional(): bool
  45. {
  46. return false;
  47. }
  48. }