Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Orm Module - Migration not getting the config #305

Closed
MohammadBnei opened this issue Dec 22, 2024 · 2 comments
Closed

Orm Module - Migration not getting the config #305

MohammadBnei opened this issue Dec 22, 2024 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@MohammadBnei
Copy link

Hello,

I followed the guide in Yokai ORM, but the migration command is not getting the correct config.

This is the config.yml :

modules:
 // ... other modules
  orm:
    dsn: "${POSTGRES_USER}:${POSTGRES_PASSWORD}@tcp(${POSTGRES_HOST}:${POSTGRES_PORT})/${POSTGRES_DATABASE}?parseTime=True"
    driver: postgres                                               # driver to use
    config:
      dry_run: false                                            # disabled by default
      skip_default_transaction: false                           # disabled by default
      full_save_associations: false                             # disabled by default
      prepare_stmt: false                                       # disabled by default
      disable_automatic_ping: false                             # disabled by default
      disable_foreign_key_constraint_when_migrating: false      # disabled by default
      ignore_relationships_when_migrating: false                # disabled by default
      disable_nested_transaction: false                         # disabled by default
      allow_global_update: false                                # disabled by default
      query_fields: false                                       # disabled by default
      translate_error: false                                    # disabled by default
    log:
      enabled: true  # to log SQL queries, disabled by default
      level: info    # with a minimal level
      values: false   # by adding or not clear SQL queries parameters values in logs, disabled by default
    trace:
      enabled: true  # to trace SQL queries, disabled by default
      values: true   # by adding or not clear SQL queries parameters values in trace spans, disabled by default

And the logs when I run the migrate command :

