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)
| 29 | // InitializeDBClient runs migration and returns a new ent.Client with additional configurations |
| 30 | // for hooks and interceptors. |
| 31 | func 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. |
| 48 | func NewRawEntClient(l logging.Logger, config conf.ConfigProvider) (*ent.Client, error) { |
no test coverage detected