Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches: ["master"]
tags: ["*"]
pull_request:
branches: [ "master" ]
branches: [ "*" ]
jobs:
lint:
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -38,7 +38,6 @@ jobs:
# Track https://github.com/pingcap/tidb/tags
- testtidb6.1.0
- testtidb6.5.3
# Fails because not yet available? 20240705
# - testtidb6.5.10
- testtidb7.1.5
- testtidb7.5.2
Expand Down
22 changes: 13 additions & 9 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@ TEST?=$$(go list ./... |grep -v 'vendor')
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
WEBSITE_REPO=github.com/hashicorp/terraform-website
PKG_NAME=mysql
TERRAFORM_VERSION=0.14.7
# Last version before hashicorp relicensing to BSL
TERRAFORM_VERSION=1.5.6
TERRAFORM_OS=$(shell uname -s | tr A-Z a-z)
TEST_USER=root
TEST_PASSWORD=my-secret-pw
DATESTAMP=$(shell date "+%Y%m%d")
SHA_SHORT=$(shell git describe --match=FORCE_NEVER_MATCH --always --abbrev=40 --dirty --abbrev)
MOST_RECENT_UPSTREAM_TAG=$(shell git for-each-ref refs/tags --sort=-taggerdate --format="%(refname)" | head -1 | grep -E -o "v\d+\.\d+\.\d+")

OS_ARCH=linux_amd64
# Set correct OS_ARCH on Mac
UNAME := $(shell uname -s)
HW := $(shell uname -m)
ifeq ($(HW),arm64)
ARCH=$(HW)
else
ARCH=amd64
endif

ifeq ($(UNAME),Darwin)
HW := $(shell uname -m)
ifeq ($(HW),arm64)
ARCH=$(HW)
else
ARCH=amd64
endif
OS_ARCH=darwin_$(ARCH)
else
ARCH=amd64
OS_ARCH=linux_$(ARCH)
endif

HOSTNAME=registry.terraform.io
Expand All @@ -39,7 +43,7 @@ test: acceptance

bin/terraform:
mkdir -p "$(CURDIR)/bin"
curl -sfL https://releases.hashicorp.com/terraform/$(TERRAFORM_VERSION)/terraform_$(TERRAFORM_VERSION)_$(TERRAFORM_OS)_amd64.zip > $(CURDIR)/bin/terraform.zip
curl -sfL https://releases.hashicorp.com/terraform/$(TERRAFORM_VERSION)/terraform_$(TERRAFORM_VERSION)_$(TERRAFORM_OS)_$(ARCH).zip > $(CURDIR)/bin/terraform.zip
(cd $(CURDIR)/bin/ ; unzip terraform.zip)

testacc: fmtcheck bin/terraform
Expand Down
39 changes: 39 additions & 0 deletions mysql/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,42 @@ func testAccPreCheckSkipNotTiDB(t *testing.T) {
t.Skip(msg)
}
}

func testAccPreCheckSkipNotTiDBVersionMin(t *testing.T, minVersion string) {
testAccPreCheck(t)

ctx := context.Background()
db, err := connectToMySQL(ctx, testAccProvider.Meta().(*MySQLConfiguration))
if err != nil {
t.Fatalf("Cannot connect to DB (SkipNotTiDBVersionMin): %v", err)
return
}

currentVersion, err := serverVersion(db)
if err != nil {
t.Fatalf("Cannot get DB version string (SkipNotTiDBVersionMin): %v", err)
return
}

versionMin, _ := version.NewVersion(minVersion)
if currentVersion.LessThan(versionMin) {
isTiDB, tidbVersion, _, err := serverTiDB(db)
if err != nil {
t.Fatalf("Cannot get DB version string (SkipNotTiDBVersionMin): %v", err)
return
}
if isTiDB {
tidbSemVar, err := version.NewVersion(tidbVersion)
if err != nil {
t.Fatalf("Cannot get DB version string for TiDB (SkipNotTiDBVersionMin): %s %v", tidbSemVar, err)
return
}
if tidbSemVar.LessThan(versionMin) {
t.Skip("Skip on TiDB (SkipNotTiDBVersionMin)")
}
return
}

t.Skip("Skip on MySQL")
}
}
11 changes: 6 additions & 5 deletions mysql/resource_ti_resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ func (rg *ResourceGroup) buildSQLQuery(prefix string) string {
query = append(query, fmt.Sprintf(`PRIORITY = %s`, rg.Priority))

if rg.QueryLimit != DefaultResourceGroup.QueryLimit {
query = append(query, fmt.Sprintf(`QUERY_LIMIT=%s`, rg.QueryLimit))

query = append(query, fmt.Sprintf(`QUERY_LIMIT=(%s)`, rg.QueryLimit))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We rely on wrapping the query_limit in parentheses here instead of assuming that it will be wrapped in parentheses by the caller.

}

query = append(query, fmt.Sprintf(`BURSTABLE = %t`, rg.Burstable))
Expand All @@ -51,9 +50,11 @@ var DefaultResourceGroup = ResourceGroup{
Name: "tfDefault",
Priority: "medium",
Burstable: false,
QueryLimit: "()",
QueryLimit: "",
}

var ResourceGroupTiDBMinVersion = "7.5.0"

func resourceTiResourceGroup() *schema.Resource {
return &schema.Resource{
CreateContext: CreateResourceGroup,
Expand Down Expand Up @@ -208,10 +209,10 @@ func getResourceGroupFromDB(db *sql.DB, name string) (*ResourceGroup, error) {
/*
Coerce types on SQL side into good types for golang
Burstable is a varchar(3) so we coerce to BOOLEAN
QUERY_LIMIT is nullable in DB, but we coerce to standard "empty" string type of "()"
QUERY_LIMIT is nullable in DB, but we coerce to standard "empty" string type of ""
Lowercase priority for less configuration variability
*/
query := `SELECT NAME, RU_PER_SEC, LOWER(PRIORITY), BURSTABLE = 'YES' as BURSTABLE, IFNULL(QUERY_LIMIT,"()") FROM information_schema.resource_groups WHERE NAME = ?`
query := `SELECT NAME, RU_PER_SEC, LOWER(PRIORITY), BURSTABLE = 'YES' as BURSTABLE, IFNULL(QUERY_LIMIT,"") FROM information_schema.resource_groups WHERE NAME = ?`

ctx := context.Background()
tflog.SetField(ctx, "query", query)
Expand Down
Loading