{"id":20533548,"url":"https://github.com/joeychilson/testdb","last_synced_at":"2025-12-07T06:02:49.526Z","repository":{"id":151693747,"uuid":"591165803","full_name":"joeychilson/testdb","owner":"joeychilson","description":"A repo for building test Postgres databases.","archived":false,"fork":false,"pushed_at":"2023-02-01T04:49:14.000Z","size":56,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-06T03:14:19.277Z","etag":null,"topics":["go","golang","mysql","postgresql","testing"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joeychilson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-20T04:10:10.000Z","updated_at":"2023-01-23T11:15:56.000Z","dependencies_parsed_at":"2023-06-04T04:30:19.396Z","dependency_job_id":null,"html_url":"https://github.com/joeychilson/testdb","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/joeychilson/testdb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeychilson%2Ftestdb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeychilson%2Ftestdb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeychilson%2Ftestdb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeychilson%2Ftestdb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joeychilson","download_url":"https://codeload.github.com/joeychilson/testdb/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeychilson%2Ftestdb/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27562172,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-07T02:00:07.896Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","mysql","postgresql","testing"],"created_at":"2024-11-16T00:22:10.944Z","updated_at":"2025-12-07T06:02:49.492Z","avatar_url":"https://github.com/joeychilson.png","language":"Go","readme":"# testdb\n\nA repo for building test Postgres databases.\n\n**This is mostly for personal use, but feel free to use whatever you want in the repo.**\n\n## Features\n\n- [x] Docker containers for PostgreSQL\n- [x] Migrations with dbmate\n- [x] Generate Go code from queries with sqlc\n- [x] Automatically generate fake data for any PostgreSQL table (uses types, not realistic)\n- [x] Music schema with realistic data generation\n\n## Requirements\n\n- [dbmate](https://github.com/amacneil/dbmate) (for migrations)\n- [sqlc](https://github.com/kyleconroy/sqlc) (for generating Go code from SQL queries)\n\n## Usage\n\n### Clone\n\n```bash\ngit clone https://github.com/joeychilson/testdb\n```\n\n### Setup\n\n```bash\n# contains POSTGRES_URL for containers\ncp .env.example .env\n```\n\n### Migration\n\n```bash\n# create new migration file\nmake dbnew name={migration_name}\n\n# migrates database to latest version\nmake dbup\n\n# migrates database to previous version\nmake dbdown\n\n```\n\n### Container\n\n```bash\n# start docker container\nmake up\n\n# stop docker container\nmake down\n\n# destory docker container\nmake stop\n```\n\n### Generate Go code\n\n```bash\n# generate Go code for both PostgreSQL and MySQL queries\nmake sqlc\n```\n\n### Generate fake data\n\n```bash\n# generate fake data for any postgres sql tables\n# only supports postgres for now\ngo run cmd/main.go autogen -t table_name -r 100\n\n# generate realistic date for music schema\n# this will generate 2 artists, 3 albums per artist, and 8 songs per album\ngo run cmd/main.go gen music -r 2 -a 3 -s 8\n```\n\n### Example using generated Go code\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"database/sql\"\n\t\"log\"\n\t\"os\"\n\n\t\"github.com/brianvoe/gofakeit/v6\"\n\t\"github.com/joho/godotenv\"\n\n\t\"github.com/joeychilson/testdb/db\"\n\t\"github.com/joeychilson/testdb/db/sqlc\"\n\t\"github.com/joeychilson/testdb/gen\"\n)\n\nfunc main() {\n\tctx := context.Background()\n\n\t_ = godotenv.Load()\n\n\tdb, err := db.NewPostgres(ctx, os.Getenv(\"POSTGRES_URL\"))\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to connect to database: %v\", err)\n\t}\n\n\tgofakeit.Seed(0)\n\n\tvar genArtist *gen.Artist\n\tgofakeit.Struct(\u0026genArtist)\n\n\tartist := sqlc.CreateArtistParams{\n\t\tName:  genArtist.Name,\n\t\tImage: sql.NullString{String: genArtist.Image, Valid: genArtist.Image != \"\"},\n\t}\n\n\tartistsID, err := g.db.CreateArtist(ctx, artist)\n\tif err != nil {\n\t\tlog.Fatalf(\"failed to create artist: %v\", err)\n\t}\n\n\tlog.Printf(\"Created artist %s with ID\", genArtist.Name, artistsID)\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoeychilson%2Ftestdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoeychilson%2Ftestdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoeychilson%2Ftestdb/lists"}