diff --git a/src/db/seed/dict.ts b/src/db/seed/dict.ts new file mode 100644 index 0000000..1ba6d7a --- /dev/null +++ b/src/db/seed/dict.ts @@ -0,0 +1,65 @@ +/** + * @description 字典数据备份 + * @author ZKS + * @date 2025-11-27 + */ + +// 真实数据 +export const flavorsData: { id: number; title: string; name: string }[] = [ + { id: 1, title: 'Bellini Mini', name: 'Bellini Mini' }, + { id: 2, title: 'Max Polarmint', name: 'Max Polarmint' }, + { id: 3, title: 'Blueberry', name: 'Blueberry' }, + { id: 4, title: 'Citrus', name: 'Citrus' }, + { id: 5, title: 'Wintergreen', name: 'Wintergreen' }, + { id: 6, title: 'COOL MINT', name: 'COOL MINT' }, + { id: 7, title: 'JUICY PEACH', name: 'JUICY PEACH' }, + { id: 8, title: 'ORANGE', name: 'ORANGE' }, + { id: 9, title: 'PEPPERMINT', name: 'PEPPERMINT' }, + { id: 10, title: 'SPEARMINT', name: 'SPEARMINT' }, + { id: 11, title: 'STRAWBERRY', name: 'STRAWBERRY' }, + { id: 12, title: 'WATERMELON', name: 'WATERMELON' }, + { id: 13, title: 'COFFEE', name: 'COFFEE' }, + { id: 14, title: 'LEMONADE', name: 'LEMONADE' }, + { id: 15, title: 'apple mint', name: 'apple mint' }, + { id: 16, title: 'PEACH', name: 'PEACH' }, + { id: 17, title: 'Mango', name: 'Mango' }, + { id: 18, title: 'ICE WINTERGREEN', name: 'ICE WINTERGREEN' }, + { id: 19, title: 'Pink Lemonade', name: 'Pink Lemonade' }, + { id: 20, title: 'Blackcherry', name: 'Blackcherry' }, + { id: 21, title: 'fresh mint', name: 'fresh mint' }, + { id: 22, title: 'Strawberry Lychee', name: 'Strawberry Lychee' }, + { id: 23, title: 'Passion Fruit', name: 'Passion Fruit' }, + { id: 24, title: 'Banana lce', name: 'Banana lce' }, + { id: 25, title: 'Bubblegum', name: 'Bubblegum' }, + { id: 26, title: 'Mango lce', name: 'Mango lce' }, + { id: 27, title: 'Grape lce', name: 'Grape lce' }, + { id: 28, title: 'Peach', name: 'Peach' }, +]; + +export const brandsData: { id: number; title: string; name: string }[] = [ + { id: 1, title: 'Yoone', name: 'YOONE' }, + { id: 2, title: 'White Fox', name: 'WHITE_FOX' }, + { id: 3, title: 'ZYN', name: 'ZYN' }, + { id: 4, title: 'Zonnic', name: 'ZONNIC' }, + { id: 5, title: 'Zolt', name: 'ZOLT' }, + { id: 6, title: 'Velo', name: 'VELO' }, + { id: 7, title: 'Lucy', name: 'LUCY' }, + { id: 8, title: 'EGP', name: 'EGP' }, + { id: 9, title: 'Bridge', name: 'BRIDGE' }, + { id: 10, title: 'ZEX', name: 'ZEX' }, + { id: 11, title: 'Sesh', name: 'Sesh' }, + { id: 12, title: 'Pablo', name: 'Pablo' }, +]; + +export const strengthsData: { id: number; title: string; name: string }[] = [ + { id: 1, title: '3MG', name: '3MG' }, + { id: 2, title: '9MG', name: '9MG' }, + { id: 3, title: '2MG', name: '2MG' }, + { id: 4, title: '4MG', name: '4MG' }, + { id: 5, title: '12MG', name: '12MG' }, + { id: 6, title: '18MG', name: '18MG' }, + { id: 7, title: '6MG', name: '6MG' }, + { id: 8, title: '16.5MG', name: '16.5MG' }, + { id: 9, title: '6.5MG', name: '6.5MG' }, + { id: 10, title: '30MG', name: '30MG' }, +]; \ No newline at end of file diff --git a/src/db/seed/index.ts b/src/db/seed/index.ts index e69de29..2e1ba10 100644 --- a/src/db/seed/index.ts +++ b/src/db/seed/index.ts @@ -0,0 +1,44 @@ +import { createConnection } from 'typeorm'; +import { Dict } from '../../entity/dict.entity'; +import { DictItem } from '../../entity/dict_item.entity'; +import { brandsData, flavorsData, strengthsData } from './dict'; + +async function seed() { + const connection = await createConnection(); + + // 创建字典 + const brandDict = await connection.manager.save(Dict, { name: '品牌', unique_key: 'brand' }); + const flavorDict = await connection.manager.save(Dict, { name: '口味', unique_key: 'flavor' }); + const strengthDict = await connection.manager.save(Dict, { name: '规格', unique_key: 'strength' }); + + // 植入品牌数据 + for (const brand of brandsData) { + await connection.manager.save(DictItem, { + name: brand.name, + unique_key: brand.unique_key, + dict_id: brandDict.id, + }); + } + + // 植入口味数据 + for (const flavor of flavorsData) { + await connection.manager.save(DictItem, { + name: flavor.name, + unique_key: flavor.unique_key, + dict_id: flavorDict.id, + }); + } + + // 植入规格数据 + for (const strength of strengthsData) { + await connection.manager.save(DictItem, { + name: strength.name, + unique_key: strength.unique_key, + dict_id: strengthDict.id, + }); + } + + await connection.close(); +} + +seed().catch(error => console.error(error));