@@ -0,0 +1,21 @@
|
||||
-- 门店多分类关联表(v4.0.9+)
|
||||
-- 执行:mysql ... < migrate-store-category-link.sql
|
||||
|
||||
CREATE TABLE IF NOT EXISTS store_category_link (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
store_id BIGINT UNSIGNED NOT NULL,
|
||||
category_id BIGINT UNSIGNED NOT NULL,
|
||||
priority INT NOT NULL DEFAULT 0,
|
||||
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_store_category_link (store_id, category_id),
|
||||
KEY idx_store_category_link_category (category_id),
|
||||
CONSTRAINT fk_store_category_link_store FOREIGN KEY (store_id) REFERENCES store_store(id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_store_category_link_category FOREIGN KEY (category_id) REFERENCES common_store_category(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
-- 从现有主分类回填
|
||||
INSERT IGNORE INTO store_category_link (store_id, category_id, priority)
|
||||
SELECT id, category_id, 0
|
||||
FROM store_store
|
||||
WHERE category_id IS NOT NULL;
|
||||
@@ -1000,12 +1000,29 @@ model CommonStoreCategory {
|
||||
parent CommonStoreCategory? @relation("StoreCategoryTree", fields: [parentId], references: [id], onDelete: Restrict)
|
||||
children CommonStoreCategory[] @relation("StoreCategoryTree")
|
||||
stores Store[]
|
||||
storeLinks StoreCategoryLink[]
|
||||
|
||||
@@index([parentId, sort])
|
||||
@@index([status])
|
||||
@@map("common_store_category")
|
||||
}
|
||||
|
||||
/// 门店 ↔ 二级分类多对多;store.category_id 保留主分类(排序第一)
|
||||
model StoreCategoryLink {
|
||||
id BigInt @id @default(autoincrement()) @db.UnsignedBigInt
|
||||
storeId BigInt @map("store_id") @db.UnsignedBigInt
|
||||
categoryId BigInt @map("category_id") @db.UnsignedBigInt
|
||||
priority Int @default(0)
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.DateTime(3)
|
||||
|
||||
store Store @relation(fields: [storeId], references: [id], onDelete: Cascade)
|
||||
category CommonStoreCategory @relation(fields: [categoryId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([storeId, categoryId])
|
||||
@@index([categoryId])
|
||||
@@map("store_category_link")
|
||||
}
|
||||
|
||||
model CommonPromoCode {
|
||||
id BigInt @id @default(autoincrement()) @db.UnsignedBigInt
|
||||
code String @unique @db.VarChar(32)
|
||||
@@ -1542,6 +1559,7 @@ model Store {
|
||||
packages StorePackage[]
|
||||
packageChangeRequests StorePackageChangeRequest[]
|
||||
infoChangeRequests StoreInfoChangeRequest[]
|
||||
categoryLinks StoreCategoryLink[]
|
||||
|
||||
@@index([cityId, status])
|
||||
@@index([partnerAccountId])
|
||||
|
||||
Reference in New Issue
Block a user