# Custom DB migration

**URL:** <https://forum.heroiclabs.com/t/custom-db-migration/2223>\
**Category:** Runtime Framework\
**Created:** [December 31, 2021, 11:03am UTC](https://forum.heroiclabs.com/t/custom-db-migration/2223 "2021-12-31T11:03:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tunglt1810](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/tunglt1810/32/924_2.png) [@tunglt1810](https://forum.heroiclabs.com/u/tunglt1810)\
**Post date:** [December 31, 2021, 11:03am UTC](https://forum.heroiclabs.com/t/custom-db-migration/2223/1 "2021-12-31T11:03:04Z")

</div>

Hi guys,

I create my own custom DB and want to use [golang-migrate/migrate: Database migrations. CLI and Golang library. (github.com)](https://github.com/golang-migrate/migrate) to setup migration script.

So now, I want to get the DB address from server config. How can i do that?

 ![image](https://us1.discourse-cdn.com/flex020/uploads/heroiclabs/original/1X/3c735bcb9e3063d9f58e50390fad7d38206ec31e.png)

---

<div class="post-metadata">

**Author:** ![zyro](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/zyro/32/14_2.png) [@zyro](https://forum.heroiclabs.com/u/zyro)\
**Post date:** [December 31, 2021, 6:07pm UTC](https://forum.heroiclabs.com/t/custom-db-migration/2223/2 "2021-12-31T18:07:28Z")

</div>

@tunglt1810 You won’t have access to the raw database connection string, but your library doesn’t require it. In your Go module’s `InitModule` function use the supplied `*sql.DB` handle to initialize your migration tool. The [project’s readme](https://github.com/golang-migrate/migrate#use-in-your-go-project) shows you how to do this.

---

<div class="post-metadata">

**Author:** ![tunglt1810](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/tunglt1810/32/924_2.png) [@tunglt1810](https://forum.heroiclabs.com/u/tunglt1810)\
**Post date:** [January 1, 2022, 6:31am UTC](https://forum.heroiclabs.com/t/custom-db-migration/2223/3 "2022-01-01T06:31:10Z")

</div>

Thank @zyro , it’s worked

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [January 3, 2022, 1:55pm UTC](https://forum.heroiclabs.com/t/custom-db-migration/2223/4 "2022-01-03T13:55:54Z")

</div>

@tunglt1810 I would suggest you avoid custom SQL as much as possible. We’ve seen a number of game teams in recent months who built their own domain model and didn’t take advantage of all the structures and APIs built directly by us in Nakama and end up creating huge performance problems with their own code.

There are use cases where I’d suggest that SQL might be useful but they’re few.

---

<div class="post-metadata">

**Author:** ![tunglt1810](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/tunglt1810/32/924_2.png) [@tunglt1810](https://forum.heroiclabs.com/u/tunglt1810)\
**Post date:** [January 3, 2022, 2:28pm UTC](https://forum.heroiclabs.com/t/custom-db-migration/2223/5 "2022-01-03T14:28:22Z")

</div>

Thank @novabyte for your suggestion.

I’m newbie with Nakama and Golang too. So I want to practice with the extendable ability of your awesome project. For now I use the Storage Engine to store the user’s data.

Related with DB structure, do you think the `storage` table will be very very big if we store everything in it.  
For example, I want to store user inventory, proficiency levels, task history, … a lot of things with complex object structure.

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [January 3, 2022, 3:48pm UTC](https://forum.heroiclabs.com/t/custom-db-migration/2223/6 "2022-01-03T15:48:20Z")

</div>

@tunglt1810 The storage table can be very large and you won’t have to worry about performance when you use the built-in Nakama APIs (especially the storage engine) because we’ve optimized those queries to perform very well at scale.

For example the largest game that uses Nakama has around ~6,500,000,000 storage objects for ~270,000,000 users. The average read time for a batch fetch of storage objects is ~4ms. To achieve these numbers we did apply some tuning to the database servers but that’s quite normal to do when operating at that scale.

---

<div class="post-metadata">

**Author:** ![tunglt1810](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/tunglt1810/32/924_2.png) [@tunglt1810](https://forum.heroiclabs.com/u/tunglt1810)\
**Post date:** [January 4, 2022, 2:55am UTC](https://forum.heroiclabs.com/t/custom-db-migration/2223/7 "2022-01-04T02:55:37Z")

</div>

@novabyte it’s a whole new happy thing for a new year 😃

---

<div class="post-metadata">

**Author:** ![tunglt1810](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/tunglt1810/32/924_2.png) [@tunglt1810](https://forum.heroiclabs.com/u/tunglt1810)\
**Post date:** [January 6, 2022, 2:58am UTC](https://forum.heroiclabs.com/t/custom-db-migration/2223/8 "2022-01-06T02:58:24Z")

</div>

Can you share your tuning story as a blog?

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [January 6, 2022, 3:54pm UTC](https://forum.heroiclabs.com/t/custom-db-migration/2223/9 "2022-01-06T15:54:35Z")

</div>

@tunglt1810 That’s a large topic and difficult to cover because a lot of it involved specifics to the game studio project we helped on (so I can’t share due to NDAs). A few things we typically do when needed at large scale:

- Tune the GC/Autovac parameters to be more aggressive on larger tables.
- Tune kernel parameters to be better suited for database server workloads. This [resource](https://docs.riak.com/riak/kv/2.2.3/using/performance.1.html) is useful though a bit outdated now.
- Repartition the storage table if its run on PG/Aurora rather than CRDB.
