MySQL Schema Generator #955 (#1055)

* [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:
Yuriy Belenko 2018-10-01 12:59:18 +05:00 committed by William Cheng
parent 755dfe53de
commit e4b5f50515
19 changed files with 2100 additions and 1 deletions

View 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

View 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

View File

@ -18,6 +18,7 @@ sleep 5
./bin/kotlin-client-string.sh > /dev/null 2>&1 ./bin/kotlin-client-string.sh > /dev/null 2>&1
./bin/kotlin-client-threetenbp.sh > /dev/null 2>&1 ./bin/kotlin-client-threetenbp.sh > /dev/null 2>&1
./bin/kotlin-server-petstore.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-petstore.sh > /dev/null 2>&1
./bin/php-silex-petstore-server.sh > /dev/null 2>&1 ./bin/php-silex-petstore-server.sh > /dev/null 2>&1
./bin/php-symfony-petstore.sh > /dev/null 2>&1 ./bin/php-symfony-petstore.sh > /dev/null 2>&1

View File

@ -25,7 +25,7 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
public enum CodegenType { public enum CodegenType {
CLIENT, SERVER, DOCUMENTATION, CONFIG, OTHER; CLIENT, SERVER, DOCUMENTATION, SCHEMA, CONFIG, OTHER;
private static Map<String, CodegenType> names = new HashMap<String, CodegenType>(); private static Map<String, CodegenType> names = new HashMap<String, CodegenType>();
@ -49,6 +49,7 @@ public enum CodegenType {
names.put("client", CLIENT); names.put("client", CLIENT);
names.put("server", SERVER); names.put("server", SERVER);
names.put("documentation", DOCUMENTATION); names.put("documentation", DOCUMENTATION);
names.put("schema", SCHEMA);
names.put("other", OTHER); names.put("other", OTHER);
} }
} }

View File

@ -53,6 +53,7 @@ org.openapitools.codegen.languages.JavascriptFlowtypedClientCodegen
org.openapitools.codegen.languages.JavascriptClosureAngularClientCodegen org.openapitools.codegen.languages.JavascriptClosureAngularClientCodegen
org.openapitools.codegen.languages.JMeterClientCodegen org.openapitools.codegen.languages.JMeterClientCodegen
org.openapitools.codegen.languages.LuaClientCodegen org.openapitools.codegen.languages.LuaClientCodegen
org.openapitools.codegen.languages.MysqlSchemaCodegen
org.openapitools.codegen.languages.NodeJSServerCodegen org.openapitools.codegen.languages.NodeJSServerCodegen
org.openapitools.codegen.languages.ObjcClientCodegen org.openapitools.codegen.languages.ObjcClientCodegen
org.openapitools.codegen.languages.OpenAPIGenerator org.openapitools.codegen.languages.OpenAPIGenerator

View File

@ -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

View File

@ -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}}

View File

@ -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𐌅𐌌"), "table_name");
}
@Test
public void testEscapeMysqlQuotedIdentifier() {
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
Assert.assertEquals(codegen.escapeMysqlQuotedIdentifier("table"), "table");
Assert.assertEquals(codegen.escapeMysqlQuotedIdentifier("table𐀀"), "table");
Assert.assertEquals(codegen.escapeMysqlQuotedIdentifier("table_name!'()<29>"), "table_name!'()<29>");
Assert.assertEquals(codegen.escapeMysqlQuotedIdentifier("table_name𐌅𐌌"), "table_name");
}
@Test
public void testIsReservedWord() {
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
Set<String> reservedWords = codegen.reservedWords();
ArrayList<String> trueFixture = new ArrayList<String>(Arrays.asList(
"accessible", "asc", "between", "blob", "change", "column", "day_hour", "distinct", "enclosed", "except", "explain", "float", "for", "function", "grant", "grouping", "high_priority", "groups", "hour_minute", "insensitive", "interval", "json_table", "keys", "kill", "leave", "left", "mediumblob", "modifies", "not", "null", "numeric", "optimize", "outer", "precision", "primary", "references", "replace", "select", "sql", "then", "tinytext", "unique", "unlock", "varchar", "virtual", "when", "where", "xor", "year_month", "zerofill"
));
ArrayList<String> falseFixture = new ArrayList<String>(Arrays.asList(
"after", "boolean", "charset", "cpu", "current", "delay_key_write", "end", "format", "global", "host", "install", "json", "key_block_size", "local", "max_size", "none", "offset", "partial", "quarter", "relay", "second", "status", "timestamp", "until", "variables", "without", "xml", "year"
));
for(String trueValue : trueFixture) {
Assert.assertTrue(reservedWords.contains(trueValue), "'" + trueValue + "' isn't MySQL reserved word");
}
for(String falseValue : falseFixture) {
Assert.assertFalse(reservedWords.contains(falseValue), "'" + falseValue + "' is MySQL reserved word");
}
}
@Test
public void testSetDefaultDatabaseName() {
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
codegen.setDefaultDatabaseName("valid_db_name");
Assert.assertSame(codegen.getDefaultDatabaseName(), "valid_db_name");
codegen.setDefaultDatabaseName("12345");
Assert.assertNotSame(codegen.getDefaultDatabaseName(), "12345");
}
@Test
public void testGetDefaultDatabaseName() {
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
Assert.assertSame(codegen.getDefaultDatabaseName(), "");
}
@Test
public void testSetJsonDataTypeEnabled() {
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
codegen.setJsonDataTypeEnabled(true);
Assert.assertTrue(codegen.getJsonDataTypeEnabled());
codegen.setJsonDataTypeEnabled(false);
Assert.assertFalse(codegen.getJsonDataTypeEnabled());
}
@Test
public void testGetJsonDataTypeEnabled() {
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
Assert.assertTrue(codegen.getJsonDataTypeEnabled());
codegen.setJsonDataTypeEnabled(false);
Assert.assertFalse(codegen.getJsonDataTypeEnabled());
}
}

