mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
fixed issue #639 , support rename
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package com.alibaba.otter.canal.parse.inbound.mysql.tsdb;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.alibaba.fastsql.sql.repository.SchemaObject;
|
||||
import com.alibaba.fastsql.sql.repository.SchemaRepository;
|
||||
import com.alibaba.fastsql.util.JdbcConstants;
|
||||
|
||||
/**
|
||||
* @author agapple 2018年6月7日 下午5:36:13
|
||||
* @since 3.1.9
|
||||
*/
|
||||
public class FastsqlSchemaTest {
|
||||
|
||||
@Test
|
||||
public void testSimple() throws FileNotFoundException, IOException {
|
||||
SchemaRepository repository = new SchemaRepository(JdbcConstants.MYSQL);
|
||||
String sql = "create table yushitai_test.card_record ( id bigint auto_increment) auto_increment=256 "
|
||||
+ "; alter table yushitai_test.card_record add column customization_id bigint unsigned NOT NULL COMMENT 'TEST' ;"
|
||||
+ "; rename table yushitai_test.card_record to yushitai_test._card_record_del;";
|
||||
repository.console(sql);
|
||||
|
||||
repository.setDefaultSchema("yushitai_test");
|
||||
SchemaObject table = repository.findTable("_card_record_del");
|
||||
System.out.println(table.getStatement().toString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.alibaba.otter.canal.parse.inbound.mysql.tsdb;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.alibaba.otter.canal.parse.inbound.TableMeta;
|
||||
|
||||
/**
|
||||
* @author agapple 2017年8月1日 下午7:15:54
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "/tsdb/mysql-tsdb.xml" })
|
||||
public class MemoryTableMeta_DDL_Test {
|
||||
|
||||
@Test
|
||||
public void test1() 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_test1.sql");
|
||||
String sql = StringUtils.join(IOUtils.readLines(new FileInputStream(create)), "\n");
|
||||
memoryTableMeta.apply(null, "test", sql, null);
|
||||
|
||||
TableMeta meta = memoryTableMeta.find("yushitai_test", "card_record");
|
||||
System.out.println(meta);
|
||||
Assert.assertNotNull(meta.getFieldMetaByName("customization_id"));
|
||||
|
||||
meta = memoryTableMeta.find("yushitai_test", "_card_record_gho");
|
||||
Assert.assertNull(meta);
|
||||
}
|
||||
}
|
||||
21
parse/src/test/resources/ddl/ddl_test1.sql
Normal file
21
parse/src/test/resources/ddl/ddl_test1.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
create table yushitai_test.card_record (
|
||||
id bigint auto_increment,
|
||||
last_update timestamp not null DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
hint varchar(64) charset ascii not null,
|
||||
value varchar(255) charset ascii not null,
|
||||
primary key(id),
|
||||
unique key hint_uidx(hint)
|
||||
) auto_increment=256 ;
|
||||
|
||||
DROP TABLE IF EXISTS _card_record_gho /* generated by server */ ;
|
||||
DROP TABLE IF EXISTS _card_record_del /* generated by server */ ;
|
||||
|
||||
create /* gh-ost */ table yushitai_test._card_record_gho like yushitai_test.card_record ;
|
||||
alter /* gh-ost */ table yushitai_test._card_record_gho add column customization_id bigint unsigned NOT NULL COMMENT 'TEST' ;
|
||||
|
||||
create /* gh-ost */ table yushitai_test._card_record_del (
|
||||
id int auto_increment primary key
|
||||
) engine=InnoDB comment='ghost-cut-over-sentry' ;
|
||||
|
||||
DROP TABLE IF EXISTS _card_record_del /* generated by server */ ;
|
||||
rename /* gh-ost */ table yushitai_test.card_record to yushitai_test._card_record_del, yushitai_test._card_record_gho to yushitai_test.card_record;
|
||||
Reference in New Issue
Block a user