Migration: Fix worklog times and schedule shift type

This commit is contained in:
Igor Scheller 2023-11-13 22:33:23 +01:00 committed by msquare
parent f3347ba140
commit ac74ab489d
2 changed files with 6 additions and 5 deletions

View File

@ -37,6 +37,7 @@ class CreateWorklogsTable extends Migration
->get(); ->get();
foreach ($previousRecords as $previousRecord) { foreach ($previousRecords as $previousRecord) {
$worked_at = Carbon::createFromTimestamp($previousRecord->work_timestamp);
$created_at = Carbon::createFromTimestamp($previousRecord->created_timestamp); $created_at = Carbon::createFromTimestamp($previousRecord->created_timestamp);
$this->schema->getConnection() $this->schema->getConnection()
->table('worklogs') ->table('worklogs')
@ -44,7 +45,7 @@ class CreateWorklogsTable extends Migration
'id' => $previousRecord->id, 'id' => $previousRecord->id,
'user_id' => $previousRecord->user_id, 'user_id' => $previousRecord->user_id,
'creator_id' => $previousRecord->created_user_id, 'creator_id' => $previousRecord->created_user_id,
'worked_at' => $previousRecord->work_timestamp, 'worked_at' => $worked_at,
'hours' => $previousRecord->work_hours, 'hours' => $previousRecord->work_hours,
'comment' => $previousRecord->comment, 'comment' => $previousRecord->comment,
'created_at' => $created_at, 'created_at' => $created_at,
@ -87,11 +88,11 @@ class CreateWorklogsTable extends Migration
->insert([ ->insert([
'id' => $record->id, 'id' => $record->id,
'user_id' => $record->user_id, 'user_id' => $record->user_id,
'work_timestamp' => $record->worked_at->timestamp, 'work_timestamp' => Carbon::createFromFormat('Y-m-d', $record->worked_at)->timestamp,
'work_hours' => $record->hours, 'work_hours' => $record->hours,
'comment' => $record->comment, 'comment' => $record->comment,
'created_user_id' => $record->creator_id, 'created_user_id' => $record->creator_id,
'created_timestamp' => $record->created_at->timestamp, 'created_timestamp' => Carbon::createFromFormat('Y-m-d H:i:s', $record->created_at)->timestamp,
]); ]);
} }

View File

@ -21,7 +21,7 @@ class AddNameMinutesAndTimestampsToSchedules extends Migration
$this->schema->table('schedules', function (Blueprint $table): void { $this->schema->table('schedules', function (Blueprint $table): void {
$table->string('name')->default('')->after('id'); $table->string('name')->default('')->after('id');
$table->integer('shift_type')->default(0)->after('name'); $table->unsignedInteger('shift_type')->default(0)->after('name');
$table->integer('minutes_before')->default(0)->after('shift_type'); $table->integer('minutes_before')->default(0)->after('shift_type');
$table->integer('minutes_after')->default(0)->after('minutes_before'); $table->integer('minutes_after')->default(0)->after('minutes_before');
$table->timestamps(); $table->timestamps();
@ -36,7 +36,7 @@ class AddNameMinutesAndTimestampsToSchedules extends Migration
$this->schema->table('schedules', function (Blueprint $table): void { $this->schema->table('schedules', function (Blueprint $table): void {
$table->string('name')->default(null)->change(); $table->string('name')->default(null)->change();
$table->integer('shift_type')->default(null)->change(); $table->unsignedInteger('shift_type')->default(null)->change();
$table->integer('minutes_before')->default(null)->change(); $table->integer('minutes_before')->default(null)->change();
$table->integer('minutes_after')->default(null)->change(); $table->integer('minutes_after')->default(null)->change();
}); });