mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
fixed issue #5094 , support function unique index
This commit is contained in:
@@ -327,4 +327,17 @@ public class FastsqlSchemaTest {
|
||||
System.out.println(data.toString());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test_function_index () throws Throwable {
|
||||
SchemaRepository repository = new SchemaRepository(JdbcConstants.MYSQL);
|
||||
repository.setDefaultSchema("test");
|
||||
String sql = "CREATE TABLE test1 (\n" + " id INT AUTO_INCREMENT PRIMARY KEY,\n"
|
||||
+ " owner_id INT NOT NULL,\n" + " code VARCHAR(100) NOT NULL,\n"
|
||||
+ " UNIQUE KEY uk_owner_id_upper_code (owner_id, (upper(code)))\n" + ");";
|
||||
repository.console(sql);
|
||||
SchemaObject table = repository.findTable("test1");
|
||||
Assert.assertTrue(table != null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@ import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.repository.SchemaObject;
|
||||
import com.alibaba.druid.sql.repository.SchemaRepository;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.junit.Assert;
|
||||
@@ -109,4 +112,26 @@ public class MemoryTableMeta_DDL_Test {
|
||||
System.out.println(sourceMeta.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_function_index () throws Throwable {
|
||||
MemoryTableMeta memoryTableMeta = new MemoryTableMeta();
|
||||
URL url = Thread.currentThread().getContextClassLoader().getResource("dummy.txt");
|
||||
File dummyFile = new File(url.getFile());
|
||||
File create = new File(dummyFile.getParent() + "/ddl", "ddl_create_function_index.sql");
|
||||
String sql = StringUtils.join(IOUtils.readLines(new FileInputStream(create)), "\n");
|
||||
memoryTableMeta.apply(null, "test", sql, null);
|
||||
|
||||
List<String> tableNames = new ArrayList<>();
|
||||
for (Schema schema : memoryTableMeta.getRepository().getSchemas()) {
|
||||
tableNames.addAll(schema.showTables());
|
||||
}
|
||||
|
||||
for (String table : tableNames) {
|
||||
TableMeta sourceMeta = memoryTableMeta.find("test", table);
|
||||
TableMeta.FieldMeta field = sourceMeta.getFieldMetaByName("code");
|
||||
System.out.println(sourceMeta.toString());
|
||||
Assert.assertTrue(field.isUnique());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
CREATE TABLE function_index_test (
|
||||
Reference in New Issue
Block a user