-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MySQL Schema Generator #955
Comments
We will need to store MySQL-specified attributes/properties (e.g. AUTO_INCREMENT) in the model defined in the OpenAPI spec. One option is to use vendor extension (e.g. x-mysql-auto-increment). |
if you do so, you could also consider to have a more general database generation option in different languages, e.g. |
Is that similar to the
|
I've significant progress working on it. Prototype name for new codegen is Openapi Data Type to MySQL Data Type
|
Here are my suggestions:
Ref: https://stackoverflow.com/questions/5959043/how-to-insert-a-file-in-mysql-database ( |
@wing328 What about |
I agree with William's addition. My comments are below. String (no format)OpenAPI string types with no data format specified should not have a maximum specified for varchar, unless there is an OpenAPI
Consider, for example, if the specification defines an API for a blogging system: ---
swagger: "2.0"
info:
version: "1.0.0"
title: "Bloggy"
description: "A blog API sample"
contact:
name: "Jim Schubert"
license:
name: "MIT"
host: "blog.example.com"
basePath: "/api"
schemes:
- "https"
consumes:
- "application/json"
produces:
- "application/json"
paths:
/posts:
get:
description: "Returns all posts (not realistic for large blogs)"
produces:
- "application/json"
responses:
"200":
description: "A list of blog posts."
schema:
type: "array"
items:
$ref: "#/definitions/Post"
definitions:
Post:
type: "object"
required:
- "id"
- "title"
- "content"
properties:
id:
type: "integer"
format: "int64"
title:
type: "string"
maxLength: 255
content:
type: "string"
related:
type: array
items:
type: "integer"
format: "int64"
edit: I didn't finish this thought. Sorry. Float/DoubleI'd be hesitant to use From Wikipedia:
From MySQL docs:
Examples of errors with Float/Double can be seen on MySQL docs B.5.4.8 Problems with Floating-Point Values. A huge concern with this is that you can use mysqldump to replicate between a master and slave, and you can end up with different values between the two. Conversely,
The above could be off by a little, but you verify against 11.8 Data Type Storage Requirements. Disclaimer: I have stopped using MySQL because of inconsistencies and confusing documentation. This is probably controversial, but my recommendation would be to use |
@jimschubert Maybe you right that Sure, I want to add cli options in future versions. Right now I want to provide prestable version without any config. Offtopic, @jimschubert what relational database you use instead of MySQL now? I've never had troubles with floats and doubles, however I haven't used decimal columns too much(for geo coordinates and money storage only). I've encountered some issues with foreign keys, varchar storage limit per table, some time it's frustrating that InnoDB doesn't support full text search and you need to create additional MyISAM table to store big articles text. |
Any suggestion of how to calculate |
@ybelenko I don't have a clear answer. I did a keyword search ("mysql decimal") in Github and found a few occurrences of the following:
I suggest we use it as a starting point and later provide instructions to the users on how to customize it to meet their requirement. |
@ybelenko I use postgresql now. No relational database system is perfect, but Postgres has way fewer "gotchas" than MySQL (at least in my use cases). MySQL, up until 5.8/8.0 or whatever the recent release was, didn't support common SQL functionality that I use such as CTEs and windowing functions. It also has very unintuitive transactional behavior. As an example if you mix InnoDB and MyISAM in a single query wrapped in a transaction, you can end up with data inserted into the MyISAM table that doesn't get rolled back because MyISAM doesn't support transactions. Also, if you're like most engineers/companies, you're probably stuck on and older version of MySQL. They had a bug open for 14 years which was pretty critical, but which was obviously not a high priority for them. You could insert data into a table with an auto-incrementing primary key, delete the record, then restart your database and the sequence would restart to the maximum existing record value. This wasn't only an issue with data corruption, replication, and the sorts-- it was a potential security issue for applications running on MySQL. Their "fix" was to document it and write it off as documented behavior. Then, there's the issue that utf8 encoding doesn't mean utf8. People had a field day on Reddit for that bug. There are numerous other issues I've encountered with MySQL over the years, but those are the main ones that would lead me to recommend anyone against using MySQL. People use to argue that it was dead-simple to setup in comparison to Postgres and had better performance. I've found postgres to be much simpler to setup over the last couple years (magnitudes simpler than it was 17 or 18 years ago). But I would question the "speed" advantage of MySQL pretty heavily, considering it's taking some shortcuts to eek out this speed. In my own experience, we recently migrated from MySQL 5.7 to Postgresql 9.6 and our database queries dropped from 200-300ms to 50-100ms (both in AWS with the same data and same queries). |
Also, I agree with @wing328 that
Or: 999,999,999,999.99999999 Realistically, there are probably very few applications working with values representing 1 trillion and higher. Some people might disagree with that as a default, so providing steps in the generated README for how to modify these and regenerate should address those concerns. |
Well, default value is important, but I mean is there any rational way to calculate that value based on |
We can use additional information provided in the spec to try to come up with a better default but I would suggest looking into those as a day-2 requirement if users complain about the default value that we chose. |
@wing328 Of course I'm not going to implement it right now. This thread has been created to think about, how we can generate perfect MySQL schema. I want to get max benefit from optional properties like |
I would only set a default if For older versions of MySQL I don't think triggers are enabled by default- at least they weren't in 5.6 with AWS default configuration (see this SO post). If using triggers in the generator, we might want to explain how to enable them in AWS. If defining triggers, also be aware that prior to MySQL 5.7.2, you couldn't have multiple triggers with the same triggering event and action (e.g. BEFORE UPDATE). We might want to limit the generator to a minimum of 5.7.2. The alternative for older versions is to create a single trigger and wrap multi-statement body in |
@ybelenko understood. I know you're trying to start the discussion earlier as you always think ahead 👍 |
General question to all. It's not clear what to do with complex model vars( |
Good point about foreign key, I think the same. But it's obvious that I cannot implement it right now, because we know nothing about primary keys in both tables(current and referenced). Don't know what workaround to use for now... thinking about simple And about
It's obvious, that I should add cli option like |
My recommendation would be to not start by trying to support very old versions of the database. 5.7.8 was released 2015-08-03. It's doubtful that someone starting a new schema will be using that old of a database. If so, they can use type overrides to change |
* [Mysql Schema] Add new generator * [Mysql Schema] Fix default definition * [Mysql Schema] Add defaultDatabaseName option * [Mysql Schema] Add jsonDataTypeEnabled option * [Mysql Schema] Add samples
@ybelenko Hi, Sorry I'm a little lost here. Do we have a MySQL Schema generator from Open API Specs now? If Yes, where to find it and how to use it please? |
Thanks I found it in https://openapi-generator.tech. |
@ybelenko is there a page that lists out the features which are yet to built? e.g. Identification of |
@DivsDibs no, we don't have page you need, but you can read conversation about undescribed features in #2587.
|
Description
As discussed with @ybelenko we want to create a MySQL schema generator so as to create the MySQL database/tables more easily given an OpenAPI spec.
openapi-generator version
Latest master
Suggest a fix/enhancement
If anyone wants to help on this, please reply to let us know.
The text was updated successfully, but these errors were encountered: