Skip to content

Commit

Permalink
feat(migrate): change migrate schema with config schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Matrix-X committed Oct 8, 2024
1 parent d176f26 commit 033c809
Show file tree
Hide file tree
Showing 63 changed files with 984 additions and 188 deletions.
6 changes: 3 additions & 3 deletions cmd/ctl/database/migrate/powerx.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,16 @@ func (m *PowerMigrator) AutoMigrate() {
&customerdomain.Lead{}, &customerdomain.Contact{}, customerdomain.RegisterCode{},
&customerdomain.Customer{}, &operation.Membership{},
)
_ = m.db.AutoMigrate(&wechat.WechatOACustomer{}, &wechat.WechatMPCustomer{}, &wechat.WeWorkExternalContact{})
_ = m.db.AutoMigrate(&wechat.WechatOACustomer{}, &wechat.WechatMPCustomer{})
_ = m.db.AutoMigrate(
&product.PivotProductToProductCategory{},
)
// product
_ = m.db.AutoMigrate(&product.Product{}, &product.ProductCategory{})
_ = m.db.AutoMigrate(&product.ProductSpecific{}, &product.SpecificOption{}, &product.ProductStatistics{})
_ = m.db.AutoMigrate(&product.SKU{}, &product.PivotSkuToSpecificOption{})
_ = m.db.AutoMigrate(&product.PriceBook{}, &product.PriceBookEntry{}, &product.PriceConfig{})
_ = m.db.AutoMigrate(&market.Store{}, &product.Artisan{}, &product.PivotStoreToArtisan{})
_ = m.db.AutoMigrate(&product.PriceBookEntry{}, &product.PriceBook{}, &product.PriceConfig{})
_ = m.db.AutoMigrate(&product.PivotStoreToArtisan{}, &market.Store{}, &product.Artisan{})

