diff --git a/internal/driver/registry_default.go b/internal/driver/registry_default.go index 5576e3ab0..2f31a18cd 100644 --- a/internal/driver/registry_default.go +++ b/internal/driver/registry_default.go @@ -5,6 +5,7 @@ package driver import ( "context" + "io/fs" "net/http" "sync" @@ -50,18 +51,19 @@ var ( type ( RegistryDefault struct { - p persistence.Persister - traverser relationtuple.Traverser - mb *popx.MigrationBox - l *logrusx.Logger - w herodot.Writer - ce *check.Engine - ee *expand.Engine - c *config.Config - conn *pop.Connection - ctxer ketoctx.Contextualizer - mapper *relationtuple.Mapper - readOnlyMapper *relationtuple.Mapper + p persistence.Persister + traverser relationtuple.Traverser + mb *popx.MigrationBox + extraMigrations []fs.FS + l *logrusx.Logger + w herodot.Writer + ce *check.Engine + ee *expand.Engine + c *config.Config + conn *pop.Connection + ctxer ketoctx.Contextualizer + mapper *relationtuple.Mapper + readOnlyMapper *relationtuple.Mapper initialized sync.Once healthH *healthx.Handler @@ -251,7 +253,7 @@ func (r *RegistryDefault) MigrationBox(ctx context.Context) (*popx.MigrationBox, } mb, err := popx.NewMigrationBox( - fsx.Merge(sql.Migrations, networkx.Migrations), + fsx.Merge(append([]fs.FS{sql.Migrations, networkx.Migrations}, r.extraMigrations...)...), popx.NewMigrator(c, r.Logger(), r.Tracer(ctx), 0), append( []popx.MigrationBoxOption{popx.WithGoMigrations(uuidmapping.Migrations(namespaces))}, diff --git a/internal/driver/registry_factory.go b/internal/driver/registry_factory.go index ebf947932..536967b06 100644 --- a/internal/driver/registry_factory.go +++ b/internal/driver/registry_factory.go @@ -83,6 +83,7 @@ func NewDefaultRegistry(ctx context.Context, flags *pflag.FlagSet, withoutNetwor defaultUnaryInterceptors: options.GRPCUnaryInterceptors(), defaultStreamInterceptors: options.GRPCStreamInterceptors(), defaultHttpMiddlewares: options.HTTPMiddlewares(), + extraMigrations: options.ExtraMigrations(), defaultMigrationOptions: options.MigrationOptions(), healthReadyCheckers: options.ReadyCheckers(), } diff --git a/ketoctx/options.go b/ketoctx/options.go index 1e0d7c4e9..27aeb2ecc 100644 --- a/ketoctx/options.go +++ b/ketoctx/options.go @@ -4,6 +4,7 @@ package ketoctx import ( + "io/fs" "net/http" "github.com/ory/x/healthx" @@ -23,6 +24,7 @@ type ( grpcStreamInterceptors []grpc.StreamServerInterceptor migrationOpts []popx.MigrationBoxOption readyCheckers healthx.ReadyCheckers + extraMigrations []fs.FS } Option func(o *opts) TracerWrapper func(*otelx.Tracer) *otelx.Tracer @@ -68,6 +70,13 @@ func WithGRPCStreamInterceptors(i ...grpc.StreamServerInterceptor) Option { } } +// WithExtraMigrations adds additional database migrations. +func WithExtraMigrations(o ...fs.FS) Option { + return func(opts *opts) { + opts.extraMigrations = append(opts.extraMigrations, o...) + } +} + // WithMigrationOptions adds migration options to the list of migration options. func WithMigrationOptions(o ...popx.MigrationBoxOption) Option { return func(opts *opts) { @@ -107,6 +116,10 @@ func (o *opts) GRPCStreamInterceptors() []grpc.StreamServerInterceptor { return o.grpcStreamInterceptors } +func (o *opts) ExtraMigrations() []fs.FS { + return o.extraMigrations +} + func (o *opts) MigrationOptions() []popx.MigrationBoxOption { return o.migrationOpts }