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,53 @@ 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 );
47
70
}
48
71
}
49
72
50
- public function down (Schema $ schema ) : void
73
+ public function down (Schema $ schema ): void
51
74
{
52
75
}
53
76
}
0 commit comments