Lae/database/migrations/2022_08_12_123308_create_modules_table.php

47 lines
1.0 KiB
PHP
Raw Normal View History

2022-08-13 06:04:47 +00:00
<?php
2022-08-13 08:37:17 +00:00
use Illuminate\Database\Migrations\Migration;
2022-11-06 11:28:22 +00:00
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
2022-08-13 06:04:47 +00:00
2023-01-30 16:14:07 +00:00
return new class extends Migration
{
2022-08-13 06:04:47 +00:00
/**
* Run the migrations.
*
* @return void
*/
2023-01-14 10:02:27 +00:00
public function up(): void
2022-08-13 06:04:47 +00:00
{
Schema::create('modules', function (Blueprint $table) {
2022-08-14 13:57:56 +00:00
$table->string('id')->index()->primary()->unique();
2022-08-13 06:04:47 +00:00
2022-08-14 14:00:22 +00:00
$table->string('name')->index();
2022-08-13 06:04:47 +00:00
2022-08-14 13:57:56 +00:00
// api token
$table->string('api_token')->nullable()->unique()->index();
2022-08-13 06:04:47 +00:00
});
2022-08-13 08:37:17 +00:00
// if env is local
2023-01-14 10:02:27 +00:00
if (config('app.env') == 'local') {
2022-08-13 08:37:17 +00:00
$module = [
2022-08-14 14:00:22 +00:00
'id' => 'test',
'name' => 'Example Module',
2023-01-30 16:14:07 +00:00
'api_token' => '123456',
2022-08-13 08:37:17 +00:00
];
2023-01-14 10:02:27 +00:00
(new App\Models\Module)->create($module);
2022-08-13 08:37:17 +00:00
}
2022-08-13 06:04:47 +00:00
}
/**
* Reverse the migrations.
*
* @return void
*/
2023-01-14 10:02:27 +00:00
public function down(): void
2022-08-13 06:04:47 +00:00
{
Schema::dropIfExists('modules');
}
};