OpenAPITools / OpenAPITools/openapi-generator
[REQ] [Postgresql] Instead of serial use identity
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Why not use identity for serial .
The serial in the PostgreSQl wiki is marked as anti pattern also,
The serial types have some weird behaviors that make schema, dependency, and permission management unnecessarily cumbersome.
Describe the solution you'd like
openapi-generator/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PostgresqlSchemaCodegen.java
Line 53, 54
Block ine 525-550 change the logic to use identity
Something like this
if (colName.equals("id") && Boolean.valueOf(additionalProperties.get(ID_AUTOINC_ENABLED).toString())) {
columnDefinition.put("colDataType", "BIGINT GENERATED ALWAYS AS IDENTITY");
} else {
columnDefinition.put("colDataType", "BIGINT");
}
---
if (colName.equals("id") && Boolean.valueOf(additionalProperties.get(ID_AUTOINC_ENABLED).toString())) {
if (colDataType.equals("BIGINT")) {
colDataType = "BIGINT GENERATED ALWAYS AS IDENTITY";
}
---
if (!columnDefinition.get("colDataType").equals("BIGINT GENERATED ALWAYS AS IDENTITY")
) { // No default value for autoincremented
// IDs
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in openapi-generator/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PostgresqlSchemaCodegen.java, especially lines 53-54 and the logic around lines 525-550. Trace how the ID_AUTOINC_ENABLED property affects column definitions and default values, then confirm that generated PostgreSQL schemas use BIGINT GENERATED ALWAYS AS IDENTITY for enabled autoincrement IDs without adding an inappropriate default.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, postgresql
- Domain
- database
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100