tables as $db) { $table = $schema->tableName($db); $columns = $schema->databaseFields($db); $query = "SHOW COLUMNS FROM $table"; $liveColumns = DB::query($query)->column(); $query = "SHOW TABLES LIKE 'Backup_$table'"; $tableExists = DB::query($query)->value(); if ($tableExists != null) { echo "Tasks run already on $table exiting"; return; } $backedUp = false; foreach ($liveColumns as $column) { if (!$backedUp) { echo "Backing up $table
"; echo "Creating Backup_$table
"; // backup table $query = "CREATE TABLE Backup_$table LIKE $table"; DB::query($query); echo "Populating Backup_$table
"; $query = "INSERT Backup_$table SELECT * FROM $table"; DB::query($query); $backedUp = true; } if (!isset($columns[$column]) && !in_array($column, $this->keepColumns ?? [])) { echo "Dropping $column from $table
"; $query = "ALTER TABLE $table DROP COLUMN $column"; DB::query($query); } } } } }