mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Convert current core timestamp columns to nullable
Adds migrations to switch all existing timestamp fields from being NOT NULL DEFAULT 0, to NULL DEFAULT NULL, in order to get around issues with new default modes in MySQL that cause errors in 0 dates.
This commit is contained in:
parent
34f2aa7dcf
commit
48090351bd
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use October\Rain\Database\Updates\Migration;
|
||||
|
||||
class DbBackendTimestampFix extends Migration
|
||||
{
|
||||
protected $backendTables = [
|
||||
'users',
|
||||
'user_groups',
|
||||
'access_log',
|
||||
];
|
||||
|
||||
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=''");
|
||||
|
||||
foreach ($this->backendTables as $table) {
|
||||
DbDongle::convertTimestamps($table);
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
// ...
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
use October\Rain\Database\Updates\Migration;
|
||||
|
||||
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::convertTimestamps('cms_theme_data');
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
// ...
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ class DbSystemPluginVersions extends Migration
|
||||
$table->increments('id');
|
||||
$table->string('code')->index();
|
||||
$table->string('version', 50);
|
||||
$table->timestamp('created_at');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ class DbSystemPluginHistory extends Migration
|
||||
$table->string('type', 20)->index();
|
||||
$table->string('version', 50);
|
||||
$table->string('detail')->nullable();
|
||||
$table->timestamp('created_at');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ class DbFailedJobs extends Migration
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->text('payload');
|
||||
$table->timestamp('failed_at');
|
||||
$table->timestamp('failed_at')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use October\Rain\Database\Updates\Migration;
|
||||
|
||||
class DbSystemTimestampFix extends Migration
|
||||
{
|
||||
protected $coreTables = [
|
||||
'deferred_bindings',
|
||||
'failed_jobs' => 'failed_at',
|
||||
'system_files',
|
||||
'system_event_logs',
|
||||
'system_mail_layouts',
|
||||
'system_mail_templates',
|
||||
'system_plugin_history' => 'created_at',
|
||||
'system_plugin_versions' => 'created_at',
|
||||
'system_request_logs',
|
||||
'system_revisions',
|
||||
];
|
||||
|
||||
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=''");
|
||||
|
||||
foreach ($this->coreTables as $table => $columns) {
|
||||
if (is_int($table)) {
|
||||
$table = $columns;
|
||||
$columns = ['created_at', 'updated_at'];
|
||||
}
|
||||
|
||||
DbDongle::convertTimestamps($table, $columns);
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
// ...
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user