migrate

package
v3.49.1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Overview

Package migrate is the one-off import of glabs-web's data from MongoDB into PostgreSQL. It exists for a single evening and is deleted with the MongoDB store afterwards.

It is a subcommand of glabs-web rather than a separate module or binary, for one practical reason: the production host has Docker and nothing else. No Go toolchain, no psql, no mongosh outside the containers. The image that is already on the host is therefore the only thing that can be run there, and `docker compose run --rm glabs-web mongo2pg` needs no new machinery at all. (plexams solved the same problem differently -- its tool reads dump files from a laptop -- because its backup format is a directory of .bson files, while glabs' is a single mongodump archive.)

Reads go through the raw driver rather than through db.DB, because the store's API is owner-scoped by design: there is deliberately no method that reads every user's courses. Decoding uses the same DTOs the application uses, so a document lands in exactly the struct the server would have read, and writes go through the same typed db.PG methods the server writes with. That is the whole reason this is a Go program and not a pile of hand-written INSERTs.

Index

Constants

View Source
const (
	EnvMongoURI = "GLABS_MONGO_URI"
	EnvPGURI    = "GLABS_PG_URI"
)

EnvMongoURI and EnvPGURI are where the two connection strings come from.

Environment variables rather than flags, and the same rule the backup scripts follow: `ps` shows every argv on this host to every user, and both of these carry a database root password.

EnvPGURI exists because of the ORDER of the cut-over: the import runs while .glabs-web.yaml still points at MongoDB, because the config is only swapped once the data is across and verified. Without a way to name the target separately, the tool would have to be run after the swap -- leaving a window in which the config says PostgreSQL and PostgreSQL is empty. It falls back to db.uri, which is what makes --verify-only convenient after the swap.

Variables

This section is empty.

Functions

func Run

func Run(args []string, loadConfig func() error, out io.Writer) error

Run is the `glabs-web mongo2pg` subcommand. args are the arguments after the subcommand name.

The PostgreSQL URI and the secrets key come from the config file that is already mounted into the container, so the only thing to pass in is the MongoDB URI.

Types

type Options

type Options struct {
	DryRun     bool
	VerifyOnly bool
	Reset      bool
}

Options is what the operator asked for.

Jump to

Keyboard shortcuts

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