legacy

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package legacy imports a lejianwen/rustdesk-api v2.7 SQLite database (`rustdeskapi.db`) into the RD Panel schema.

The source file is opened read-only and immutable; the whole import runs in one transaction on the target database and follows the mapping of docs/research/legacy-model-and-migration.md §7.4 (operator guide: docs/migration.md). Every run produces a Report with per-table counts (read = imported + deduped + orphaned + skipped) and warnings.

Index

Constants

View Source
const DefaultTagColor int64 = 0xFF9E9E9E

DefaultTagColor is the ARGB colour given to tags that exist only inside address_books.tags (no legacy `tags` row): 0xFF9E9E9E, Material grey 500.

View Source
const ExpectedVersion = 265

ExpectedVersion is the legacy `versions.version` this importer was written for (rustdesk-api v2.7, DatabaseVersion = 265).

View Source
const SourceName = "lejianwen/rustdesk-api"

SourceName is recorded in migration_runs.source.

Variables

View Source
var (
	// ErrTargetNotEmpty: the target already has users or a completed import (use Force).
	ErrTargetNotEmpty = errors.New("legacy: target database is not empty")
	// ErrVersion: the legacy schema version is not the expected one (use AllowVersion).
	ErrVersion = errors.New("legacy: unexpected legacy schema version")
	// ErrBlocking: the report contains errors that make the import unsafe;
	// nothing was committed. See Report.Errors.
	ErrBlocking = errors.New("legacy: import blocked by errors (see report)")
)

Errors returned by Run.

View Source
var ErrUnsupportedTarget = errors.New("migrate-legacy: importing into PostgreSQL is not supported; the target must be a SQLite panel database")

ErrUnsupportedTarget is returned when the target panel database is not SQLite: the importer relies on SQLite specifics (explicit ids with sqlite_sequence bookkeeping), so importing into PostgreSQL is not supported.

Functions

func OpenSource

func OpenSource(path string) (*sql.DB, error)

OpenSource opens a legacy database read-only and immutable. It refuses a database with a non-empty write-ahead log, because immutable mode would silently ignore the un-checkpointed transactions in it.

func ParseLocation

func ParseLocation(s string) (*time.Location, error)

ParseLocation resolves a --legacy-tz value: an IANA zone name ("Asia/Shanghai"), "UTC"/"Local", or a fixed offset ("+08:00", "-0530").

Types

type Counts

type Counts struct {
	Target   string `json:"target"`
	Read     int    `json:"read"`
	Imported int    `json:"imported"`
	// Deduped rows were merged into another row with the same natural key.
	Deduped int `json:"deduped"`
	// Orphaned rows referenced a missing (or not imported) parent and were dropped.
	Orphaned int `json:"orphaned"`
	// Skipped rows were dropped deliberately (expired, invalid, disabled owner, ...).
	Skipped int `json:"skipped"`
	// Extra holds table-specific numbers (e.g. derived rows created).
	Extra map[string]int `json:"extra,omitempty"`
}

Counts are per-legacy-table statistics. Read = Imported + Deduped + Orphaned + Skipped.

type Issue

type Issue struct {
	Code     string `json:"code"`
	Table    string `json:"table,omitempty"`
	LegacyID string `json:"legacy_id,omitempty"`
	Message  string `json:"message"`
}

Issue is a warning or error attached to a legacy row (or the whole import).

type Options

type Options struct {
	// SourcePath is the legacy rustdeskapi.db file.
	SourcePath string
	// DryRun performs the full import and rolls it back.
	DryRun bool
	// Force imports even if the target already has users or a completed import.
	Force bool
	// AllowVersion, when non-nil, accepts this legacy schema version instead of 265.
	AllowVersion *int
	// LegacyLocation interprets legacy timestamps that carry no UTC offset
	// (default UTC). Values written by rustdesk-api always carry one.
	LegacyLocation *time.Location
	// AEAD encrypts secrets (address-book passwords/hashes, OAuth client
	// secrets, share-link passwords). Required.
	AEAD *crypto.AEAD
	// Now overrides the clock (tests). Default time.Now.
	Now func() time.Time
	// Log receives progress messages (optional).
	Log *slog.Logger
}

Options configure Run.

type Report

type Report struct {
	Source         string             `json:"source"`
	SourcePath     string             `json:"source_path"`
	SourceVersion  int                `json:"source_version"`
	DryRun         bool               `json:"dry_run"`
	Force          bool               `json:"force"`
	Status         string             `json:"status"` // succeeded | failed | dry_run
	StartedAt      time.Time          `json:"started_at"`
	FinishedAt     time.Time          `json:"finished_at"`
	MigrationRunID int64              `json:"migration_run_id,omitempty"`
	Tables         map[string]*Counts `json:"tables"`
	Warnings       []Issue            `json:"warnings"`
	Errors         []Issue            `json:"errors"`
}

Report summarises one run. It never contains secrets.

func Run

func Run(ctx context.Context, target *db.DB, opts Options) (*Report, error)

Run imports the legacy database at opts.SourcePath into target (already migrated). The returned report is non-nil whenever the source could be opened, also on error. Nothing is committed on error or in dry-run mode.

func (*Report) JSON

func (r *Report) JSON() []byte

JSON renders the report (indented).

func (*Report) Summary

func (r *Report) Summary() string

Summary renders a short human-readable table.

Jump to

Keyboard shortcuts

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