pla-version/database/migrations/2025_03_09_085609_version.php
Deon George 7e720b1970
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 30s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m24s
Create Docker Image / Final Docker Image Manifest (push) Successful in 10s
Implement version table, update APIs when getting version info from github because the tags API was not retrieving our current git tags
2025-03-09 21:54:23 +11:00

56 lines
1.4 KiB
PHP

<?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');
}
};