Skip to content

Commit acbd4c3

Browse files
committed
#3 Store spent_at and export into csv
1 parent 1042f27 commit acbd4c3

File tree

4 files changed

+59
-4
lines changed

4 files changed

+59
-4
lines changed

app/Model/Entity/Spent.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/**
66
* @property int note_id
77
* @property float hours
8+
* @property string spent_at
89
* @property string description
910
*/
1011
class Spent extends EntityAbstract
@@ -26,6 +27,7 @@ class Spent extends EntityAbstract
2627
protected $fillable = [
2728
'note_id',
2829
'hours',
30+
'spent_at',
2931
'description',
3032
];
3133

app/Model/Repository/SpentRepositoryEloquent.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function getListQuery(array $parameters): Builder
2828
'spent.note_id',
2929
'spent.hours',
3030
'note.gitlab_created_at',
31+
'spent.spent_at',
3132
'issue.iid as issue',
3233
DB::raw("issue.title || CASE WHEN spent.description IS NOT NULL THEN ' |\n' || spent.description ELSE '' END as description")
3334
])

database/migrations/2018_10_26_154958_alter_issue_table_add_column_estimate.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public function up()
2525
*/
2626
public function down()
2727
{
28-
Schema::table('issue', function (Blueprint $table)
29-
{
30-
$table->dropColumn('estimate');
31-
});
28+
Schema::table('issue', function (Blueprint $table)
29+
{
30+
$table->dropColumn('estimate');
31+
});
3232
}
3333
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\DB;
4+
use Illuminate\Support\Facades\Schema;
5+
use Illuminate\Database\Schema\Blueprint;
6+
use Illuminate\Database\Migrations\Migration;
7+
8+
class AlterSpentTableAddSpentAtColumn extends Migration
9+
{
10+
/**
11+
* Run the migrations.
12+
*
13+
* @return void
14+
*/
15+
public function up()
16+
{
17+
DB::beginTransaction();
18+
try {
19+
Schema::table('spent', function (Blueprint $table) {
20+
$table->timestamp('spent_at')->nullable()->index();
21+
});
22+
23+
DB::statement('
24+
UPDATE spent AS s
25+
SET spent_at = n.gitlab_created_at
26+
FROM note AS n
27+
WHERE n.id = s.note_id
28+
');
29+
30+
DB::statement('ALTER TABLE spent ALTER spent_at SET NOT NULL');
31+
32+
DB::commit();
33+
}
34+
catch (\Throwable $e) {
35+
DB::rollback();
36+
throw $e;
37+
}
38+
}
39+
40+
/**
41+
* Reverse the migrations.
42+
*
43+
* @return void
44+
*/
45+
public function down()
46+
{
47+
Schema::table('spent', function (Blueprint $table)
48+
{
49+
$table->dropColumn('spent_at');
50+
});
51+
}
52+
}

0 commit comments

Comments
 (0)