/** * Run the migrations. * * @return void */ public function up() { DB::transaction(function () { DB::statement("create temporary table unique_entities (select e.id as orig_id, e.name as name, (select min(id) from entities where entities.name=e.name) as uniq_id from entities as e);"); $pairs = DB::select("select orig_id, uniq_id from unique_entities where orig_id != uniq_id;"); $oldToUnique = []; foreach ($pairs as $pair) { $oldToUnique[$pair->orig_id] = $pair->uniq_id; } $charts = Chart::all(); foreach ($charts as $chart) { $config = json_decode($chart->config); $countries = $config->{'selected-countries'}; if (empty($countries)) { continue; } foreach ($countries as $country) { if (array_key_exists($country->id, $oldToUnique)) { echo "Updating chart config for " . $chart->id . " changing entity id from " . $country->id . " to " . $oldToUnique[$country->id] . "\n"; $country->id = $oldToUnique[$country->id]; } } $chart->config = json_encode($config); $chart->save(); } DB::statement("update data_values as dv inner join unique_entities as e on e.orig_id=dv.fk_ent_id set dv.fk_ent_id=e.uniq_id;"); DB::statement("delete from entities where entities.id in (select orig_id from unique_entities where orig_id != uniq_id);"); DB::statement("drop table unique_entities;"); }); Schema::table("entities", function ($table) { $table->unique('name'); }); }
/** * Run the migrations. * * @return void */ public function up() { Schema::table('charts', function ($table) { $table->dropForeign('charts_updated_by_foreign'); $table->renameColumn('updated_by', 'last_edited_by'); $table->foreign('last_edited_by')->references('name')->on('users'); $table->timestamp('last_edited_at'); }); foreach (Chart::all() as $chart) { $chart->last_edited_at = $chart->updated_at; $chart->save(); } }
/** * Run the migrations. * * @return void */ public function up() { Schema::table('charts', function ($table) { $table->text('slug'); }); $charts = Chart::all(); foreach ($charts as $chart) { $s = strtolower($chart->name); $s = preg_replace('/\\s*\\*.+\\*/', '', $s); $s = preg_replace('/[^\\w- ]+/', '', $s); $s = preg_replace('/ +/', '-', trim($s)); $chart->slug = $s; $chart->save(); } }
/** * Run the migrations. * * @return void */ public function up() { DB::transaction(function () { $charts = Chart::all(); foreach ($charts as $chart) { $config = json_decode($chart->config); if (!isset($config->{'map-config'})) { continue; } $interval = $config->{'map-config'}->timeInterval; if ($interval && $interval != 1) { $timeRanges = [array("startYear" => "first", "endYear" => "last", "interval" => $interval)]; var_dump($timeRanges); $config->{'map-config'}->timeRanges = $timeRanges; } $chart->config = json_encode($config); $chart->save(); } }); }
/** * Run the migrations. * * @return void */ public function up() { DB::transaction(function () { DataValue::where('fk_ent_id', 341)->update(array('fk_ent_id' => 355)); Entity::where('id', 341)->delete(); $charts = Chart::all(); foreach ($charts as $chart) { $config = json_decode($chart->config); $countries = $config->{'selected-countries'}; if (empty($countries)) { continue; } foreach ($countries as $country) { if ($country->id == "341") { echo "Updating chart config for " . $chart->id . "\n"; $country->id = "355"; $country->name = "World"; } } $chart->config = json_encode($config); $chart->save(); } }); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $charts = Chart::all(); return view('charts.index', compact('charts')); }