View File

@ -0,0 +1,51 @@
/*
* 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.openapitools.codegen.AbstractOptionsTest;
import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.languages.MysqlSchemaCodegen;
import org.openapitools.codegen.options.MysqlSchemaOptionsProvider;
import mockit.Expectations;
import mockit.Tested;
public class MysqlSchemaOptionsTest extends AbstractOptionsTest {
@Tested
private MysqlSchemaCodegen clientCodegen;
public MysqlSchemaOptionsTest() {
super(new MysqlSchemaOptionsProvider());
}
@Override
protected CodegenConfig getCodegenConfig() {
return clientCodegen;
}
@SuppressWarnings("unused")
@Override
protected void setExpectations() {
new Expectations(clientCodegen) {{
clientCodegen.setDefaultDatabaseName(MysqlSchemaOptionsProvider.DEFAULT_DATABASE_NAME_VALUE);
times = 1;
clientCodegen.setJsonDataTypeEnabled(Boolean.valueOf(MysqlSchemaOptionsProvider.JSON_DATA_TYPE_ENABLED_VALUE));
times = 1;
}};
}
}

View File

@ -0,0 +1,46 @@
/*
* 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.options;
import org.openapitools.codegen.languages.MysqlSchemaCodegen;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
public class MysqlSchemaOptionsProvider implements OptionsProvider {
public static final String DEFAULT_DATABASE_NAME_VALUE = "database_name";
public static final String JSON_DATA_TYPE_ENABLED_VALUE = "false";
@Override
public String getLanguage() {
return "mysql-schema";
}
@Override
public Map<String, String> createOptions() {
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
return builder.put(MysqlSchemaCodegen.DEFAULT_DATABASE_NAME, DEFAULT_DATABASE_NAME_VALUE)
.put(MysqlSchemaCodegen.JSON_DATA_TYPE_ENABLED, JSON_DATA_TYPE_ENABLED_VALUE)
.build();
}
@Override
public boolean isServer() {
return false;
}
}

View File

@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.
# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

View File

@ -0,0 +1 @@
3.3.0-SNAPSHOT

View File

@ -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

View File

@ -0,0 +1,16 @@
/* SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; */
/* SET AUTOCOMMIT = 0; */
/* START TRANSACTION; */
/* SET time_zone = "+00:00"; */
-- --------------------------------------------------------
--
-- Table structure for table `Return` generated from model 'Return'
-- Model for testing reserved words *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r
--
CREATE TABLE IF NOT EXISTS `Return` (
`return` INT DEFAULT NULL COMMENT 'property description *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Model for testing reserved words *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r';

View File

@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.
# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

View File

@ -0,0 +1 @@
3.3.0-SNAPSHOT

View File

@ -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

View File

@ -0,0 +1,333 @@
/* SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; */
/* SET AUTOCOMMIT = 0; */
/* START TRANSACTION; */
/* SET time_zone = "+00:00"; */
-- --------------------------------------------------------
--
-- Table structure for table `$special[model.name]` generated from model 'DollarspecialLeft_Square_BracketmodelPeriodnameRight_Square_Bracket'
--
CREATE TABLE IF NOT EXISTS `$special[model.name]` (
`$special[property.name]` BIGINT DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `200_response` generated from model '200Underscoreresponse'
-- Model for testing model name starting with number
--
CREATE TABLE IF NOT EXISTS `200_response` (
`name` INT DEFAULT NULL,
`class` TEXT DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Model for testing model name starting with number';
--
-- Table structure for table `AdditionalPropertiesClass` generated from model 'AdditionalPropertiesClass'
--
CREATE TABLE IF NOT EXISTS `AdditionalPropertiesClass` (
`map_property` JSON DEFAULT NULL,
`map_of_map_property` JSON DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `Animal` generated from model 'Animal'
--
CREATE TABLE IF NOT EXISTS `Animal` (
`className` TEXT NOT NULL,
`color` TEXT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `ApiResponse` generated from model 'ApiResponse'
--
CREATE TABLE IF NOT EXISTS `ApiResponse` (
`code` INT DEFAULT NULL,
`type` TEXT DEFAULT NULL,
`message` TEXT DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `ArrayOfArrayOfNumberOnly` generated from model 'ArrayOfArrayOfNumberOnly'
--
CREATE TABLE IF NOT EXISTS `ArrayOfArrayOfNumberOnly` (
`ArrayArrayNumber` JSON DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `ArrayOfNumberOnly` generated from model 'ArrayOfNumberOnly'
--
CREATE TABLE IF NOT EXISTS `ArrayOfNumberOnly` (
`ArrayNumber` JSON DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `ArrayTest` generated from model 'ArrayTest'
--
CREATE TABLE IF NOT EXISTS `ArrayTest` (
`array_of_string` JSON DEFAULT NULL,
`array_array_of_integer` JSON DEFAULT NULL,
`array_array_of_model` JSON DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `Capitalization` generated from model 'Capitalization'
--
CREATE TABLE IF NOT EXISTS `Capitalization` (
`smallCamel` TEXT DEFAULT NULL,
`CapitalCamel` TEXT DEFAULT NULL,
`small_Snake` TEXT DEFAULT NULL,
`Capital_Snake` TEXT DEFAULT NULL,
`SCA_ETH_Flow_Points` TEXT DEFAULT NULL,
`ATT_NAME` TEXT DEFAULT NULL COMMENT 'Name of the pet '
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `Cat` generated from model 'Cat'
--
CREATE TABLE IF NOT EXISTS `Cat` (
`className` TEXT NOT NULL,
`color` TEXT,
`declawed` TINYINT(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `Category` generated from model 'Category'
--
CREATE TABLE IF NOT EXISTS `Category` (
`id` BIGINT DEFAULT NULL,
`name` TEXT DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `ClassModel` generated from model 'ClassModel'
-- Model for testing model with \&quot;_class\&quot; property
--
CREATE TABLE IF NOT EXISTS `ClassModel` (
`_class` TEXT DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Model for testing model with \&quot;_class\&quot; property';
--
-- Table structure for table `Client` generated from model 'Client'
--
CREATE TABLE IF NOT EXISTS `Client` (
`client` TEXT DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `Dog` generated from model 'Dog'
--
CREATE TABLE IF NOT EXISTS `Dog` (
`className` TEXT NOT NULL,
`color` TEXT,
`breed` TEXT DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `EnumArrays` generated from model 'EnumArrays'
--
CREATE TABLE IF NOT EXISTS `EnumArrays` (
`just_symbol` ENUM('&gt;&#x3D;', '$') DEFAULT NULL,
`array_enum` JSON DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `Enum_Test` generated from model 'EnumUnderscoreTest'
--
CREATE TABLE IF NOT EXISTS `Enum_Test` (
`enum_string` ENUM('UPPER', 'lower', '') DEFAULT NULL,
`enum_string_required` ENUM('UPPER', 'lower', '') NOT NULL,
`enum_integer` ENUM('1', '-1') DEFAULT NULL,
`enum_number` ENUM('1.1', '-1.2') DEFAULT NULL,
`outerEnum` TEXT DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `File` generated from model 'File'
-- Must be named &#x60;File&#x60; for test.
--
CREATE TABLE IF NOT EXISTS `File` (
`sourceURI` TEXT DEFAULT NULL COMMENT 'Test capitalization'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Must be named &#x60;File&#x60; for test.';
--
-- Table structure for table `FileSchemaTestClass` generated from model 'FileSchemaTestClass'
--
CREATE TABLE IF NOT EXISTS `FileSchemaTestClass` (
`file` TEXT DEFAULT NULL,
`files` JSON DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `format_test` generated from model 'formatUnderscoretest'
--
CREATE TABLE IF NOT EXISTS `format_test` (
`integer` TINYINT UNSIGNED DEFAULT NULL,
`int32` TINYINT UNSIGNED DEFAULT NULL,
`int64` BIGINT DEFAULT NULL,
`number` DECIMAL(20, 9) UNSIGNED NOT NULL,
`float` DECIMAL(20, 9) UNSIGNED DEFAULT NULL,
`double` DECIMAL(20, 9) UNSIGNED DEFAULT NULL,
`string` TEXT DEFAULT NULL,
`byte` MEDIUMBLOB NOT NULL,
`binary` MEDIUMBLOB DEFAULT NULL,
`date` DATE NOT NULL,
`dateTime` DATETIME DEFAULT NULL,
`uuid` TEXT DEFAULT NULL,
`password` VARCHAR(64) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `hasOnlyReadOnly` generated from model 'hasOnlyReadOnly'
--
CREATE TABLE IF NOT EXISTS `hasOnlyReadOnly` (
`bar` TEXT DEFAULT NULL,
`foo` TEXT DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `List` generated from model 'List'
--
CREATE TABLE IF NOT EXISTS `List` (
`123-list` TEXT DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `MapTest` generated from model 'MapTest'
--
CREATE TABLE IF NOT EXISTS `MapTest` (
`map_map_of_string` JSON DEFAULT NULL,
`map_of_enum_string` JSON DEFAULT NULL,
`direct_map` JSON DEFAULT NULL,
`indirect_map` JSON DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `MixedPropertiesAndAdditionalPropertiesClass` generated from model 'MixedPropertiesAndAdditionalPropertiesClass'
--
CREATE TABLE IF NOT EXISTS `MixedPropertiesAndAdditionalPropertiesClass` (
`uuid` TEXT DEFAULT NULL,
`dateTime` DATETIME DEFAULT NULL,
`map` JSON DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `Name` generated from model 'Name'
-- Model for testing model name same as property name
--
CREATE TABLE IF NOT EXISTS `Name` (
`name` INT NOT NULL,
`snake_case` INT DEFAULT NULL,
`property` TEXT DEFAULT NULL,
`123Number` INT DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Model for testing model name same as property name';
--
-- Table structure for table `NumberOnly` generated from model 'NumberOnly'
--
CREATE TABLE IF NOT EXISTS `NumberOnly` (
`JustNumber` DECIMAL(20, 9) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `Order` generated from model 'Order'
--
CREATE TABLE IF NOT EXISTS `Order` (
`id` BIGINT DEFAULT NULL,
`petId` BIGINT DEFAULT NULL,
`quantity` INT DEFAULT NULL,
`shipDate` DATETIME DEFAULT NULL,
`status` ENUM('placed', 'approved', 'delivered') DEFAULT NULL COMMENT 'Order Status',
`complete` TINYINT(1) DEFAULT false
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `OuterComposite` generated from model 'OuterComposite'
--
CREATE TABLE IF NOT EXISTS `OuterComposite` (
`my_number` DECIMAL(20, 9) DEFAULT NULL,
`my_string` TEXT DEFAULT NULL,
`my_boolean` TINYINT(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `Pet` generated from model 'Pet'
--
CREATE TABLE IF NOT EXISTS `Pet` (
`id` BIGINT DEFAULT NULL,
`category` TEXT DEFAULT NULL,
`name` TEXT NOT NULL,
`photoUrls` JSON NOT NULL,
`tags` JSON DEFAULT NULL,
`status` ENUM('available', 'pending', 'sold') DEFAULT NULL COMMENT 'pet status in the store'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `ReadOnlyFirst` generated from model 'ReadOnlyFirst'
--
CREATE TABLE IF NOT EXISTS `ReadOnlyFirst` (
`bar` TEXT DEFAULT NULL,
`baz` TEXT DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `Return` generated from model 'Return'
-- Model for testing reserved words
--
CREATE TABLE IF NOT EXISTS `Return` (
`return` INT DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Model for testing reserved words';
--
-- Table structure for table `Tag` generated from model 'Tag'
--
CREATE TABLE IF NOT EXISTS `Tag` (
`id` BIGINT DEFAULT NULL,
`name` TEXT DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `User` generated from model 'User'
--
CREATE TABLE IF NOT EXISTS `User` (
`id` BIGINT DEFAULT NULL,
`username` TEXT DEFAULT NULL,
`firstName` TEXT DEFAULT NULL,
`lastName` TEXT DEFAULT NULL,
`email` TEXT DEFAULT NULL,
`password` TEXT DEFAULT NULL,
`phone` TEXT DEFAULT NULL,
`userStatus` INT DEFAULT NULL COMMENT 'User Status'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;