6
6
7
7
use Doctrine \DBAL \Connection ;
8
8
use Doctrine \DBAL \Schema \Schema ;
9
+ use Doctrine \DBAL \Schema \SchemaConfig ;
9
10
use Doctrine \Migrations \AbstractMigration ;
10
11
use Psr \Log \LoggerInterface ;
11
12
use Symfony \Component \DependencyInjection \ContainerAwareInterface ;
@@ -23,31 +24,68 @@ public function __construct(Connection $connection, LoggerInterface $logger)
23
24
$ this ->tablePrefix = 'bolt ' ;
24
25
}
25
26
26
- public function getDescription () : string
27
+ public function getDescription (): string
27
28
{
28
29
return 'Bolt 4.2 Migration: bolt_reset_password and bolt_column.avatar ' ;
29
30
}
30
31
31
- public function up (Schema $ schema ) : void
32
+ public function up (Schema $ schema ): void
32
33
{
34
+ $ schemaConfig = new SchemaConfig ();
35
+ $ options = [
36
+ 'charset ' => 'utf8 ' ,
37
+ ];
38
+ if ($ this ->connection ->getDatabasePlatform ()->getName () === 'mysql ' ) {
39
+ $ options = [
40
+ 'engine ' => 'InnoDB ' ,
41
+ 'charset ' => 'utf8mb4 ' ,
42
+ 'collate ' => 'utf8mb4_unicode_ci '
43
+ ];
44
+ }
45
+ $ schemaConfig ->setDefaultTableOptions ($ options );
46
+
33
47
// Create the user avatar. See https://github.com/bolt/core/pull/2114
34
48
$ userTable = $ schema ->getTable ($ this ->tablePrefix . '_user ' );
35
49
36
- if (! $ userTable ->hasColumn ('avatar ' )) {
50
+ if (!$ userTable ->hasColumn ('avatar ' )) {
37
51
$ userTable ->addColumn ('avatar ' , 'string ' , ['notnull ' => false , 'length ' => 250 ]);
38
52
}
39
53
40
54
// Create the reset password table. See https://github.com/bolt/core/pull/2131
41
- if (!$ schema ->hasTable ($ this ->tablePrefix . '_password_request ' )) {
42
- $ resetPaswordTable = $ schema ->createTable ($ this ->tablePrefix . '_password_request ' );
43
- $ resetPaswordTable ->addColumn ('id ' , 'integer ' , ['autoincrement ' => true ]);
44
- $ resetPaswordTable ->setPrimaryKey (["id " ]); // MySQL / MariaDB needs autoincrement column to be the primary key
45
- $ resetPaswordTable ->addColumn ('user_id ' , 'integer ' , ['notnull ' => true , '' , 'default ' => 0 ]);
46
- $ resetPaswordTable ->addForeignKeyConstraint ($ this ->tablePrefix . '_user ' , ['user_id ' ], ['id ' ], ['onUpdate ' => 'CASCADE ' ]);
55
+ if ($ schema ->hasTable ($ this ->tablePrefix . '_reset_password_request ' ) === false ) {
56
+
57
+ $ table = $ schema ->createTable ($ this ->tablePrefix . '_reset_password_request ' );
58
+ $ table ->addColumn ('id ' , 'integer ' , ['autoincrement ' => true , 'notnull ' => true ]);
59
+ $ table ->addColumn ('user_id ' , 'integer ' , ['notnull ' => true ]);
60
+ $ table ->addColumn ('selector ' , 'string ' , ['notnull ' => true , 'length ' => 20 ]);
61
+ $ table ->addColumn ('hashed_token ' , 'string ' , ['notnull ' => true , 'length ' => 100 ]);
62
+ $ table ->addColumn ('requested_at ' , 'datetime ' ,
63
+ ['notnull ' => true , 'comment ' => '(DC2Type:datetime_immutable) ' ]);
64
+ $ table ->addColumn ('expires_at ' , 'datetime ' ,
65
+ ['notnull ' => true , 'comment ' => '(DC2Type:datetime_immutable) ' ]);
66
+
67
+ $ table ->setPrimaryKey (['id ' ]);
68
+ $ table ->addIndex (['user_id ' ], 'IDX_D04070DCA76ED395 ' );
69
+ $ table ->setSchemaConfig ($ schemaConfig );
70
+ $ table ->addForeignKeyConstraint (
71
+ $ this ->tablePrefix . '_user ' ,
72
+ ['user_id ' ],
73
+ ['id ' ],
74
+ [],
75
+ 'FK_D04070DCA76ED395 '
76
+ );
77
+ }
78
+
79
+ $ fieldTranstationTable = $ schema ->getTable ($ this ->tablePrefix . '_field_translation ' );
80
+ foreach ($ fieldTranstationTable ->getIndexes () as $ index ) {
81
+ if ($ index ->getName () === 'bolt_field_translation_unique_translation ' ) {
82
+ $ fieldTranstationTable ->renameIndex ('bolt_field_translation_unique_translation ' ,
83
+ 'field_translation_unique_translation ' );
84
+ }
47
85
}
48
86
}
49
87
50
- public function down (Schema $ schema ) : void
88
+ public function down (Schema $ schema ): void
51
89
{
52
90
}
53
91
}
0 commit comments