오늘은 작업중에 DB를 수정하게 돼서 배포하는 것에 대한 내용을 적어보려고 합니다.
# Laravel DB 배포 과정
git rollback
git을 통해 배포를 진행했습니다.
완료되지 않은 기능은 제외하고 배포를 진행하기 위해 rollback 을 진행했습니다.
// git log 확인
$ git log
commit 24f026af288b35929a9cbd08114b303824f9aee1 // commit 번호 확인
Merge: 9e6ef50 df13ffc
Author: ****
Date: Wed Jan 5 15:09:53 2022 +0900
Merge branch 'develop' into develop_gf
// reset --hard
PCD-0033@DESKTOP-JRNS7KH MINGW64 /c/home/dmaster/dmaster (develop_gf)
$ git reset --hard 24f026af288b35929a9cbd08114b303824f9aee1
HEAD is now at 24f026a Merge branch 'develop' into develop_gf
PCD-0033@DESKTOP-JRNS7KH MINGW64 /c/home/dmaster/dmaster (develop_gf)
git log를 통해 rollback 할 commit 번호를 확인하고 reset --hard 를 진행
라라벨 DB 배포 : Migrate
우선 migration 파일을 생성해야 합니다.
$ php artisan make:migration [파일명]
$ php artisan make:migration edit_bbsarticles_configs
Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(
Created Migration: 2022_01_06_093531_edit_bbsarticles_configs
파일 생성 후, 코드를 적어줍니다.
[2022_01_06_093531_edit_bbsarticles_configs]
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class EditBbsarticlesConfigs extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
DB::statement("
ALTER TABLE `dmaster`.`bbs_articles`
ADD COLUMN `use_secret` ENUM('Y','N') NOT NULL DEFAULT 'N' COMMENT '비밀글 사용 여부' AFTER `user_name`;
");
DB::statement("
ALTER TABLE `dmaster`.`bbs_configs`
ADD COLUMN `use_secret` ENUM('Y','N') NOT NULL DEFAULT 'Y' COMMENT '비밀글 사용 여부' AFTER `enabled`;
");
DB::statement("
ALTER TABLE `dmaster`.`bbs_configs`
ADD COLUMN `use_comment` ENUM('Y','N') NOT NULL DEFAULT 'Y' COMMENT '댓글 사용 여부' AFTER `use_secret`;
");
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
마이그레이션 완료 !
PCD-0033@DESKTOP-JRNS7KH MINGW64 /c/home/dmaster/dmaster (develop_gf)
$ php artisan migrate
Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(
Migrating: 2022_01_06_093531_edit_bbsarticles_configs
Migrated: 2022_01_06_093531_edit_bbsarticles_configs (250.63ms)
라라벨 migrate - Rollback
마이그레이션을 진행하다 누락한 부분이 있어 Rollback을 진행하고 다시 진행했습니다.
// --step N : 최근 N개의 마이그레이션을 되돌림
PCD-0033@DESKTOP-JRNS7KH MINGW64 /c/home/dmaster/dmaster (develop_gf)
$ php artisan migrate:rollback --step=1
Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(
Rolling back: 2022_01_06_093531_edit_bbsarticles_configs
Rolled back: 2022_01_06_093531_edit_bbsarticles_configs (0.76ms)
// 후에 재실행
// 애플리케이션의 모든 마이그레이션을 되돌림
php artisan migrate:reset