{"id":21846570,"url":"https://github.com/tidbcloud/branching-gorm-example","last_synced_at":"2025-09-22T09:05:00.320Z","repository":{"id":238718317,"uuid":"697332938","full_name":"tidbcloud/branching-gorm-example","owner":"tidbcloud","description":null,"archived":false,"fork":false,"pushed_at":"2023-09-28T05:51:57.000Z","size":11,"stargazers_count":0,"open_issues_count":2,"forks_count":1,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-07-01T11:51:11.295Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/tidbcloud.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-09-27T14:12:26.000Z","updated_at":"2023-09-28T02:53:48.000Z","dependencies_parsed_at":"2024-05-07T18:10:44.309Z","dependency_job_id":"d9c1b93b-5597-4d45-8651-2f9311fabce1","html_url":"https://github.com/tidbcloud/branching-gorm-example","commit_stats":null,"previous_names":["tidbcloud/branching-gorm-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tidbcloud/branching-gorm-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidbcloud%2Fbranching-gorm-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidbcloud%2Fbranching-gorm-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidbcloud%2Fbranching-gorm-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidbcloud%2Fbranching-gorm-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tidbcloud","download_url":"https://codeload.github.com/tidbcloud/branching-gorm-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tidbcloud%2Fbranching-gorm-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276375766,"owners_count":25631316,"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-09-22T02:00:08.972Z","response_time":79,"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":[],"created_at":"2024-11-27T23:14:28.490Z","updated_at":"2025-09-22T09:05:00.258Z","avatar_url":"https://github.com/tidbcloud.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# branching-gorm-example\n\n\u003e **Warning:** This repo is only for testing. Please don't use it in production.\n\nThis repo is a gorm example of CI/CD workflow powered by the TiDB Serverless branching. From this repo, you can learn:\n\n- How to connect to TiDB Serverless in gorm.\n- How to use branching GitHub integration.\n\n## About this repo\n\nThis repo is based on [gorm playground](https://github.com/go-gorm/playground), with some changes:\n\n- A tidb dialect is added to the repo to test the TiDB Cloud.\n- The [gormigrate](https://github.com/go-gormigrate/gormigrate) is used in `RunMigrations` to help migration.\n- Delete some useless files like GitHub actions, docker-compose, etc.\n\n## Connect to TiDB Serverless in gorm\n\n\u003e Make sure you have installed the go environment.\n\n1. clone the code\n\n```\ngit clone git@github.com:tidbcloud/branching-gorm-example.git\ncd branching-gorm-example\n```\n\n2. Fill in the following environment variable. You can find the information in the TiDB Serverless console.\n\n```\nexport GORM_ENABLE_CACHE=true\nexport GORM_DIALECT=tidb\nexport GORM_DSN=\"${{ username }}:${{ password }}@tcp(${{ host }}:${{ port }})/test?parseTime=true\u0026tls=tidb\"\n```\n\n3. Connect to the TiDB Serverless (migration will be executed automatically)\n\n```\n./test.sh\n```\n\n## Use branching GitHub integration\n\nThis repo has been connected to a TiDB Serverless using the [Branching GitHub integration](https://docs.pingcap.com/tidbcloud/branch-github-integration). This brings database branches to your GitHub workflows, and a TiDB Cloud App will automatically manage database branches for you in the pull request.\n\n**CI workflow**\n\nThe repo has a [Test GitHub Action](./.github/workflows/tests.yml) to run the test on the created TiDB Serverless branch. This action uses the [wait-for-tidbcloud-branch](https://github.com/tidbcloud/wait-for-tidbcloud-branch) to get branch connection information and pass it by environment variables. We can do it because the repo accepts the `GORM_DSN` environment variable as connection information. See the [code](https://github.com/tidbcloud/branching-gorm-example/blob/9ca6e4037edd25abafc35e1a378fc29ad62b5f68/db.go#L49) for more details.\n\nCheck the [pull request](https://github.com/tidbcloud/branching-gorm-example/pulls) to see how we use the CI workflow!\n\n**CD workflow**\n\nThe CD workflow works well with native frameworks.\n\nTake DDL as an example, you can use the [gormigrate](https://github.com/go-gormigrate/gormigrate) to manage your database migrations. Any DDL changes can be applied to the production cluster when the PR is merged. Don't worry about the influence of production business, the TiDB Serverless cluster supports online DDL without blocking your business.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftidbcloud%2Fbranching-gorm-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftidbcloud%2Fbranching-gorm-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftidbcloud%2Fbranching-gorm-example/lists"}