Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaifan committed Mar 31, 2022
1 parent b1e35e6 commit 9d56dd1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/Models/FileLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
* App\Models\FileLink
*
* @property int $id
* @property int|null $file_id 项目ID
* @property int|null $file_id 文件ID
* @property int|null $num 累计访问
* @property string|null $code 链接码
* @property int|null $userid 会员ID
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \App\Models\File|null $file
Expand All @@ -21,6 +22,7 @@
* @method static \Illuminate\Database\Eloquent\Builder|FileLink whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|FileLink whereNum($value)
* @method static \Illuminate\Database\Eloquent\Builder|FileLink whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|FileLink whereUserid($value)
* @mixin \Eloquent
*/
class FileLink extends AbstractModel
Expand Down
12 changes: 12 additions & 0 deletions database/migrations/2022_03_31_093754_add_file_links_userid.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,23 @@ class AddFileLinksUserid extends Migration
*/
public function up()
{
$isAdd = false;
Schema::table('file_links', function (Blueprint $table) {
if (!Schema::hasColumn('file_links', 'userid')) {
$isAdd = true;
$table->integer('userid')->nullable()->default(0)->after('code')->comment('会员ID');
}
});
if ($isAdd) {
// 更新数据
\App\Models\FileLink::chunkById(100, function ($lists) {
/** @var \App\Models\FileLink $item */
foreach ($lists as $item) {
$item->userid = intval(\App\Models\File::whereId($item->file_id)->value('userid'));
$item->save();
}
});
}
}

/**
Expand Down

0 comments on commit 9d56dd1

Please sign in to comment.