From 014f6e1c8d9a261935e818b5625664114f5c8417 Mon Sep 17 00:00:00 2001 From: marvin Date: Fri, 25 Aug 2023 16:37:22 +0800 Subject: [PATCH] Fix actions --- .github/workflows/tests.yml | 34 +++++++++++++++++++++------------- README.md | 4 ++++ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a5e2915..41abb8c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -40,9 +40,10 @@ jobs: env: DIALECTOR: postgres - DATABASE_URL: postgres://gorm:gorm@localhost:5432/sharding-test - DATABASE_READ_URL: postgres://gorm:gorm@localhost:5432/sharding-read-test - DATABASE_WRITE_URL: postgres://gorm:gorm@localhost:5432/sharding-write-test + DB_URL: postgres://gorm:gorm@localhost:5432/sharding-test + DB_NOID_URL: postgres://gorm:gorm@localhost:5432/sharding-noid-test + DB_READ_URL: postgres://gorm:gorm@localhost:5432/sharding-read-test + DB_WRITE_URL: postgres://gorm:gorm@localhost:5432/sharding-write-test steps: - name: Set up Go uses: actions/setup-go@v4 @@ -50,6 +51,9 @@ jobs: go-version: "1.20" id: go + - name: Create No ID Database + run: PGPASSWORD=gorm psql -h localhost -U gorm -d sharding-test -c 'CREATE DATABASE "sharding-noid-test";' + - name: Create Read Database run: PGPASSWORD=gorm psql -h localhost -U gorm -d sharding-test -c 'CREATE DATABASE "sharding-read-test";' @@ -93,9 +97,10 @@ jobs: env: DIALECTOR: mysql - DATABASE_URL: gorm:gorm@tcp(127.0.0.1:3306)/sharding-test?charset=utf8mb4&parseTime=True&loc=Local - DATABASE_READ_URL: root:gorm@tcp(127.0.0.1:3306)/sharding-read-test?charset=utf8mb4&parseTime=True&loc=Local - DATABASE_WRITE_URL: root:gorm@tcp(127.0.0.1:3306)/sharding-write-test?charset=utf8mb4&parseTime=True&loc=Local + DB_URL: gorm:gorm@tcp(127.0.0.1:3306)/sharding-test?charset=utf8mb4&parseTime=True&loc=Local + DB_NOID_URL: gorm:gorm@tcp(127.0.0.1:3306)/sharding-noid-test?charset=utf8mb4&parseTime=True&loc=Local + DB_READ_URL: root:gorm@tcp(127.0.0.1:3306)/sharding-read-test?charset=utf8mb4&parseTime=True&loc=Local + DB_WRITE_URL: root:gorm@tcp(127.0.0.1:3306)/sharding-write-test?charset=utf8mb4&parseTime=True&loc=Local steps: - name: Set up Go uses: actions/setup-go@v4 @@ -103,13 +108,14 @@ jobs: go-version: "1.20" id: go + - name: Create No ID Database + run: mysqladmin -h 127.0.0.1 -uroot -pgorm create sharding-noid-test + - name: Create Read Database run: mysqladmin -h 127.0.0.1 -uroot -pgorm create sharding-read-test - #run: mysql -e 'CREATE DATABASE sharding-read-test' -ugorm -pgorm - name: Create Write Database run: mysqladmin -h 127.0.0.1 -uroot -pgorm create sharding-write-test - #run: mysql -e 'CREATE DATABASE sharding-write-test' -ugorm -pgorm - name: Check out code into the Go module directory uses: actions/checkout@v3 @@ -148,9 +154,10 @@ jobs: env: DIALECTOR: mariadb - DATABASE_URL: gorm:gorm@tcp(127.0.0.1:3306)/sharding-test?charset=utf8mb4&parseTime=True&loc=Local - DATABASE_READ_URL: root:gorm@tcp(127.0.0.1:3306)/sharding-read-test?charset=utf8mb4&parseTime=True&loc=Local - DATABASE_WRITE_URL: root:gorm@tcp(127.0.0.1:3306)/sharding-write-test?charset=utf8mb4&parseTime=True&loc=Local + DB_URL: gorm:gorm@tcp(127.0.0.1:3306)/sharding-test?charset=utf8mb4&parseTime=True&loc=Local + DB_NOID_URL: root:gorm@tcp(127.0.0.1:3306)/sharding-noid-test?charset=utf8mb4&parseTime=True&loc=Local + DB_READ_URL: root:gorm@tcp(127.0.0.1:3306)/sharding-read-test?charset=utf8mb4&parseTime=True&loc=Local + DB_WRITE_URL: root:gorm@tcp(127.0.0.1:3306)/sharding-write-test?charset=utf8mb4&parseTime=True&loc=Local steps: - name: Set up Go uses: actions/setup-go@v4 @@ -158,13 +165,14 @@ jobs: go-version: "1.20" id: go + - name: Create No ID Database + run: mysqladmin -h 127.0.0.1 -uroot -pgorm create sharding-noid-test + - name: Create Read Database run: mysqladmin -h 127.0.0.1 -uroot -pgorm create sharding-read-test - #run: mysql -e 'CREATE DATABASE sharding-read-test' -ugorm -pgorm - name: Create Write Database run: mysqladmin -h 127.0.0.1 -uroot -pgorm create sharding-write-test - #run: mysql -e 'CREATE DATABASE sharding-write-test' -ugorm -pgorm - name: Check out code into the Go module directory uses: actions/checkout@v3 diff --git a/README.md b/README.md index 6fb441e..0c0a1ba 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,10 @@ db.Use(sharding.Register(sharding.Config{ }, "orders") ``` +### No primary key + +If your table doesn't have a primary key, or has a primary key that isn't called `id`, anyway, you don't want to auto-fill the `id` field, then you can set `PrimaryKeyGenerator` to `PKCustom` and have `PrimaryKeyGeneratorFn` return `0`. + ## Combining with dbresolver > 🚨 NOTE: Use dbresolver first.