πŸ₯•
TIL
  • [TIL] Studying tech / computer science knowledge
  • KeyMap
  • μ•Œκ³ λ¦¬μ¦˜
    • λ³΅μž‘λ„ 계산 ( Computational Complexity )
    • DisjointSet-unionFind
    • Bellman-ford Algorithm
    • Dijkstra's Algorithm
    • DP ( Dynamic Programming , 동적 κ³„νšλ²• )
    • ν”Œλ‘œμ΄λ“œ-μ›Œμ…œ μ•Œκ³ λ¦¬μ¦˜ (Floyd-Warshall algorithm)
    • Kruskal's Algorithm
    • 졜μž₯ 증가 μˆ˜μ—΄ (Longes Increasing Subsequence)
    • Prim's Algorithm
    • μ •λ ¬
    • μ‹œκ°„λ³΅μž‘λ„ 와 κ³΅κ°„λ³΅μž‘λ„ ( Time Complexity & Space Complexity )
    • Topological Sort (μœ„μƒ μ •λ ¬)
  • μ±… μ½κ³ λ‚œ ν›„ μš”μ•½
    • ν”„λ‘œκ·Έλž˜λ° λŒ€νšŒμ—μ„œ λ°°μš°λŠ” μ•Œκ³ λ¦¬μ¦˜ λ¬Έμ œν•΄κ²° μ „λž΅
    • cleancode
    • 도메인 주도 μ„€κ³„λ‘œ μ‹œμž‘ν•˜λŠ” λ§ˆμ΄ν¬λ‘œμ„œλΉ„μŠ€ 개발
    • 였브젝트
  • CDC
    • debzium
    • kafka
  • 개발 상식
    • asciidoctor
    • 컴파일러
    • ELK μŠ€νƒ
    • μ—”λ””μ•ˆ
    • git
    • Gitmoji
    • ν…ŒμŠ€νŠΈ μ’…λ₯˜
    • λΌμ΄λΈŒλŸ¬λ¦¬μ™€ ν”„λ ˆμž„μ›Œν¬
    • μ •κ·œ ν‘œν˜„μ‹
    • REST API
    • 동기와 비동기 / Blockingκ³Ό NonBlocking
    • Transaction Script와 Domain Model
    • λ””μžμΈ νŒ¨ν„΄
      • 행동 νŒ¨ν„΄
      • 객체 생성 νŒ¨ν„΄
        • 좔상 νŒ©ν† λ¦¬ νŒ¨ν„΄
        • λΉŒλ” νŒ¨ν„΄
        • νŒ©ν† λ¦¬ λ©”μ„œλ“œ νŒ¨ν„΄
        • [생성 νŒ¨ν„΄] ν”„λ‘œν†  νƒ€μž… (Prototype Parttern)
        • 싱글톀
      • ꡬ쑰 νŒ¨ν„΄
        • μ–΄λŒ‘ν„° νŒ¨ν„΄
        • λΈŒλ¦Ώμ§€ νŒ¨ν„΄
        • 컴포짓(Composite) νŒ¨ν„΄
        • λ°μ½”λ ˆμ΄ν„°
        • ν”„λ‘μ‹œ
    • refactoring
      • 쀑볡 μ½”λ“œ
      • μ „μ—­ 데이터
      • κΈ΄ ν•¨μˆ˜
      • κΈ΄ λ§€κ°œλ³€μˆ˜ λͺ©λ‘
      • κ°€λ³€ 데이터
      • μ΄ν•΄ν•˜κΈ° νž˜λ“  이름
  • 자료ꡬ쑰
    • AVL Tree
    • Splay Tree
    • aaTree
    • array-list
    • 자료ꡬ쑰 μ‹œκ°„/곡간 λ³΅μž‘λ„
    • κ·Έλž˜ν”„
    • νž™
    • Red Black Tree
    • stack-queue
    • 트리 ( Tree )
  • DevOps
    • MSA
    • Kubernetes
      • AccessingAPI
      • controller
      • dashboard
      • kubernetes
      • object
      • pod
      • service
      • volume
  • Java
    • μ–΄λ…Έν…Œμ΄μ…˜
    • μ œμ–΄λ¬Έ
    • 데이터 νƒ€μž…
    • Enum
    • jvm
    • μ—°μ‚°μž
    • thread
    • Java8
      • CompletableFuture
      • Date/Time
      • μ–΄λ…Έν…Œμ΄μ…˜κ³Ό λ©”νƒ€μŠ€νŽ˜μ΄μŠ€
      • μΈν„°νŽ˜μ΄μŠ€
      • λžŒλ‹€μ‹
      • Optional
      • 슀트림
  • JavaScript
    • moduleProject
    • webpack-babel
    • μ½”μ–΄ μžλ°”μŠ€ν¬λ¦½νŠΈ
      • array
      • ν•¨μˆ˜ 바인딩
      • λ°μ½”λ ˆμ΄ν„°μ™€ ν¬μ›Œλ”©
      • Class
      • 비ꡐ μ—°μ‚°μž
      • Date λ‚΄μž₯ 객체
      • destructuring-assignment
      • function
      • ν•¨μˆ˜μ˜ prototype ν”„λ‘œνΌν‹°
      • κ°€λΉ„μ§€ μ»¬λ ‰μ…˜ ( Garbage Collection )
      • JSON (JavaScript Object Notation)
      • map-set
      • λ‚΄μž₯ ν”„λ‘œν† νƒ€μž…
      • newμ—°μ‚°μžμ™€ μƒμ„±μž ν•¨μˆ˜
      • 객체
      • Object.keys, values, entries
      • μ˜΅μ…”λ„ 체이닝 '?.'
      • ν”„λ‘œνΌν‹° ν”Œλž˜κ·Έ
      • ν”„λ‘œνΌν‹° μ’…λ₯˜
      • ν”„λ‘œν†  νƒ€μž…
      • 호좜 μŠ€μΌ€μ€„λ§ ( scheduling a call )
      • scope
      • this
      • type-conversions
      • type
      • ν•¨μˆ˜μ˜ μžλ£Œν˜•
      • var_let_const
  • Linux
    • κΈ°λ³Έ λͺ…λ Ήμ–΄
    • 파일 μ’…λ₯˜
    • λ¦¬λˆ…μŠ€
  • λ„€νŠΈμ›Œν¬
    • μ‘μš© 계측 ( Application Layer )
    • 였λ₯˜ κ²€μΆœκ³Ό 였λ₯˜ μ •μ •
    • Http
    • Http Header
    • 컴퓨터 λ„€νŠΈμ›Œν¬λž€
    • λ„€νŠΈμ›Œν¬ 계측
    • λ„€νŠΈμ›Œν¬ μ œμ–΄ μ˜μ—­
    • 전솑 계측 ( Transport Layer )
  • PHP
    • Facade
    • composer
    • scopeResolutionOperator
    • Laravel
      • SocialProvider
      • architecture
      • blade
      • controller
      • db
      • dbArchitecture
      • debug
      • eloquent
      • email
      • event
      • exceptionHandling
      • middleware
      • model
      • modelFactory
      • pagingLoading
      • queryBuilder
      • route
      • scout
      • seeding
      • tntsearch
      • validate
      • view
  • React
    • Next.js
    • React λž€?
  • Spring
    • Controller
    • μš”μ²­μ΄ λ“€μ–΄μ™”μ„λ•Œ μŠ€ν”„λ§μ΄ μ²˜λ¦¬ν•˜λŠ” 방법 ( 내뢀ꡬ쑰 )
    • ConfigurationProperties
    • Entity / DTO / VO
    • Maven
    • Repository와 DAO
    • μŠ€ν”„λ§ 빈
    • Spring Framework
    • MVC νŒ¨ν„΄
    • 도메인 μž…λ ₯κ°’ 검증
    • Spring Cloud
      • Spring Cloud
      • Eureka
    • Spring Data
      • JPA
      • JPA μ–΄λ…Έν…Œμ΄μ…˜
      • μ—”ν‹°ν‹° 비ꡐ
      • 볡합 킀와 식별 관계 λ§€ν•‘
      • JPA μ˜ˆμ™Έμ²˜λ¦¬
      • 객체지ν–₯ 쿼리
      • EntityManagerFactory와 EntityManager
      • JPA μ΅œμ ν™”
      • ν”„λ‘μ‹œμ™€ 연관관계 λ§΅ν•‘
      • 연관관계
      • 상속관계 λ§΅ν•‘
      • νŠΈλžœμž­μ…˜ λ²”μœ„μ™€ μ˜μ†μ„± μ»¨ν…μŠ€νŠΈ
      • 데이터 νƒ€μž…
      • MySQL μ—°κ²°
      • Pageable
    • Spring Projectλ“€κ³Ό library
      • Custom Serialize
      • Elasticsearch Index API
      • Spring HATEOAS
      • lombok (둬볡)
      • Model Mapper
      • Object Mapper
      • Representation Model
      • Spring REST Docs
      • Spring Boot
    • Spring Security
      • Spring Security
      • Authentication
      • Authentication Filter
      • Authorization Filter
      • Filter Chain
      • SecurityContext
      • Spring OAuth2.0
    • Spring Test
      • AssertJ
      • Junit5
      • JunitParams
      • Mock Object
  • DataBase
    • ALIAS
    • CONCAT
    • CTE
    • Group By
    • HAVING
    • IFNULL
    • 인덱슀
    • JOIN
    • ORDER BY
    • ROLLUP
    • SELECT
    • SELECT DISTINCT
    • SQL
    • WHERE
  • Web 상식
    • OAuth
    • WAS
    • HTTP톡신 기반 인증
    • λΈŒλΌμš°μ €
    • CSR κ³Ό SSR
    • HTTPS
    • Web
