Skip to content

yaegi plugins cannot implement migrations: xorm and xormigrate are not exposed in the symbol table #3501

Description

@npmanos

Pre-submission checklist

  • I have searched for existing open or closed issue reports with the same problem.

Description

The plugin docs (Database Migrations → "Optional Capabilities") tell plugins to implement migrations like this:

import (
	"src.techknowlogick.com/xormigrate"
	"xorm.io/xorm"
)

func (p *MyPlugin) Migrations() []*xormigrate.Migration {
	return []*xormigrate.Migration{{
		ID: "20240101000000-create-plugin-table",
		Migrate: func(tx *xorm.Engine) error { return tx.Sync2(new(PluginData)) },
	}}
}

This doesn't work under the yaegi loader. Neither xorm nor xormigrate is registered in the symbol table (pkg/yaegi_symbols/), which exposes only db, events, log, models, plugins, user, echo/v5, watermill/message. A plugin importing either fails to load at the import itself (verified against vikunja/vikunja:2.5, yaegi loader):

package main

import (
	"code.vikunja.io/api/pkg/log"
	"code.vikunja.io/api/pkg/plugins"

	"src.techknowlogick.com/xormigrate"
	"xorm.io/xorm"
)

type P struct{}

func (p *P) Name() string        { return "repro-migration" }
func (p *P) Version() string     { return "0.0.1" }
func (p *P) Init() error          { return nil }
func (p *P) Shutdown() error     { return nil }
func (p *P) Migrations() []*xormigrate.Migration {
	return []*xormigrate.Migration{{
		ID: "20260101000000-repro",
		Migrate: func(tx *xorm.Engine) error { return tx.Sync2(new(struct{ ID int64 `xorm:"pk autoincr"` })) },
	}}
}

func NewPlugin() plugins.Plugin                  { return &P{} }
func NewMigrationPlugin() plugins.MigrationPlugin { return &P{} }
level=ERROR msg="Failed to load yaegi plugin custom-fields: evaluating main.go: 7:2: import \"src.techknowlogick.com/xormigrate\" error: unable to find source related to: \"src.techknowlogick.com/xormigrate\". Either the GOPATH environment variable, or the Interpreter.Options.GoPath needs to be set"

The loader stops at the first unresolvable import (xormigrate here; xorm would fail identically). A minimal plugin using only the registered packages loads cleanly against the same instance.

The runtime wiring for plugin migrations exists and runs (MigrationPlugin, NewMigrationPlugin(), pkg/plugins/manager.gomigration.AddPluginMigrationsMigrate), but it's unreachable under yaegi because a plugin can't import the package that defines *xormigrate.Migration.

Vikunja Version

2.5.0

Browser and version

No response

Can you reproduce the bug on the Vikunja demo site?

No

Screenshots

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-processedFix agent has picked this uparea/internal-codeInternal refactoring, cleanup, code-quality workarea/migrationsDatabase schema migrations (NOT data import)

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions