fixed fastsql upgrade

This commit is contained in:
七锋
2018-10-17 15:43:26 +08:00
parent 5eb67990ca
commit 5d55c7ac00
4 changed files with 32 additions and 5 deletions
@@ -18,13 +18,17 @@ public class FastsqlSchemaTest {
@Test @Test
public void testSimple() throws FileNotFoundException, IOException { public void testSimple() throws FileNotFoundException, IOException {
SchemaRepository repository = new SchemaRepository(JdbcConstants.MYSQL); SchemaRepository repository = new SchemaRepository(JdbcConstants.MYSQL);
String sql = "create table yushitai_test.card_record ( id bigint auto_increment) auto_increment=256 " String sql = "create table yushitai_test.card_record ( id bigint auto_increment, name varchar(32) DEFAULT NULL) auto_increment=256 "
+ "; alter table yushitai_test.card_record add column customization_id bigint unsigned NOT NULL COMMENT 'TEST' ;" + "alter table yushitai_test.card_record add index index_name(name) ;"
+ "; rename table yushitai_test.card_record to yushitai_test._card_record_del;"; + "alter table yushitai_test.card_record add index index_name(name) ;"
+ "alter table yushitai_test.card_record add Constraint pk_id PRIMARY KEY (id);"
+ "alter table yushitai_test.card_record add Constraint pk_id PRIMARY KEY (id);"
+ "alter table yushitai_test.card_record add Constraint UNIQUE index uk_name(name);"
+ "alter table yushitai_test.card_record add Constraint UNIQUE index uk_name(name);";
repository.console(sql); repository.console(sql);
repository.setDefaultSchema("yushitai_test"); repository.setDefaultSchema("yushitai_test");
SchemaObject table = repository.findTable("_card_record_del"); SchemaObject table = repository.findTable("card_record");
System.out.println(table.getStatement().toString()); System.out.println(table.getStatement().toString());
} }
} }
@@ -37,4 +37,19 @@ public class MemoryTableMeta_DDL_Test {
meta = memoryTableMeta.find("yushitai_test", "_card_record_gho"); meta = memoryTableMeta.find("yushitai_test", "_card_record_gho");
Assert.assertNull(meta); Assert.assertNull(meta);
} }
@Test
public void test2() 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_test2.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.assertEquals(meta.getFieldMetaByName("id").isKey(), true);
Assert.assertEquals(meta.getFieldMetaByName("name").isUnique(), true);
}
} }
@@ -0,0 +1,8 @@
CREATE TABLE yushitai_test.card_record (
id bigint AUTO_INCREMENT,
name varchar(32) DEFAULT NULL,
alias varchar(32) DEFAULT NULL,
INDEX index_name(name),
CONSTRAINT pk_id PRIMARY KEY (id),
UNIQUE uk_name (name,alias)
) AUTO_INCREMENT = 256
+1 -1
View File
@@ -247,7 +247,7 @@
<dependency> <dependency>
<groupId>com.alibaba.fastsql</groupId> <groupId>com.alibaba.fastsql</groupId>
<artifactId>fastsql</artifactId> <artifactId>fastsql</artifactId>
<version>2.0.0_preview_617</version> <version>2.0.0_preview_630</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>