Skip to content

Commit 133c74f

Browse files
authored
Migrate to bigint for UNIX timestamps (#186)
1 parent 6a825d5 commit 133c74f

File tree

5 files changed

+53
-6
lines changed

5 files changed

+53
-6
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DoctrineMigrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Doctrine\Migrations\AbstractMigration;
9+
10+
/**
11+
* Scale timestamps to big int for the Year 2038 problem
12+
*/
13+
final class Version20250409193948 extends AbstractMigration
14+
{
15+
public function getDescription(): string
16+
{
17+
return 'Scale timestamps to big int for the Year 2038 problem';
18+
}
19+
20+
public function up(Schema $schema): void
21+
{
22+
$this->skipIf('sqlite' === $this->connection->getDatabasePlatform()->getName(), 'This migration is not needed on \'sqlite\'. Skipping it is fine.');
23+
24+
// MySQL
25+
if ('mysql' === $this->connection->getDatabasePlatform()->getName()) {
26+
$this->addSql('ALTER TABLE calendarobjects CHANGE lastmodified lastmodified BIGINT DEFAULT NULL, CHANGE firstoccurence firstoccurence BIGINT DEFAULT NULL, CHANGE lastoccurence lastoccurence BIGINT DEFAULT NULL');
27+
$this->addSql('ALTER TABLE calendarsubscriptions CHANGE lastmodified lastmodified BIGINT DEFAULT NULL');
28+
$this->addSql('ALTER TABLE locks CHANGE created created BIGINT DEFAULT NULL');
29+
$this->addSql('ALTER TABLE schedulingobjects CHANGE lastmodified lastmodified BIGINT DEFAULT NULL');
30+
}
31+
32+
// Posgres
33+
if ('postgresql' === $this->connection->getDatabasePlatform()->getName()) {
34+
$this->addSql('ALTER TABLE calendarobjects ALTER COLUMN lastmodified TYPE BIGINT');
35+
$this->addSql('ALTER TABLE calendarobjects ALTER COLUMN firstoccurence TYPE BIGINT');
36+
$this->addSql('ALTER TABLE calendarobjects ALTER COLUMN lastoccurence TYPE BIGINT');
37+
$this->addSql('ALTER TABLE calendarsubscriptions ALTER COLUMN lastmodified TYPE BIGINT');
38+
$this->addSql('ALTER TABLE locks ALTER COLUMN created TYPE BIGINT');
39+
$this->addSql('ALTER TABLE schedulingobjects ALTER COLUMN lastmodified TYPE BIGINT');
40+
}
41+
}
42+
43+
public function down(Schema $schema): void
44+
{
45+
// No need for a down here, it's fine
46+
}
47+
}

src/Entity/CalendarObject.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CalendarObject
2626
#[ORM\JoinColumn(name: 'calendarid', nullable: false)]
2727
private $calendar;
2828

29-
#[ORM\Column(name: 'lastmodified', type: 'integer', nullable: true)]
29+
#[ORM\Column(name: 'lastmodified', type: 'bigint', nullable: true)]
3030
private $lastModified;
3131

3232
#[ORM\Column(type: 'string', length: 255, nullable: true)]
@@ -38,10 +38,10 @@ class CalendarObject
3838
#[ORM\Column(name: 'componenttype', type: 'string', length: 255, nullable: true)]
3939
private $componentType;
4040

41-
#[ORM\Column(name: 'firstoccurence', type: 'integer', nullable: true)]
41+
#[ORM\Column(name: 'firstoccurence', type: 'bigint', nullable: true)]
4242
private $firstOccurence;
4343

44-
#[ORM\Column(name: 'lastoccurence', type: 'integer', nullable: true)]
44+
#[ORM\Column(name: 'lastoccurence', type: 'bigint', nullable: true)]
4545
private $lastOccurence;
4646

4747
#[ORM\Column(type: 'string', length: 255, nullable: true)]

src/Entity/CalendarSubscription.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class CalendarSubscription
4343
#[ORM\Column(name: 'stripattachments', type: 'smallint', nullable: true)]
4444
private $stripAttachments;
4545

46-
#[ORM\Column(name: 'lastmodified', type: 'integer', nullable: true)]
46+
#[ORM\Column(name: 'lastmodified', type: 'bigint', nullable: true)]
4747
private $lastModified;
4848

4949
public function getId(): ?int

src/Entity/Lock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Lock
1919
#[ORM\Column(type: 'integer', nullable: true)]
2020
private $timeout;
2121

22-
#[ORM\Column(type: 'integer', nullable: true)]
22+
#[ORM\Column(type: 'bigint', nullable: true)]
2323
private $created;
2424

2525
#[ORM\Column(type: 'string', length: 255, nullable: true)]

src/Entity/SchedulingObject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class SchedulingObject
2727
#[Assert\Regex("/[0-9a-z\-]+/")]
2828
private $uri;
2929

30-
#[ORM\Column(name: 'lastmodified', type: 'integer', nullable: true)]
30+
#[ORM\Column(name: 'lastmodified', type: 'bigint', nullable: true)]
3131
private $lastModified;
3232

3333
#[ORM\Column(type: 'string', length: 255, nullable: true)]

0 commit comments

Comments
 (0)