MCPcopy Index your code
hub / github.com/cloudreve/cloudreve / InitializeDBClient

Function InitializeDBClient

inventory/client.go:31–45  ·  view source on GitHub ↗

InitializeDBClient runs migration and returns a new ent.Client with additional configurations for hooks and interceptors.

(l logging.Logger,
	client *ent.Client, kv cache.Driver, requiredDbVersion string)

Source from the content-addressed store, hash-verified

29// InitializeDBClient runs migration and returns a new ent.Client with additional configurations
30// for hooks and interceptors.
31func InitializeDBClient(l logging.Logger,
32 client *ent.Client, kv cache.Driver, requiredDbVersion string) (*ent.Client, error) {
33 ctx := context.WithValue(context.Background(), logging.LoggerCtx{}, l)
34 if needMigration(client, ctx, requiredDbVersion) {
35 // Run the auto migration tool.
36 if err := migrate(l, client, ctx, kv, requiredDbVersion); err != nil {
37 return nil, fmt.Errorf("failed to migrate database: %w", err)
38 }
39 } else {
40 l.Info("Database schema is up to date.")
41 }
42
43 //createMockData(client, ctx)
44 return client, nil
45}
46
47// NewRawEntClient returns a new ent.Client without additional configurations.
48func NewRawEntClient(l logging.Logger, config conf.ConfigProvider) (*ent.Client, error) {

Callers 1

DBClientMethod · 0.92

Calls 3

needMigrationFunction · 0.85
migrateFunction · 0.85
InfoMethod · 0.65

Tested by

no test coverage detected