forked from loafle/openapi-generator-original
* [Mysql Schema] Add new generator * [Mysql Schema] Fix default definition * [Mysql Schema] Add defaultDatabaseName option * [Mysql Schema] Add jsonDataTypeEnabled option * [Mysql Schema] Add samples
This commit is contained in:
parent
755dfe53de
commit
e4b5f50515
32
bin/mysql-schema-petstore.sh
Normal file
32
bin/mysql-schema-petstore.sh
Normal file
@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn -B clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/mysql-schema -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g mysql-schema -o samples/schema/petstore/mysql $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
32
bin/security/mysql-schema-petstore.sh
Normal file
32
bin/security/mysql-schema-petstore.sh
Normal file
@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/mysql-schema -i modules/openapi-generator/src/test/resources/2_0/petstore-security-test.yaml -g mysql-schema -o samples/schema/petstore-security-test/mysql $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
@ -18,6 +18,7 @@ sleep 5
|
||||
./bin/kotlin-client-string.sh > /dev/null 2>&1
|
||||
./bin/kotlin-client-threetenbp.sh > /dev/null 2>&1
|
||||
./bin/kotlin-server-petstore.sh > /dev/null 2>&1
|
||||
./bin/mysql-schema-petstore.sh > /dev/null 2>&1
|
||||
./bin/php-petstore.sh > /dev/null 2>&1
|
||||
./bin/php-silex-petstore-server.sh > /dev/null 2>&1
|
||||
./bin/php-symfony-petstore.sh > /dev/null 2>&1
|
||||
|
@ -25,7 +25,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public enum CodegenType {
|
||||
CLIENT, SERVER, DOCUMENTATION, CONFIG, OTHER;
|
||||
CLIENT, SERVER, DOCUMENTATION, SCHEMA, CONFIG, OTHER;
|
||||
|
||||
private static Map<String, CodegenType> names = new HashMap<String, CodegenType>();
|
||||
|
||||
@ -49,6 +49,7 @@ public enum CodegenType {
|
||||
names.put("client", CLIENT);
|
||||
names.put("server", SERVER);
|
||||
names.put("documentation", DOCUMENTATION);
|
||||
names.put("schema", SCHEMA);
|
||||
names.put("other", OTHER);
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -53,6 +53,7 @@ org.openapitools.codegen.languages.JavascriptFlowtypedClientCodegen
|
||||
org.openapitools.codegen.languages.JavascriptClosureAngularClientCodegen
|
||||
org.openapitools.codegen.languages.JMeterClientCodegen
|
||||
org.openapitools.codegen.languages.LuaClientCodegen
|
||||
org.openapitools.codegen.languages.MysqlSchemaCodegen
|
||||
org.openapitools.codegen.languages.NodeJSServerCodegen
|
||||
org.openapitools.codegen.languages.ObjcClientCodegen
|
||||
org.openapitools.codegen.languages.OpenAPIGenerator
|
||||
|
@ -0,0 +1,48 @@
|
||||
# MySQL Schema Codegen
|
||||
|
||||
Main goal of this generator is to provide database structure file almost identical you usually generate with:
|
||||
- PHPMyAdmin (Export structure only, SQL syntax)
|
||||
- Adminer
|
||||
- `mysqldump` function
|
||||
|
||||
[MySQL documentation](https://dev.mysql.com/doc/)
|
||||
|
||||
## Requirements
|
||||
- MySQL Server ^5.7.8 (`JSON` column type added)
|
||||
|
||||
## Openapi Data Type to MySQL Data Type mapping
|
||||
|
||||
| Openapi Data Type | Openapi Data Format | Dependent properties | MySQL Data Types | Default MySQL Data Type |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| `integer` | `int32` | `minimum` / `maximum` / `minimumExclusive` / `maximumExclusive` | `TINYINT` / `SMALLINT` / `MEDIUMINT`/ `INT` / `BIGINT` | `INT` |
|
||||
| `integer` | `int64` | `minimum` / `maximum` / `minimumExclusive` / `maximumExclusive` | `TINYINT` / `SMALLINT` / `MEDIUMINT` / `INT` / `BIGINT` | `BIGINT` |
|
||||
| `boolean` | | | `TINYINT` | `TINYINT` |
|
||||
| `number` | `float` | | `DECIMAL` | `DECIMAL` |
|
||||
| `number` | `double` | | `DECIMAL` | `DECIMAL` |
|
||||
| `string` | | `minLength` / `maxLength` | `CHAR` / `VARCHAR` / `TEXT` / `MEDIUMTEXT` / `LONGTEXT` | `TEXT` |
|
||||
| `string` | `byte` | | `TEXT` | `TEXT` |
|
||||
| `string` | `binary` | | `MEDIUMBLOB` | `MEDIUMBLOB` |
|
||||
| `file` | | | `MEDIUMBLOB` | `MEDIUMBLOB` |
|
||||
| `string` | `date` | | `DATE` | `DATE` |
|
||||
| `string` | `date-time` | | `DATETIME` | `DATETIME` |
|
||||
| `string` | `enum` | | `ENUM` | `ENUM` |
|
||||
| `array` | | | `JSON` | `JSON` |
|
||||
| `object` | | | `JSON` | `JSON` |
|
||||
| `\Model\User` (referenced definition) | | | `TEXT` | `TEXT` |
|
||||
|
||||
## How to use
|
||||
|
||||
Produced file(`mysql_schema.sql`) contains every table definition. Current implementation doesn't drop or modify existed tables, if you want rewrite whole schema make sure they're not presented.
|
||||
|
||||
### PHPMyAdmin
|
||||
|
||||
1. Choose **Import** tab from the home screen
|
||||
2. In section **File to import** click to **Choose File** and find generated `mysql_schema.sql`
|
||||
3. Make sure **Format** selector set to **SQL**
|
||||
4. Push **Go** button
|
||||
|
||||
### Adminer
|
||||
|
||||
1. Click **Import** link in left sidebar
|
||||
2. In **File upload** fieldset click to **Choose Files** and find generated `mysql_schema.sql`
|
||||
3. Push **Execute** button
|
@ -0,0 +1,45 @@
|
||||
/* SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; */
|
||||
/* SET AUTOCOMMIT = 0; */
|
||||
/* START TRANSACTION; */
|
||||
/* SET time_zone = "+00:00"; */
|
||||
{{#defaultDatabaseName}}
|
||||
--
|
||||
-- Database: `{{{defaultDatabaseName}}}`
|
||||
--
|
||||
CREATE DATABASE IF NOT EXISTS `{{{defaultDatabaseName}}}` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
{{/defaultDatabaseName}}
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
{{#models}}{{#model}}{{#hasVars}}{{^isArrayModel}}--
|
||||
-- Table structure{{#vendorExtensions}}{{#x-mysqlSchema}}{{#tableDefinition}} for table `{{tblName}}`{{/tableDefinition}}{{/x-mysqlSchema}}{{/vendorExtensions}} generated from model '{{classVarName}}'
|
||||
{{#description}}
|
||||
-- {{description}}
|
||||
{{/description}}
|
||||
--
|
||||
|
||||
{{#vendorExtensions}}
|
||||
{{#x-mysqlSchema}}
|
||||
{{#tableDefinition}}
|
||||
CREATE TABLE IF NOT EXISTS {{#defaultDatabaseName}}`{{{defaultDatabaseName}}}`.{{/defaultDatabaseName}}`{{tblName}}` (
|
||||
{{/tableDefinition}}
|
||||
{{/x-mysqlSchema}}
|
||||
{{/vendorExtensions}}
|
||||
{{#vars}}
|
||||
{{#vendorExtensions}}
|
||||
{{#x-mysqlSchema}}
|
||||
{{#columnDefinition}}
|
||||
`{{colName}}` {{colDataType}}{{#colDataTypeArguments}}{{#-first}}({{/-first}}{{#isString}}'{{/isString}}{{argumentValue}}{{#isString}}'{{/isString}}{{^-last}}, {{/-last}}{{#-last}}){{/-last}}{{/colDataTypeArguments}}{{#colUnsigned}} UNSIGNED{{/colUnsigned}}{{#colNotNull}} NOT NULL{{/colNotNull}}{{#colDefault}} DEFAULT {{#isString}}'{{defaultValue}}'{{/isString}}{{^isString}}{{defaultValue}}{{/isString}}{{/colDefault}}{{#colComment}} COMMENT '{{colComment}}'{{/colComment}}{{^-last}},{{/-last}}
|
||||
{{/columnDefinition}}
|
||||
{{/x-mysqlSchema}}
|
||||
{{/vendorExtensions}}
|
||||
{{/vars}}
|
||||
{{#vendorExtensions}}
|
||||
{{#x-mysqlSchema}}
|
||||
{{#tableDefinition}}
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci{{#tblComment}} COMMENT='{{tblComment}}'{{/tblComment}};
|
||||
{{/tableDefinition}}
|
||||
{{/x-mysqlSchema}}
|
||||
{{/vendorExtensions}}
|
||||
|
||||
{{/isArrayModel}}{{/hasVars}}{{/model}}{{/models}}
|
@ -0,0 +1,278 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen.mysql;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.openapitools.codegen.languages.MysqlSchemaCodegen;
|
||||
|
||||
public class MysqlSchemaCodegenTest {
|
||||
|
||||
@Test
|
||||
public void testGetMysqlMatchedIntegerDataType() {
|
||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(null, null, null), "INT");
|
||||
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(-128L, 127L, false), "TINYINT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(0L, 255L, true), "TINYINT");
|
||||
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(500L, 100L, null), "SMALLINT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(500L, 100L, true), "SMALLINT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(500L, 100L, false), "SMALLINT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(-32768L, 32767L, false), "SMALLINT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(0L, 65535L, true), "SMALLINT");
|
||||
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(-8388608L, 8388607L, false), "MEDIUMINT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(0L, 16777215L, true), "MEDIUMINT");
|
||||
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(-2147483648L, 2147483647L, false), "INT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(Long.parseLong(String.valueOf(Integer.MIN_VALUE)), Long.parseLong(String.valueOf(Integer.MAX_VALUE)), false), "INT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(0L, 4294967295L, true), "INT");
|
||||
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(-2147483649L, 2147483648L, false), "BIGINT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(0L, 4294967296L, true), "BIGINT");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMysqlMatchedStringDataType() {
|
||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(6, 6), "CHAR");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(0, 0), "CHAR");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(255, 255), "CHAR");
|
||||
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 100), "VARCHAR");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 255), "VARCHAR");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(50, 255), "VARCHAR");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, 20), "VARCHAR");
|
||||
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, null), "TEXT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, null), "TEXT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(255, null), "TEXT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 256), "TEXT");
|
||||
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(16777215, null), "MEDIUMTEXT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(16777215, 100), "MEDIUMTEXT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 16777215), "MEDIUMTEXT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, 16777215), "MEDIUMTEXT");
|
||||
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(16777216, null), "LONGTEXT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 16777216), "LONGTEXT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(16777216, 16777216), "LONGTEXT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, 16777216), "LONGTEXT");
|
||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, Integer.MAX_VALUE), "LONGTEXT");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToCodegenMysqlDataTypeArgument() {
|
||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||
String strArgument = "HelloWorld";
|
||||
HashMap<String, Object> strProp = codegen.toCodegenMysqlDataTypeArgument(strArgument, true);
|
||||
Assert.assertTrue((Boolean) strProp.get("isString"));
|
||||
Assert.assertTrue((Boolean) strProp.get("hasMore"));
|
||||
Assert.assertFalse((Boolean) strProp.get("isFloat"));
|
||||
Assert.assertFalse((Boolean) strProp.get("isInteger"));
|
||||
Assert.assertFalse((Boolean) strProp.get("isNumeric"));
|
||||
Assert.assertSame((String) strProp.get("argumentValue"), strArgument);
|
||||
|
||||
Integer intArgument = 10;
|
||||
HashMap<String, Object> intProp = codegen.toCodegenMysqlDataTypeArgument(intArgument, true);
|
||||
Assert.assertFalse((Boolean) intProp.get("isString"));
|
||||
Assert.assertTrue((Boolean) intProp.get("hasMore"));
|
||||
Assert.assertFalse((Boolean) intProp.get("isFloat"));
|
||||
Assert.assertTrue((Boolean) intProp.get("isInteger"));
|
||||
Assert.assertTrue((Boolean) intProp.get("isNumeric"));
|
||||
Assert.assertSame((Integer) intProp.get("argumentValue"), intArgument);
|
||||
|
||||
Double floatArgument = 3.14;
|
||||
HashMap<String, Object> floatProp = codegen.toCodegenMysqlDataTypeArgument(floatArgument, false);
|
||||
Assert.assertFalse((Boolean) floatProp.get("isString"));
|
||||
Assert.assertFalse((Boolean) floatProp.get("hasMore"));
|
||||
Assert.assertTrue((Boolean) floatProp.get("isFloat"));
|
||||
Assert.assertFalse((Boolean) floatProp.get("isInteger"));
|
||||
Assert.assertTrue((Boolean) floatProp.get("isNumeric"));
|
||||
Assert.assertSame((Double) floatProp.get("argumentValue"), floatArgument);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToCodegenMysqlDataTypeDefault() {
|
||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||
HashMap<String, Object> defaultMap = null;
|
||||
ArrayList<String> intFixture = new ArrayList<String>(Arrays.asList(
|
||||
"TINYINT", "SmallInt", "Mediumint", "INT", "bigint"
|
||||
));
|
||||
for(String intType : intFixture) {
|
||||
defaultMap = codegen.toCodegenMysqlDataTypeDefault("150", intType);
|
||||
Assert.assertTrue((Boolean) defaultMap.get("isNumeric"));
|
||||
Assert.assertFalse((Boolean) defaultMap.get("isString"));
|
||||
Assert.assertFalse((Boolean) defaultMap.get("isKeyword"));
|
||||
Assert.assertSame(defaultMap.get("defaultValue"), "150");
|
||||
}
|
||||
defaultMap = codegen.toCodegenMysqlDataTypeDefault("SERIAL DEFAULT VALUE", "TINYINT");
|
||||
Assert.assertFalse((Boolean) defaultMap.get("isNumeric"));
|
||||
Assert.assertFalse((Boolean) defaultMap.get("isString"));
|
||||
Assert.assertTrue((Boolean) defaultMap.get("isKeyword"));
|
||||
Assert.assertSame(defaultMap.get("defaultValue"), "SERIAL DEFAULT VALUE");
|
||||
|
||||
ArrayList<String> dateFixture = new ArrayList<String>(Arrays.asList(
|
||||
"Timestamp", "DateTime"
|
||||
));
|
||||
for(String dateType : dateFixture) {
|
||||
defaultMap = codegen.toCodegenMysqlDataTypeDefault("2018-08-12", dateType);
|
||||
Assert.assertFalse((Boolean) defaultMap.get("isNumeric"));
|
||||
Assert.assertTrue((Boolean) defaultMap.get("isString"));
|
||||
Assert.assertFalse((Boolean) defaultMap.get("isKeyword"));
|
||||
Assert.assertSame(defaultMap.get("defaultValue"), "2018-08-12");
|
||||
}
|
||||
defaultMap = codegen.toCodegenMysqlDataTypeDefault("CURRENT_TIMESTAMP", "Timestamp");
|
||||
Assert.assertFalse((Boolean) defaultMap.get("isNumeric"));
|
||||
Assert.assertFalse((Boolean) defaultMap.get("isString"));
|
||||
Assert.assertTrue((Boolean) defaultMap.get("isKeyword"));
|
||||
Assert.assertSame(defaultMap.get("defaultValue"), "CURRENT_TIMESTAMP");
|
||||
|
||||
ArrayList<String> restFixture = new ArrayList<String>(Arrays.asList(
|
||||
"VARCHAR", "CHAR", "ENUM", "UNKNOWN"
|
||||
));
|
||||
for(String restType : restFixture) {
|
||||
defaultMap = codegen.toCodegenMysqlDataTypeDefault("sometext", restType);
|
||||
Assert.assertFalse((Boolean) defaultMap.get("isNumeric"));
|
||||
Assert.assertTrue((Boolean) defaultMap.get("isString"));
|
||||
Assert.assertFalse((Boolean) defaultMap.get("isKeyword"));
|
||||
Assert.assertSame(defaultMap.get("defaultValue"), "sometext");
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = RuntimeException.class)
|
||||
public void testToCodegenMysqlDataTypeDefaultWithExceptionalColumnType() {
|
||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||
HashMap<String, Object> defaultMap = null;
|
||||
ArrayList<String> specialFixture = new ArrayList<String>(Arrays.asList(
|
||||
"TINYBLOB", "Blob", "MEDIUMBLOB", "LONGBLOB", "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT", "GEOMETRY", "JSON"
|
||||
));
|
||||
for(String specialType : specialFixture) {
|
||||
defaultMap = codegen.toCodegenMysqlDataTypeDefault("2018-08-12", specialType);
|
||||
Assert.assertNull(defaultMap);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsMysqlDataType() {
|
||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||
ArrayList<String> trueFixture = new ArrayList<String>(Arrays.asList(
|
||||
"INTEGER", "integer", "Integer", "DATETIME", "datetime", "DateTime", "VARCHAR", "varchar", "VarChar", "POINT", "Point", "point", "JSON", "json", "Json"
|
||||
));
|
||||
ArrayList<String> falseFixture = new ArrayList<String>(Arrays.asList(
|
||||
"unknown", "HashMap", "HASHMAP", "hashmap"
|
||||
));
|
||||
for(String trueValue : trueFixture) {
|
||||
Assert.assertTrue(codegen.isMysqlDataType(trueValue), "'" + trueValue + "' isn't MySQL data type");
|
||||
}
|
||||
for(String falseValue : falseFixture) {
|
||||
Assert.assertFalse(codegen.isMysqlDataType(falseValue), "'" + falseValue + "' is MySQL data type");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToMysqlIdentifier() {
|
||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||
Assert.assertEquals(codegen.toMysqlIdentifier("table_name", "tbl_", ""), "table_name");
|
||||
Assert.assertEquals(codegen.toMysqlIdentifier("table_name ", "tbl_", ""), "table_name");
|
||||
Assert.assertEquals(codegen.toMysqlIdentifier("12345678", "tbl_", ""), "tbl_12345678");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = RuntimeException.class)
|
||||
public void testToMysqlIdentifierWithEmptyString() {
|
||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||
codegen.toMysqlIdentifier(" ", "tbl_", "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEscapeMysqlUnquotedIdentifier() {
|
||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||
Assert.assertEquals(codegen.escapeMysqlUnquotedIdentifier("table1Z$_"), "table1Z$_");
|
||||
Assert.assertEquals(codegen.escapeMysqlUnquotedIdentifier("table1Z$_!#%~&?()*+-./"), "table1Z$_");
|
||||
Assert.assertEquals(codegen.escapeMysqlUnquotedIdentifier("table1Z$_русскийтекст"), "table1Z$_русскийтекст");
|
||||
Assert.assertEquals(codegen.escapeMysqlQuotedIdentifier("table𐀀"), "table");
|
||||
Assert.assertEquals(codegen.escapeMysqlQuotedIdentifier("table_name!'()<29>"), "table_name!'()<29>");
|
||||
Assert.assertEquals(codegen.escapeMysqlQuotedIdentifier("table_name𐌅𐌌 |