优化结构

This commit is contained in:
Yvan
2026-08-21 09:07:33 +08:00
parent 77e192b6c0
commit 80e62acf7d
6 changed files with 57 additions and 1 deletions
+12
View File
@@ -0,0 +1,12 @@
# Data Layer
`data` owns database clients, persistence models, migrations, configuration
watching, and repository implementations.
- `repository/`: system repositories and table persistence
- `payment/`: payment configuration and payment-order persistence
- root files: shared database lifecycle, runtime clients, integration-config
storage, data-scope auditing, and migration orchestration
Root files intentionally stay in one package because they share `Data` state and
reload locks. Do not split them into packages only to reduce file count.
@@ -85,6 +85,12 @@ func (r *taskRepo) FindTask(ctx context.Context, id uint) (*biz.TimedTask, error
return taskFromPO(po), nil
}
func (r *taskRepo) ListTasks(ctx context.Context, page, size int, q *biz.TimedTask) ([]*biz.TimedTask, int64, error) {
// During first-install the data layer intentionally serves a bootstrap
// database without system tables. The scheduler starts before /init/initdb
// and should remain idle instead of logging a missing-table SQL error.
if !r.data.DatabaseReady() {
return []*biz.TimedTask{}, 0, nil
}
db := r.data.DB().WithContext(ctx).Model(&taskPO{})
if q != nil {
if q.Name != "" {
@@ -0,0 +1,17 @@
package system
import (
"context"
"testing"
)
func TestTaskRepoListIsEmptyBeforeDatabaseInitialization(t *testing.T) {
repo := NewTaskRepo(&Data{})
items, total, err := repo.ListTasks(context.Background(), 0, 0, nil)
if err != nil {
t.Fatal(err)
}
if total != 0 || len(items) != 0 {
t.Fatalf("bootstrap tasks = (%d, %d), want empty", total, len(items))
}
}