-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolves Postgres sequence identifier length error (#7115)
Changes the sequence name generator to handle cases where PostgreSQL auto-generated sequence name differed from TypeORM generated sequence name. Closes: #7106
- Loading branch information
1 parent
bcd998b
commit 568ef35
Showing
4 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
test/github-issues/7106/entity/ReallyReallyVeryVeryVeryLongTableName.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn"; | ||
import {Column, Entity, Generated } from "../../../../src"; | ||
|
||
@Entity() | ||
export class ReallyReallyVeryVeryVeryLongTableName { | ||
@PrimaryGeneratedColumn() // typeORM requires a pkey | ||
PrimaryGeneratedColumnIDBlahBlahBlahThisIsReallyLong: number; | ||
|
||
@Column() | ||
Name: string; | ||
|
||
@Column() @Generated("increment") | ||
MyNumber: number; | ||
|
||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn"; | ||
import {Column, Entity } from "../../../../src"; | ||
|
||
@Entity() | ||
export class ShortTableName { | ||
@PrimaryGeneratedColumn() // typeORM requires a pkey | ||
PrimaryGeneratedColumnIDBlahBlahBlahThisIsReallyLong: number; | ||
|
||
@Column() | ||
Name: string; | ||
|
||
@Column() | ||
Value: number; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import "reflect-metadata"; | ||
import {expect} from "chai"; | ||
import {Connection} from "../../../src/connection/Connection"; | ||
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../utils/test-utils"; | ||
import { ShortTableName } from "./entity/ShortTableName"; | ||
import { ReallyReallyVeryVeryVeryLongTableName } from "./entity/ReallyReallyVeryVeryVeryLongTableName"; | ||
import { QueryFailedError } from "../../../src/error/QueryFailedError"; | ||
|
||
|
||
/** | ||
* @see https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS | ||
* "The system uses no more than NAMEDATALEN-1 bytes of an identifier; longer names can be | ||
* written in commands, but they will be truncated. By default, NAMEDATALEN is 64 so the | ||
* maximum identifier length is 63 bytes. If this limit is problematic, it can be raised | ||
* by changing the NAMEDATALEN constant in src/include/pg_config_manual.h." | ||
*/ | ||
describe("github issues > #7106 shorten sequence names (for RDBMS with a limit) when they are longer than 63 characters", () => { | ||
let connections: Connection[]; | ||
before(async () => connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
enabledDrivers: ["postgres"] | ||
})); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should be able to work with long sequence name with short table name", () => Promise.all(connections.map(async (connection) => { | ||
const short = new ShortTableName(); | ||
short.Name = "Dharawal"; | ||
short.Value = 2500; | ||
await connection.getRepository(ShortTableName).save(short); | ||
return expect(connection.synchronize()).to.not.be.rejectedWith(QueryFailedError); | ||
}))); | ||
|
||
it("should be able to work with long sequence name with long table name", () => Promise.all(connections.map(async (connection) => { | ||
const long = new ReallyReallyVeryVeryVeryLongTableName(); | ||
long.Name = "Eora"; | ||
await connection.getRepository(ReallyReallyVeryVeryVeryLongTableName).save(long); | ||
return expect(connection.synchronize()).to.not.be.rejectedWith(QueryFailedError); | ||
}))); | ||
|
||
}); |