Powered by GitBook
On this page
  • db λ§ˆμ΄κ·Έλ ˆμ΄μ…˜
  • λ§ˆμ΄κ·Έλ ˆμ΄μ…˜μ΄ ν•„μš”ν•œ 이유
  • λ§Œλ“œλŠ” 방법
  • μ‹€ν–‰
  • λ‘€λ°±
  • μ΄ˆκΈ°ν™”
  • μž‘μ„±λ˜λŠ” SQLλ¬Έ 보기
  1. PHP
  2. Laravel

db

db λ§ˆμ΄κ·Έλ ˆμ΄μ…˜

ν…Œμ΄λΈ” μŠ€ν‚€λ§ˆμ˜ λ²„μ „κ΄€λ¦¬λ‘œ ν…Œμ΄λΈ”μ— μƒˆλ‘œμš΄ 열을 μΆ”κ°€,μˆ˜μ • 이λ ₯을 남겨 λ‘€λ°±ν•˜λŠ” λ“±μ˜ μž‘μ—…μ„ μˆ˜ν–‰ν•  수 있게 ν•΄μ€€λ‹€.

λ§ˆμ΄κ·Έλ ˆμ΄μ…˜μ΄ ν•„μš”ν•œ 이유

  1. λͺ¨λ˜ 개발 방법둠

    νŒ€ λ‚΄ κ°œλ°œμžλ“€μ€ 같은 μŠ€ν‚€λ§ˆλ‘œ κ°œλ°œν•΄μ•Ό ν•˜κΈ° λ•Œλ¬Έμ— κ°œλ°œν™˜κ²½λΏλ§Œ μ•„λ‹ˆλΌ μš΄μ˜ν™˜κ²½μ„ 쉽고 λΉ λ₯΄κ²Œ λ§Œλ“€μˆ˜ 있게 ν•΄μ€€λ‹€.

  2. μ‹œκ°„μ΄μ§€λ‚¨μ— 따라 μš”κ΅¬μ‚¬ν•­μ΄ λ°”λ€Œκ³  λͺ¨λΈλ§μ΄ λ°”λ€Œκ²Œ λ˜κΈ°λ„ ν•˜κ³ , μ‹€μˆ˜κ°€ λ°œμƒν–ˆμ„λ•Œ λΉ λ₯΄κ²Œ λ‘€λ°±ν•΄μ•Ό ν•˜λŠ” μƒν™©ν•˜λŠ” 것과 같이 효과적으둜 λŒ€μ‘ν•  수 있기 λ•Œλ¬Έμ΄λ‹€.

λ§Œλ“œλŠ” 방법

$ php artisan make:migration create_posts_table --create=posts
$ php artisan make:migration create_authors_table --create=authors

생성을 ν•˜λ©΄ database/migrations디렉토리 ν•˜μœ„μ— μƒμ„±λ˜κ³  κ΄€λ‘€μ μœΌλ‘œ μŠ€λ„€μ΄ν¬ ν‘œκΈ°λ²•μ„ μ‚¬μš©ν•΄μ„œ create_,make_,add_,drop_,change_λ“±μœΌλ‘œ μ‹œμž‘ν•˜κ³  _table둜 λλ‚œλ‹€.

μ˜΅μ…˜μœΌλ‘œ --createμ˜΅μ…˜μ„ μ£Όλ©΄ upκ³Ό down이 create와 drop으둜 생성이 되고, --tableμ˜΅μ…˜μ„ μ£Όλ©΄ up(),down()λ©”μ„œλ“œκ°€ table()λ©”μ„œλ“œλ‘œ μžλ™μƒμ„±λœλ‹€.

createμ˜΅μ…˜

class CreatePostsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->id();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('posts');
    }
}

table μ˜΅μ…˜

class CreateExampleTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('example', function (Blueprint $table) {
            //
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('example', function (Blueprint $table) {
            //
        });
    }
}

class CreateAuthorsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('authors', function (Blueprint $table) {
            $table->increments('id');
            $table->string('email',255);
            $table->string('password',60);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('authors');
    }
}

up()λ©”μ„œλ“œλŠ” λ§ˆμ΄κ·Έλ ˆμ΄μ…˜μ„ μ‹€ν–‰ν•˜λŠ” λ©”μ„œλ“œμ΄κ³  down()은 둀백을 μœ„ν•œ λ©”μ„œλ“œμ΄λ‹€. up()λ‚΄λΆ€μ˜ increments()λŠ” μžλ™μ¦κ°€ κΈ°λ³Έ ν‚€ μ»¬λŸΌμ„ λ§Œλ“€κ³ , timestamp()λŠ” created_atκ³Ό updated_at μ»¬λŸΌμ„ λ§Œλ“ λ‹€.

create()λ©”μ„œλ“œμ˜ λ‘λ²ˆμ§Έ λ§€κ°œλ³€μˆ˜λŠ” 콜백 ν•¨μˆ˜μ΄κ³  이 ν•¨μˆ˜μ˜μ˜ λ§€κ°œλ³€μˆ˜λ‘œ BlueprintλŠ” νƒ€μž… 힌트둜써, ν•΄λ‹Ή 클래슀의 μΈμŠ€ν„΄μŠ€μ—¬μ•Όν•œλ‹€κ³  κ°•μ œν•˜λŠ” 것이닀.

  • Schema::create() : ν…Œμ΄λΈ”μ„ 생성

  • Schema::drop() : ν…Œμ΄λΈ”μ„ μ‚­μ œ

  • Schema::table() : ν…Œμ΄λΈ”μ„ 생성/μ‚­μ œλ₯Ό μ œμ™Έν•œ λ‚˜λ¨Έμ§€ μŠ€ν‚€λ§ˆ κ΄€λ ¨ μž‘μ—…λ“€

μ»¬λŸΌνƒ€μž…μ— λŒ€μ‘λ˜λŠ” λ©”μ„œλ“œ μ’…λ₯˜

  • boolean(), dateTime(), enum(), integer()λ“±κ³Ό 같은 μ»¬λŸΌνƒ€μž… λ©”μ„œλ“œ

  • timestamps(), softDeletes()λ“±μ˜ λ„μš°λ―Έ λ©”μ„œλ“œ

  • nullable(), default(), unsinged()λ“±μ˜ μž₯식 λ©”μ„œλ“œ

  • unique(), index()λ“±μ˜ 인덱슀 λ©”μ„œλ“œ

  • dropColumn()

μ‹€ν–‰

$ php artisan migrate

λ‘€λ°±

$ php artisan migrate:rollback

μ΄ˆκΈ°ν™”

$ php artisan migrate:refresh

μž‘μ„±λ˜λŠ” SQLλ¬Έ 보기

$ php artisan migrate --pretend
PreviouscontrollerNextdbArchitecture

Last updated 3 years ago

이외에도 을 보면 λ§Žμ€ λ©”μ„œλ“œκ°€ μ‘΄μž¬ν•œλ‹€.

κ³΅μ‹λ¬Έμ„œ