Connect to an existing MySQL database and use runtime sql?

We have an existing SQL database with our current user data, and we need to access that db to migrate existing users to nakama. What’s the recommended approach for this? We could keep our current application server up and use its REST api’s, but is there a way to directly make sql calls from lua modules to a non “nakama” database?

Hey @oscargoldman. There isn’t a way to create database connections from Lua. However, you can freely do whatever you’d like via Go.

Having said this, this seems like something that should be done as a one-off maintenance/devops task outside of Nakama.

Thanks Mo. Is there any documentation around adding custom Go code? Can you point the binary to Go modules outside of the compiled server app or does it need to be compiled from source if you add custom Go? Regarding one-off, we have a lot of user accounts who (sadly) are inactive, and we don’t really want to populate our db with users who haven’t used the app and are not likely to return. BUT, if they currently active or return within a reasonable time frame, we’d like to support that and migrate their data to the new nakama back end.

You can find information about getting started with the Go runtime in the same runtime basics docs as the Lua runtime. Using Go modules does not require compiling the whole server from source.

Depending how much existing data you would need to import it may be a good idea to do it regardless of inactivity. It would simplify your code and make data compliance that much easier. How many users would you be importing, and how much data does each have that would go into storage collections for example?

It’s tough to say. We don’t have a ton of active users and we will only support our legacy backend for the short term before decommissioning it, which will shut down any current users unless they update. Our current app has no forced updated mechanism unfortunately. Our data schema is not particularly efficient - which is one of the reasons we wanted to move to nakama. For example we have something like 3 millions score records for around 400 unique users, and we don’t really use that data at all - we’re only interested in the highest level achieved. I think we’ll try a go module and a stored sql procedure for pulling the data we need, and only worry about user migration for a set period of time before returning players will be considered new players.

3 million score records for 400 users seems excessive. If 400 users total is all you have then rather than connecting to the old database I would definitely recommend a migration where you move over the user accounts and only the most recent score for each one.