// market
_ = m.db.AutoMigrate(&market.Media{})
Expand Down
1 change: 1 addition & 0 deletions cmd/ctl/powerxctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func ActionSeed(cCtx *cli.Context) error {
var c config.Config
conf.MustLoad(configFile, &c)
c.EtcDir = filepath.Dir(configFile)
model.PowerXSchema = c.PowerXDatabase.Schema

// seed tables
s, _ := seed.NewPowerSeeder(&c)
Expand Down
12 changes: 12 additions & 0 deletions internal/model/crm/market/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ type Media struct {

const MediaUniqueId = powermodel.UniqueId

func (mdl *Media) TableName() string {
return model.PowerXSchema + "." + model.TableNameMedia
}

func (mdl *Media) GetTableName(needFull bool) string {
tableName := model.TableNameMedia
if needFull {
tableName = mdl.TableName()
}
return tableName
}

const TypeMediaType = "_media_type"

const (
Expand Down
61 changes: 61 additions & 0 deletions internal/model/crm/market/mgm.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package market

import (
"PowerX/internal/model"
"PowerX/internal/model/powermodel"
)

Expand All @@ -16,6 +17,18 @@ type MGMRule struct {

const MGMRuleUniqueId = powermodel.UniqueId

func (mdl *MGMRule) TableName() string {
return model.PowerXSchema + "." + model.TableNameMGMRule
}

func (mdl *MGMRule) GetTableName(needFull bool) string {
tableName := model.TableNameMGMRule
if needFull {
tableName = mdl.TableName()
}
return tableName
}

const (
TypeMGMScene = "_mgm_scene"

Expand Down Expand Up @@ -43,6 +56,18 @@ type CustomerChannel struct {
Code string `gorm:"comment:渠道码" json:"code"`
}

func (mdl *CustomerChannel) TableName() string {
return model.PowerXSchema + "." + model.TableNameCustomerChannel
}

func (mdl *CustomerChannel) GetTableName(needFull bool) string {
tableName := model.TableNameCustomerChannel
if needFull {
tableName = mdl.TableName()
}
return tableName
}

// InviteRecord 表示会员邀请记录
type InviteRecord struct {
powermodel.PowerModel
Expand All @@ -53,6 +78,18 @@ type InviteRecord struct {
MgmSceneId int `gorm:"comment:MGM场景ID" json:"mgmSceneId"`
}

func (mdl *InviteRecord) TableName() string {
return model.PowerXSchema + "." + model.TableNameInviteRecord
}

func (mdl *InviteRecord) GetTableName(needFull bool) string {
tableName := model.TableNameInviteRecord
if needFull {
tableName = mdl.TableName()
}
return tableName
}

// CommissionRecord 表示分佣记录
type CommissionRecord struct {
powermodel.PowerModel
Expand All @@ -64,6 +101,18 @@ type CommissionRecord struct {
OperationId int64 `gorm:"comment:操作对象ID" json:"operationId"`
}

func (mdl *CommissionRecord) TableName() string {
return model.PowerXSchema + "." + model.TableNameCommissionRecord
}

func (mdl *CommissionRecord) GetTableName(needFull bool) string {
tableName := model.TableNameCommissionRecord
if needFull {
tableName = mdl.TableName()
}
return tableName
}

// RewardRecord 表示奖励记录
type RewardRecord struct {
powermodel.PowerModel
Expand All @@ -73,3 +122,15 @@ type RewardRecord struct {
OperationType string `gorm:"comment:操作对象类型" json:"operationType"`
OperationId int64 `gorm:"comment:操作对象ID" json:"operationId"`
}

func (mdl *RewardRecord) TableName() string {
return model.PowerXSchema + "." + model.TableNameRewardRecord
}

func (mdl *RewardRecord) GetTableName(needFull bool) string {
tableName := model.TableNameRewardRecord
if needFull {
tableName = mdl.TableName()
}
return tableName
}
17 changes: 16 additions & 1 deletion internal/model/crm/market/promotion.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
package market

import "PowerX/internal/model/powermodel"
import (
"PowerX/internal/model"
"PowerX/internal/model/powermodel"
)

type PromotionRule struct {
powermodel.PowerModel

MinPurchase float64 `gorm:"comment:起订购买量" json:"minPurchase"`
BonusAmount float64 `gorm:"comment:额外赠送" json:"bonusAmount"`
}

func (mdl *PromotionRule) TableName() string {
return model.PowerXSchema + "." + model.TableNamePromotionRule
}

func (mdl *PromotionRule) GetTableName(needFull bool) string {
tableName := model.TableNamePromotionRule
if needFull {
tableName = mdl.TableName()
}
return tableName
}
14 changes: 13 additions & 1 deletion internal/model/crm/market/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type Store struct {
powermodel.PowerModel

Artisans []*product.Artisan `gorm:"many2many:public.pivot_store_to_artisan;foreignKey:Id;joinForeignKey:StoreId;References:Id;JoinReferences:ArtisanId" json:"priceBooks"`
Artisans []*product.Artisan `gorm:"many2many:pivot_store_to_artisan;foreignKey:Id;joinForeignKey:StoreId;References:Id;JoinReferences:ArtisanId" json:"priceBooks"`
PivotDetailImages []*media.PivotMediaResourceToObject `gorm:"polymorphic:Object;polymorphicValue:stores" json:"pivotDetailImages"`
CoverImage *media.MediaResource `gorm:"foreignKey:CoverImageId;references:Id" json:"coverImage"`

Expand All @@ -31,6 +31,18 @@ type Store struct {

const StoreUniqueId = powermodel.UniqueId

func (mdl *Store) TableName() string {
return model.PowerXSchema + "." + model.TableNameStore
}

func (mdl *Store) GetTableName(needFull bool) string {
tableName := model.TableNameStore
if needFull {
tableName = mdl.TableName()
}
return tableName
}

func (mdl *Store) LoadArtisans(db *gorm.DB, conditions *map[string]interface{}, withClauseAssociations bool) error {

mdl.Artisans = []*product.Artisan{}
Expand Down
13 changes: 13 additions & 0 deletions internal/model/crm/operation/membership.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package operation

import (
"PowerX/internal/model"
"PowerX/internal/model/crm/customerdomain"
"PowerX/internal/model/powermodel"
"time"
Expand Down Expand Up @@ -30,6 +31,18 @@ type Membership struct {

const MembershipUniqueId = powermodel.UniqueId

func (mdl *Membership) TableName() string {
return model.PowerXSchema + "." + model.TableNameMembership
}

func (mdl *Membership) GetTableName(needFull bool) string {
tableName := model.TableNameMembership
if needFull {
tableName = mdl.TableName()
}
return tableName
}

const TypeMembershipType = "_membership_type"
const TypeMembershipStatus = "_membership_status"

Expand Down
4 changes: 2 additions & 2 deletions internal/model/crm/operation/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ type TicketRecord struct {
}

func (mdl *TicketRecord) TableName() string {
return model.TableNameTicketRecord
return model.PowerXSchema + "." + model.TableNameTicketRecord
}

func (mdl *TicketRecord) GetTableName(needFull bool) string {
tableName := model.TableNameTicketRecord
if needFull {
tableName = "public." + tableName
tableName = mdl.TableName()
}
return tableName
}
Expand Down
12 changes: 11 additions & 1 deletion internal/model/crm/product/artisan.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,17 @@ type Artisan struct {

const ArtisanUniqueId = powermodel.UniqueId

// artisan level dd type
func (mdl *Artisan) TableName() string {
return model.PowerXSchema + "." + model.TableNameArtisan
}

func (mdl *Artisan) GetTableName(needFull bool) string {
tableName := model.TableNameArtisan
if needFull {
tableName = mdl.TableName()
}
return tableName
} // artisan level dd type
const ArtisanLevelType = "_artisan_level"

// artisan level dd items
Expand Down
17 changes: 12 additions & 5 deletions internal/model/crm/product/pivotproducttoproductcategory.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ import (
"PowerX/internal/model/powermodel"
)

// Table Name
func (mdl *PivotProductToProductCategory) TableName() string {
return model.TableNamePivotProductToProductCategory
}

// 数据表结构
type PivotProductToProductCategory struct {
powermodel.PowerPivot
Expand All @@ -18,6 +13,18 @@ type PivotProductToProductCategory struct {
ProductCategoryId int64 `gorm:"column:product_category_id; not null;index:idx_product_category_id" json:"productCategoryId"`
}

func (mdl *PivotProductToProductCategory) TableName() string {
return model.PowerXSchema + "." + model.TableNamePivotProductToProductCategory
}

func (mdl *PivotProductToProductCategory) GetTableName(needFull bool) string {
tableName := model.TableNamePivotProductToProductCategory
if needFull {
tableName = mdl.TableName()
}
return tableName
}

const PivotProductToCategoryForeignKey = "product_id"
const PivotProductToCategoryJoinKey = "product_category_id"

Expand Down
17 changes: 12 additions & 5 deletions internal/model/crm/product/pivotskutospecificoption.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import (
"github.com/ArtisanCloud/PowerLibs/v3/object"
)

// Table Name
func (mdl *PivotSkuToSpecificOption) TableName() string {
return model.TableNamePivotSkuToSpecificOption
}

// 数据表结构
type PivotSkuToSpecificOption struct {
powermodel.PowerPivot
Expand All @@ -27,6 +22,18 @@ type PivotSkuToSpecificOption struct {

const PivotPivotSkuToSpecificOptionsUniqueId = "index_unique_id"

func (mdl *PivotSkuToSpecificOption) TableName() string {
return model.PowerXSchema + "." + model.TableNamePivotSkuToSpecificOption
}

func (mdl *PivotSkuToSpecificOption) GetTableName(needFull bool) string {
tableName := model.TableNamePivotSkuToSpecificOption
if needFull {
tableName = mdl.TableName()
}
return tableName
}

func (mdl *PivotSkuToSpecificOption) GetPivotComposedUniqueID() object.NullString {
if mdl.ProductId > 0 && mdl.SkuId > 0 && mdl.SpecificId > 0 && mdl.SpecificOptionId > 0 {
strUniqueID := fmt.Sprintf("%d-%d-%d-%d-%d", mdl.ProductId, mdl.SkuId, mdl.SpecificId, mdl.SpecificOptionId, mdl.DeletedAt.Time.Unix())
Expand Down
17 changes: 12 additions & 5 deletions internal/model/crm/product/pivotstoretoartisan.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ import (
"PowerX/internal/model/powermodel"
)

// Table Name
func (mdl *PivotStoreToArtisan) TableName() string {
return model.TableNamePivotStoreToArtisan
}

// 数据表结构
type PivotStoreToArtisan struct {
powermodel.PowerPivot
Expand All @@ -18,6 +13,18 @@ type PivotStoreToArtisan struct {
ArtisanId int64 `gorm:"column:artisan_id; not null;index:idx_artisan_id" json:"artisanId"`
}

func (mdl *PivotStoreToArtisan) TableName() string {
return model.PowerXSchema + "." + model.TableNamePivotStoreToArtisan
}

func (mdl *PivotStoreToArtisan) GetTableName(needFull bool) string {
tableName := model.TableNamePivotStoreToArtisan
if needFull {
tableName = mdl.TableName()
}
return tableName
}

const PivotStoreToArtisanForeignKey = "store_id"
const PivotStoreToArtisanJoinKey = "artisan_id"

Expand Down
13 changes: 13 additions & 0 deletions internal/model/crm/product/pricebook.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package product

import (
"PowerX/internal/model"
"PowerX/internal/model/powermodel"
)

Expand All @@ -17,3 +18,15 @@ type PriceBook struct {
}

const PriceBookUniqueId = powermodel.UniqueId

func (mdl *PriceBook) TableName() string {
return model.PowerXSchema + "." + model.TableNamePriceBook
}

func (mdl *PriceBook) GetTableName(needFull bool) string {
tableName := model.TableNamePriceBook
if needFull {
tableName = mdl.TableName()
}
return tableName
}
Loading

0 comments on commit 033c809

Please sign in to comment.