Skip to content

Commit

Permalink
Add db to workflow #6
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasss93 committed Dec 10, 2023
1 parent 62c8bac commit 86d507f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 25 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
- name: Deploy to production server
uses: appleboy/ssh-action@master
with:
command_timeout: 60m
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
password: ${{ secrets.SSH_PASS }}
Expand Down
18 changes: 6 additions & 12 deletions app/Models/Statistic.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,27 @@ public static function getStatsForBot(): array

// stickers optimized
$stickersOptimizedYesterday = self::query()
->where('action', 'sticker')
->where('category', 'optimized')
->where('action', 'sticker.optimized')
->whereBetween('collected_at', [$date->subDay()->startOfDay(), $date->subDay()->endOfDay()])
->count();
$stickersOptimizedToday = self::query()
->where('action', 'sticker')
->where('category', 'optimized')
->where('action', 'sticker.optimized')
->whereBetween('collected_at', [$date->startOfDay(), $date->endOfDay()])
->count();
$stickersOptimizedWeek = self::query()
->where('action', 'sticker')
->where('category', 'optimized')
->where('action', 'sticker.optimized')
->whereBetween('collected_at', [$date->startOfWeek(), $date->endOfWeek()])
->count();
$stickersOptimizedMonth = self::query()
->where('action', 'sticker')
->where('category', 'optimized')
->where('action', 'sticker.optimized')
->whereBetween('collected_at', [$date->startOfMonth(), $date->endOfMonth()])
->count();
$stickersOptimizedYear = self::query()
->where('action', 'sticker')
->where('category', 'optimized')
->where('action', 'sticker.optimized')
->whereBetween('collected_at', [$date->startOfYear(), $date->endOfYear()])
->count();
$stickersOptimizedTotal = self::query()
->where('action', 'sticker')
->where('category', 'optimized')
->where('action', 'sticker.optimized')
->count();

//active users
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,71 @@
return new class extends Migration {
public function up(): void
{
Schema::table('statistics', function (Blueprint $table) {
$table->index('category');
});

echo "\n\nAdded index to category\n";

DB::table('statistics')
->where('category', 'command')
->update(['action' => DB::raw("concat('command.', action)")]);

echo "Updated where category is command set action to command.action\n";

DB::table('statistics')
->where('category', 'handler')
->update(['action' => DB::raw("concat('handler.', action)")]);

echo "Updated where category is handler set action to handler.action\n";

DB::table('statistics')
->update([
'action' => DB::raw("case
when category='command' then concat('command.', action)
when category='handler' then concat('handler.', action)
when action='chat.blocked' then 'user.status.blocked'
when action='chat.unblocked' then 'user.status.unblocked'
when action='sticker' then 'sticker.optimized'
when category='settings' then 'settings.news'
when action='donation' then 'donate.success'
when action='precheckout' then 'donate.precheckout'
else action
end"),
]);
->where('category', 'donation')
->update(['action' => 'settings.news']);

echo "Updated where category is donation set action to settings.news\n";

Schema::table('statistics', function (Blueprint $table) {
$table->string('action')->index()->change();
});

echo "Changed action column to index\n";

DB::table('statistics')
->where('action', 'chat.blocked')
->update(['action' => 'user.status.blocked']);

echo "Updated where action is chat.blocked set action to user.status.blocked\n";

DB::table('statistics')
->where('action', 'chat.unblocked')
->update(['action' => 'user.status.unblocked']);

echo "Updated where action is chat.unblocked set action to user.status.unblocked\n";

DB::table('statistics')
->where('action', 'sticker')
->update(['action' => 'sticker.optimized']);

echo "Updated where action is sticker set action to sticker.optimized\n";

DB::table('statistics')
->where('action', 'donation')
->update(['action' => 'donate.success']);

echo "Updated where action is donation set action to donate.success\n";

DB::table('statistics')
->where('action', 'precheckout')
->update(['action' => 'donate.precheckout']);

echo "Updated where action is precheckout set action to donate.precheckout\n";

Schema::table('statistics', function (Blueprint $table) {
$table->dropColumn('category');
});

echo "Dropped category column\n";
}

public function down(): void
Expand Down

0 comments on commit 86d507f

Please sign in to comment.