миграция нового кастомного поля для примера и удаление неактуальной миграции с аватарами пользователя
This commit is contained in:
1 parent
9ec9401a6e
commit
be51cd3b93
2 files changed
+50
-32
No files matched your search
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Migrations;
|
||||
|
||||
use Rsgrinko\Proton\Database\Migration;
|
||||
use Rsgrinko\Proton\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* Фото профиля. Путь к файлу и его MIME — отдельно от общего хранилища
|
||||
* вложений (`attachments`): аватар не «прикладывается» к записи, у него всегда
|
||||
* ровно один текущий файл на пользователя, который просто перезаписывается.
|
||||
*/
|
||||
final class AddUserAvatar extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
$this->table('users', function (Blueprint $table): void {
|
||||
$table->string('avatar_path', 255)->default('');
|
||||
$table->string('avatar_mime', 100)->default('');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$this->table('users', function (Blueprint $table): void {
|
||||
$table->dropColumn('avatar_path');
|
||||
$table->dropColumn('avatar_mime');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Migrations;
|
||||
|
||||
use Rsgrinko\Proton\Database\Migration;
|
||||
|
||||
/**
|
||||
* Добавление кастомного поля профиля Telegram
|
||||
*/
|
||||
final class AddUserMetaTelegramField extends Migration
|
||||
{
|
||||
private const META_FIELDS = [
|
||||
[
|
||||
'field_key' => 'telegram',
|
||||
'label' => 'Telegram',
|
||||
'type' => 'string',
|
||||
'description' => 'Профиль Telegram в формате @nickname',
|
||||
],
|
||||
];
|
||||
public function up(): void
|
||||
{
|
||||
foreach (self::META_FIELDS as $field) {
|
||||
$this->statement(
|
||||
'INSERT INTO user_fields (field_key, label, type, description, sort, created_at, updated_at)
|
||||
VALUES (:field_key, :label, :type, :description, :sort, :created_at, :updated_at)',
|
||||
[
|
||||
'field_key' => $field['field_key'],
|
||||
'label' => $field['label'],
|
||||
'type' => $field['type'],
|
||||
'description' => $field['description'],
|
||||
'sort' => 0,
|
||||
'created_at' => $this->now(),
|
||||
'updated_at' => $this->now(),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
foreach (self::META_FIELDS as $field) {
|
||||
$this->statement(
|
||||
'DELETE FROM user_fields WHERE field_key = :field_key',
|
||||
['field_key' => $field['field_key']]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user