@@ -15,11 +15,27 @@ public function up(Schema $schema)
15
15
// this up() migration is auto-generated, please modify it to your needs
16
16
$ this ->abortIf ($ this ->connection ->getDatabasePlatform ()->getName () != "mysql " , "Migration can only be executed safely on 'mysql'. " );
17
17
18
- $ this ->addSql ("ALTER TABLE os_user DROP FOREIGN KEY FK_7BB0CD52BF396750 " );
19
- $ this ->addSql ("ALTER TABLE os_clock ADD uid INT DEFAULT NULL " );
20
- $ this ->addSql ("ALTER TABLE os_clock ADD CONSTRAINT FK_34E85465539B0606 FOREIGN KEY (uid) REFERENCES os_user (id) " );
21
- $ this ->addSql ("UPDATE os_clock SET uid = id " );
22
- $ this ->addSql ("CREATE UNIQUE INDEX UNIQ_34E85465539B0606 ON os_clock (uid) " );
18
+ $ tables = $ schema ->getTables ();
19
+ foreach ($ tables as $ table ) {
20
+ if ($ table ->getName () === "os_user " ) {
21
+ if ($ table ->hasForeignKey ('FK_7BB0CD52BF396750 ' )) {
22
+ $ this ->addSql ("ALTER TABLE os_user DROP FOREIGN KEY FK_7BB0CD52BF396750 " );
23
+ }
24
+ } else if ($ table ->getName () === "os_clock " ) {
25
+ if (!$ table ->hasColumn ("uid " )) {
26
+ $ this ->addSql ("ALTER TABLE os_clock ADD uid INT DEFAULT NULL " );
27
+ $ this ->addSql ("UPDATE os_clock SET uid = id " );
28
+ }
29
+
30
+ if (!$ table ->hasForeignKey ('FK_34E85465539B0606 ' )) {
31
+ $ this ->addSql ("ALTER TABLE os_clock ADD CONSTRAINT FK_34E85465539B0606 FOREIGN KEY (uid) REFERENCES os_user (id) " );
32
+ }
33
+
34
+ if (!$ table ->hasIndex ('UNIQ_34E85465539B0606 ' )) {
35
+ $ this ->addSql ("CREATE UNIQUE INDEX UNIQ_34E85465539B0606 ON os_clock (uid) " );
36
+ }
37
+ }
38
+ }
23
39
}
24
40
25
41
public function down (Schema $ schema )
0 commit comments