1:56PM INF provided constructor=go.uber.org/fx.New.func1() service=grpc-app type=fx.Lifecycle
1:56PM INF provided constructor=go.uber.org/fx.(*App).shutdowner-fm() service=grpc-app type=fx.Shutdowner
1:56PM INF provided constructor=go.uber.org/fx.(*App).dotGraph-fm() service=grpc-app type=fx.DotGraph
1:56PM INF supplied service=grpc-app type=context.backgroundCtx
1:56PM INF provided constructor=github.com/ankorstore/yokai/fxcore.NewFxModuleInfoRegistry() service=grpc-app type=*fxcore.FxModuleInfoRegistry
1:56PM INF provided constructor=github.com/ankorstore/yokai/fxcore.NewFxCore() service=grpc-app type=*fxcore.Core
1:56PM INF provided constructor="fx.Annotate(github.com/ankorstore/yokai/fxcore.NewFxCoreModuleInfo(), fx.ResultTags([\"group:\\\"core-module-infos\\\"\"]), fx.As([[interface {}]])" service=grpc-app type="interface {}[group = \"core-module-infos\"]"
1:56PM INF provided constructor="fx.Annotate(github.com/ankorstore/yokai/generate/uuid.NewDefaultUuidGeneratorFactory(), fx.As([[uuid.UuidGeneratorFactory]])" service=grpc-app type=uuid.UuidGeneratorFactory
1:56PM INF provided constructor="fx.Annotate(github.com/ankorstore/yokai/generate/uuidv7.NewDefaultUuidV7GeneratorFactory(), fx.As([[uuidv7.UuidV7GeneratorFactory]])" service=grpc-app type=uuidv7.UuidV7GeneratorFactory
1:56PM INF provided constructor=github.com/ankorstore/yokai/fxgenerate.NewFxUuidGenerator() service=grpc-app type=uuid.UuidGenerator
1:56PM INF provided constructor=github.com/ankorstore/yokai/fxgenerate.NewFxUuidV7Generator() service=grpc-app type=uuidv7.UuidV7Generator
1:56PM INF provided constructor=github.com/ankorstore/yokai/config.NewDefaultConfigFactory() service=grpc-app type=config.ConfigFactory
1:56PM INF provided constructor=github.com/ankorstore/yokai/fxconfig.NewFxConfig() service=grpc-app type=*config.Config
1:56PM INF provided constructor=github.com/ankorstore/yokai/log.NewDefaultLoggerFactory() service=grpc-app type=log.LoggerFactory
1:56PM INF provided constructor=github.com/ankorstore/yokai/log/logtest.NewDefaultTestLogBuffer() service=grpc-app type=logtest.TestLogBuffer
1:56PM INF provided constructor=github.com/ankorstore/yokai/fxlog.NewFxLogger() service=grpc-app type=*log.Logger
1:56PM INF provided constructor=github.com/ankorstore/yokai/trace.NewDefaultTracerProviderFactory() service=grpc-app type=trace.TracerProviderFactory
1:56PM INF provided constructor=github.com/ankorstore/yokai/trace/tracetest.NewDefaultTestTraceExporter() service=grpc-app type=tracetest.TestTraceExporter
1:56PM INF provided constructor="fx.Annotate(github.com/ankorstore/yokai/fxtrace.NewFxTracerProvider(), fx.As([[trace.TracerProvider]])" service=grpc-app type=trace.TracerProvider
1:56PM INF provided constructor=github.com/ankorstore/yokai/fxmetrics.NewDefaultMetricsRegistryFactory() service=grpc-app type=fxmetrics.MetricsRegistryFactory
1:56PM INF provided constructor=github.com/ankorstore/yokai/fxmetrics.NewFxMetricsRegistry() service=grpc-app type=*prometheus.Registry
1:56PM INF provided constructor=github.com/ankorstore/yokai/healthcheck.NewDefaultCheckerFactory() service=grpc-app type=healthcheck.CheckerFactory
1:56PM INF provided constructor=github.com/ankorstore/yokai/fxhealthcheck.NewFxCheckerProbeRegistry() service=grpc-app type=*fxhealthcheck.CheckerProbeRegistry
1:56PM INF provided constructor=github.com/ankorstore/yokai/fxhealthcheck.NewFxChecker() service=grpc-app type=*healthcheck.Checker
1:56PM INF provided constructor=github.com/ankorstore/yokai/orm.NewDefaultOrmFactory() service=grpc-app type=orm.OrmFactory
1:56PM INF provided constructor=github.com/ankorstore/yokai/fxorm.NewFxOrm() service=grpc-app type=*gorm.DB
1:56PM INF initialized custom fxevent.Logger function=github.com/ankorstore/yokai/fxlog.NewFxEventLogger() service=grpc-app
1:56PM DBG registered metrics handler module=core service=grpc-app
1:56PM DBG registered healthcheck startup handler module=core service=grpc-app
1:56PM DBG registered healthcheck liveness handler module=core service=grpc-app
1:56PM DBG registered healthcheck readiness handler module=core service=grpc-app
1:56PM DBG registered debug config handler module=core service=grpc-app
1:56PM DBG registered debug pprof handlers module=core service=grpc-app
1:56PM DBG registered debug routes handler module=core service=grpc-app
1:56PM DBG registered debug stats handler module=core service=grpc-app
1:56PM DBG registered debug build handler module=core service=grpc-app
1:56PM DBG registered debug modules handler module=core service=grpc-app
1:56PM DBG registered dashboard theme handler module=core service=grpc-app
1:56PM DBG registered dashboard handler module=core service=grpc-app
1:56PM DBG starting core service=grpc-app
1:56PM INF invoked function=github.com/ankorstore/yokai/fxcore.init.func1() service=grpc-app
1:56PM ERR failed to initialize database, got error failed to connect to `host=/private/tmp user=mb database=`: dial error (dial unix /private/tmp/.s.PGSQL.5432: connect: no such file or directory) service=grpc-app
1:56PM ERR invoke failed error="could not build arguments for function \"github.com/mb/vos-personal-words/cmd\".init.func1.1 (/vos-personal-words/cmd/migrate.go:27): failed to build *gorm.DB: received non-nil error from function \"github.com/ankorstore/yokai/fxorm\".NewFxOrm (/go/pkg/mod/github.com/ankorstore/yokai/[email protected]/module.go:40): failed to connect to `host=/private/tmp user=mb database=`: dial error (dial unix /private/tmp/.s.PGSQL.5432: connect: no such file or directory)" function=github.com/mb/vos-personal-words/cmd.init.func1.1() service=grpc-app stack="github.com/mb/vos-personal-words/cmd.init.func1\n\t/vos-personal-words/cmd/migrate.go:27\ngithub.com/spf13/cobra.(*Command).execute\n\t/go/pkg/mod/github.com/spf13/[email protected]/command.go:989\ngithub.com/spf13/cobra.(*Command).ExecuteC\n\t/go/pkg/mod/github.com/spf13/[email protected]/command.go:1117\ngithub.com/spf13/cobra.(*Command).Execute\n\t/go/pkg/mod/github.com/spf13/[email protected]/command.go:1041\ngithub.com/mb/vos-personal-words/cmd.Execute\n\t/vos-personal-words/cmd/root.go:18\nmain.main\n\t/vos-personal-words/main.go:8\nruntime.main\n\t/opt/homebrew/Cellar/go/1.23.3/libexec/src/runtime/proc.go:272\n"
1:56PM ERR start failed error="could not build arguments for function \"github.com/mb/vos-personal-words/cmd\".init.func1.1 (/vos-personal-words/cmd/migrate.go:27): failed to build *gorm.DB: received non-nil error from function \"github.com/ankorstore/yokai/fxorm\".NewFxOrm (/go/pkg/mod/github.com/ankorstore/yokai/[email protected]/module.go:40): failed to connect to `host=/private/tmp user=mb database=`: dial error (dial unix /private/tmp/.s.PGSQL.5432: connect: no such file or directory)" service=grpc-app
exit status 1
2024/12/21 13:56:29 exit status 1
exit status 1
make: *** [migrate] Error 1
@ekkinox
Copy link
Contributor

ekkinox commented Dec 23, 2024

Hello,

The DSN you use here seems to be formatted like for MySQL.

Yokai's ORM being based on GORM, that uses pgx for postgres, I let you check how to configure a postgres connection from their docs: https://pkg.go.dev/github.com/jackc/pgx/v4/[email protected]#ParseConfig.

So you can try something like dsn: "user=${POSTGRES_USER} password=${POSTGRES_PASSWORD} host=${POSTGRES_HOST} port=${POSTGRES_PORT} dbname=${POSTGRES_DATABASE} sslmode=disable"

Or if you want to use the URL DSN style, maybe try adding postgres:// at the start.

Let me know if this solves your issue 👍

@ekkinox ekkinox self-assigned this Dec 23, 2024
@ekkinox ekkinox added the question Further information is requested label Dec 23, 2024
@MohammadBnei
Copy link
Author

It works now, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants