From 95741a89f40c8be79db27715dc27e871ec68053d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=96=8C?= <259278618@qq.com> Date: Thu, 13 Aug 2026 12:01:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=2019=20=E5=BC=A0=E8=A1=A8=20DAO=20?= =?UTF-8?q?=E4=B8=8E=E5=BB=BA=E8=A1=A8=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- biz/dao/dao_admin_user.go | 26 +++++++++++++++++++++++ biz/dao/dao_badge.go | 27 ++++++++++++++++++++++++ biz/dao/dao_chapter_review.go | 28 +++++++++++++++++++++++++ biz/dao/dao_child.go | 32 ++++++++++++++++++++++++++++ biz/dao/dao_element.go | 30 +++++++++++++++++++++++++++ biz/dao/dao_level.go | 33 +++++++++++++++++++++++++++++ biz/dao/dao_life_task.go | 29 ++++++++++++++++++++++++++ biz/dao/dao_life_task_log.go | 29 ++++++++++++++++++++++++++ biz/dao/dao_node_option.go | 32 ++++++++++++++++++++++++++++ biz/dao/dao_parent.go | 31 +++++++++++++++++++++++++++ biz/dao/dao_point_log.go | 29 ++++++++++++++++++++++++++ biz/dao/dao_prize.go | 30 +++++++++++++++++++++++++++ biz/dao/dao_redemption.go | 30 +++++++++++++++++++++++++++ biz/dao/dao_scene_node.go | 36 ++++++++++++++++++++++++++++++++ biz/dao/dao_strategy.go | 38 ++++++++++++++++++++++++++++++++++ biz/dao/dao_user_badge.go | 26 +++++++++++++++++++++++ biz/dao/dao_user_collection.go | 26 +++++++++++++++++++++++ biz/dao/dao_user_progress.go | 30 +++++++++++++++++++++++++++ biz/dao/dao_user_route_log.go | 29 ++++++++++++++++++++++++++ biz/dao/init.go | 37 +++++++++++++++++++++++++++++++-- config.yml | 2 +- 21 files changed, 607 insertions(+), 3 deletions(-) create mode 100644 biz/dao/dao_admin_user.go create mode 100644 biz/dao/dao_badge.go create mode 100644 biz/dao/dao_chapter_review.go create mode 100644 biz/dao/dao_child.go create mode 100644 biz/dao/dao_element.go create mode 100644 biz/dao/dao_level.go create mode 100644 biz/dao/dao_life_task.go create mode 100644 biz/dao/dao_life_task_log.go create mode 100644 biz/dao/dao_node_option.go create mode 100644 biz/dao/dao_parent.go create mode 100644 biz/dao/dao_point_log.go create mode 100644 biz/dao/dao_prize.go create mode 100644 biz/dao/dao_redemption.go create mode 100644 biz/dao/dao_scene_node.go create mode 100644 biz/dao/dao_strategy.go create mode 100644 biz/dao/dao_user_badge.go create mode 100644 biz/dao/dao_user_collection.go create mode 100644 biz/dao/dao_user_progress.go create mode 100644 biz/dao/dao_user_route_log.go diff --git a/biz/dao/dao_admin_user.go b/biz/dao/dao_admin_user.go new file mode 100644 index 0000000..8928ca0 --- /dev/null +++ b/biz/dao/dao_admin_user.go @@ -0,0 +1,26 @@ +package dao + +import ( + "context" + + "github.com/gogf/gf/v2/frame/g" + + "36wisdom/biz/consts" + "36wisdom/common" +) + +type adminUserDao struct{ common.BaseDao } + +var AdminUser = &adminUserDao{BaseDao: common.BaseDao{Table: consts.TableAdminUser}} + +func (d *adminUserDao) Init(ctx context.Context) error { + _, err := g.DB().Exec(ctx, ` +CREATE TABLE IF NOT EXISTS admin_user ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + username TEXT UNIQUE NOT NULL, + password TEXT NOT NULL, + status INTEGER NOT NULL DEFAULT 1, + created_at DATETIME +);`) + return err +} diff --git a/biz/dao/dao_badge.go b/biz/dao/dao_badge.go new file mode 100644 index 0000000..26ec854 --- /dev/null +++ b/biz/dao/dao_badge.go @@ -0,0 +1,27 @@ +package dao + +import ( + "context" + + "github.com/gogf/gf/v2/frame/g" + + "36wisdom/biz/consts" + "36wisdom/common" +) + +type badgeDao struct{ common.BaseDao } + +var Badge = &badgeDao{BaseDao: common.BaseDao{Table: consts.TableBadge}} + +func (d *badgeDao) Init(ctx context.Context) error { + _, err := g.DB().Exec(ctx, ` +CREATE TABLE IF NOT EXISTS badge ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL, + icon TEXT, + cond_type INTEGER NOT NULL, + cond_value INTEGER NOT NULL, + status INTEGER NOT NULL DEFAULT 1 +);`) + return err +} diff --git a/biz/dao/dao_chapter_review.go b/biz/dao/dao_chapter_review.go new file mode 100644 index 0000000..38dd896 --- /dev/null +++ b/biz/dao/dao_chapter_review.go @@ -0,0 +1,28 @@ +package dao + +import ( + "context" + + "github.com/gogf/gf/v2/frame/g" + + "36wisdom/biz/consts" + "36wisdom/common" +) + +type chapterReviewDao struct{ common.BaseDao } + +var ChapterReview = &chapterReviewDao{BaseDao: common.BaseDao{Table: consts.TableChapterReview}} + +func (d *chapterReviewDao) Init(ctx context.Context) error { + _, err := g.DB().Exec(ctx, ` +CREATE TABLE IF NOT EXISTS chapter_review ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + child_id INTEGER NOT NULL, + strategy_id INTEGER NOT NULL, + level_ids TEXT NOT NULL, + status INTEGER NOT NULL DEFAULT 1, + created_at DATETIME, + UNIQUE(child_id, strategy_id) +);`) + return err +} diff --git a/biz/dao/dao_child.go b/biz/dao/dao_child.go new file mode 100644 index 0000000..7825e3a --- /dev/null +++ b/biz/dao/dao_child.go @@ -0,0 +1,32 @@ +package dao + +import ( + "context" + + "github.com/gogf/gf/v2/frame/g" + + "36wisdom/biz/consts" + "36wisdom/common" +) + +type childDao struct{ common.BaseDao } + +var Child = &childDao{BaseDao: common.BaseDao{Table: consts.TableChild}} + +func (d *childDao) Init(ctx context.Context) error { + _, err := g.DB().Exec(ctx, ` +CREATE TABLE IF NOT EXISTS child ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + parent_id INTEGER NOT NULL, + nickname TEXT, + avatar TEXT, + age_group TEXT NOT NULL DEFAULT '4-6', + points INTEGER NOT NULL DEFAULT 0, + daily_limit_minutes INTEGER NOT NULL DEFAULT 0, + status INTEGER NOT NULL DEFAULT 1, + created_at DATETIME, + updated_at DATETIME +); +CREATE INDEX IF NOT EXISTS idx_child_parent ON child(parent_id);`) + return err +} diff --git a/biz/dao/dao_element.go b/biz/dao/dao_element.go new file mode 100644 index 0000000..dad67d3 --- /dev/null +++ b/biz/dao/dao_element.go @@ -0,0 +1,30 @@ +package dao + +import ( + "context" + + "github.com/gogf/gf/v2/frame/g" + + "36wisdom/biz/consts" + "36wisdom/common" +) + +type elementDao struct{ common.BaseDao } + +var Element = &elementDao{BaseDao: common.BaseDao{Table: consts.TableElement}} + +func (d *elementDao) Init(ctx context.Context) error { + _, err := g.DB().Exec(ctx, ` +CREATE TABLE IF NOT EXISTS element ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + e_type INTEGER NOT NULL, + name TEXT NOT NULL, + image TEXT, + audio TEXT, + description TEXT, + status INTEGER NOT NULL DEFAULT 1, + sort_order INTEGER NOT NULL DEFAULT 1 +); +CREATE INDEX IF NOT EXISTS idx_element_type ON element(e_type);`) + return err +} diff --git a/biz/dao/dao_level.go b/biz/dao/dao_level.go new file mode 100644 index 0000000..41ba415 --- /dev/null +++ b/biz/dao/dao_level.go @@ -0,0 +1,33 @@ +package dao + +import ( + "context" + + "github.com/gogf/gf/v2/frame/g" + + "36wisdom/biz/consts" + "36wisdom/common" +) + +type levelDao struct{ common.BaseDao } + +var Level = &levelDao{BaseDao: common.BaseDao{Table: consts.TableLevel}} + +func (d *levelDao) Init(ctx context.Context) error { + _, err := g.DB().Exec(ctx, ` +CREATE TABLE IF NOT EXISTS level ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + strategy_id INTEGER NOT NULL, + title TEXT NOT NULL, + scene_id INTEGER, + scene_content TEXT NOT NULL, + scene_image TEXT, + scene_audio TEXT, + age_group TEXT NOT NULL DEFAULT '4-6', + content_version INTEGER NOT NULL DEFAULT 1, + sort_order INTEGER NOT NULL, + status INTEGER NOT NULL DEFAULT 1 +); +CREATE INDEX IF NOT EXISTS idx_level_strategy ON level(strategy_id, sort_order);`) + return err +} diff --git a/biz/dao/dao_life_task.go b/biz/dao/dao_life_task.go new file mode 100644 index 0000000..e5cc78a --- /dev/null +++ b/biz/dao/dao_life_task.go @@ -0,0 +1,29 @@ +package dao + +import ( + "context" + + "github.com/gogf/gf/v2/frame/g" + + "36wisdom/biz/consts" + "36wisdom/common" +) + +type lifeTaskDao struct{ common.BaseDao } + +var LifeTask = &lifeTaskDao{BaseDao: common.BaseDao{Table: consts.TableLifeTask}} + +func (d *lifeTaskDao) Init(ctx context.Context) error { + _, err := g.DB().Exec(ctx, ` +CREATE TABLE IF NOT EXISTS life_task ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + strategy_id INTEGER NOT NULL, + title TEXT NOT NULL, + description TEXT NOT NULL, + guide TEXT NOT NULL, + reward_points INTEGER NOT NULL DEFAULT 20, + status INTEGER NOT NULL DEFAULT 1 +); +CREATE INDEX IF NOT EXISTS idx_life_task_strategy ON life_task(strategy_id);`) + return err +} diff --git a/biz/dao/dao_life_task_log.go b/biz/dao/dao_life_task_log.go new file mode 100644 index 0000000..2069301 --- /dev/null +++ b/biz/dao/dao_life_task_log.go @@ -0,0 +1,29 @@ +package dao + +import ( + "context" + + "github.com/gogf/gf/v2/frame/g" + + "36wisdom/biz/consts" + "36wisdom/common" +) + +type lifeTaskLogDao struct{ common.BaseDao } + +var LifeTaskLog = &lifeTaskLogDao{BaseDao: common.BaseDao{Table: consts.TableLifeTaskLog}} + +func (d *lifeTaskLogDao) Init(ctx context.Context) error { + _, err := g.DB().Exec(ctx, ` +CREATE TABLE IF NOT EXISTS life_task_log ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + child_id INTEGER NOT NULL, + task_id INTEGER NOT NULL, + status INTEGER NOT NULL DEFAULT 1, + confirm_photo TEXT, + confirmed_at DATETIME, + created_at DATETIME, + UNIQUE(child_id, task_id) +);`) + return err +} diff --git a/biz/dao/dao_node_option.go b/biz/dao/dao_node_option.go new file mode 100644 index 0000000..7f6e157 --- /dev/null +++ b/biz/dao/dao_node_option.go @@ -0,0 +1,32 @@ +package dao + +import ( + "context" + + "github.com/gogf/gf/v2/frame/g" + + "36wisdom/biz/consts" + "36wisdom/common" +) + +type nodeOptionDao struct{ common.BaseDao } + +var NodeOption = &nodeOptionDao{BaseDao: common.BaseDao{Table: consts.TableNodeOption}} + +func (d *nodeOptionDao) Init(ctx context.Context) error { + _, err := g.DB().Exec(ctx, ` +CREATE TABLE IF NOT EXISTS node_option ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + node_id INTEGER NOT NULL, + text TEXT NOT NULL, + prop_id INTEGER, + audio TEXT, + next_node_id INTEGER, + feedback TEXT NOT NULL, + feedback_audio TEXT, + sort_order INTEGER NOT NULL DEFAULT 1, + status INTEGER NOT NULL DEFAULT 1 +); +CREATE INDEX IF NOT EXISTS idx_option_node ON node_option(node_id);`) + return err +} diff --git a/biz/dao/dao_parent.go b/biz/dao/dao_parent.go new file mode 100644 index 0000000..46a5e82 --- /dev/null +++ b/biz/dao/dao_parent.go @@ -0,0 +1,31 @@ +package dao + +import ( + "context" + + "github.com/gogf/gf/v2/frame/g" + + "36wisdom/biz/consts" + "36wisdom/common" +) + +type parentDao struct{ common.BaseDao } + +var Parent = &parentDao{BaseDao: common.BaseDao{Table: consts.TableParent}} + +func (d *parentDao) Init(ctx context.Context) error { + _, err := g.DB().Exec(ctx, ` +CREATE TABLE IF NOT EXISTS parent ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + openid TEXT UNIQUE, + phone TEXT UNIQUE, + password TEXT, + nickname TEXT, + avatar TEXT, + status INTEGER NOT NULL DEFAULT 1, + created_at DATETIME, + updated_at DATETIME +); +CREATE INDEX IF NOT EXISTS idx_parent_openid ON parent(openid);`) + return err +} diff --git a/biz/dao/dao_point_log.go b/biz/dao/dao_point_log.go new file mode 100644 index 0000000..db05e22 --- /dev/null +++ b/biz/dao/dao_point_log.go @@ -0,0 +1,29 @@ +package dao + +import ( + "context" + + "github.com/gogf/gf/v2/frame/g" + + "36wisdom/biz/consts" + "36wisdom/common" +) + +type pointLogDao struct{ common.BaseDao } + +var PointLog = &pointLogDao{BaseDao: common.BaseDao{Table: consts.TablePointLog}} + +func (d *pointLogDao) Init(ctx context.Context) error { + _, err := g.DB().Exec(ctx, ` +CREATE TABLE IF NOT EXISTS point_log ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + user_id INTEGER NOT NULL, + change INTEGER NOT NULL, + reason_type INTEGER NOT NULL, + ref_id INTEGER, + balance_after INTEGER NOT NULL, + created_at DATETIME +); +CREATE INDEX IF NOT EXISTS idx_point_log_user ON point_log(user_id, created_at);`) + return err +} diff --git a/biz/dao/dao_prize.go b/biz/dao/dao_prize.go new file mode 100644 index 0000000..5d308fb --- /dev/null +++ b/biz/dao/dao_prize.go @@ -0,0 +1,30 @@ +package dao + +import ( + "context" + + "github.com/gogf/gf/v2/frame/g" + + "36wisdom/biz/consts" + "36wisdom/common" +) + +type prizeDao struct{ common.BaseDao } + +var Prize = &prizeDao{BaseDao: common.BaseDao{Table: consts.TablePrize}} + +func (d *prizeDao) Init(ctx context.Context) error { + _, err := g.DB().Exec(ctx, ` +CREATE TABLE IF NOT EXISTS prize ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL, + description TEXT, + icon TEXT, + p_type INTEGER NOT NULL DEFAULT 1, + points_cost INTEGER NOT NULL, + stock INTEGER NOT NULL DEFAULT 0, + status INTEGER NOT NULL DEFAULT 1, + sort_order INTEGER NOT NULL DEFAULT 1 +);`) + return err +} diff --git a/biz/dao/dao_redemption.go b/biz/dao/dao_redemption.go new file mode 100644 index 0000000..897b4e2 --- /dev/null +++ b/biz/dao/dao_redemption.go @@ -0,0 +1,30 @@ +package dao + +import ( + "context" + + "github.com/gogf/gf/v2/frame/g" + + "36wisdom/biz/consts" + "36wisdom/common" +) + +type redemptionDao struct{ common.BaseDao } + +var Redemption = &redemptionDao{BaseDao: common.BaseDao{Table: consts.TableRedemption}} + +func (d *redemptionDao) Init(ctx context.Context) error { + _, err := g.DB().Exec(ctx, ` +CREATE TABLE IF NOT EXISTS redemption ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + user_id INTEGER NOT NULL, + prize_id INTEGER NOT NULL, + points_cost INTEGER NOT NULL, + status INTEGER NOT NULL DEFAULT 1, + code TEXT, + created_at DATETIME, + updated_at DATETIME +); +CREATE INDEX IF NOT EXISTS idx_redemption_user ON redemption(user_id, created_at);`) + return err +} diff --git a/biz/dao/dao_scene_node.go b/biz/dao/dao_scene_node.go new file mode 100644 index 0000000..495aafb --- /dev/null +++ b/biz/dao/dao_scene_node.go @@ -0,0 +1,36 @@ +package dao + +import ( + "context" + + "github.com/gogf/gf/v2/frame/g" + + "36wisdom/biz/consts" + "36wisdom/common" +) + +type sceneNodeDao struct{ common.BaseDao } + +var SceneNode = &sceneNodeDao{BaseDao: common.BaseDao{Table: consts.TableSceneNode}} + +func (d *sceneNodeDao) Init(ctx context.Context) error { + _, err := g.DB().Exec(ctx, ` +CREATE TABLE IF NOT EXISTS scene_node ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + level_id INTEGER NOT NULL, + title TEXT, + character_id INTEGER, + content TEXT NOT NULL, + image TEXT, + audio TEXT, + node_type INTEGER NOT NULL DEFAULT 1, + interaction_type INTEGER NOT NULL DEFAULT 1, + config TEXT, + result_type INTEGER NOT NULL DEFAULT 0, + is_entry INTEGER NOT NULL DEFAULT 0, + sort_order INTEGER NOT NULL DEFAULT 1, + status INTEGER NOT NULL DEFAULT 1 +); +CREATE INDEX IF NOT EXISTS idx_node_level ON scene_node(level_id);`) + return err +} diff --git a/biz/dao/dao_strategy.go b/biz/dao/dao_strategy.go new file mode 100644 index 0000000..91af543 --- /dev/null +++ b/biz/dao/dao_strategy.go @@ -0,0 +1,38 @@ +package dao + +import ( + "context" + + "github.com/gogf/gf/v2/frame/g" + + "36wisdom/biz/consts" + "36wisdom/common" +) + +type strategyDao struct{ common.BaseDao } + +var Strategy = &strategyDao{BaseDao: common.BaseDao{Table: consts.TableStrategy}} + +func (d *strategyDao) Init(ctx context.Context) error { + _, err := g.DB().Exec(ctx, ` +CREATE TABLE IF NOT EXISTS strategy ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL, + pinyin TEXT NOT NULL, + group_no INTEGER NOT NULL, + group_name TEXT NOT NULL, + meaning TEXT NOT NULL, + teach_content TEXT, + teach_image TEXT, + teach_audio TEXT, + summary_q TEXT, + summary_options TEXT, + summary_audio TEXT, + icon TEXT, + sort_order INTEGER NOT NULL, + unlock_before INTEGER, + status INTEGER NOT NULL DEFAULT 1 +); +CREATE INDEX IF NOT EXISTS idx_strategy_group ON strategy(group_no, sort_order);`) + return err +} diff --git a/biz/dao/dao_user_badge.go b/biz/dao/dao_user_badge.go new file mode 100644 index 0000000..e5b924b --- /dev/null +++ b/biz/dao/dao_user_badge.go @@ -0,0 +1,26 @@ +package dao + +import ( + "context" + + "github.com/gogf/gf/v2/frame/g" + + "36wisdom/biz/consts" + "36wisdom/common" +) + +type userBadgeDao struct{ common.BaseDao } + +var UserBadge = &userBadgeDao{BaseDao: common.BaseDao{Table: consts.TableUserBadge}} + +func (d *userBadgeDao) Init(ctx context.Context) error { + _, err := g.DB().Exec(ctx, ` +CREATE TABLE IF NOT EXISTS user_badge ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + user_id INTEGER NOT NULL, + badge_id INTEGER NOT NULL, + earned_at DATETIME, + UNIQUE(user_id, badge_id) +);`) + return err +} diff --git a/biz/dao/dao_user_collection.go b/biz/dao/dao_user_collection.go new file mode 100644 index 0000000..fc278ce --- /dev/null +++ b/biz/dao/dao_user_collection.go @@ -0,0 +1,26 @@ +package dao + +import ( + "context" + + "github.com/gogf/gf/v2/frame/g" + + "36wisdom/biz/consts" + "36wisdom/common" +) + +type userCollectionDao struct{ common.BaseDao } + +var UserCollection = &userCollectionDao{BaseDao: common.BaseDao{Table: consts.TableUserCollection}} + +func (d *userCollectionDao) Init(ctx context.Context) error { + _, err := g.DB().Exec(ctx, ` +CREATE TABLE IF NOT EXISTS user_collection ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + user_id INTEGER NOT NULL, + strategy_id INTEGER NOT NULL, + unlocked_at DATETIME, + UNIQUE(user_id, strategy_id) +);`) + return err +} diff --git a/biz/dao/dao_user_progress.go b/biz/dao/dao_user_progress.go new file mode 100644 index 0000000..a0474ba --- /dev/null +++ b/biz/dao/dao_user_progress.go @@ -0,0 +1,30 @@ +package dao + +import ( + "context" + + "github.com/gogf/gf/v2/frame/g" + + "36wisdom/biz/consts" + "36wisdom/common" +) + +type userProgressDao struct{ common.BaseDao } + +var UserProgress = &userProgressDao{BaseDao: common.BaseDao{Table: consts.TableUserProgress}} + +func (d *userProgressDao) Init(ctx context.Context) error { + _, err := g.DB().Exec(ctx, ` +CREATE TABLE IF NOT EXISTS user_progress ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + child_id INTEGER NOT NULL, + level_id INTEGER NOT NULL, + stars INTEGER NOT NULL DEFAULT 0, + score INTEGER NOT NULL DEFAULT 0, + perfect INTEGER NOT NULL DEFAULT 0, + content_version INTEGER NOT NULL DEFAULT 1, + completed_at DATETIME, + UNIQUE(child_id, level_id) +);`) + return err +} diff --git a/biz/dao/dao_user_route_log.go b/biz/dao/dao_user_route_log.go new file mode 100644 index 0000000..8863bc3 --- /dev/null +++ b/biz/dao/dao_user_route_log.go @@ -0,0 +1,29 @@ +package dao + +import ( + "context" + + "github.com/gogf/gf/v2/frame/g" + + "36wisdom/biz/consts" + "36wisdom/common" +) + +type userRouteLogDao struct{ common.BaseDao } + +var UserRouteLog = &userRouteLogDao{BaseDao: common.BaseDao{Table: consts.TableUserRouteLog}} + +func (d *userRouteLogDao) Init(ctx context.Context) error { + _, err := g.DB().Exec(ctx, ` +CREATE TABLE IF NOT EXISTS user_route_log ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + child_id INTEGER NOT NULL, + level_id INTEGER NOT NULL, + node_id INTEGER NOT NULL, + option_id INTEGER NOT NULL DEFAULT 0, + result_type INTEGER NOT NULL DEFAULT 0, + created_at DATETIME +); +CREATE INDEX IF NOT EXISTS idx_route_log_child ON user_route_log(child_id, level_id, created_at);`) + return err +} diff --git a/biz/dao/init.go b/biz/dao/init.go index c549403..b55193e 100644 --- a/biz/dao/init.go +++ b/biz/dao/init.go @@ -1,7 +1,40 @@ package dao -import "context" +import ( + "context" -// InitTables 创建全部业务表与索引;具体建表在 biz/dao 各文件 init 中按依赖序接入。 + "github.com/gogf/gf/v2/frame/g" +) + +type tableInitializer func(ctx context.Context) error + +var tableInitializers = []tableInitializer{ + Parent.Init, + Child.Init, + Strategy.Init, + Level.Init, + SceneNode.Init, + NodeOption.Init, + Element.Init, + UserProgress.Init, + ChapterReview.Init, + UserRouteLog.Init, + UserCollection.Init, + Badge.Init, + UserBadge.Init, + PointLog.Init, + Prize.Init, + Redemption.Init, + AdminUser.Init, + LifeTask.Init, + LifeTaskLog.Init, +} + +// InitTables 创建全部业务表与索引(IF NOT EXISTS 幂等)。 func InitTables(ctx context.Context) { + for _, init := range tableInitializers { + if err := init(ctx); err != nil { + g.Log().Fatal(ctx, err) + } + } } diff --git a/config.yml b/config.yml index bd97588..7923281 100644 --- a/config.yml +++ b/config.yml @@ -6,7 +6,7 @@ logger: level: "info" database: type: "sqlite" - link: "data/36wisdom.db" + link: "sqlite::@file(data/36wisdom.db)" cache: ttl: 300 maxSize: 10000