MCPcopy
hub / github.com/ory/hydra / Init

Method Init

driver/registry_sql.go:175–250  ·  view source on GitHub ↗
(
	ctx context.Context,
	skipNetworkInit bool,
	migrate bool,
	extraMigrations []fs.FS,
	goMigrations []popx.Migration,
)

Source from the content-addressed store, hash-verified

173}
174
175func (m *RegistrySQL) Init(
176 ctx context.Context,
177 skipNetworkInit bool,
178 migrate bool,
179 extraMigrations []fs.FS,
180 goMigrations []popx.Migration,
181) error {
182 if m.basePersister == nil {
183 if m.Config().CGroupsV1AutoMaxProcsEnabled() {
184 _, err := maxprocs.Set(maxprocs.Logger(m.Logger().Infof))
185 if err != nil {
186 return fmt.Errorf("could not set GOMAXPROCS: %w", err)
187 }
188 }
189
190 // new db connection
191 pool, idlePool, connMaxLifetime, connMaxIdleTime, cleanedDSN := sqlcon.ParseConnectionOptions(
192 m.l, m.Config().DSN(),
193 )
194
195 opts := &pop.ConnectionDetails{
196 URL: sqlcon.FinalizeDSN(m.l, cleanedDSN),
197 IdlePool: idlePool,
198 ConnMaxLifetime: connMaxLifetime,
199 ConnMaxIdleTime: connMaxIdleTime,
200 Pool: pool,
201 TracerProvider: m.Tracer(ctx).Provider(),
202 Unsafe: m.Config().DbIgnoreUnknownTableColumns(),
203 }
204
205 for _, f := range m.dbOptsModifier {
206 f(opts)
207 }
208
209 c, err := pop.NewConnection(opts)
210 if err != nil {
211 return errors.WithStack(err)
212 }
213 if err := resilience.Retry(m.l, 5*time.Second, 5*time.Minute, c.Open); err != nil {
214 return errors.WithStack(err)
215 }
216
217 m.basePersister = sql.NewBasePersister(c, m)
218 if err := m.initialPing(ctx, m.Logger(), m.basePersister); err != nil {
219 m.Logger().Print("Could not ping database: ", err)
220 return err
221 }
222
223 m.migrator = sql.NewMigrationManager(c, m, extraMigrations, goMigrations)
224
225 // if dsn is memory we have to run the migrations on every start
226 // use case - such as
227 // - just in memory
228 // - shared connection
229 // - shared but unique in the same process
230 // see: https://sqlite.org/inmemorydb.html
231 switch {
232 case dbal.IsMemorySQLite(m.Config().DSN()):

Callers 2

NewFunction · 0.45

Calls 15

ConfigMethod · 0.95
LoggerMethod · 0.95
TracerMethod · 0.95
InitNetworkMethod · 0.95
NewBasePersisterFunction · 0.92
NewMigrationManagerFunction · 0.92
DSNMethod · 0.80
ProviderMethod · 0.80
PrintMethod · 0.80
PrintlnMethod · 0.80