SQL MODE code may fail in other drivers, use Dongle instead

This commit is contained in:
Samuel Georges 2016-04-30 06:22:00 +10:00
parent f45c04a3aa
commit f5633c1bc6
4 changed files with 25 additions and 9 deletions

View File

@ -2,6 +2,12 @@
use October\Rain\Database\Updates\Migration;
/**
* This migration addresses a MySQL specific issue around STRICT MODE.
* In past versions, Laravel would give timestamps a bad default value
* of "0" considered invalid by MySQL. Strict mode is disabled and the
* the timestamps are patched up. Credit for this work: Dave Shoreman.
*/
class DbBackendTimestampFix extends Migration
{
protected $backendTables = [
@ -12,9 +18,7 @@ class DbBackendTimestampFix extends Migration
public function up()
{
// Disable all special modes such as NO_ZERO_DATE to prevent any
// errors from MySQL before we can update the timestamp columns.
Db::statement("SET @@SQL_MODE=''");
DbDongle::disableStrictMode();
foreach ($this->backendTables as $table) {
DbDongle::convertTimestamps($table);

View File

@ -2,13 +2,18 @@
use October\Rain\Database\Updates\Migration;
/**
* This migration addresses a MySQL specific issue around STRICT MODE.
* In past versions, Laravel would give timestamps a bad default value
* of "0" considered invalid by MySQL. Strict mode is disabled and the
* the timestamps are patched up. Credit for this work: Dave Shoreman.
*/
class DbCmsTimestampFix extends Migration
{
public function up()
{
// Disable all special modes such as NO_ZERO_DATE to prevent any
// errors from MySQL before we can update the timestamp columns.
Db::statement("SET @@SQL_MODE=''");
DbDongle::disableStrictMode();
DbDongle::convertTimestamps('cms_theme_data');
}

View File

@ -7,6 +7,9 @@ class DbSystemPluginHistoryDetailText extends Migration
{
public function up()
{
// Migration occurs before timestamps are patched (see next migration)
DbDongle::disableStrictMode();
Schema::table('system_plugin_history', function (Blueprint $table) {
$table->text('detail')->nullable()->change();
});

View File

@ -2,6 +2,12 @@
use October\Rain\Database\Updates\Migration;
/**
* This migration addresses a MySQL specific issue around STRICT MODE.
* In past versions, Laravel would give timestamps a bad default value
* of "0" considered invalid by MySQL. Strict mode is disabled and the
* the timestamps are patched up. Credit for this work: Dave Shoreman.
*/
class DbSystemTimestampFix extends Migration
{
protected $coreTables = [
@ -19,9 +25,7 @@ class DbSystemTimestampFix extends Migration
public function up()
{
// Disable all special modes such as NO_ZERO_DATE to prevent any
// errors from MySQL before we can update the timestamp columns.
Db::statement("SET @@SQL_MODE=''");
DbDongle::disableStrictMode();
foreach ($this->coreTables as $table => $columns) {
if (is_int($table)) {