-
Notifications
You must be signed in to change notification settings - Fork 110
Support multi-column foreign keys in SQL #1494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 24 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
3bfb1f0
Add end-to-end tests for composite primary key support in Postgres in…
jgaleotti 1534a09
Add end-to-end tests for multi-column foreign key support in Postgres…
jgaleotti f2e7b99
DbInfoExtractor extracts the target columns in the foreign keys
jgaleotti ed8453d
Add tests for composite foreign key support in Postgres and MySQL dat…
jgaleotti c072298
Refactor and consolidate composite foreign key tests across databases…
jgaleotti 5dc9ba2
Merge remote-tracking branch 'origin/master' into sql-multi-column-fo…
jgaleotti a32b7f8
Disable `PostgresMultiColumnFKEMTest` until supporting multiple colum…
jgaleotti d6c1e9f
bugfix: Unique constraint evaluation correctly handles the presene of…
jgaleotti b70e865
Refactor SQL foreign key handling to store target columns.
jgaleotti 0b21414
Add test for multi-column foreign key gene creation
jgaleotti 7483daf
Add test for implicit composite foreign keys and for multiple foreign…
jgaleotti b5ccd1d
removed deprecated constructor
jgaleotti b26ddda
`isValidForeignKeys` checks for constraints accross multiple columns
jgaleotti d6504a5
Merge remote-tracking branch 'origin/master' into sql-multi-column-fo…
jgaleotti d2f2e1c
Add other source columns in foreign key for multiple column foreign k…
jgaleotti cc21cab
Update tests to include `otherSourceColumnsInCompositeFK` in `SqlFore…
jgaleotti d750291
`SqlForeignKeyGene.isReferenceToNonPrintable()` and `getValueAsPrinta…
jgaleotti e369123
Add support for CASCADE in TRUNCATE for PostgreSQL / handling of mult…
jgaleotti 4fda1fd
isValidForeignKeys() consider the case where a foreign key column is …
jgaleotti 7d89618
Merge remote-tracking branch 'origin/master' into sql-multi-column-fo…
jgaleotti 30fbdf6
Merge remote-tracking branch 'origin/master' into sql-multi-column-fo…
jgaleotti 20de60c
Merge remote-tracking branch 'origin/master' into sql-multi-column-fo…
jgaleotti aea69bb
Fix `getEnterpriseTopGroups` call in `SqlPrimaryKeyGeneTest` to inclu…
jgaleotti 9a97d53
Merge remote-tracking branch 'origin/master' into sql-multi-column-fo…
jgaleotti d211090
Merge remote-tracking branch 'origin/master' into sql-multi-column-fo…
jgaleotti d219aaf
Clarify documentation of `uniqueId` in both `SqlPrimaryKeyGene` and `…
jgaleotti 5a31b86
Change `otherSourceColumnsInCompositeFK` from `List` to `Set`.
jgaleotti 14c85ba
Merge remote-tracking branch 'origin/master' into sql-multi-column-fo…
jgaleotti 004f98a
Refactor handling of composite foreign keys to improve clarity and us…
jgaleotti 368d889
Clarify `ForeignKey.sourceColumns` documentation.
jgaleotti a75b4d1
Refactor: replace `seeTopGenes().flatMap()` with `seeAllGenes()` for …
jgaleotti 3f7072f
Refactor: simplify creation of `previousPkMap` using `associateBy`
jgaleotti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
.../org/evomaster/client/java/controller/internal/db/sql/mysql/MySQLSchemaExtractorTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
client-java/sql/src/test/java/org/evomaster/client/java/sql/DbInfoExtractorH2Test.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package org.evomaster.client.java.sql; | ||
|
|
||
| import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType; | ||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
|
|
||
| import java.sql.Connection; | ||
| import java.sql.DriverManager; | ||
|
|
||
|
|
||
| public class DbInfoExtractorH2Test extends DbInfoExtractorTestBase { | ||
|
|
||
| private static Connection connection; | ||
|
|
||
| @BeforeAll | ||
| public static void initClass() throws Exception { | ||
| connection = DriverManager.getConnection("jdbc:h2:mem:db_test", "sa", ""); | ||
| } | ||
|
|
||
| @AfterAll | ||
| public static void afterClass() throws Exception { | ||
| connection.close(); | ||
| } | ||
|
|
||
| @BeforeEach | ||
| public void initTest() throws Exception { | ||
| //custom H2 command | ||
| SqlScriptRunner.execCommand(connection, "DROP ALL OBJECTS;"); | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| protected DatabaseType getDbType() { | ||
| return DatabaseType.H2; | ||
| } | ||
|
|
||
| @Override | ||
| protected Connection getConnection() { | ||
| return connection; | ||
| } | ||
| } |
75 changes: 75 additions & 0 deletions
75
client-java/sql/src/test/java/org/evomaster/client/java/sql/DbInfoExtractorMySQLTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package org.evomaster.client.java.sql; | ||
|
|
||
| import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType; | ||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.testcontainers.containers.GenericContainer; | ||
|
|
||
| import java.sql.Connection; | ||
| import java.sql.DriverManager; | ||
| import java.sql.SQLException; | ||
| import java.text.SimpleDateFormat; | ||
| import java.util.Date; | ||
| import java.util.HashMap; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| public class DbInfoExtractorMySQLTest extends DbInfoExtractorTestBase { | ||
|
|
||
| private static final String DB_NAME = "test"; | ||
|
|
||
| private static final int PORT = 3306; | ||
|
|
||
| private static final String MYSQL_VERSION = "8.0.27"; | ||
|
|
||
| public static final GenericContainer mysql = new GenericContainer("mysql:" + MYSQL_VERSION) | ||
| .withEnv(new HashMap<String, String>(){{ | ||
| put("MYSQL_ROOT_PASSWORD", "root"); | ||
| put("MYSQL_DATABASE", DB_NAME); | ||
| put("MYSQL_USER", "test"); | ||
| put("MYSQL_PASSWORD", "test"); | ||
| }}) | ||
| .withExposedPorts(PORT); | ||
|
|
||
| private static Connection connection; | ||
|
|
||
| @BeforeAll | ||
| public static void initClass() throws Exception { | ||
|
|
||
| mysql.start(); | ||
|
|
||
| String host = mysql.getContainerIpAddress(); | ||
| int port = mysql.getMappedPort(PORT); | ||
| String url = "jdbc:mysql://"+host+":"+port+"/"+DB_NAME; | ||
|
|
||
| connection = DriverManager.getConnection(url, "test", "test"); | ||
|
|
||
| } | ||
|
|
||
| @AfterAll | ||
| public static void afterClass() throws Exception { | ||
| connection.close(); | ||
| mysql.stop(); | ||
| } | ||
|
|
||
| @AfterEach | ||
| public void afterTest() throws SQLException { | ||
| SqlScriptRunner.execCommand(connection, "DROP TABLE IF EXISTS example_table;"); | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| protected DatabaseType getDbType() { | ||
| return DatabaseType.MYSQL; | ||
| } | ||
|
|
||
| @Override | ||
| protected Connection getConnection() { | ||
| return connection; | ||
| } | ||
|
|
||
|
|
||
| } |
63 changes: 63 additions & 0 deletions
63
client-java/sql/src/test/java/org/evomaster/client/java/sql/DbInfoExtractorPostgresTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package org.evomaster.client.java.sql; | ||
|
|
||
| import org.evomaster.client.java.controller.api.dto.database.schema.DatabaseType; | ||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.testcontainers.containers.GenericContainer; | ||
|
|
||
| import java.sql.Connection; | ||
| import java.sql.DriverManager; | ||
| import java.util.Collections; | ||
|
|
||
| public class DbInfoExtractorPostgresTest extends DbInfoExtractorTestBase { | ||
|
|
||
| private static final String POSTGRES_VERSION = "14"; | ||
|
|
||
| private static final GenericContainer<?> postgres = new GenericContainer("postgres:" + POSTGRES_VERSION) | ||
| .withExposedPorts(5432) | ||
| .withTmpFs(Collections.singletonMap("/var/lib/postgresql/data", "rw")) | ||
| .withEnv("POSTGRES_HOST_AUTH_METHOD","trust"); | ||
|
|
||
| private static Connection connection; | ||
|
|
||
| @BeforeAll | ||
| public static void initClass() throws Exception{ | ||
| postgres.start(); | ||
| String host = postgres.getHost(); | ||
| int port = postgres.getMappedPort(5432); | ||
| String url = "jdbc:postgresql://"+host+":"+port+"/postgres"; | ||
|
|
||
| connection = DriverManager.getConnection(url, "postgres", ""); | ||
| } | ||
|
|
||
| @AfterAll | ||
| public static void afterClass() throws Exception{ | ||
| connection.close(); | ||
| postgres.stop(); | ||
| } | ||
|
|
||
| @BeforeEach | ||
| public void initTest() throws Exception { | ||
| /* | ||
| see: | ||
| https://stackoverflow.com/questions/3327312/how-can-i-drop-all-the-tables-in-a-postgresql-database | ||
| */ | ||
| SqlScriptRunner.execCommand(connection, "DROP SCHEMA public CASCADE;"); | ||
| SqlScriptRunner.execCommand(connection, "CREATE SCHEMA public;"); | ||
| SqlScriptRunner.execCommand(connection, "GRANT ALL ON SCHEMA public TO postgres;"); | ||
| SqlScriptRunner.execCommand(connection, "GRANT ALL ON SCHEMA public TO public;"); | ||
| } | ||
|
|
||
| @Override | ||
| protected Connection getConnection(){ | ||
| return connection; | ||
| } | ||
|
|
||
| @Override | ||
| protected DatabaseType getDbType() { | ||
| return DatabaseType.POSTGRES; | ||
| } | ||
|
|
||
|
|
||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx. this fix seems not related to PK/FK, isn't it? for future, it would had been better to have in a separate PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree. Unfortunately it was blocking my progress, so I pushed as a change here. But next time I will try to have a separate small PR.