@@ -68,7 +68,7 @@ protected static function table($db_name)
68
68
$ class = str_replace (
69
69
'App \\' ,
70
70
'' ,
71
- implode ('\\' , $ all_names ) . '\\' . $ table_name
71
+ implode ('\\' , $ all_names ) . '\\' . $ table_name,
72
72
);
73
73
74
74
# Drop Table
@@ -90,7 +90,7 @@ protected static function table($db_name)
90
90
if ($ table_name != 'options.sql ' ) {
91
91
static ::log (
92
92
'WARNING ' ,
93
- "Ignored Table ` $ table_name` in ` $ db_name` Database. "
93
+ "Ignored Table ` $ table_name` in ` $ db_name` Database. " ,
94
94
);
95
95
}
96
96
continue ;
@@ -102,7 +102,7 @@ protected static function table($db_name)
102
102
$ query = DB ::query (
103
103
'SELECT * FROM information_schema.tables WHERE table_schema=%s AND table_name=%s ' ,
104
104
$ db_name ,
105
- $ table_name
105
+ $ table_name,
106
106
);
107
107
108
108
if (!empty ($ query )) {
@@ -121,18 +121,21 @@ protected static function table($db_name)
121
121
'REFERENCES ' => null ,
122
122
'DELETE ' => null ,
123
123
'UPDATE ' => null ,
124
- 'OTHERS ' => null
124
+ 'OTHERS ' => null ,
125
125
];
126
126
127
- $ db_columns = array_keys (DB ::columnList ($ table_name ));
127
+ $ db_columns = [];
128
+ if ($ table_already_exists ) {
129
+ $ db_columns = array_keys (DB ::columnList ($ table_name ));
130
+ }
128
131
129
132
/**
130
133
* Filter the array, if the column already exists in the database
131
134
* then remove it from the array of columns that will be created.
132
135
*/
133
136
$ filePath = array_filter ($ filePath , function ($ path ) use (
134
137
$ table_already_exists ,
135
- $ db_columns
138
+ $ db_columns,
136
139
) {
137
140
if ($ table_already_exists ) {
138
141
$ column_name = self ::get_column_name ($ path );
@@ -166,7 +169,7 @@ protected static function table($db_name)
166
169
column_name: $ columns [$ i ][0 ],
167
170
path: $ columns [$ i ][1 ],
168
171
constraint: $ constraint ,
169
- table_name: $ table_name
172
+ table_name: $ table_name,
170
173
);
171
174
$ query [] = $ res [0 ];
172
175
$ constraint = $ res [1 ];
@@ -240,20 +243,20 @@ protected static function table($db_name)
240
243
DB ::query ("ALTER TABLE $ table_name $ query " );
241
244
static ::log (
242
245
'INFO ' ,
243
- "Altered Table ` $ table_name` and adds column ` $ only_columns` "
246
+ "Altered Table ` $ table_name` and adds column ` $ only_columns` " ,
244
247
);
245
248
} else {
246
249
DB ::query ("CREATE TABLE $ table_name ( $ query) " );
247
250
static ::log (
248
251
'INFO ' ,
249
- "Created Table ` $ table_name` in ` $ db_name` Database "
252
+ "Created Table ` $ table_name` in ` $ db_name` Database " ,
250
253
);
251
254
}
252
255
}
253
256
} catch (\Exception $ e ) {
254
257
static ::log (
255
258
'ERROR ' ,
256
- "Unable to create Table ` $ table_name` in ` $ db_name` Database. [Exception]: {$ e ->getMessage ()}"
259
+ "Unable to create Table ` $ table_name` in ` $ db_name` Database. [Exception]: {$ e ->getMessage ()}" ,
257
260
);
258
261
return ;
259
262
}
0 commit comments