@@ -118,31 +118,10 @@ protected function backupTablesForSqlite($newTableName, $table)
118
118
119
119
protected function backupTablesForForMysqlAndMariaDb ($ newTableName , $ table ): array
120
120
{
121
- // Step 1: Create the new table structure, excluding generated columns
122
- // DB::statement(/**@lang MySQL**/ "CREATE TABLE $newTableName AS SELECT * FROM $table WHERE 1=0;");
123
- DB ::statement (/**@lang MySQL**/ "CREATE TABLE $ newTableName AS SELECT * FROM $ table " );
124
-
125
- DB ::statement (/**@lang MySQL**/ "INSERT INTO $ newTableName SELECT * FROM $ table " );
126
-
127
- // Step 2: Fetch all non-generated columns
128
- // $nonGeneratedColumns = DB::table('INFORMATION_SCHEMA.COLUMNS')
129
- // ->select('COLUMN_NAME')
130
- // ->where('TABLE_SCHEMA', config('database.connections.mysql.database'))
131
- // ->where('TABLE_NAME', $table)
132
- // ->where('EXTRA', 'NOT LIKE', '%VIRTUAL GENERATED%')
133
- // ->pluck('COLUMN_NAME')
134
- // ->toArray();
135
-
136
- // Step 3: Escape reserved keywords and construct the column list
137
- // $escapedColumns = array_map(function ($column) {
138
- // return '`'.$column.'`'; // Escape column names with backticks
139
- // }, $nonGeneratedColumns);
140
-
141
- // Convert array to comma-separated string
142
- // $columnList = implode(', ', $escapedColumns);
143
-
144
- // Step 4: Insert data excluding generated columns
145
- // DB::statement(/**@lang MySQL* */ "INSERT INTO $newTableName ($columnList) SELECT $columnList FROM $table");
121
+ if ($ this ->getMysqlVersion () >= Constants::VERSION_AFTER_STORED_AS_VIRTUAL_AS_SUPPORT ){
122
+ DB ::statement (/**@lang MySQL**/ "CREATE TABLE $ newTableName AS SELECT * FROM $ table " );
123
+ DB ::statement (/**@lang MySQL**/ "INSERT INTO $ newTableName SELECT * FROM $ table " );
124
+ }
146
125
147
126
$ newCreatedTables [] = $ newTableName ;
148
127
$ response [] = " Table ' $ table' cloned successfully. " ;
@@ -163,4 +142,9 @@ protected function backupTablesForForSqlServer($newTableName, $table)
163
142
{
164
143
dd ('sql server ' );
165
144
}
145
+
146
+ private function getMysqlVersion ()
147
+ {
148
+ return (float ) DB ::select ('select version() ' )[0 ]->{'version() ' };
149
+ }
166
150
}
0 commit comments