Created scripts to structure our DB for us (Users table) using Go Migrate.We created a bare bones Postgres Docker container.This proceeds to then return the index that was last inserted in case we wanted to perform another action after. The above is just taking our original connection when we did our schema setup and then executing a SQL query to insert into our users table. Package main import ( "database/sql" "fmt" "/golang-migrate/migrate/v4" "/golang-migrate/migrate/v4/database/postgres" _ "/golang-migrate/migrate/v4/source/file" "/joho/godotenv" _ "/lib/pq" "log" "os" ) func main () Įnter fullscreen mode Exit fullscreen mode So to start we want to create our bare bone Postgres container: In short we are going to use a predefined Docker image for Postgres and then modify and put some data into it. So if you are not very well versed in Docker do not worry. Now you will not need to worry about getting too advanced with Docker features. One important aspect we want to ensure is that it is quick and easy to reboot and create these scenarios or get us back to a stable point.ġ) Building Your Postgres Docker Containerīefore we can start seeding our database we first have to get our container up and running.īefore we begin with creating a container we need to ensure that we have Docker installed and running. In general, seeding a database with fake data can help ensure that the database is working properly and can be useful for a variety of purposes. Database seeding can be useful for testing the functionality of a database, as well as for experimenting with different queries and data structures. This is often done for testing or development purposes, as it allows developers to work with a sample dataset without having to worry about corrupting real data. Whatever your preference, this article just hopes to achieve bringing light to how you can go about it.ĭatabase seeding is the process of adding initial data to a database. However there are tools in other languages to achieve the same results. In this article we will focus on using Go as our language to programatically seed our data. This article help us understand the importance of creating silo'ed development environments that allow us to quickly iterate, create scenarios and test. Building Your Postgres Docker Container.Adventure time Golang Gopher character growing out of ground, chaotic composition, photorealistic - Created with Midjourney
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |