kra-new/internal/data
Yvan 63dbb4cfbc 优化结构 2026-08-20 21:46:52 +08:00
..
gormkit 优化结构 2026-08-20 21:46:52 +08:00
migration 优化结构 2026-08-20 21:46:52 +08:00
pagination 优化结构 2026-08-20 21:46:52 +08:00
payment 优化结构 2026-08-20 21:46:52 +08:00
system 优化结构 2026-08-20 21:46:52 +08:00
README.md 优化结构 2026-08-20 21:46:52 +08:00
config_helpers.go 优化结构 2026-08-20 21:46:52 +08:00
config_store.go 优化结构 2026-08-20 20:46:18 +08:00
config_watch.go 优化 2026-08-17 15:52:59 +08:00
data.go 优化结构 2026-08-20 21:46:52 +08:00
data_scope.go 优化 2026-08-18 15:04:07 +08:00
data_scope_audit.go 优化 2026-08-16 20:58:57 +08:00
data_scope_audit_test.go 优化 2026-08-18 15:04:07 +08:00
data_scope_record.go 优化结构 2026-08-20 20:46:18 +08:00
data_scope_test.go 优化 2026-08-18 15:04:07 +08:00
database.go 优化结构 2026-08-20 21:46:52 +08:00
gorm_logger_test.go 优化结构 2026-08-20 21:46:52 +08:00
initialization_backend.go 优化结构 2026-08-20 21:46:52 +08:00
initialization_backend_test.go 优化结构 2026-08-20 21:46:52 +08:00
integration_config.go 优化 2026-08-17 15:52:59 +08:00
integration_config_test.go 优化结构 2026-08-20 21:46:52 +08:00
migrations.go 优化结构 2026-08-20 21:46:52 +08:00
migrations_test.go 优化结构 2026-08-20 21:46:52 +08:00
mongo.go fix 2026-08-14 16:34:17 +08:00
runtime_clients.go 优化 2026-08-16 20:58:57 +08:00

README.md

Data Layer

internal/data is the persistence composition root. It owns the shared database/runtime container (Data), database clients, configuration storage, and the Wire ProviderSet. Business repositories live in submodules so a new feature can be found by its domain instead of by scanning one large package.

Modules

  • internal/data/system contains the built-in administration domain: users, authorities, APIs, permissions, menus, organization, dictionaries, parameters, tokens, security, audit/logging, media, announcements, tasks, versions, exports, bootstrap seeding, and system migrations.
  • internal/data/payment contains payment configuration and payment-order persistence. Provider SDK implementations are separate in internal/integration/payment.
  • internal/data/migration contains the version-table runner used by the root migration coordinator. It stays under data because it executes and records database schema steps.
  • internal/adminsurface contains the small menu/API metadata contract used when a business module contributes pages to the administration UI. It lives outside data because the contract itself is not persistence code.

The root package intentionally keeps only cross-cutting infrastructure: database lifecycle/reloads, runtime configuration persistence, data-scope auditing, integration configuration storage, and migration orchestration. Repositories depend on narrow module seams (system.Provider and payment.Provider) rather than importing the root implementation details.

First-install and configuration-management orchestration lives in internal/initialize. It implements biz.InitializationRepo through a narrow backend interface that *data.Data satisfies. This keeps administrator/menu/API seeding out of the database lifecycle package while retaining one migration entry point.

Non-database adapters remain under internal/integration (storage, email, payment SDKs, and cache). Their constructors are provided by internal/integration.ProviderSet, separate from the data provider set. GORM and pagination helpers live beside the data layer; stateless payment parsing lives in internal/utils/paymentutil; admin JWT handling lives in internal/security/adminauth.

Migration and bootstrap

There is one migration execution entry point: migrateAll in the root data package. The root owns the shared integration-configuration table and appends the steps returned by system.Migrations() and payment.Migrations().

Migrations create schemas and module-required fixed records only. Initial business data is separate: initialize.Repo invokes system.SeedSystem only from the explicit first-install flow to create the administrator, roles, menus, APIs, departments, policies, and module-provided administration surfaces.