How to "upgrade" from Gitea to Forgejo (not for the faint of heart!)
from witten@lemmy.world to selfhosted@lemmy.world on 16 Mar 18:06
https://lemmy.world/post/44345452

Here’s the background: I’d been using Gitea for open source project hosting for a quite a while. So when the Forgejo fork started up, I thought to myself: Eh, I’ll see how that all unfolds and maybe look into it at some point. After all, Forgejo is a soft fork, so I can just switch over whenever.

But then Forgejo became a hard fork while I was busy with other stuff, and before I knew it, It seemed too late to switch unless I wanted to lose all my tickets and stuff.

Then I saw this post and read this background and decided it was time for me to switch to Forgejo, hard fork be damned.

But I’m very stubborn, and I still wanted to keep all of my Gitea data intact. So here’s what I did, and what you could do too if you’re as stubborn and reckless as I am!

Step one: Create a SQL “migration” that downgrades the Gitea database from the modern version you’re using to the last version that Forgejo supports upgrading, Gitea 1.22.6, from back when Forgejo was still a soft-ish fork. That means you’re effectively rolling back each migration from Gitea 1.25 all the way through 1.24 and 1.23.

When I did this, I used an LLM (specifically MiniMax with OpenCode) to generate the reverse mega-migration, pointing it at the Gitea codebase and also feeding it this very outdated starting point as inspiration. But I totally understand if not everyone is comfortable with using AI for this. In fact, I really wasn’t either, but I figured this is a mostly mechanical one-off. If you don’t want to use AI, you can generate the reverse migration manually by combing through the migrations linked above.

I did find three mistakes the LLM made: 1. An off-by-one error in UPDATE version … because the value should be the last migration number (298 in this case) plus one, 2. Some of the steps it generated to back out an individual migration were out of order, e.g. dropping the issue_pin table before copying data out of it, and 3. It apparently missed making one particular column (type in the review table) into an int instead of a varchar.

I should also note that there were some forward data migrations in the original Gitea migrations that could not be backed out, because the data simply wasn’t there anymore. I just skipped reversing those, because YOLO.

Once I fixed these issues as best I could (well, the ones I found ahead of time instead of after the fact), the mega-migration was ready to go.

(I’m not including the mega-migration here, because even if it worked for me, I don’t want to be responsible for people fucking up their systems if it doesn’t work for them. I’d much rather people be responsible for fucking up their own systems.)

Step two: Backup your Gitea database and files!!!

Step three: Stop Gitea and run the mega-rollback-migration against your Gitea database. This effectively downgrades the database to Gitea 1.22.6. You can optionally then deploy the Gitea 1.22.6 binary or container and start it up to poke around the Gitea web UI and verify that the downgrade worked. (Reminder that there are known security issues in this ancient version of Gitea, so maybe firewall off general web traffic temporarily?) Then stop Gitea again.

Step four: Replace the Gitea binary or container with the last release of Forgejo to support upgrades from Gitea, Forgejo 10.0.3. Start Forgejo and try out the web UI to make sure it’s working.

Step five: Upgrade your Forgejo binary or container to the latest release of Forgejo, 14.0.3 at the time of this writing. Restart Forgejo and hopefully enjoy your newly “upgraded” instance, complete with all of your repos and ticket history!

Some additional notes:

#selfhosted

threaded - newest

LodeMike@lemmy.today on 16 Mar 18:51 next collapse

Literally

  1. Back up instance config and data
  2. Swap out ELF for same or newer Forgejo version

Edit: this seems to have changed recently :/

witten@lemmy.world on 16 Mar 19:05 collapse

Forgejo past 10.0.x is not compatible with Gitea’s database schema. Have you tried it?

LodeMike@lemmy.today on 16 Mar 19:06 collapse

No

witten@lemmy.world on 16 Mar 19:12 collapse

I haven’t either. 😄 But I’m just taking Forgejo’s docs on this at their word.

devtoolkit_api@discuss.tchncs.de on 16 Mar 19:39 next collapse

Thanks for writing this up. I went through the same migration last year and can confirm — it is not as smooth as “just swap the binary” anymore since the hard fork.

A few extra tips that saved me headaches:

  • Backup everything first — obvious but worth emphasizing. Dump the database AND copy the entire data directory. pg_dump if you are on Postgres, or just copy the SQLite file.
  • Check your Gitea version first — Forgejo migration paths assume specific Gitea versions. If you are on an old Gitea, you might need to step through intermediate Gitea versions before jumping to Forgejo.
  • Webhooks and integrations — These survived the migration for me, but the API tokens did not. Had to regenerate them all.
  • Runner compatibility — If you use Gitea Actions/runners, make sure to switch to Forgejo’s runner binary too. They have diverged enough that mixing them causes subtle issues.

Overall though, Forgejo has been great post-migration. More responsive to community issues and the federation work they are doing is exciting.

eleijeep@piefed.social on 16 Mar 19:50 next collapse

Using an LLM to do a database migration is like asking your neighbour’s kid to file your taxes.

witten@lemmy.world on 16 Mar 21:00 collapse

Lol that’s a good idea… I hate doing taxes!

moonpiedumplings@programming.dev on 16 Mar 20:01 next collapse

Yes. But this is a lot. It may be easier to use Forgejo’s built in migration tools, to copy over repositories along with their issues and other info. You would have to rebuild the admin parts of the site, like “organizations” and user privileges. (Well if you are using oauth and mapping users from oautb groups then you don’t…). And I don’t know if it’s automated for a many, many repos. But it’s just a click click click in the gui.

I remember there was a tool, I think it was related to forgefed, that could do batch repo migrations via the cli. I can’t find it anymore though.

witten@lemmy.world on 16 Mar 21:02 collapse

That would be ideal if it worked, yeah. But personally I wouldn’t want to manually recreate the bits that it didn’t support migrating. I realize everyone’s instance and situation is different.

mbirth@lemmy.ml on 16 Mar 21:09 collapse

I’m staying with Gitea. They’ve created the Ltd. so they can sell professional support as most businesses will want a proper invoice. I don’t see anything wrong with that. Also, ForgeJo was promising federation which is still a WIP several years later. And, the one time I’ve tried ForgeJo it shit itself when I’ve added an emoji to my username. For some reason Gitea didn’t have any problem with that.