Needs advice

Hey everyone, I just started developing with Go and want to build a small expense tracking app. Therefore I decided to use PostgreSQL as DB. My question is the following: What is a standard way or best practice to set up a Postgresql Database. Until now, I used a Go package called go-pg, but as I was told, this is not feasible for migration purposes. It is ok to handle and write data, though. But not ok or at least not good to set up the DB. So how would you set up the Postgresql DB for your golang (backend) project, e.g., create a table, define columns as serials, etc.? What are your thoughts on this?

Thanks in advance.

5 upvotes6.1K views
Replies (7)
Full Stack Product Designer at Serif & Semaphore

Why do you need to be concerned with database migrations? There's nothing wrong with the modules you chose. Set up the schema manually or bring in a separate module... likely just a go install for a binary that will have a CLI for you to do any db schema creation and migration work you need - outside of your code base.

There's absolutely no reason at all that you need a more feature rich module. If you wanted something that offered a little more try an ORM likely possibly gorm.

I'd honestly just get a database GUI tool (dbeaver is what I use) and create your schema there. How often is your schema going to change? How often will you undo schema changes? Probably not much. I wouldn't worry about a DB migrations solution yet. You likely won't get any value from one. Edumacation could learn about how they work.

5 upvotes1 comment5.4K views
May 27th 2021 at 7:11AM

I would agree, by not using a migration tool, you will become more familiar with how your application interacts with the database and, therefore, create a more secure application. Honestly, creating the schema through the database won't be as much work as you might think.


You can use golang-migrate/migrate ( as CLI (binary or Docker image) or import it as a Go library. One thing I like about golang-migrate/migrate is that, unlike many other migration tools, it doesn't use magical SQL comments in migration files -- just a simple file naming convention and standard SQL.

3 upvotes5.3K views
View all (7)
Avatar of knowerbescheidt