Skip to content

Commit

Permalink
fix: fix use of 'json' column type (#1885)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Oct 8, 2018
1 parent 41a77dd commit d5a6bd1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ UNRELEASED CHANGES:
* Add ability to set a reminder for a life event
* Stop reporting OAuth exceptions
* Replace karakus/laravel-cloudflare with monicahq/laravel-cloudflare to fix dependencies issues
* Fix use of 'json' mysql column type

RELEASED VERSIONS:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function up()
$table->increments('id');
$table->unsignedInteger('default_life_event_category_id');
$table->string('translation_key');
$table->json('specific_information_structure');
$table->text('specific_information_structure');
$table->boolean('migrated')->default(0);
$table->timestamps();
$table->foreign('default_life_event_category_id')->references('id')->on('default_life_event_categories')->onDelete('cascade');
Expand Down Expand Up @@ -57,7 +57,7 @@ public function up()
$table->string('name');
$table->string('default_life_event_type_key')->nullable();
$table->boolean('core_monica_data')->default(0);
$table->json('specific_information_structure')->nullable();
$table->text('specific_information_structure')->nullable();
$table->timestamps();
$table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
$table->foreign('life_event_category_id')->references('id')->on('life_event_categories')->onDelete('cascade');
Expand All @@ -73,7 +73,7 @@ public function up()
$table->dateTime('happened_at');
$table->boolean('happened_at_month_unknown')->default(false);
$table->boolean('happened_at_day_unknown')->default(false);
$table->json('specific_information')->nullable();
$table->text('specific_information')->nullable();
$table->timestamps();
$table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
$table->foreign('contact_id')->references('id')->on('contacts')->onDelete('cascade');
Expand Down
40 changes: 40 additions & 0 deletions database/migrations/2018_10_07_120133_fix_json_column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

use Illuminate\Support\Facades\DB;
use Illuminate\Database\Migrations\Migration;

class FixJsonColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$connection = DB::connection();

if ($connection->getDriverName() != 'mysql') {
return;
}

$databasename = $connection->getDatabaseName();

$columns = $connection->table('information_schema.columns')
->select('table_name', 'column_name')
->where([
['table_schema', '=', $databasename],
['data_type', '=', 'json'],
])
->whereIn('table_name', [
'default_life_event_types',
'life_event_types',
'life_events',
])
->get();

foreach ($columns as $column) {
DB::statement('ALTER TABLE `'.$databasename.'`.`'.$column->table_name.'` MODIFY `'.$column->column_name.'` text;');
}
}
}

0 comments on commit d5a6bd1

Please sign in to comment.