Implement version table, update APIs when getting version info from github because the tags API was not retrieving our current git tags
This commit is contained in:
55
database/migrations/2025_03_09_085609_version.php
Normal file
55
database/migrations/2025_03_09_085609_version.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('versions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->timestamp('created_at',0)->nullable();
|
||||
$table->string('version');
|
||||
|
||||
$table->index(['version']);
|
||||
});
|
||||
|
||||
foreach (DB::table('site_versions')->select(['version',DB::raw('MIN(created_at) AS created_at')])->groupBy('version')->cursor() as $o) {
|
||||
$oo = new \App\Models\Version;
|
||||
$oo->created_at = $o->created_at;
|
||||
$oo->version = $o->version;
|
||||
$oo->save();
|
||||
}
|
||||
|
||||
Schema::table('site_versions', function (Blueprint $table) {
|
||||
$table->bigInteger('version_id')->nullable();
|
||||
$table->foreign('version_id')->references('id')->on('versions');
|
||||
$table->dropColumn(['updated_at']);
|
||||
});
|
||||
|
||||
foreach (DB::table('versions')->select(['id','version'])->cursor() as $o) {
|
||||
DB::table('site_versions')->where('version',$o->version)->update(['version_id'=>$o->id]);
|
||||
}
|
||||
|
||||
Schema::table('site_versions', function (Blueprint $table) {
|
||||
$table->dropColumn(['version']);
|
||||
});
|
||||
|
||||
Schema::table('sites', function (Blueprint $table) {
|
||||
$table->dropColumn(['updated_at']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
throw new \Exception('Cant go back');
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user