Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat(schema system): support PostgreSQL syntax advisor (#1564)

rebelice25720ebacdf0
diff --git a/bin/server/cmd/root.go b/bin/server/cmd/root.go
index 1475bff071..18e1385d3d 100644
--- a/bin/server/cmd/root.go
+++ b/bin/server/cmd/root.go
@@ -33,6 +33,8 @@ import (
_ "github.com/bytebase/bytebase/plugin/advisor/fake"
// Register mysql advisor.
_ "github.com/bytebase/bytebase/plugin/advisor/mysql"
+ // Register postgresql advisor.
+ _ "github.com/bytebase/bytebase/plugin/advisor/pg"
)
// -----------------------------------Global constant BEGIN----------------------------------------
diff --git a/go.mod b/go.mod
index 33a80525c3..92a39d00e3 100644
--- a/go.mod
+++ b/go.mod
@@ -5,8 +5,9 @@ go 1.16
require (
github.com/ClickHouse/clickhouse-go/v2 v2.0.7
github.com/VictoriaMetrics/fastcache v1.6.0
+ github.com/auxten/postgresql-parser v1.0.0
github.com/blang/semver/v4 v4.0.0
- github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
+ github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869
github.com/casbin/casbin/v2 v2.40.6
github.com/github/gh-ost v1.1.4
github.com/go-sql-driver/mysql v1.6.0
diff --git a/go.sum b/go.sum
index 7db66efb65..9610e08fd0 100644
--- a/go.sum
+++ b/go.sum
@@ -122,6 +122,8 @@ github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hC
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
+github.com/auxten/postgresql-parser v1.0.0 h1:n4kNwCI9pn914VZUtiu/9hhlc360CL4NfXQusBxQkZ8=
+github.com/auxten/postgresql-parser v1.0.0/go.mod h1:GrH7yBe6rhxgNxUCp1pbAYdIItcuAMmLpCtML5vUyLc=
github.com/aws/aws-sdk-go v1.30.19/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.35.3 h1:r0puXncSaAfRt7Btml2swUo74Kao+vKhO3VLjwDjK54=
github.com/aws/aws-sdk-go v1.35.3/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48=
@@ -176,6 +178,8 @@ github.com/casbin/casbin/v2 v2.40.6 h1:Fy8UmYaLst1zjyQ7Uw/Kq9Vxgyk91EtZO/cUUSm3k
github.com/casbin/casbin/v2 v2.40.6/go.mod h1:sEL80qBYTbd+BPeL4iyvwYzFT3qwLaESq5aFKVLbLfA=
github.com/cenkalti/backoff/v4 v4.0.2/go.mod h1:eEew/i+1Q6OrCDZh3WiXYv3+nJwBASZ8Bog/87DQnVg=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
+github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054 h1:uH66TXeswKn5PW5zdZ39xEwfS9an067BirqA+P4QaLI=
+github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
@@ -193,15 +197,21 @@ github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnht
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
-github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
+github.com/cockroachdb/apd v1.1.1-0.20181017181144-bced77f817b4 h1:XWEdfNxDkZI3DXXlpo0hZJ1xdaH/f3CKuZpk93pS/Y0=
+github.com/cockroachdb/apd v1.1.1-0.20181017181144-bced77f817b4/go.mod h1:mdGz2CnkJrefFtlLevmE7JpL2zB9tKofya/6w7wWzNA=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/cockroachdb/datadriven v1.0.0/go.mod h1:5Ib8Meh+jk1RlHIXej6Pzevx/NLlNvQB9pmSBZErGA4=
github.com/cockroachdb/errors v1.6.1/go.mod h1:tm6FTP5G81vwJ5lC0SizQo374JNCOPrHyXGitRJoDqM=
github.com/cockroachdb/errors v1.8.1/go.mod h1:qGwQn6JmZ+oMjuLwjWzUNqblqk0xl4CVV3SQbGwK7Ac=
+github.com/cockroachdb/errors v1.8.2 h1:rnnWK9Nn5kEMOGz9531HuDx/FOleL4NVH20VsDexVC8=
+github.com/cockroachdb/errors v1.8.2/go.mod h1:qGwQn6JmZ+oMjuLwjWzUNqblqk0xl4CVV3SQbGwK7Ac=
+github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f h1:o/kfcElHqOiXqcou5a3rIlMc7oJbMQkeLk0VQJ7zgqY=
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
github.com/cockroachdb/pebble v0.0.0-20210719141320-8c3bd06debb5/go.mod h1:JXfQr3d+XO4bL1pxGwKKo09xylQSdZ/mpZ9b2wfVcPs=
+github.com/cockroachdb/redact v1.0.8 h1:8QG/764wK+vmEYoOlfobpe12EQcS81ukx/a4hdVMxNw=
github.com/cockroachdb/redact v1.0.8/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
+github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2 h1:IKgmqgMQlVJIZj19CdocBeSfSaiCbEBZGKODaixqtHM=
github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2/go.mod h1:8BT+cPK6xvFOcRlk0R8eg+OTkcqI6baNH4xAkpiYVvQ=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM=
@@ -297,6 +307,8 @@ github.com/fzipp/gocyclo v0.3.1/go.mod h1:DJHO6AUmbdqj2ET4Z9iArSuwWgYDRryYt2wASx
github.com/gabriel-vasile/mimetype v1.3.1 h1:qevA6c2MtE1RorlScnixeG0VA1H4xrXyhyX3oWBynNQ=
github.com/gabriel-vasile/mimetype v1.3.1/go.mod h1:fA8fi6KUiG7MgQQ+mEWotXoEOvmxRtOJlERCzSmRvr8=
github.com/gavv/httpexpect v2.0.0+incompatible/go.mod h1:x+9tiU1YnrOvnB725RkpoLv1M62hOWzwo5OXotisrKc=
+github.com/getsentry/raven-go v0.2.0 h1:no+xWJRb5ZI7eE8TWgIq1jLulQiIoLG0IfYxv5JYMGs=
+github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ=
github.com/ghemawat/stream v0.0.0-20171120220530-696b145b53b9/go.mod h1:106OIgooyS7OzLDOpUGgm9fA3bQENb/cFSyyBmMoJDs=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/gzip v0.0.1/go.mod h1:fGBJBCdt6qCZuCAOwWuFhBB4OOq9EFqlo5dEaFhhu5w=
@@ -309,6 +321,7 @@ github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmC
github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98=
github.com/go-chi/chi v4.0.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
github.com/go-echarts/go-echarts v1.0.0/go.mod h1:qbmyAb/Rl1f2w7wKba1D4LoNq4U164yO4/wedFbcWyo=
+github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w=
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
@@ -659,6 +672,7 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxv
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
+github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
@@ -679,6 +693,7 @@ github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdA
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
+github.com/lib/pq v1.9.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lib/pq v1.10.2 h1:AqzbZs4ZoCBp+GtejcpCpcxM3zlSMx29dXbUSeVtJb8=
github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
@@ -792,6 +807,7 @@ github.com/pborman/getopt v0.0.0-20180729010549-6fdd0a2c7117/go.mod h1:85jBQOZwp
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml v1.3.0/go.mod h1:PN7xzY2wHTK0K9p34ErDQMlFxa51Fk0OUruD3k1mMwo=
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
+github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ=
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o=
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2/go.mod h1:iIss55rKnNBTvrwdmkUpLnDpZoAHvWaiq5+iMmen4AE=
github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d h1:U+PMnTlV2tu7RuMK5etusZG3Cf+rpow5hqQByeCzJ2g=
@@ -1358,6 +1374,7 @@ golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -1570,6 +1587,7 @@ google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6D
google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
+google.golang.org/genproto v0.0.0-20200911024640-645f7a48b24f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20201109203340-2640f1f9cdfb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20201201144952-b05cb90ed32e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
@@ -1679,6 +1697,7 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/mysql v1.0.6/go.mod h1:KdrTanmfLPPyAOeYGyG+UpDys7/7eeWT1zCq+oekYnU=
diff --git a/plugin/advisor/advisor.go b/plugin/advisor/advisor.go
index 35b04db2e0..6b9167f29f 100644
--- a/plugin/advisor/advisor.go
+++ b/plugin/advisor/advisor.go
@@ -57,6 +57,8 @@ const (
// Fake is a fake advisor type for testing.
Fake Type = "bb.plugin.advisor.fake"
+ // MySQL Advisor
+
// MySQLSyntax is an advisor type for MySQL syntax.
MySQLSyntax Type = "bb.plugin.advisor.mysql.syntax"
@@ -98,6 +100,11 @@ const (
// MySQLTableRequirePK is an advisor type for MySQL table require primary key.
MySQLTableRequirePK Type = "bb.plugin.advisor.mysql.table.require-pk"
+
+ // PostgreSQL Advisor
+
+ // PostgreSQLSyntax is an advisor type for PostgreSQL syntax.
+ PostgreSQLSyntax Type = "bb.plugin.advisor.postgresql.syntax"
)
// Advice is the result of an advisor.
@@ -178,7 +185,7 @@ func Check(dbType db.Type, advType Type, ctx Context, statement string) ([]Advic
dbAdvisors, ok := advisors[dbType]
defer advisorMu.RUnlock()
if !ok {
- return nil, fmt.Errorf("advisor: unknown advisor %v for %v", advType, dbType)
+ return nil, fmt.Errorf("advisor: unknown db advisor type %v", dbType)
}
f, ok := dbAdvisors[advType]
@@ -188,3 +195,19 @@ func Check(dbType db.Type, advType Type, ctx Context, statement string) ([]Advic
return f.Check(ctx, statement)
}
+
+// IsSyntaxCheckSupported checks the engine type if syntax check supports it.
+func IsSyntaxCheckSupported(engine db.Type) bool {
+ if engine == db.MySQL || engine == db.TiDB || engine == db.Postgres {
+ return true
+ }
+ return false
+}
+
+// IsSchemaReviewSupported checks the engine type if schema review supports it.
+func IsSchemaReviewSupported(engine db.Type) bool {
+ if engine == db.MySQL || engine == db.TiDB {
+ return true
+ }
+ return false
+}
diff --git a/plugin/advisor/mysql/advisor_column_no_null_test.go b/plugin/advisor/mysql/advisor_column_no_null_test.go
index 5413c5139f..71d60d4f50 100644
--- a/plugin/advisor/mysql/advisor_column_no_null_test.go
+++ b/plugin/advisor/mysql/advisor_column_no_null_test.go
@@ -8,10 +8,10 @@ import (
)
func TestColumnNoNull(t *testing.T) {
- tests := []test{
+ tests := []advisor.TestCase{
{
- statement: "CREATE TABLE book(id int, name varchar(255))",
- want: []advisor.Advice{
+ Statement: "CREATE TABLE book(id int, name varchar(255))",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.ColumnCanNotNull,
@@ -27,8 +27,8 @@ func TestColumnNoNull(t *testing.T) {
},
},
{
- statement: "CREATE TABLE book(id int PRIMARY KEY, name varchar(255))",
- want: []advisor.Advice{
+ Statement: "CREATE TABLE book(id int PRIMARY KEY, name varchar(255))",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.ColumnCanNotNull,
@@ -38,8 +38,8 @@ func TestColumnNoNull(t *testing.T) {
},
},
{
- statement: "CREATE TABLE book(id int NOT NULL, name varchar(255))",
- want: []advisor.Advice{
+ Statement: "CREATE TABLE book(id int NOT NULL, name varchar(255))",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.ColumnCanNotNull,
@@ -49,8 +49,8 @@ func TestColumnNoNull(t *testing.T) {
},
},
{
- statement: "CREATE TABLE book(id int PRIMARY KEY, name varchar(255) NOT NULL)",
- want: []advisor.Advice{
+ Statement: "CREATE TABLE book(id int PRIMARY KEY, name varchar(255) NOT NULL)",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -60,8 +60,8 @@ func TestColumnNoNull(t *testing.T) {
},
},
{
- statement: "ALTER TABLE book ADD COLUMN (id int, name varchar(255) NOT NULL)",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE book ADD COLUMN (id int, name varchar(255) NOT NULL)",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.ColumnCanNotNull,
@@ -71,8 +71,8 @@ func TestColumnNoNull(t *testing.T) {
},
},
{
- statement: "ALTER TABLE book ADD COLUMN (id int PRIMARY KEY, name varchar(255) NOT NULL)",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE book ADD COLUMN (id int PRIMARY KEY, name varchar(255) NOT NULL)",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -82,8 +82,8 @@ func TestColumnNoNull(t *testing.T) {
},
},
{
- statement: "ALTER TABLE book CHANGE COLUMN id name varchar(255)",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE book CHANGE COLUMN id name varchar(255)",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.ColumnCanNotNull,
@@ -93,8 +93,8 @@ func TestColumnNoNull(t *testing.T) {
},
},
{
- statement: "ALTER TABLE book CHANGE COLUMN id name varchar(255) NOT NULL",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE book CHANGE COLUMN id name varchar(255) NOT NULL",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -105,9 +105,9 @@ func TestColumnNoNull(t *testing.T) {
},
}
- runSchemaReviewRuleTests(t, tests, &ColumnNoNullAdvisor{}, &advisor.SchemaReviewRule{
+ advisor.RunSchemaReviewRuleTests(t, tests, &ColumnNoNullAdvisor{}, &advisor.SchemaReviewRule{
Type: advisor.SchemaRuleColumnNotNull,
Level: advisor.SchemaRuleLevelWarning,
Payload: "",
- }, &MockCatalogService{})
+ }, &advisor.MockCatalogService{})
}
diff --git a/plugin/advisor/mysql/advisor_column_required_test.go b/plugin/advisor/mysql/advisor_column_required_test.go
index d0481ae863..eaacafdad3 100644
--- a/plugin/advisor/mysql/advisor_column_required_test.go
+++ b/plugin/advisor/mysql/advisor_column_required_test.go
@@ -10,10 +10,10 @@ import (
)
func TestColumnRequirement(t *testing.T) {
- tests := []test{
+ tests := []advisor.TestCase{
{
- statement: "CREATE TABLE book(id int)",
- want: []advisor.Advice{
+ Statement: "CREATE TABLE book(id int)",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.NoRequiredColumn,
@@ -23,13 +23,13 @@ func TestColumnRequirement(t *testing.T) {
},
},
{
- statement: `CREATE TABLE book(
+ Statement: `CREATE TABLE book(
id int,
creator_id int,
created_ts timestamp,
updater_id int,
updated_ts timestamp)`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -39,14 +39,14 @@ func TestColumnRequirement(t *testing.T) {
},
},
{
- statement: `CREATE TABLE book(
+ Statement: `CREATE TABLE book(
id int,
creator_id int,
created_ts timestamp,
updater_id int,
updated_ts timestamp);
ALTER TABLE book RENAME COLUMN creator_id TO creator;`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.NoRequiredColumn,
@@ -56,14 +56,14 @@ func TestColumnRequirement(t *testing.T) {
},
},
{
- statement: `CREATE TABLE book(
+ Statement: `CREATE TABLE book(
id int,
creator int,
created_ts timestamp,
updater_id int,
updated_ts timestamp);
ALTER TABLE book RENAME COLUMN creator TO creator_id;`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -73,14 +73,14 @@ func TestColumnRequirement(t *testing.T) {
},
},
{
- statement: `CREATE TABLE book(
+ Statement: `CREATE TABLE book(
id int,
creator_id int,
created_ts timestamp,
updater_id int,
updated_ts timestamp);
ALTER TABLE book CHANGE COLUMN creator_id creator int;`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.NoRequiredColumn,
@@ -90,14 +90,14 @@ func TestColumnRequirement(t *testing.T) {
},
},
{
- statement: `CREATE TABLE book(
+ Statement: `CREATE TABLE book(
id int,
creator int,
created_ts timestamp,
updater_id int,
updated_ts timestamp);
ALTER TABLE book CHANGE COLUMN creator creator_id int;`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -107,14 +107,14 @@ func TestColumnRequirement(t *testing.T) {
},
},
{
- statement: `CREATE TABLE book(
+ Statement: `CREATE TABLE book(
id int,
creator_id int,
created_ts timestamp,
updater_id int,
updated_ts timestamp);
ALTER TABLE book DROP COLUMN creator_id;`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.NoRequiredColumn,
@@ -124,7 +124,7 @@ func TestColumnRequirement(t *testing.T) {
},
},
{
- statement: `CREATE TABLE book(
+ Statement: `CREATE TABLE book(
id int,
creator_id int,
created_ts timestamp,
@@ -132,7 +132,7 @@ func TestColumnRequirement(t *testing.T) {
updated_ts timestamp,
content varchar(255));
ALTER TABLE book DROP COLUMN content;`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -142,13 +142,13 @@ func TestColumnRequirement(t *testing.T) {
},
},
{
- statement: `CREATE TABLE book(
+ Statement: `CREATE TABLE book(
id int,
creator_id int,
created_ts timestamp,
updated_ts timestamp);
ALTER TABLE book ADD COLUMN content varchar(255);`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.NoRequiredColumn,
@@ -158,14 +158,14 @@ func TestColumnRequirement(t *testing.T) {
},
},
{
- statement: `CREATE TABLE book(
+ Statement: `CREATE TABLE book(
id int,
creator int,
created_ts timestamp,
updater_id int,
updated_ts timestamp);
ALTER TABLE book ADD COLUMN creator_id int;`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -175,7 +175,7 @@ func TestColumnRequirement(t *testing.T) {
},
},
{
- statement: `CREATE TABLE book(
+ Statement: `CREATE TABLE book(
id int,
created_ts timestamp,
updater_id int,
@@ -184,7 +184,7 @@ func TestColumnRequirement(t *testing.T) {
id int,
created_ts timestamp,
updated_ts timestamp);`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.NoRequiredColumn,
@@ -200,14 +200,14 @@ func TestColumnRequirement(t *testing.T) {
},
},
{
- statement: `CREATE TABLE book(
+ Statement: `CREATE TABLE book(
id int,
creator int,
created_ts timestamp,
updater_id int,
updated_ts timestamp);
DROP TABLE book;`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -227,9 +227,9 @@ func TestColumnRequirement(t *testing.T) {
},
})
require.NoError(t, err)
- runSchemaReviewRuleTests(t, tests, &ColumnRequirementAdvisor{}, &advisor.SchemaReviewRule{
+ advisor.RunSchemaReviewRuleTests(t, tests, &ColumnRequirementAdvisor{}, &advisor.SchemaReviewRule{
Type: advisor.SchemaRuleRequiredColumn,
Level: advisor.SchemaRuleLevelWarning,
Payload: string(payload),
- }, &MockCatalogService{})
+ }, &advisor.MockCatalogService{})
}
diff --git a/plugin/advisor/mysql/advisor_migration_compatibility_test.go b/plugin/advisor/mysql/advisor_migration_compatibility_test.go
index c1d840b44b..c8e3f1db89 100644
--- a/plugin/advisor/mysql/advisor_migration_compatibility_test.go
+++ b/plugin/advisor/mysql/advisor_migration_compatibility_test.go
@@ -10,10 +10,10 @@ import (
)
func TestBasic(t *testing.T) {
- tests := []test{
+ tests := []advisor.TestCase{
{
- statement: "DROP DATABASE d1",
- want: []advisor.Advice{
+ Statement: "DROP DATABASE d1",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.CompatibilityDropDatabase,
@@ -23,8 +23,8 @@ func TestBasic(t *testing.T) {
},
},
{
- statement: "DROP TABLE t1",
- want: []advisor.Advice{
+ Statement: "DROP TABLE t1",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.CompatibilityDropTable,
@@ -34,8 +34,8 @@ func TestBasic(t *testing.T) {
},
},
{
- statement: "RENAME TABLE t1 to t2",
- want: []advisor.Advice{
+ Statement: "RENAME TABLE t1 to t2",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.CompatibilityRenameTable,
@@ -45,8 +45,8 @@ func TestBasic(t *testing.T) {
},
},
{
- statement: "DROP VIEW v1",
- want: []advisor.Advice{
+ Statement: "DROP VIEW v1",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.CompatibilityDropTable,
@@ -56,8 +56,8 @@ func TestBasic(t *testing.T) {
},
},
{
- statement: "CREATE UNIQUE INDEX idx1 ON t1 (f1)",
- want: []advisor.Advice{
+ Statement: "CREATE UNIQUE INDEX idx1 ON t1 (f1)",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.CompatibilityAddUniqueKey,
@@ -67,8 +67,8 @@ func TestBasic(t *testing.T) {
},
},
{
- statement: "DROP TABLE t1;DROP TABLE t2;",
- want: []advisor.Advice{
+ Statement: "DROP TABLE t1;DROP TABLE t2;",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.CompatibilityDropTable,
@@ -85,18 +85,18 @@ func TestBasic(t *testing.T) {
},
}
- runSchemaReviewRuleTests(t, tests, &CompatibilityAdvisor{}, &advisor.SchemaReviewRule{
+ advisor.RunSchemaReviewRuleTests(t, tests, &CompatibilityAdvisor{}, &advisor.SchemaReviewRule{
Type: advisor.SchemaRuleSchemaBackwardCompatibility,
Level: advisor.SchemaRuleLevelWarning,
Payload: "",
- }, &MockCatalogService{})
+ }, &advisor.MockCatalogService{})
}
func TestAlterTable(t *testing.T) {
- tests := []test{
+ tests := []advisor.TestCase{
{
- statement: "ALTER TABLE t1 ADD f1 TEXT",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE t1 ADD f1 TEXT",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -106,8 +106,8 @@ func TestAlterTable(t *testing.T) {
},
},
{
- statement: "ALTER TABLE t1 RENAME COLUMN f1 to f2",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE t1 RENAME COLUMN f1 to f2",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.CompatibilityRenameColumn,
@@ -117,8 +117,8 @@ func TestAlterTable(t *testing.T) {
},
},
{
- statement: "ALTER TABLE t1 DROP COLUMN f1",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE t1 DROP COLUMN f1",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.CompatibilityDropColumn,
@@ -128,8 +128,8 @@ func TestAlterTable(t *testing.T) {
},
},
{
- statement: "ALTER TABLE t1 ADD PRIMARY KEY (f1)",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE t1 ADD PRIMARY KEY (f1)",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.CompatibilityAddPrimaryKey,
@@ -139,8 +139,8 @@ func TestAlterTable(t *testing.T) {
},
},
{
- statement: "ALTER TABLE t1 ADD UNIQUE (f1)",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE t1 ADD UNIQUE (f1)",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.CompatibilityAddUniqueKey,
@@ -150,8 +150,8 @@ func TestAlterTable(t *testing.T) {
},
},
{
- statement: "ALTER TABLE t1 ADD UNIQUE KEY (f1)",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE t1 ADD UNIQUE KEY (f1)",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.CompatibilityAddUniqueKey,
@@ -161,8 +161,8 @@ func TestAlterTable(t *testing.T) {
},
},
{
- statement: "ALTER TABLE t1 ADD UNIQUE INDEX (f1)",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE t1 ADD UNIQUE INDEX (f1)",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.CompatibilityAddUniqueKey,
@@ -172,8 +172,8 @@ func TestAlterTable(t *testing.T) {
},
},
{
- statement: "ALTER TABLE t1 ADD FOREIGN KEY (f1) REFERENCES t2(f2)",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE t1 ADD FOREIGN KEY (f1) REFERENCES t2(f2)",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.CompatibilityAddForeignKey,
@@ -183,8 +183,8 @@ func TestAlterTable(t *testing.T) {
},
},
{
- statement: "ALTER TABLE t1 ADD CHECK (f1 > 0)",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE t1 ADD CHECK (f1 > 0)",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.CompatibilityAddCheck,
@@ -194,8 +194,8 @@ func TestAlterTable(t *testing.T) {
},
},
{
- statement: "ALTER TABLE t1 ADD CHECK (f1 > 0) NOT ENFORCED",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE t1 ADD CHECK (f1 > 0) NOT ENFORCED",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Title: "OK",
@@ -204,8 +204,8 @@ func TestAlterTable(t *testing.T) {
},
},
{
- statement: "ALTER TABLE t1 ALTER CHECK chk1 ENFORCED",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE t1 ALTER CHECK chk1 ENFORCED",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.CompatibilityAlterCheck,
@@ -215,8 +215,8 @@ func TestAlterTable(t *testing.T) {
},
},
{
- statement: "ALTER TABLE t1 ALTER CHECK chk1 NOT ENFORCED",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE t1 ALTER CHECK chk1 NOT ENFORCED",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Title: "OK",
@@ -225,8 +225,8 @@ func TestAlterTable(t *testing.T) {
},
},
{
- statement: "ALTER TABLE t1 ADD CONSTRAINT CHECK (f1 > 0)",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE t1 ADD CONSTRAINT CHECK (f1 > 0)",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.CompatibilityAddCheck,
@@ -236,8 +236,8 @@ func TestAlterTable(t *testing.T) {
},
},
{
- statement: "ALTER TABLE t1 ADD CONSTRAINT CHECK (f1 > 0) NOT ENFORCED",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE t1 ADD CONSTRAINT CHECK (f1 > 0) NOT ENFORCED",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -247,8 +247,8 @@ func TestAlterTable(t *testing.T) {
},
},
{
- statement: "ALTER TABLE t1 RENAME TO t2",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE t1 RENAME TO t2",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.CompatibilityRenameTable,
@@ -259,18 +259,18 @@ func TestAlterTable(t *testing.T) {
},
}
- runSchemaReviewRuleTests(t, tests, &CompatibilityAdvisor{}, &advisor.SchemaReviewRule{
+ advisor.RunSchemaReviewRuleTests(t, tests, &CompatibilityAdvisor{}, &advisor.SchemaReviewRule{
Type: advisor.SchemaRuleSchemaBackwardCompatibility,
Level: advisor.SchemaRuleLevelWarning,
Payload: "",
- }, &MockCatalogService{})
+ }, &advisor.MockCatalogService{})
}
func TestAlterTableChangeColumnType(t *testing.T) {
- tests := []test{
+ tests := []advisor.TestCase{
{
- statement: "ALTER TABLE t1 CHANGE f1 f2 TEXT",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE t1 CHANGE f1 f2 TEXT",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.CompatibilityAlterColumn,
@@ -280,8 +280,8 @@ func TestAlterTableChangeColumnType(t *testing.T) {
},
},
{
- statement: "ALTER TABLE t1 MODIFY f1 TEXT",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE t1 MODIFY f1 TEXT",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.CompatibilityAlterColumn,
@@ -291,8 +291,8 @@ func TestAlterTableChangeColumnType(t *testing.T) {
},
},
{
- statement: "ALTER TABLE t1 MODIFY f1 TEXT NULL",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE t1 MODIFY f1 TEXT NULL",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.CompatibilityAlterColumn,
@@ -302,8 +302,8 @@ func TestAlterTableChangeColumnType(t *testing.T) {
},
},
{
- statement: "ALTER TABLE t1 MODIFY f1 TEXT NOT NULL",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE t1 MODIFY f1 TEXT NOT NULL",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.CompatibilityAlterColumn,
@@ -313,8 +313,8 @@ func TestAlterTableChangeColumnType(t *testing.T) {
},
},
{
- statement: "ALTER TABLE t1 MODIFY f1 TEXT COMMENT 'bla'",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE t1 MODIFY f1 TEXT COMMENT 'bla'",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.CompatibilityAlterColumn,
@@ -325,9 +325,9 @@ func TestAlterTableChangeColumnType(t *testing.T) {
},
}
- runSchemaReviewRuleTests(t, tests, &CompatibilityAdvisor{}, &advisor.SchemaReviewRule{
+ advisor.RunSchemaReviewRuleTests(t, tests, &CompatibilityAdvisor{}, &advisor.SchemaReviewRule{
Type: advisor.SchemaRuleSchemaBackwardCompatibility,
Level: advisor.SchemaRuleLevelWarning,
Payload: "",
- }, &MockCatalogService{})
+ }, &advisor.MockCatalogService{})
}
diff --git a/plugin/advisor/mysql/advisor_naming_column_test.go b/plugin/advisor/mysql/advisor_naming_column_test.go
index 89ac04d21a..db25c1d60b 100644
--- a/plugin/advisor/mysql/advisor_naming_column_test.go
+++ b/plugin/advisor/mysql/advisor_naming_column_test.go
@@ -10,10 +10,10 @@ import (
)
func TestNamingColumnConvention(t *testing.T) {
- tests := []test{
+ tests := []advisor.TestCase{
{
- statement: "CREATE TABLE book(id int, creatorId int)",
- want: []advisor.Advice{
+ Statement: "CREATE TABLE book(id int, creatorId int)",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.NamingColumnConventionMismatch,
@@ -23,8 +23,8 @@ func TestNamingColumnConvention(t *testing.T) {
},
},
{
- statement: "CREATE TABLE book(id int, creator_id int)",
- want: []advisor.Advice{
+ Statement: "CREATE TABLE book(id int, creator_id int)",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -34,9 +34,9 @@ func TestNamingColumnConvention(t *testing.T) {
},
},
{
- statement: `CREATE TABLE book(id int, creator_id int);
+ Statement: `CREATE TABLE book(id int, creator_id int);
ALTER TABLE book RENAME COLUMN creator_id TO creatorId`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.NamingColumnConventionMismatch,
@@ -46,8 +46,8 @@ func TestNamingColumnConvention(t *testing.T) {
},
},
{
- statement: `ALTER TABLE book RENAME COLUMN creatorId TO creator_id;`,
- want: []advisor.Advice{
+ Statement: `ALTER TABLE book RENAME COLUMN creatorId TO creator_id;`,
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -57,14 +57,14 @@ func TestNamingColumnConvention(t *testing.T) {
},
},
{
- statement: `CREATE TABLE book(
+ Statement: `CREATE TABLE book(
id int,
creator_id int,
created_ts timestamp,
updater_id int,
updated_ts timestamp);
ALTER TABLE book CHANGE COLUMN creator_id creatorId int;`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.NamingColumnConventionMismatch,
@@ -74,8 +74,8 @@ func TestNamingColumnConvention(t *testing.T) {
},
},
{
- statement: `ALTER TABLE book CHANGE COLUMN creatorId creator_id int;`,
- want: []advisor.Advice{
+ Statement: `ALTER TABLE book CHANGE COLUMN creatorId creator_id int;`,
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -85,8 +85,8 @@ func TestNamingColumnConvention(t *testing.T) {
},
},
{
- statement: `ALTER TABLE book DROP COLUMN contentString;`,
- want: []advisor.Advice{
+ Statement: `ALTER TABLE book DROP COLUMN contentString;`,
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -96,13 +96,13 @@ func TestNamingColumnConvention(t *testing.T) {
},
},
{
- statement: `CREATE TABLE book(
+ Statement: `CREATE TABLE book(
id int,
creator_id int,
created_ts timestamp,
updated_ts timestamp);
ALTER TABLE book ADD COLUMN contentString varchar(255);`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.NamingColumnConventionMismatch,
@@ -112,7 +112,7 @@ func TestNamingColumnConvention(t *testing.T) {
},
},
{
- statement: `CREATE TABLE book(
+ Statement: `CREATE TABLE book(
id int,
createdTs timestamp,
updaterId int,
@@ -121,7 +121,7 @@ func TestNamingColumnConvention(t *testing.T) {
id int,
createdTs timestamp,
updatedTs timestamp);`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.NamingColumnConventionMismatch,
@@ -154,9 +154,9 @@ func TestNamingColumnConvention(t *testing.T) {
Format: "^[a-z]+(_[a-z]+)*$",
})
require.NoError(t, err)
- runSchemaReviewRuleTests(t, tests, &NamingColumnConventionAdvisor{}, &advisor.SchemaReviewRule{
+ advisor.RunSchemaReviewRuleTests(t, tests, &NamingColumnConventionAdvisor{}, &advisor.SchemaReviewRule{
Type: advisor.SchemaRuleColumnNaming,
Level: advisor.SchemaRuleLevelWarning,
Payload: string(payload),
- }, &MockCatalogService{})
+ }, &advisor.MockCatalogService{})
}
diff --git a/plugin/advisor/mysql/advisor_naming_foreign_key_convention_test.go b/plugin/advisor/mysql/advisor_naming_foreign_key_convention_test.go
index 2fe350721c..b729c87ea1 100644
--- a/plugin/advisor/mysql/advisor_naming_foreign_key_convention_test.go
+++ b/plugin/advisor/mysql/advisor_naming_foreign_key_convention_test.go
@@ -10,10 +10,10 @@ import (
)
func TestNamingFKConvention(t *testing.T) {
- tests := []test{
+ tests := []advisor.TestCase{
{
- statement: "ALTER TABLE tech_book ADD CONSTRAINT fk_tech_book_author_id_author_id FOREIGN KEY (author_id) REFERENCES author (id)",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE tech_book ADD CONSTRAINT fk_tech_book_author_id_author_id FOREIGN KEY (author_id) REFERENCES author (id)",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -23,8 +23,8 @@ func TestNamingFKConvention(t *testing.T) {
},
},
{
- statement: "ALTER TABLE tech_book ADD CONSTRAINT fk_author_id FOREIGN KEY (author_id) REFERENCES author (id)",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE tech_book ADD CONSTRAINT fk_author_id FOREIGN KEY (author_id) REFERENCES author (id)",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.NamingFKConventionMismatch,
@@ -34,8 +34,8 @@ func TestNamingFKConvention(t *testing.T) {
},
},
{
- statement: "CREATE TABLE book(id INT, author_id INT, FOREIGN KEY fk_book_author_id_author_id (author_id) REFERENCES author (id))",
- want: []advisor.Advice{
+ Statement: "CREATE TABLE book(id INT, author_id INT, FOREIGN KEY fk_book_author_id_author_id (author_id) REFERENCES author (id))",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -45,8 +45,8 @@ func TestNamingFKConvention(t *testing.T) {
},
},
{
- statement: "CREATE TABLE book(id INT, author_id INT, FOREIGN KEY fk_book_author_id (author_id) REFERENCES author (id))",
- want: []advisor.Advice{
+ Statement: "CREATE TABLE book(id INT, author_id INT, FOREIGN KEY fk_book_author_id (author_id) REFERENCES author (id))",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.NamingFKConventionMismatch,
@@ -61,9 +61,9 @@ func TestNamingFKConvention(t *testing.T) {
Format: "^fk_{{referencing_table}}_{{referencing_column}}_{{referenced_table}}_{{referenced_column}}$",
})
require.NoError(t, err)
- runSchemaReviewRuleTests(t, tests, &NamingFKConventionAdvisor{}, &advisor.SchemaReviewRule{
+ advisor.RunSchemaReviewRuleTests(t, tests, &NamingFKConventionAdvisor{}, &advisor.SchemaReviewRule{
Type: advisor.SchemaRuleFKNaming,
Level: advisor.SchemaRuleLevelError,
Payload: string(payload),
- }, &MockCatalogService{})
+ }, &advisor.MockCatalogService{})
}
diff --git a/plugin/advisor/mysql/advisor_naming_index_convention_test.go b/plugin/advisor/mysql/advisor_naming_index_convention_test.go
index dd0b142ba6..6112d0d8ed 100644
--- a/plugin/advisor/mysql/advisor_naming_index_convention_test.go
+++ b/plugin/advisor/mysql/advisor_naming_index_convention_test.go
@@ -12,10 +12,10 @@ import (
)
func TestNamingIndexConvention(t *testing.T) {
- tests := []test{
+ tests := []advisor.TestCase{
{
- statement: "CREATE INDEX idx_tech_book_id_name ON tech_book(id, name)",
- want: []advisor.Advice{
+ Statement: "CREATE INDEX idx_tech_book_id_name ON tech_book(id, name)",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -25,8 +25,8 @@ func TestNamingIndexConvention(t *testing.T) {
},
},
{
- statement: "CREATE INDEX tech_book_id_name ON tech_book(id, name)",
- want: []advisor.Advice{
+ Statement: "CREATE INDEX tech_book_id_name ON tech_book(id, name)",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.NamingIndexConventionMismatch,
@@ -36,12 +36,12 @@ func TestNamingIndexConvention(t *testing.T) {
},
},
{
- statement: fmt.Sprintf(
+ Statement: fmt.Sprintf(
"ALTER TABLE tech_book RENAME INDEX %s TO idx_tech_book_%s",
- MockOldIndexName,
- strings.Join(MockIndexColumnList, "_"),
+ advisor.MockOldIndexName,
+ strings.Join(advisor.MockIndexColumnList, "_"),
),
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -51,11 +51,11 @@ func TestNamingIndexConvention(t *testing.T) {
},
},
{
- statement: fmt.Sprintf(
+ Statement: fmt.Sprintf(
"ALTER TABLE tech_book RENAME INDEX %s TO idx_tech_book",
- MockOldIndexName,
+ advisor.MockOldIndexName,
),
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.NamingIndexConventionMismatch,
@@ -65,8 +65,8 @@ func TestNamingIndexConvention(t *testing.T) {
},
},
{
- statement: "ALTER TABLE tech_book ADD INDEX idx_tech_book_id_name (id, name)",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE tech_book ADD INDEX idx_tech_book_id_name (id, name)",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -76,8 +76,8 @@ func TestNamingIndexConvention(t *testing.T) {
},
},
{
- statement: "ALTER TABLE tech_book ADD INDEX tech_book_id_name (id, name)",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE tech_book ADD INDEX tech_book_id_name (id, name)",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.NamingIndexConventionMismatch,
@@ -87,8 +87,8 @@ func TestNamingIndexConvention(t *testing.T) {
},
},
{
- statement: "CREATE TABLE tech_book(id INT PRIMARY KEY, name VARCHAR(20), INDEX idx_tech_book_name (name))",
- want: []advisor.Advice{
+ Statement: "CREATE TABLE tech_book(id INT PRIMARY KEY, name VARCHAR(20), INDEX idx_tech_book_name (name))",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -98,8 +98,8 @@ func TestNamingIndexConvention(t *testing.T) {
},
},
{
- statement: "CREATE TABLE tech_book(id INT PRIMARY KEY, name VARCHAR(20), INDEX (name))",
- want: []advisor.Advice{
+ Statement: "CREATE TABLE tech_book(id INT PRIMARY KEY, name VARCHAR(20), INDEX (name))",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.NamingIndexConventionMismatch,
@@ -114,9 +114,9 @@ func TestNamingIndexConvention(t *testing.T) {
Format: "^idx_{{table}}_{{column_list}}$",
})
require.NoError(t, err)
- runSchemaReviewRuleTests(t, tests, &NamingIndexConventionAdvisor{}, &advisor.SchemaReviewRule{
+ advisor.RunSchemaReviewRuleTests(t, tests, &NamingIndexConventionAdvisor{}, &advisor.SchemaReviewRule{
Type: advisor.SchemaRuleIDXNaming,
Level: advisor.SchemaRuleLevelError,
Payload: string(payload),
- }, &MockCatalogService{})
+ }, &advisor.MockCatalogService{})
}
diff --git a/plugin/advisor/mysql/advisor_naming_table_test.go b/plugin/advisor/mysql/advisor_naming_table_test.go
index 175c557ebc..32b0bea5a0 100644
--- a/plugin/advisor/mysql/advisor_naming_table_test.go
+++ b/plugin/advisor/mysql/advisor_naming_table_test.go
@@ -9,11 +9,11 @@ import (
"github.com/stretchr/testify/require"
)
-func TestNamingTableConvention(t *testing.T) {
- tests := []test{
+func TestMySQLNamingTableConvention(t *testing.T) {
+ tests := []advisor.TestCase{
{
- statement: "CREATE TABLE techBook(id int, name varchar(255))",
- want: []advisor.Advice{
+ Statement: "CREATE TABLE techBook(id int, name varchar(255))",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.NamingTableConventionMismatch,
@@ -23,8 +23,8 @@ func TestNamingTableConvention(t *testing.T) {
},
},
{
- statement: "CREATE TABLE tech_book(id int, name varchar(255))",
- want: []advisor.Advice{
+ Statement: "CREATE TABLE tech_book(id int, name varchar(255))",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -34,8 +34,8 @@ func TestNamingTableConvention(t *testing.T) {
},
},
{
- statement: "ALTER TABLE techBook RENAME TO TechBook",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE techBook RENAME TO TechBook",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.NamingTableConventionMismatch,
@@ -45,8 +45,8 @@ func TestNamingTableConvention(t *testing.T) {
},
},
{
- statement: "ALTER TABLE techBook RENAME TO tech_book",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE techBook RENAME TO tech_book",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -56,8 +56,8 @@ func TestNamingTableConvention(t *testing.T) {
},
},
{
- statement: "RENAME TABLE techBook TO tech_book, literaryBook TO LiteraryBook",
- want: []advisor.Advice{
+ Statement: "RENAME TABLE techBook TO tech_book, literaryBook TO LiteraryBook",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.NamingTableConventionMismatch,
@@ -67,8 +67,8 @@ func TestNamingTableConvention(t *testing.T) {
},
},
{
- statement: "RENAME TABLE techBook TO TechBook, literaryBook TO LiteraryBook",
- want: []advisor.Advice{
+ Statement: "RENAME TABLE techBook TO TechBook, literaryBook TO LiteraryBook",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.NamingTableConventionMismatch,
@@ -84,8 +84,8 @@ func TestNamingTableConvention(t *testing.T) {
},
},
{
- statement: "RENAME TABLE techBook TO tech_book, literaryBook TO literary_book",
- want: []advisor.Advice{
+ Statement: "RENAME TABLE techBook TO tech_book, literaryBook TO literary_book",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -99,9 +99,9 @@ func TestNamingTableConvention(t *testing.T) {
Format: "^[a-z]+(_[a-z]+)*$",
})
require.NoError(t, err)
- runSchemaReviewRuleTests(t, tests, &NamingTableConventionAdvisor{}, &advisor.SchemaReviewRule{
+ advisor.RunSchemaReviewRuleTests(t, tests, &NamingTableConventionAdvisor{}, &advisor.SchemaReviewRule{
Type: advisor.SchemaRuleTableNaming,
Level: advisor.SchemaRuleLevelError,
Payload: string(payload),
- }, &MockCatalogService{})
+ }, &advisor.MockCatalogService{})
}
diff --git a/plugin/advisor/mysql/advisor_naming_unique_key_convention_test.go b/plugin/advisor/mysql/advisor_naming_unique_key_convention_test.go
index b35abcbf11..01162d88ab 100644
--- a/plugin/advisor/mysql/advisor_naming_unique_key_convention_test.go
+++ b/plugin/advisor/mysql/advisor_naming_unique_key_convention_test.go
@@ -12,10 +12,10 @@ import (
)
func TestNamingUKConvention(t *testing.T) {
- tests := []test{
+ tests := []advisor.TestCase{
{
- statement: "CREATE UNIQUE INDEX uk_tech_book_id_name ON tech_book(id, name)",
- want: []advisor.Advice{
+ Statement: "CREATE UNIQUE INDEX uk_tech_book_id_name ON tech_book(id, name)",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -25,8 +25,8 @@ func TestNamingUKConvention(t *testing.T) {
},
},
{
- statement: "CREATE UNIQUE INDEX tech_book_id_name ON tech_book(id, name)",
- want: []advisor.Advice{
+ Statement: "CREATE UNIQUE INDEX tech_book_id_name ON tech_book(id, name)",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.NamingUKConventionMismatch,
@@ -36,8 +36,8 @@ func TestNamingUKConvention(t *testing.T) {
},
},
{
- statement: "ALTER TABLE tech_book ADD UNIQUE uk_tech_book_id_name (id, name)",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE tech_book ADD UNIQUE uk_tech_book_id_name (id, name)",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -47,8 +47,8 @@ func TestNamingUKConvention(t *testing.T) {
},
},
{
- statement: "ALTER TABLE tech_book ADD UNIQUE tech_book_id_name (id, name)",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE tech_book ADD UNIQUE tech_book_id_name (id, name)",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.NamingUKConventionMismatch,
@@ -58,12 +58,12 @@ func TestNamingUKConvention(t *testing.T) {
},
},
{
- statement: fmt.Sprintf(
+ Statement: fmt.Sprintf(
"ALTER TABLE tech_book RENAME INDEX %s TO uk_tech_book_%s",
- MockOldUKName,
- strings.Join(MockIndexColumnList, "_"),
+ advisor.MockOldUKName,
+ strings.Join(advisor.MockIndexColumnList, "_"),
),
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -73,11 +73,11 @@ func TestNamingUKConvention(t *testing.T) {
},
},
{
- statement: fmt.Sprintf(
+ Statement: fmt.Sprintf(
"ALTER TABLE tech_book RENAME INDEX %s TO uk_tech_book",
- MockOldUKName,
+ advisor.MockOldUKName,
),
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.NamingUKConventionMismatch,
@@ -87,8 +87,8 @@ func TestNamingUKConvention(t *testing.T) {
},
},
{
- statement: "CREATE TABLE tech_book(id INT PRIMARY KEY, name VARCHAR(20), UNIQUE INDEX uk_tech_book_name (name))",
- want: []advisor.Advice{
+ Statement: "CREATE TABLE tech_book(id INT PRIMARY KEY, name VARCHAR(20), UNIQUE INDEX uk_tech_book_name (name))",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -98,8 +98,8 @@ func TestNamingUKConvention(t *testing.T) {
},
},
{
- statement: "CREATE TABLE tech_book(id INT PRIMARY KEY, name VARCHAR(20), UNIQUE KEY (name))",
- want: []advisor.Advice{
+ Statement: "CREATE TABLE tech_book(id INT PRIMARY KEY, name VARCHAR(20), UNIQUE KEY (name))",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.NamingUKConventionMismatch,
@@ -109,8 +109,8 @@ func TestNamingUKConvention(t *testing.T) {
},
},
{
- statement: "CREATE TABLE tech_book(id INT PRIMARY KEY, name VARCHAR(20), UNIQUE INDEX (name))",
- want: []advisor.Advice{
+ Statement: "CREATE TABLE tech_book(id INT PRIMARY KEY, name VARCHAR(20), UNIQUE INDEX (name))",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.NamingUKConventionMismatch,
@@ -120,8 +120,8 @@ func TestNamingUKConvention(t *testing.T) {
},
},
{
- statement: "CREATE TABLE tech_book(id INT PRIMARY KEY, name VARCHAR(20), UNIQUE KEY (name))",
- want: []advisor.Advice{
+ Statement: "CREATE TABLE tech_book(id INT PRIMARY KEY, name VARCHAR(20), UNIQUE KEY (name))",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.NamingUKConventionMismatch,
@@ -136,9 +136,9 @@ func TestNamingUKConvention(t *testing.T) {
Format: "^uk_{{table}}_{{column_list}}$",
})
require.NoError(t, err)
- runSchemaReviewRuleTests(t, tests, &NamingUKConventionAdvisor{}, &advisor.SchemaReviewRule{
+ advisor.RunSchemaReviewRuleTests(t, tests, &NamingUKConventionAdvisor{}, &advisor.SchemaReviewRule{
Type: advisor.SchemaRuleUKNaming,
Level: advisor.SchemaRuleLevelError,
Payload: string(payload),
- }, &MockCatalogService{})
+ }, &advisor.MockCatalogService{})
}
diff --git a/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like_test.go b/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like_test.go
index c81da6f127..339293f486 100644
--- a/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like_test.go
+++ b/plugin/advisor/mysql/advisor_stmt_no_leading_wildcard_like_test.go
@@ -8,10 +8,10 @@ import (
)
func TestNoLeadingWildcardLike(t *testing.T) {
- tests := []test{
+ tests := []advisor.TestCase{
{
- statement: "SELECT * FROM t WHERE a LIKE 'abc%'",
- want: []advisor.Advice{
+ Statement: "SELECT * FROM t WHERE a LIKE 'abc%'",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -21,8 +21,8 @@ func TestNoLeadingWildcardLike(t *testing.T) {
},
},
{
- statement: "SELECT * FROM t WHERE a LIKE '%abc'",
- want: []advisor.Advice{
+ Statement: "SELECT * FROM t WHERE a LIKE '%abc'",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.StatementLeadingWildcardLike,
@@ -32,8 +32,8 @@ func TestNoLeadingWildcardLike(t *testing.T) {
},
},
{
- statement: "SELECT * FROM t WHERE a LIKE 'abc' OR a LIKE '%abc'",
- want: []advisor.Advice{
+ Statement: "SELECT * FROM t WHERE a LIKE 'abc' OR a LIKE '%abc'",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.StatementLeadingWildcardLike,
@@ -43,8 +43,8 @@ func TestNoLeadingWildcardLike(t *testing.T) {
},
},
{
- statement: "SELECT * FROM t WHERE a LIKE '%acc' OR a LIKE '%abc'",
- want: []advisor.Advice{
+ Statement: "SELECT * FROM t WHERE a LIKE '%acc' OR a LIKE '%abc'",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.StatementLeadingWildcardLike,
@@ -54,8 +54,8 @@ func TestNoLeadingWildcardLike(t *testing.T) {
},
},
{
- statement: "SELECT * FROM (SELECT * FROM t WHERE a LIKE '%acc' OR a LIKE '%abc') t1",
- want: []advisor.Advice{
+ Statement: "SELECT * FROM (SELECT * FROM t WHERE a LIKE '%acc' OR a LIKE '%abc') t1",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.StatementLeadingWildcardLike,
@@ -66,9 +66,9 @@ func TestNoLeadingWildcardLike(t *testing.T) {
},
}
- runSchemaReviewRuleTests(t, tests, &NoLeadingWildcardLikeAdvisor{}, &advisor.SchemaReviewRule{
+ advisor.RunSchemaReviewRuleTests(t, tests, &NoLeadingWildcardLikeAdvisor{}, &advisor.SchemaReviewRule{
Type: advisor.SchemaRuleStatementNoLeadingWildcardLike,
Level: advisor.SchemaRuleLevelError,
Payload: "",
- }, &MockCatalogService{})
+ }, &advisor.MockCatalogService{})
}
diff --git a/plugin/advisor/mysql/advisor_stmt_no_select_all_test.go b/plugin/advisor/mysql/advisor_stmt_no_select_all_test.go
index d490827d24..8637937833 100644
--- a/plugin/advisor/mysql/advisor_stmt_no_select_all_test.go
+++ b/plugin/advisor/mysql/advisor_stmt_no_select_all_test.go
@@ -8,10 +8,10 @@ import (
)
func TestNoSelectAll(t *testing.T) {
- tests := []test{
+ tests := []advisor.TestCase{
{
- statement: "SELECT * FROM t",
- want: []advisor.Advice{
+ Statement: "SELECT * FROM t",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.StatementSelectAll,
@@ -21,8 +21,8 @@ func TestNoSelectAll(t *testing.T) {
},
},
{
- statement: "SELECT a, b FROM t",
- want: []advisor.Advice{
+ Statement: "SELECT a, b FROM t",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -32,8 +32,8 @@ func TestNoSelectAll(t *testing.T) {
},
},
{
- statement: "SELECT a, b FROM (SELECT * from t1 JOIN t2) t",
- want: []advisor.Advice{
+ Statement: "SELECT a, b FROM (SELECT * from t1 JOIN t2) t",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.StatementSelectAll,
@@ -44,9 +44,9 @@ func TestNoSelectAll(t *testing.T) {
},
}
- runSchemaReviewRuleTests(t, tests, &NoSelectAllAdvisor{}, &advisor.SchemaReviewRule{
+ advisor.RunSchemaReviewRuleTests(t, tests, &NoSelectAllAdvisor{}, &advisor.SchemaReviewRule{
Type: advisor.SchemaRuleStatementNoSelectAll,
Level: advisor.SchemaRuleLevelError,
Payload: "",
- }, &MockCatalogService{})
+ }, &advisor.MockCatalogService{})
}
diff --git a/plugin/advisor/mysql/advisor_stmt_where_required_test.go b/plugin/advisor/mysql/advisor_stmt_where_required_test.go
index 19517663c4..b86875276c 100644
--- a/plugin/advisor/mysql/advisor_stmt_where_required_test.go
+++ b/plugin/advisor/mysql/advisor_stmt_where_required_test.go
@@ -8,10 +8,10 @@ import (
)
func TestWhereRequirement(t *testing.T) {
- tests := []test{
+ tests := []advisor.TestCase{
{
- statement: "DELETE FROM t1",
- want: []advisor.Advice{
+ Statement: "DELETE FROM t1",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.StatementNoWhere,
@@ -21,8 +21,8 @@ func TestWhereRequirement(t *testing.T) {
},
},
{
- statement: "UPDATE t1 SET a = 1",
- want: []advisor.Advice{
+ Statement: "UPDATE t1 SET a = 1",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.StatementNoWhere,
@@ -32,8 +32,8 @@ func TestWhereRequirement(t *testing.T) {
},
},
{
- statement: "DELETE FROM t1 WHERE a > 0",
- want: []advisor.Advice{
+ Statement: "DELETE FROM t1 WHERE a > 0",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -43,8 +43,8 @@ func TestWhereRequirement(t *testing.T) {
},
},
{
- statement: "UPDATE t1 SET a = 1 WHERE a > 10",
- want: []advisor.Advice{
+ Statement: "UPDATE t1 SET a = 1 WHERE a > 10",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -54,8 +54,8 @@ func TestWhereRequirement(t *testing.T) {
},
},
{
- statement: "SELECT a FROM t",
- want: []advisor.Advice{
+ Statement: "SELECT a FROM t",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.StatementNoWhere,
@@ -65,8 +65,8 @@ func TestWhereRequirement(t *testing.T) {
},
},
{
- statement: "SELECT a FROM t WHERE a > 0",
- want: []advisor.Advice{
+ Statement: "SELECT a FROM t WHERE a > 0",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -76,8 +76,8 @@ func TestWhereRequirement(t *testing.T) {
},
},
{
- statement: "SELECT a FROM t WHERE a > (SELECT max(id) FROM user)",
- want: []advisor.Advice{
+ Statement: "SELECT a FROM t WHERE a > (SELECT max(id) FROM user)",
+ Want: []advisor.Advice{
{
Status: advisor.Warn,
Code: common.StatementNoWhere,
@@ -88,9 +88,9 @@ func TestWhereRequirement(t *testing.T) {
},
}
- runSchemaReviewRuleTests(t, tests, &WhereRequirementAdvisor{}, &advisor.SchemaReviewRule{
+ advisor.RunSchemaReviewRuleTests(t, tests, &WhereRequirementAdvisor{}, &advisor.SchemaReviewRule{
Type: advisor.SchemaRuleStatementRequireWhere,
Level: advisor.SchemaRuleLevelWarning,
Payload: "",
- }, &MockCatalogService{})
+ }, &advisor.MockCatalogService{})
}
diff --git a/plugin/advisor/mysql/advisor_table_require_pk_test.go b/plugin/advisor/mysql/advisor_table_require_pk_test.go
index d08e01a6fa..770d37b2ff 100644
--- a/plugin/advisor/mysql/advisor_table_require_pk_test.go
+++ b/plugin/advisor/mysql/advisor_table_require_pk_test.go
@@ -8,10 +8,10 @@ import (
)
func TestRequirePK(t *testing.T) {
- tests := []test{
+ tests := []advisor.TestCase{
{
- statement: "CREATE TABLE t(id INT PRIMARY KEY)",
- want: []advisor.Advice{
+ Statement: "CREATE TABLE t(id INT PRIMARY KEY)",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -21,8 +21,8 @@ func TestRequirePK(t *testing.T) {
},
},
{
- statement: "CREATE TABLE t(id INT, PRIMARY KEY (id))",
- want: []advisor.Advice{
+ Statement: "CREATE TABLE t(id INT, PRIMARY KEY (id))",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -32,8 +32,8 @@ func TestRequirePK(t *testing.T) {
},
},
{
- statement: "CREATE TABLE t(id INT)",
- want: []advisor.Advice{
+ Statement: "CREATE TABLE t(id INT)",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.TableNoPK,
@@ -43,9 +43,9 @@ func TestRequirePK(t *testing.T) {
},
},
{
- statement: `CREATE TABLE t(id INT);
+ Statement: `CREATE TABLE t(id INT);
DROP TABLE t`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -55,9 +55,9 @@ func TestRequirePK(t *testing.T) {
},
},
{
- statement: `CREATE TABLE t(id INT);
+ Statement: `CREATE TABLE t(id INT);
ALTER TABLE t ADD CONSTRAINT PRIMARY KEY (id)`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -67,9 +67,9 @@ func TestRequirePK(t *testing.T) {
},
},
{
- statement: `CREATE TABLE t(id INT PRIMARY KEY);
+ Statement: `CREATE TABLE t(id INT PRIMARY KEY);
ALTER TABLE t DROP PRIMARY KEY`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.TableNoPK,
@@ -79,9 +79,9 @@ func TestRequirePK(t *testing.T) {
},
},
{
- statement: "CREATE TABLE t(id INT PRIMARY KEY);" +
+ Statement: "CREATE TABLE t(id INT PRIMARY KEY);" +
"ALTER TABLE t DROP INDEX `PRIMARY`",
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.TableNoPK,
@@ -91,9 +91,9 @@ func TestRequirePK(t *testing.T) {
},
},
{
- statement: `CREATE TABLE t(id INT);
+ Statement: `CREATE TABLE t(id INT);
ALTER TABLE t ADD COLUMN name varchar(30) PRIMARY KEY`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -103,9 +103,9 @@ func TestRequirePK(t *testing.T) {
},
},
{
- statement: `CREATE TABLE t(id INT);
+ Statement: `CREATE TABLE t(id INT);
ALTER TABLE t CHANGE COLUMN id id INT PRIMARY KEY`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -116,8 +116,8 @@ func TestRequirePK(t *testing.T) {
},
{
// Use MockCatalogService
- statement: `ALTER TABLE t CHANGE COLUMN id uid INT`,
- want: []advisor.Advice{
+ Statement: `ALTER TABLE t CHANGE COLUMN id uid INT`,
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -127,9 +127,9 @@ func TestRequirePK(t *testing.T) {
},
},
{
- statement: `CREATE TABLE t(id INT);
+ Statement: `CREATE TABLE t(id INT);
ALTER TABLE t MODIFY COLUMN id INT PRIMARY KEY`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -140,8 +140,8 @@ func TestRequirePK(t *testing.T) {
},
{
// Use MockCatalogService
- statement: `ALTER TABLE t MODIFY COLUMN id INT PRIMARY KEY`,
- want: []advisor.Advice{
+ Statement: `ALTER TABLE t MODIFY COLUMN id INT PRIMARY KEY`,
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -151,9 +151,9 @@ func TestRequirePK(t *testing.T) {
},
},
{
- statement: `CREATE TABLE t(id INT, name varchar(30), PRIMARY KEY(id, name));
+ Statement: `CREATE TABLE t(id INT, name varchar(30), PRIMARY KEY(id, name));
ALTER TABLE t DROP COLUMN id`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -163,9 +163,9 @@ func TestRequirePK(t *testing.T) {
},
},
{
- statement: `CREATE TABLE t(id INT, name varchar(30), comment varchar(255), PRIMARY KEY(id, name));
+ Statement: `CREATE TABLE t(id INT, name varchar(30), comment varchar(255), PRIMARY KEY(id, name));
ALTER TABLE t DROP COLUMN id, DROP COLUMN name`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.TableNoPK,
@@ -176,8 +176,8 @@ func TestRequirePK(t *testing.T) {
},
{
// Use MockCatalogService
- statement: `ALTER TABLE t DROP COLUMN id, DROP COLUMN name`,
- want: []advisor.Advice{
+ Statement: `ALTER TABLE t DROP COLUMN id, DROP COLUMN name`,
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.TableNoPK,
@@ -188,8 +188,8 @@ func TestRequirePK(t *testing.T) {
},
{
// Use MockCatalogService
- statement: `ALTER TABLE t DROP COLUMN uid, DROP COLUMN name`,
- want: []advisor.Advice{
+ Statement: `ALTER TABLE t DROP COLUMN uid, DROP COLUMN name`,
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -200,9 +200,9 @@ func TestRequirePK(t *testing.T) {
},
{
// Use MockCatalogService
- statement: `ALTER TABLE t CHANGE COLUMN id uid int;
+ Statement: `ALTER TABLE t CHANGE COLUMN id uid int;
ALTER TABLE t DROP COLUMN uid, DROP COLUMN name`,
- want: []advisor.Advice{
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.TableNoPK,
@@ -213,9 +213,9 @@ func TestRequirePK(t *testing.T) {
},
}
- runSchemaReviewRuleTests(t, tests, &TableRequirePKAdvisor{}, &advisor.SchemaReviewRule{
+ advisor.RunSchemaReviewRuleTests(t, tests, &TableRequirePKAdvisor{}, &advisor.SchemaReviewRule{
Type: advisor.SchemaRuleTableRequirePK,
Level: advisor.SchemaRuleLevelError,
Payload: "",
- }, &MockCatalogService{})
+ }, &advisor.MockCatalogService{})
}
diff --git a/plugin/advisor/mysql/advisor_use_innodb_test.go b/plugin/advisor/mysql/advisor_use_innodb_test.go
index 99a08313e4..9a937f105a 100644
--- a/plugin/advisor/mysql/advisor_use_innodb_test.go
+++ b/plugin/advisor/mysql/advisor_use_innodb_test.go
@@ -8,10 +8,10 @@ import (
)
func TestUseInnoDB(t *testing.T) {
- tests := []test{
+ tests := []advisor.TestCase{
{
- statement: "CREATE TABLE book(id int) ENGINE = INNODB",
- want: []advisor.Advice{
+ Statement: "CREATE TABLE book(id int) ENGINE = INNODB",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -21,8 +21,8 @@ func TestUseInnoDB(t *testing.T) {
},
},
{
- statement: "CREATE TABLE book(id int)",
- want: []advisor.Advice{
+ Statement: "CREATE TABLE book(id int)",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -32,8 +32,8 @@ func TestUseInnoDB(t *testing.T) {
},
},
{
- statement: "CREATE TABLE book(id int) ENGINE = CSV",
- want: []advisor.Advice{
+ Statement: "CREATE TABLE book(id int) ENGINE = CSV",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.NotInnoDBEngine,
@@ -43,8 +43,8 @@ func TestUseInnoDB(t *testing.T) {
},
},
{
- statement: "ALTER TABLE book ENGINE = INNODB",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE book ENGINE = INNODB",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -54,8 +54,8 @@ func TestUseInnoDB(t *testing.T) {
},
},
{
- statement: "ALTER TABLE book ENGINE = CSV",
- want: []advisor.Advice{
+ Statement: "ALTER TABLE book ENGINE = CSV",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.NotInnoDBEngine,
@@ -65,8 +65,8 @@ func TestUseInnoDB(t *testing.T) {
},
},
{
- statement: "SET default_storage_engine=INNODB",
- want: []advisor.Advice{
+ Statement: "SET default_storage_engine=INNODB",
+ Want: []advisor.Advice{
{
Status: advisor.Success,
Code: common.Ok,
@@ -76,8 +76,8 @@ func TestUseInnoDB(t *testing.T) {
},
},
{
- statement: "SET default_storage_engine=CSV",
- want: []advisor.Advice{
+ Statement: "SET default_storage_engine=CSV",
+ Want: []advisor.Advice{
{
Status: advisor.Error,
Code: common.NotInnoDBEngine,
@@ -87,9 +87,9 @@ func TestUseInnoDB(t *testing.T) {
},
},
}
- runSchemaReviewRuleTests(t, tests, &UseInnoDBAdvisor{}, &advisor.SchemaReviewRule{
+ advisor.RunSchemaReviewRuleTests(t, tests, &UseInnoDBAdvisor{}, &advisor.SchemaReviewRule{
Type: advisor.SchemaRuleMySQLEngine,
Level: advisor.SchemaRuleLevelError,
Payload: "",
- }, &MockCatalogService{})
+ }, &advisor.MockCatalogService{})
}
diff --git a/plugin/advisor/pg/advisor_syntax.go b/plugin/advisor/pg/advisor_syntax.go
new file mode 100644
index 0000000000..dca4c3e006
--- /dev/null
+++ b/plugin/advisor/pg/advisor_syntax.go
@@ -0,0 +1,35 @@
+package pg
+
+import (
+ "github.com/bytebase/bytebase/common"
+ "github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/db"
+)
+
+var (
+ _ advisor.Advisor = (*SyntaxAdvisor)(nil)
+)
+
+func init() {
+ advisor.Register(db.Postgres, advisor.PostgreSQLSyntax, &SyntaxAdvisor{})
+}
+
+// SyntaxAdvisor is the advisor for checking syntax.
+type SyntaxAdvisor struct {
+}
+
+// Check parses the given statement and checks for errors.
+func (adv *SyntaxAdvisor) Check(ctx advisor.Context, statement string) ([]advisor.Advice, error) {
+ if _, errAdvice := parseStatement(statement); errAdvice != nil {
+ return errAdvice, nil
+ }
+
+ return []advisor.Advice{
+ {
+ Status: advisor.Success,
+ Code: common.Ok,
+ Title: "Syntax OK",
+ Content: "OK",
+ },
+ }, nil
+}
diff --git a/plugin/advisor/pg/advisor_syntax_test.go b/plugin/advisor/pg/advisor_syntax_test.go
new file mode 100644
index 0000000000..df511fe3ac
--- /dev/null
+++ b/plugin/advisor/pg/advisor_syntax_test.go
@@ -0,0 +1,45 @@
+package pg
+
+import (
+ "testing"
+
+ "github.com/bmizerany/assert"
+ "github.com/bytebase/bytebase/common"
+ "github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/stretchr/testify/require"
+)
+
+func TestPostgreSQLSyntax(t *testing.T) {
+ tests := []advisor.TestCase{
+ {
+ Statement: "CREATE TABLE book(id int);",
+ Want: []advisor.Advice{
+ {
+ Status: advisor.Success,
+ Code: common.Ok,
+ Title: "Syntax OK",
+ Content: "OK",
+ },
+ },
+ },
+ {
+ Statement: "CREATE TABLE book(id int) ENGINE=INNODB;",
+ Want: []advisor.Advice{
+ {
+ Status: advisor.Error,
+ Code: common.DbStatementSyntaxError,
+ Title: "Syntax error",
+ Content: "at or near \"engine\": syntax error",
+ },
+ },
+ },
+ }
+
+ adv := &SyntaxAdvisor{}
+
+ for _, tc := range tests {
+ adviceList, err := adv.Check(advisor.Context{}, tc.Statement)
+ require.NoError(t, err)
+ assert.Equal(t, tc.Want, adviceList)
+ }
+}
diff --git a/plugin/advisor/pg/parser.go b/plugin/advisor/pg/parser.go
new file mode 100644
index 0000000000..9611bdcfb3
--- /dev/null
+++ b/plugin/advisor/pg/parser.go
@@ -0,0 +1,22 @@
+package pg
+
+import (
+ "github.com/auxten/postgresql-parser/pkg/sql/parser"
+ "github.com/bytebase/bytebase/common"
+ "github.com/bytebase/bytebase/plugin/advisor"
+)
+
+func parseStatement(statement string) (parser.Statements, []advisor.Advice) {
+ stmts, err := parser.Parse(statement)
+ if err != nil {
+ return nil, []advisor.Advice{
+ {
+ Status: advisor.Error,
+ Code: common.DbStatementSyntaxError,
+ Title: advisor.SyntaxErrorTitle,
+ Content: err.Error(),
+ },
+ }
+ }
+ return stmts, nil
+}
diff --git a/plugin/advisor/mysql/utils_for_test.go b/plugin/advisor/utils_for_tests.go
similarity index 58%
rename from plugin/advisor/mysql/utils_for_test.go
rename to plugin/advisor/utils_for_tests.go
index 8683b30353..dc135733d4 100644
--- a/plugin/advisor/mysql/utils_for_test.go
+++ b/plugin/advisor/utils_for_tests.go
@@ -1,28 +1,33 @@
-package mysql
+package advisor
import (
"context"
"fmt"
"testing"
- "github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bmizerany/assert"
"github.com/bytebase/bytebase/plugin/catalog"
- "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
+// MockCatalogService is the mock catalog service for test.
type MockCatalogService struct{}
const (
+ // MockOldIndexName is the mock old index for test.
MockOldIndexName = "old_index"
- MockOldUKName = "old_uk"
- MockOldPKName = "PRIMARY"
+ // MockOldUKName is the mock old unique key for test.
+ MockOldUKName = "old_uk"
+ // MockOldPKName is the mock old foreign key for test.
+ MockOldPKName = "PRIMARY"
)
var (
+ // MockIndexColumnList is the mock index column list for test.
MockIndexColumnList = []string{"id", "name"}
)
+// FindIndex implements the catalog interface.
func (c *MockCatalogService) FindIndex(ctx context.Context, find *catalog.IndexFind) (*catalog.Index, error) {
switch find.IndexName {
case MockOldIndexName:
@@ -46,27 +51,29 @@ func (c *MockCatalogService) FindIndex(ctx context.Context, find *catalog.IndexF
return nil, fmt.Errorf("cannot find index for %v", find)
}
-type test struct {
- statement string
- want []advisor.Advice
+// TestCase is the data struct for test.
+type TestCase struct {
+ Statement string
+ Want []Advice
}
-func runSchemaReviewRuleTests(
+// RunSchemaReviewRuleTests helps to test the schema review rule.
+func RunSchemaReviewRuleTests(
t *testing.T,
- tests []test,
- adv advisor.Advisor,
- rule *advisor.SchemaReviewRule,
+ tests []TestCase,
+ adv Advisor,
+ rule *SchemaReviewRule,
catalog catalog.Catalog,
) {
- ctx := advisor.Context{
+ ctx := Context{
Charset: "",
Collation: "",
Rule: rule,
Catalog: catalog,
}
for _, tc := range tests {
- adviceList, err := adv.Check(ctx, tc.statement)
+ adviceList, err := adv.Check(ctx, tc.Statement)
require.NoError(t, err)
- assert.Equal(t, tc.want, adviceList)
+ assert.Equal(t, tc.Want, adviceList)
}
}
diff --git a/server/task.go b/server/task.go
index d53892155b..05a5562ae7 100644
--- a/server/task.go
+++ b/server/task.go
@@ -14,7 +14,7 @@ import (
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/common"
"github.com/bytebase/bytebase/common/log"
- "github.com/bytebase/bytebase/plugin/db"
+ "github.com/bytebase/bytebase/plugin/advisor"
)
var (
@@ -178,8 +178,7 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to create activity after updating task statement: %v", taskPatched.Name)).SetInternal(err)
}
- // For now, we supported MySQL and TiDB dialect check
- if taskPatched.Database.Instance.Engine == db.MySQL || taskPatched.Database.Instance.Engine == db.TiDB {
+ if advisor.IsSyntaxCheckSupported(taskPatched.Database.Instance.Engine) {
payload, err := json.Marshal(api.TaskCheckDatabaseStatementAdvisePayload{
Statement: *taskPatch.Statement,
DbType: taskPatched.Database.Instance.Engine,
@@ -204,11 +203,11 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {
zap.Error(err),
)
}
+ }
- if s.feature(api.FeatureSchemaReviewPolicy) {
- if err := s.triggerDatabaseStatementAdviseTask(ctx, *taskPatch.Statement, taskPatched); err != nil {
- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("failed to trigger database statement advise task, err: %w", err)).SetInternal(err)
- }
+ if s.feature(api.FeatureSchemaReviewPolicy) && advisor.IsSchemaReviewSupported(taskPatched.Database.Instance.Engine) {
+ if err := s.triggerDatabaseStatementAdviseTask(ctx, *taskPatch.Statement, taskPatched); err != nil {
+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("failed to trigger database statement advise task, err: %w", err)).SetInternal(err)
}
}
}
diff --git a/server/task_check_executor_statement_advisor_simple.go b/server/task_check_executor_statement_advisor_simple.go
index b0ee53b430..56cd75cc23 100644
--- a/server/task_check_executor_statement_advisor_simple.go
+++ b/server/task_check_executor_statement_advisor_simple.go
@@ -8,6 +8,7 @@ import (
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/common"
"github.com/bytebase/bytebase/plugin/advisor"
+ "github.com/bytebase/bytebase/plugin/db"
)
// NewTaskCheckStatementAdvisorSimpleExecutor creates a task check statement simple advisor executor.
@@ -21,17 +22,24 @@ type TaskCheckStatementAdvisorSimpleExecutor struct {
// Run will run the task check statement advisor executor once.
func (exec *TaskCheckStatementAdvisorSimpleExecutor) Run(ctx context.Context, server *Server, taskCheckRun *api.TaskCheckRun) (result []api.TaskCheckResult, err error) {
+ payload := &api.TaskCheckDatabaseStatementAdvisePayload{}
+ if err := json.Unmarshal([]byte(taskCheckRun.Payload), payload); err != nil {
+ return nil, common.Errorf(common.Invalid, fmt.Errorf("invalid check statement advise payload: %w", err))
+ }
+
var advisorType advisor.Type
switch taskCheckRun.Type {
case api.TaskCheckDatabaseStatementFakeAdvise:
advisorType = advisor.Fake
case api.TaskCheckDatabaseStatementSyntax:
- advisorType = advisor.MySQLSyntax
- }
-
- payload := &api.TaskCheckDatabaseStatementAdvisePayload{}
- if err := json.Unmarshal([]byte(taskCheckRun.Payload), payload); err != nil {
- return nil, common.Errorf(common.Invalid, fmt.Errorf("invalid check statement advise payload: %w", err))
+ switch payload.DbType {
+ case db.MySQL, db.TiDB:
+ advisorType = advisor.MySQLSyntax
+ case db.Postgres:
+ advisorType = advisor.PostgreSQLSyntax
+ default:
+ return nil, common.Errorf(common.Invalid, fmt.Errorf("invalid database type: %s for syntax statement advisor", payload.DbType))
+ }
}
adviceList, err := advisor.Check(
diff --git a/server/task_check_scheduler.go b/server/task_check_scheduler.go
index e1537fe737..f40daae010 100644
--- a/server/task_check_scheduler.go
+++ b/server/task_check_scheduler.go
@@ -10,7 +10,7 @@ import (
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/common"
"github.com/bytebase/bytebase/common/log"
- "github.com/bytebase/bytebase/plugin/db"
+ "github.com/bytebase/bytebase/plugin/advisor"
"go.uber.org/zap"
)
@@ -293,8 +293,7 @@ func (s *TaskCheckScheduler) ScheduleCheckIfNeeded(ctx context.Context, task *ap
return nil, err
}
- // For now we only supported MySQL dialect syntax and compatibility check
- if database.Instance.Engine == db.MySQL || database.Instance.Engine == db.TiDB {
+ if advisor.IsSyntaxCheckSupported(database.Instance.Engine) {
payload, err := json.Marshal(api.TaskCheckDatabaseStatementAdvisePayload{
Statement: statement,
DbType: database.Instance.Engine,
@@ -316,9 +315,7 @@ func (s *TaskCheckScheduler) ScheduleCheckIfNeeded(ctx context.Context, task *ap
}
}
- if s.server.feature(api.FeatureSchemaReviewPolicy) &&
- // For now we only supported MySQL dialect schema review check.
- (database.Instance.Engine == db.MySQL || database.Instance.Engine == db.TiDB) {
+ if s.server.feature(api.FeatureSchemaReviewPolicy) && advisor.IsSchemaReviewSupported(database.Instance.Engine) {
policyID, err := s.server.store.GetSchemaReviewPolicyIDByEnvID(ctx, task.Instance.EnvironmentID)
if err != nil {
return nil, fmt.Errorf("failed to get schema review policy ID for task: %v, in environment: %v, err: %w", task.Name, task.Instance.EnvironmentID, err)
diff --git a/server/task_scheduler.go b/server/task_scheduler.go
index 95a4f83e4d..e65012ca79 100644
--- a/server/task_scheduler.go
+++ b/server/task_scheduler.go
@@ -11,7 +11,7 @@ import (
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/common"
"github.com/bytebase/bytebase/common/log"
- "github.com/bytebase/bytebase/plugin/db"
+ "github.com/bytebase/bytebase/plugin/advisor"
"go.uber.org/zap"
)
@@ -277,8 +277,7 @@ func (s *TaskScheduler) ScheduleIfNeeded(ctx context.Context, task *api.Task) (*
if instance == nil {
return nil, fmt.Errorf("instance ID not found %v", task.InstanceID)
}
- // For now we only supported MySQL dialect syntax and compatibility check
- if instance.Engine == db.MySQL || instance.Engine == db.TiDB {
+ if advisor.IsSyntaxCheckSupported(instance.Engine) {
pass, err = s.server.passCheck(ctx, s.server, task, api.TaskCheckDatabaseStatementSyntax)
if err != nil {
return nil, err
@@ -286,15 +285,15 @@ func (s *TaskScheduler) ScheduleIfNeeded(ctx context.Context, task *api.Task) (*
if !pass {
return task, nil
}
+ }
- if s.server.feature(api.FeatureSchemaReviewPolicy) {
- pass, err = s.server.passCheck(ctx, s.server, task, api.TaskCheckDatabaseStatementAdvise)
- if err != nil {
- return nil, err
- }
- if !pass {
- return task, nil
- }
+ if s.server.feature(api.FeatureSchemaReviewPolicy) && advisor.IsSchemaReviewSupported(instance.Engine) {
+ pass, err = s.server.passCheck(ctx, s.server, task, api.TaskCheckDatabaseStatementAdvise)
+ if err != nil {
+ return nil, err
+ }
+ if !pass {
+ return task, nil
}
}
}