Code Monkey home page Code Monkey logo

branching-gorm-example's Introduction

branching-gorm-example

Warning: This repo is only for testing. Please don't use it in production.

This repo is a gorm example of CI/CD workflow powered by the TiDB Serverless branching. From this repo, you can learn:

  • How to connect to TiDB Serverless in gorm.
  • How to use branching GitHub integration.

About this repo

This repo is based on gorm playground, with some changes:

  • A tidb dialect is added to the repo to test the TiDB Cloud.
  • The gormigrate is used in RunMigrations to help migration.
  • Delete some useless files like GitHub actions, docker-compose, etc.

Connect to TiDB Serverless in gorm

Make sure you have installed the go environment.

  1. clone the code
git clone [email protected]:tidbcloud/branching-gorm-example.git
cd branching-gorm-example
  1. Fill in the following environment variable. You can find the information in the TiDB Serverless console.
export GORM_ENABLE_CACHE=true
export GORM_DIALECT=tidb
export GORM_DSN="${{ username }}:${{ password }}@tcp(${{ host }}:${{ port }})/test?parseTime=true&tls=tidb"
  1. Connect to the TiDB Serverless (migration will be executed automatically)
./test.sh

Use branching GitHub integration

This repo has been connected to a TiDB Serverless using the Branching 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.

CI workflow

The repo has a Test GitHub Action to run the test on the created TiDB Serverless branch. This action uses the 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 for more details.

Check the pull request to see how we use the CI workflow!

CD workflow

The CD workflow works well with native frameworks.

Take DDL as an example, you can use the 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.

branching-gorm-example's People

Contributors

shiyuhang0 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.