coolify/database/migrations/2024_06_25_184323_update_db.php

93 lines
4.1 KiB
PHP
Raw Normal View History

<?php
2024-06-26 13:00:36 +02:00
use App\Models\EnvironmentVariable;
use App\Models\Server;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
2024-06-26 13:00:36 +02:00
use Visus\Cuid2\Cuid2;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('applications', function (Blueprint $table) {
$table->dropColumn('docker_compose_pr_location');
$table->dropColumn('docker_compose_pr');
$table->dropColumn('docker_compose_pr_raw');
});
2024-06-27 12:48:37 +02:00
Schema::table('subscriptions', function (Blueprint $table) {
$table->dropColumn('lemon_subscription_id');
$table->dropColumn('lemon_order_id');
$table->dropColumn('lemon_product_id');
$table->dropColumn('lemon_variant_id');
$table->dropColumn('lemon_variant_name');
$table->dropColumn('lemon_customer_id');
$table->dropColumn('lemon_status');
$table->dropColumn('lemon_renews_at');
$table->dropColumn('lemon_update_payment_menthod_url');
$table->dropColumn('lemon_trial_ends_at');
$table->dropColumn('lemon_ends_at');
});
2024-06-26 13:00:36 +02:00
Schema::table('environment_variables', function (Blueprint $table) {
$table->string('uuid')->nullable()->after('id');
});
EnvironmentVariable::all()->each(function (EnvironmentVariable $environmentVariable) {
$environmentVariable->update([
2024-07-24 14:27:21 +02:00
'uuid' => (string) new Cuid2,
2024-06-26 13:00:36 +02:00
]);
});
Schema::table('environment_variables', function (Blueprint $table) {
$table->string('uuid')->nullable(false)->change();
});
Schema::table('server_settings', function (Blueprint $table) {
$table->integer('metrics_history_days')->default(7)->change();
});
Server::all()->each(function (Server $server) {
$server->settings->update([
'metrics_history_days' => 7,
]);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('applications', function (Blueprint $table) {
$table->string('docker_compose_pr_location')->nullable()->default('/docker-compose.yaml')->after('docker_compose_location');
$table->longText('docker_compose_pr')->nullable()->after('docker_compose_location');
$table->longText('docker_compose_pr_raw')->nullable()->after('docker_compose');
});
2024-06-27 12:48:37 +02:00
Schema::table('subscriptions', function (Blueprint $table) {
$table->string('lemon_subscription_id')->nullable()->after('stripe_subscription_id');
$table->string('lemon_order_id')->nullable()->after('lemon_subscription_id');
$table->string('lemon_product_id')->nullable()->after('lemon_order_id');
$table->string('lemon_variant_id')->nullable()->after('lemon_product_id');
$table->string('lemon_variant_name')->nullable()->after('lemon_variant_id');
$table->string('lemon_customer_id')->nullable()->after('lemon_variant_name');
$table->string('lemon_status')->nullable()->after('lemon_customer_id');
$table->timestamp('lemon_renews_at')->nullable()->after('lemon_status');
$table->string('lemon_update_payment_menthod_url')->nullable()->after('lemon_renews_at');
$table->timestamp('lemon_trial_ends_at')->nullable()->after('lemon_update_payment_menthod_url');
$table->timestamp('lemon_ends_at')->nullable()->after('lemon_trial_ends_at');
});
2024-06-26 13:00:36 +02:00
Schema::table('environment_variables', function (Blueprint $table) {
$table->dropColumn('uuid');
});
Schema::table('server_settings', function (Blueprint $table) {
$table->integer('metrics_history_days')->default(30)->change();
});
Server::all()->each(function (Server $server) {
$server->settings->update([
'metrics_history_days' => 30,
]);
});
}
};