migration

package
v0.68.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2026 License: BSD-3-Clause, AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package migration provides utility functions for migrating from the external IdP solution in pre v0.62.0 to the new embedded IdP manager (Dex based), which is the default in v0.62.0 and later. It includes functions to seed connectors and migrate existing users to use these connectors.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSeedInfo = errors.New("no seed info found in environment")
View Source
var RequiredEventSchema = []SchemaCheck{
	{Table: "events", Columns: []string{"initiator_id", "target_id"}},
	{Table: "deleted_users", Columns: []string{"id"}},
}

RequiredEventSchema lists all tables and columns that the migration tool needs in the activity/event store.

View Source
var RequiredSchema = []SchemaCheck{
	{Table: "users", Columns: []string{"id", "email", "name", "account_id"}},
	{Table: "personal_access_tokens", Columns: []string{"user_id", "created_by"}},
	{Table: "peers", Columns: []string{"user_id"}},
	{Table: "accounts", Columns: []string{"created_by"}},
	{Table: "user_invites", Columns: []string{"created_by"}},
	{Table: "proxy_access_tokens", Columns: []string{"created_by"}},
	{Table: "jobs", Columns: []string{"triggered_by"}},
}

RequiredSchema lists all tables and columns that the migration tool needs. If any are missing, the user must upgrade their management server first so that the automatic GORM migrations create them.

Functions

func MigrateUsersToStaticConnectors

func MigrateUsersToStaticConnectors(s Server, conn *dex.Connector) error

MigrateUsersToStaticConnectors re-keys every user ID in the main store (and the activity store, if present) so that it encodes the given connector ID, skipping users that have already been migrated. Set NB_IDP_MIGRATION_DRY_RUN=true to log what would happen without writing any changes.

func PopulateUserInfo

func PopulateUserInfo(s Server, idpManager idp.Manager, dryRun bool) error

PopulateUserInfo fetches user email and name from the external IDP and updates the store for users that are missing this information.

func SeedConnectorFromEnv

func SeedConnectorFromEnv() (*dex.Connector, error)

SeedConnectorFromEnv reads the IDP_SEED_INFO env var, base64-decodes it, and JSON-unmarshals it into a dex.Connector. Returns nil if not set.

Types

type EventStore

type EventStore interface {
	// CheckSchema verifies that all tables and columns required by the migration
	// exist in the event database. Returns a list of problems; an empty slice means OK.
	CheckSchema(checks []SchemaCheck) []SchemaError

	// UpdateUserID updates all event references (initiator_id, target_id) and
	// deleted_users records to use the new user ID format.
	UpdateUserID(ctx context.Context, oldUserID, newUserID string) error
}

EventStore defines the activity event store operations required for migration. Like Store, this is a temporary interface for migration tooling only.

type SchemaCheck

type SchemaCheck struct {
	Table   string
	Columns []string
}

SchemaCheck represents a table and the columns required on it.

type SchemaError

type SchemaError struct {
	Table  string
	Column string // empty when the whole table is missing
}

SchemaError describes a single missing table or column.

func (SchemaError) String

func (e SchemaError) String() string

type Server

type Server interface {
	Store() Store
	EventStore() EventStore // may return nil
}

Server is the dependency interface that migration functions use to access the main data store and the activity event store.

type Store

type Store interface {
	// ListUsers returns all users across all accounts.
	ListUsers(ctx context.Context) ([]*types.User, error)

	// UpdateUserID atomically updates a user's ID and all foreign key references
	// across the database (peers, groups, policies, PATs, etc.).
	UpdateUserID(ctx context.Context, accountID, oldUserID, newUserID string) error

	// UpdateUserInfo updates a user's email and name in the store.
	UpdateUserInfo(ctx context.Context, userID, email, name string) error

	// CheckSchema verifies that all tables and columns required by the migration
	// exist in the database. Returns a list of problems; an empty slice means OK.
	CheckSchema(checks []SchemaCheck) []SchemaError
}

Store defines the data store operations required for IdP user migration. This interface is separate from the main store.Store interface because these methods are only used during one-time migration and should be removed once migration tooling is no longer needed.

The SQL store implementations (SqlStore) already have these methods on their concrete types, so they satisfy this interface via Go's structural typing with zero code changes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL