Skip to content

Commit

Permalink
fix GetConstraints for MySQL 5.7
Browse files Browse the repository at this point in the history
MySQL 5.7 doesn't support SELECT ... WHERE ... without a FROM clause, which
causes the introspection_scripts/mysql_constraints.sql script to fail.

Fixed by adding a FROM information_schema.table_constraints to the first part
of the query.
  • Loading branch information
bokwoon95 committed Apr 9, 2023
1 parent 3936433 commit b5386de
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions ddl/START_HERE.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ If you have docker, you can use the docker-compose.yml (run `docker-compose up`)
# docker-compose up -d
POSTGRES_URL='postgres://user1:Hunter2!@localhost:5456/sakila?sslmode=disable'
MYSQL_URL='root:Hunter2!@tcp(localhost:3330)/sakila?multiStatements=true&parseTime=true'
MYSQL5_URL='root:Hunter2!@tcp(localhost:3320)/sakila?multiStatements=true&parseTime=true'
MARIADB_URL='root:Hunter2!@tcp(localhost:3340)/sakila?multiStatements=true&parseTime=true'
SQLSERVER_URL='sqlserver://sa:Hunter2!@localhost:1447'
```
Expand Down
10 changes: 10 additions & 0 deletions ddl/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func TestMySQL(t *testing.T) {
if err != nil {
t.Fatal(testutil.Callers(), err)
}

dbi := NewDatabaseIntrospector(dialect, db)
version, err := dbi.GetVersion()
if err != nil {
Expand All @@ -92,6 +93,15 @@ func TestMySQL(t *testing.T) {
if strings.Contains(version, "MariaDB") {
t.Skip("skipping integration tests for MariaDB because it doesn't support indexed expressions (which are present in the mysql migration scripts)")
}

versionNums, err := dbi.GetVersionNums()
if err != nil {
t.Fatal(testutil.Callers(), err)
}
if versionNums.LowerThan(8) {
t.Skip(fmt.Sprintf("skipping integration tests for MySQL %d because the tests are only designed for MySQL 8 and above", versionNums[0]))
}

t.Parallel()
testMigrateIntrospect(t, dialect, driver, *mysqlDSN)
testAutomigrate(t, dialect, *mysqlDSN,
Expand Down
2 changes: 2 additions & 0 deletions ddl/introspection_scripts/mysql_constraints.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ SELECT
,'' AS delete_rule
,'' AS match_option
,'' AS check_expr
FROM
information_schema.table_constraints
WHERE
FALSE
{{- if .IncludeConstraintType "PRIMARY KEY" }}
Expand Down
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ services:
MYSQL_DATABASE: 'sakila'
platform: 'linux/amd64'

mysql5:
container_name: 'mysql5_sakila'
image: 'mysql:5.7'
ports:
- '3320:3306'
volumes:
- 'mysql5_data:/var/lib/mysql'
environment:
MYSQL_ROOT_PASSWORD: 'Hunter2!'
MYSQL_USER: 'user1'
MYSQL_PASSWORD: 'Hunter2!'
MYSQL_DATABASE: 'sakila'
platform: 'linux/amd64'

mariadb:
container_name: 'mariadb_sakila'
image: 'mariadb'
Expand Down Expand Up @@ -70,6 +84,7 @@ services:
volumes:
postgres_data:
mysql_data:
mysql5_data:
mariadb_data:
sqlserver_data:
# oracle_data:

0 comments on commit b5386de

Please sign in to comment.