@@ -21,11 +21,27 @@ class UpgradeSchema implements UpgradeSchemaInterface
21
21
*/
22
22
public function upgrade (SchemaSetupInterface $ setup , ModuleContextInterface $ context )
23
23
{
24
- $ installer = $ setup ;
25
- $ installer ->startSetup ();
26
- $ tableAdmins = $ installer ->getTable ('admin_user ' );
24
+ $ setup ->startSetup ();
27
25
28
- $ installer ->getConnection ()->addColumn (
26
+ if (version_compare ($ context ->getVersion (), '2.0.1 ' , '< ' )) {
27
+ $ this ->addFailuresToAdminUserTable ($ setup );
28
+ $ this ->createAdminPasswordsTable ($ setup );
29
+ }
30
+
31
+ $ setup ->endSetup ();
32
+ }
33
+
34
+ /**
35
+ * Adds 'failures_num', 'first_failure', and 'lock_expires' columns to 'admin_user' table
36
+ *
37
+ * @param SchemaSetupInterface $setup
38
+ * @return void
39
+ */
40
+ private function addFailuresToAdminUserTable (SchemaSetupInterface $ setup )
41
+ {
42
+ $ tableAdmins = $ setup ->getTable ('admin_user ' );
43
+
44
+ $ setup ->getConnection ()->addColumn (
29
45
$ tableAdmins ,
30
46
'failures_num ' ,
31
47
[
@@ -35,28 +51,38 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
35
51
'comment ' => 'Failure Number '
36
52
]
37
53
);
38
- $ installer ->getConnection ()->addColumn (
54
+ $ setup ->getConnection ()->addColumn (
39
55
$ tableAdmins ,
40
56
'first_failure ' ,
41
57
[
42
58
'type ' => \Magento \Framework \DB \Ddl \Table::TYPE_TIMESTAMP ,
43
59
'comment ' => 'First Failure '
44
60
]
45
61
);
46
- $ installer ->getConnection ()->addColumn (
62
+ $ setup ->getConnection ()->addColumn (
47
63
$ tableAdmins ,
48
64
'lock_expires ' ,
49
65
[
50
66
'type ' => \Magento \Framework \DB \Ddl \Table::TYPE_TIMESTAMP ,
51
67
'comment ' => 'Expiration Lock Dates '
52
68
]
53
69
);
70
+ }
71
+
72
+ /**
73
+ * Create table 'admin_passwords'
74
+ *
75
+ * @param SchemaSetupInterface $setup
76
+ * @return void
77
+ */
78
+ private function createAdminPasswordsTable (SchemaSetupInterface $ setup )
79
+ {
80
+ if ($ setup ->tableExists ($ setup ->getTable ('admin_passwords ' ))) {
81
+ return ;
82
+ }
54
83
55
- /**
56
- * Create table 'admin_passwords'
57
- */
58
- $ table = $ installer ->getConnection ()->newTable (
59
- $ installer ->getTable ('admin_passwords ' )
84
+ $ table = $ setup ->getConnection ()->newTable (
85
+ $ setup ->getTable ('admin_passwords ' )
60
86
)->addColumn (
61
87
'password_id ' ,
62
88
\Magento \Framework \DB \Ddl \Table::TYPE_INTEGER ,
@@ -88,19 +114,17 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
88
114
['unsigned ' => true , 'nullable ' => false , 'default ' => '0 ' ],
89
115
'Last Updated '
90
116
)->addIndex (
91
- $ installer ->getIdxName ('admin_passwords ' , ['user_id ' ]),
117
+ $ setup ->getIdxName ('admin_passwords ' , ['user_id ' ]),
92
118
['user_id ' ]
93
119
)->addForeignKey (
94
- $ installer ->getFkName ('admin_passwords ' , 'user_id ' , 'admin_user ' , 'user_id ' ),
120
+ $ setup ->getFkName ('admin_passwords ' , 'user_id ' , 'admin_user ' , 'user_id ' ),
95
121
'user_id ' ,
96
- $ installer ->getTable ('admin_user ' ),
122
+ $ setup ->getTable ('admin_user ' ),
97
123
'user_id ' ,
98
124
\Magento \Framework \DB \Ddl \Table::ACTION_CASCADE
99
125
)->setComment (
100
126
'Admin Passwords '
101
127
);
102
- $ installer ->getConnection ()->createTable ($ table );
103
-
104
- $ installer ->endSetup ();
128
+ $ setup ->getConnection ()->createTable ($ table );
105
129
}
106
130
}
0 commit comments