-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVersion20210701185233.php
187 lines (151 loc) · 9.45 KB
/
Version20210701185233.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210701185233 extends AbstractMigration
{
public function getDescription(): string
{
return 'Update databases to use datetime instead of datetime timezone. Only affects postgres.';
}
public function upPostgresql(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
// Regarding SELECT age(now() at time zone 'UTC', now())
// this will return an interval of how far away UTC is from the database server's timezone
// once we remove the timezone offset, we can add this to the value to adjust it to be UTC time.
$this->addSql('ALTER TABLE tag ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE tag ALTER created_at DROP DEFAULT');
$this->addSql("UPDATE tag SET created_at = created_at + (SELECT age(now() at time zone 'UTC', now()))");
$this->addSql('ALTER TABLE task ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE task ALTER created_at DROP DEFAULT');
$this->addSql("UPDATE task SET created_at = created_at + (SELECT age(now() at time zone 'UTC', now()))");
$this->addSql('ALTER TABLE task ALTER completed_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE task ALTER completed_at DROP DEFAULT');
$this->addSql("UPDATE task SET completed_at = completed_at + (SELECT age(now() at time zone 'UTC', now()))");
$this->addSql('ALTER TABLE task ALTER updated_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE task ALTER updated_at DROP DEFAULT');
$this->addSql("UPDATE task SET updated_at = updated_at + (SELECT age(now() at time zone 'UTC', now()))");
$this->addSql('ALTER TABLE time_entry ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE time_entry ALTER created_at DROP DEFAULT');
$this->addSql("UPDATE time_entry SET created_at = created_at + (SELECT age(now() at time zone 'UTC', now()))");
$this->addSql('ALTER TABLE time_entry ALTER ended_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE time_entry ALTER ended_at DROP DEFAULT');
$this->addSql("UPDATE time_entry SET ended_at = ended_at + (SELECT age(now() at time zone 'UTC', now()))");
$this->addSql('ALTER TABLE time_entry ALTER deleted_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE time_entry ALTER deleted_at DROP DEFAULT');
$this->addSql("UPDATE time_entry SET deleted_at = deleted_at + (SELECT age(now() at time zone 'UTC', now()))");
$this->addSql('ALTER TABLE time_entry ALTER updated_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE time_entry ALTER updated_at DROP DEFAULT');
$this->addSql("UPDATE time_entry SET updated_at = updated_at + (SELECT age(now() at time zone 'UTC', now()))");
$this->addSql('ALTER TABLE time_entry ALTER started_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE time_entry ALTER started_at DROP DEFAULT');
$this->addSql("UPDATE time_entry SET started_at = started_at + (SELECT age(now() at time zone 'UTC', now()))");
$this->addSql('ALTER TABLE "timestamp" ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE "timestamp" ALTER created_at DROP DEFAULT');
$this->addSql("UPDATE \"timestamp\" SET created_at = created_at + (SELECT age(now() at time zone 'UTC', now()))");
$this->addSql('ALTER TABLE users ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
$this->addSql('ALTER TABLE users ALTER created_at DROP DEFAULT');
$this->addSql("UPDATE users SET created_at = created_at + (SELECT age(now() at time zone 'UTC', now()))");
}
public function downPostgresql(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
// Regarding SELECT age(now(), now() at time zone 'UTC')
// this will return an interval of how far away the database server's timezone is from UTC
// once we add the timezone offset back, we can add this to the value to adjust it to be local time with the appropriate offset
$this->addSql('ALTER TABLE tag ALTER created_at TYPE TIMESTAMP(0) WITH TIME ZONE');
$this->addSql('ALTER TABLE tag ALTER created_at DROP DEFAULT');
$this->addSql("UPDATE tag SET created_at = created_at + (SELECT age(now(), now() at time zone 'UTC'))");
$this->addSql('ALTER TABLE time_entry ALTER started_at TYPE TIMESTAMP(0) WITH TIME ZONE');
$this->addSql('ALTER TABLE time_entry ALTER started_at DROP DEFAULT');
$this->addSql("UPDATE time_entry SET started_at = started_at + (SELECT age(now(), now() at time zone 'UTC'))");
$this->addSql('ALTER TABLE time_entry ALTER ended_at TYPE TIMESTAMP(0) WITH TIME ZONE');
$this->addSql('ALTER TABLE time_entry ALTER ended_at DROP DEFAULT');
$this->addSql("UPDATE time_entry SET ended_at = ended_at + (SELECT age(now(), now() at time zone 'UTC'))");
$this->addSql('ALTER TABLE time_entry ALTER deleted_at TYPE TIMESTAMP(0) WITH TIME ZONE');
$this->addSql('ALTER TABLE time_entry ALTER deleted_at DROP DEFAULT');
$this->addSql("UPDATE time_entry SET deleted_at = deleted_at + (SELECT age(now(), now() at time zone 'UTC'))");
$this->addSql('ALTER TABLE time_entry ALTER created_at TYPE TIMESTAMP(0) WITH TIME ZONE');
$this->addSql('ALTER TABLE time_entry ALTER created_at DROP DEFAULT');
$this->addSql("UPDATE time_entry SET created_at = created_at + (SELECT age(now(), now() at time zone 'UTC'))");
$this->addSql('ALTER TABLE time_entry ALTER updated_at TYPE TIMESTAMP(0) WITH TIME ZONE');
$this->addSql('ALTER TABLE time_entry ALTER updated_at DROP DEFAULT');
$this->addSql("UPDATE time_entry SET updated_at = updated_at + (SELECT age(now(), now() at time zone 'UTC'))");
$this->addSql('ALTER TABLE timestamp ALTER created_at TYPE TIMESTAMP(0) WITH TIME ZONE');
$this->addSql('ALTER TABLE timestamp ALTER created_at DROP DEFAULT');
$this->addSql("UPDATE timestamp SET created_at = created_at + (SELECT age(now(), now() at time zone 'UTC'))");
$this->addSql('ALTER TABLE task ALTER completed_at TYPE TIMESTAMP(0) WITH TIME ZONE');
$this->addSql('ALTER TABLE task ALTER completed_at DROP DEFAULT');
$this->addSql("UPDATE task SET completed_at = completed_at + (SELECT age(now(), now() at time zone 'UTC'))");
$this->addSql('ALTER TABLE task ALTER created_at TYPE TIMESTAMP(0) WITH TIME ZONE');
$this->addSql('ALTER TABLE task ALTER created_at DROP DEFAULT');
$this->addSql("UPDATE task SET created_at = created_at + (SELECT age(now(), now() at time zone 'UTC'))");
$this->addSql('ALTER TABLE task ALTER updated_at TYPE TIMESTAMP(0) WITH TIME ZONE');
$this->addSql('ALTER TABLE task ALTER updated_at DROP DEFAULT');
$this->addSql("UPDATE task SET updated_at = updated_at + (SELECT age(now(), now() at time zone 'UTC'))");
$this->addSql('ALTER TABLE users ALTER created_at TYPE TIMESTAMP(0) WITH TIME ZONE');
$this->addSql('ALTER TABLE users ALTER created_at DROP DEFAULT');
$this->addSql("UPDATE users SET created_at = created_at + (SELECT age(now(), now() at time zone 'UTC'))");
}
protected function upMysql(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
// do nothing
}
protected function downMysql(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
// do nothing
}
protected function upSqlite(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
// do nothing
}
protected function downSqlite(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
// do nothing
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$platformName = $this->platform->getName();
switch ($platformName) {
case 'sqlite':
$this->upSqlite($schema);
break;
case 'postgresql':
$this->upPostgresql($schema);
break;
case 'mysql':
$this->upMysql($schema);
break;
default:
throw new \Exception("Unsupported database '{$platformName}'");
}
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$platformName = $this->platform->getName();
switch ($platformName) {
case 'sqlite':
$this->downSqlite($schema);
break;
case 'postgresql':
$this->downPostgresql($schema);
break;
case 'mysql':
$this->downMysql($schema);
break;
default:
throw new \Exception("Unsupported database '{$platformName}'");
}
}
}