I use GORM to work with PostgreSQL.
For example I have a such struct with custom enum type:
type MonitoringDatabase struct {
Name string `gorm:"primaryKey"`
DBType DbType `gorm:"type:db_type"`
}
I create Enum using Exec in the scheme i need:
type DbType string
const (
PostgreSQL DbType = "PostgreSQL"
Oracle DbType = "Oracle"
Ignite DbType = "Ignite"
)
_, errDbEnum := sqlDB.Exec(fmt.Sprintf("CREATE TYPE %s.db_type AS ENUM ('%s','%s','%s')", PgSchema, PostgreSQL, Oracle, Ignite))
But when migrating the table, I get an error (type “db_type” does not exist (SQLSTATE 42704)) because GORM is looking for enum in the public schema.
I’ve tried to set search_path and configure NamingStrategy, but it doesn’t helps.
Are there any solutions on how to defeat this problem?