Gorm: ๋ชจ๋“  ๊ตฌ์กฐ์ฒด๋ฅผ ์ž๋™์œผ๋กœ ์ž๋™ ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜

์— ๋งŒ๋“  2014๋…„ 01์›” 02์ผ  ยท  3์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: go-gorm/gorm

๋ชจ๋“  ๊ตฌ์กฐ์ฒด๋ฅผ ์ž๋™์œผ๋กœ ์ž๋™ ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๊นŒ?

๋งˆ์ด๊ทธ๋ ˆ์ด์…˜์ด ํ•จ์ˆ˜์— ์ „๋‹ฌ ๋  ํ•„์š”๊ฐ€์— ํ˜„์žฌ ๊ฐ ๊ตฌ์กฐ์ฒด์˜ ์ด๋ฆ„์ฒ˜๋Ÿผ ๋ณด์ธ๋‹ค https://github.com/jinzhu/gorm/blob/690cb1430c2e27011324c51826301a7daf728e65/main.go#L261

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

gorm์€ ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜ํ•˜๋ ค๋Š” ๊ตฌ์กฐ์ฒด๋ฅผ ์•Œ ์ˆ˜ ์—†์œผ๋ฏ€๋กœ ์ž๋™์œผ๋กœ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ ๋‚ด ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์—์„œ ์ด์™€ ๊ฐ™์€ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

package main

import (
    "fmt"
    . "xxx.com/xxxx/xxxx/app/models"
    . "xxx.com/xxxx/xxxx/db"
    "reflect"
)

func main() {
    for _, model := range []interface{}{
        Payment{}, Invoice{}, Transaction{},
        SubscriptionService{}, SubscriptionBenefit{}, Subscription{},
        Address{}, User{}, UserService{},
        Service{},
    } {
        if err := DB.AutoMigrate(model).Error; err != nil {
            fmt.Println(err)
        } else {
            fmt.Println("Auto migrating", reflect.TypeOf(model).Name(), "...")
        }
    }
}

๋ชจ๋“  3 ๋Œ“๊ธ€

gorm์€ ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜ํ•˜๋ ค๋Š” ๊ตฌ์กฐ์ฒด๋ฅผ ์•Œ ์ˆ˜ ์—†์œผ๋ฏ€๋กœ ์ž๋™์œผ๋กœ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ ๋‚ด ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์—์„œ ์ด์™€ ๊ฐ™์€ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

package main

import (
    "fmt"
    . "xxx.com/xxxx/xxxx/app/models"
    . "xxx.com/xxxx/xxxx/db"
    "reflect"
)

func main() {
    for _, model := range []interface{}{
        Payment{}, Invoice{}, Transaction{},
        SubscriptionService{}, SubscriptionBenefit{}, Subscription{},
        Address{}, User{}, UserService{},
        Service{},
    } {
        if err := DB.AutoMigrate(model).Error; err != nil {
            fmt.Println(err)
        } else {
            fmt.Println("Auto migrating", reflect.TypeOf(model).Name(), "...")
        }
    }
}

ํŒ ๊ณ ๋งˆ์›Œ!

2014๋…„ 1์›” 2์ผ ๋ชฉ์š”์ผ ์˜คํ›„ 1์‹œ 49๋ถ„์— Jinzhu [email protected]์—์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ผ์Šต๋‹ˆ๋‹ค.

ํ์‡„ #38 https://github.com/jinzhu/gorm/issues/38.

โ€”
์ด ์ด๋ฉ”์ผ์— ์ง์ ‘ ๋‹ต์žฅํ•˜๊ฑฐ๋‚˜ Gi tHubhttps://github.com/jinzhu/gorm/issues/38์—์„œ ํ™•์ธํ•˜์„ธ์š”.
.

์ด์ œ ๊ทธ๊ฒƒ์„ ํ•ด๊ฒฐํ•  ์ƒˆ๋กœ์šด ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๊นŒ?
๊ฐ์‚ฌ ํ•ด์š”. @jinzhu

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