๋ชจ๋ ๊ตฌ์กฐ์ฒด๋ฅผ ์๋์ผ๋ก ์๋ ๋ง์ด๊ทธ๋ ์ด์ ํ ์ ์์ต๋๊น?
๋ง์ด๊ทธ๋ ์ด์ ์ด ํจ์์ ์ ๋ฌ ๋ ํ์๊ฐ์ ํ์ฌ ๊ฐ ๊ตฌ์กฐ์ฒด์ ์ด๋ฆ์ฒ๋ผ ๋ณด์ธ๋ค 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(), "...")
}
}
}
ํ ๊ณ ๋ง์!
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
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
gorm์ ๋ง์ด๊ทธ๋ ์ด์ ํ๋ ค๋ ๊ตฌ์กฐ์ฒด๋ฅผ ์ ์ ์์ผ๋ฏ๋ก ์๋์ผ๋ก ์ํํ ์ ์์ต๋๋ค.
ํ์ง๋ง ๋ด ์์ฉ ํ๋ก๊ทธ๋จ์์ ์ด์ ๊ฐ์ ์์ ์ ์ํํ๊ณ ์์ต๋๋ค.