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 ¶
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.