mirror of
https://github.com/twentyhq/twenty.git
synced 2025-01-03 17:53:58 +03:00
Fix array enum renaming (#9067)
When creating an enum type (let's say post_type_enum), postgres will automatically create a array enum type based on this enum and prefix it with an underscore (so _post_type_enum). Our code was not taking this case into account while dealing with MULTISELECT Resources: https://www.postgresql.org/docs/current/sql-createtype.html <img width="1329" alt="image" src="https://github.com/user-attachments/assets/c41bc90c-9884-4995-8fae-d26869153a1d" />
This commit is contained in:
parent
042b6c65ed
commit
2ceb1c87b3
@ -231,20 +231,23 @@ export class WorkspaceMigrationEnumService {
|
|||||||
tableName: string,
|
tableName: string,
|
||||||
columnName: string,
|
columnName: string,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const result = await queryRunner.query(
|
const [result] = await queryRunner.query(
|
||||||
`SELECT udt_name FROM information_schema.columns WHERE table_schema = $1 AND table_name = $2 AND column_name = $3`,
|
`SELECT udt_name, data_type FROM information_schema.columns WHERE table_schema = $1 AND table_name = $2 AND column_name = $3`,
|
||||||
[schemaName, tableName, columnName],
|
[schemaName, tableName, columnName],
|
||||||
);
|
);
|
||||||
|
|
||||||
const enumTypeName = result[0]?.udt_name;
|
if (!result) {
|
||||||
|
|
||||||
if (!enumTypeName) {
|
|
||||||
throw new WorkspaceMigrationException(
|
throw new WorkspaceMigrationException(
|
||||||
`Enum type name not found for column ${columnName} in table ${tableName} while trying to alter enum`,
|
`Enum type name not found for column ${columnName} in table ${tableName} while trying to alter enum`,
|
||||||
WorkspaceMigrationExceptionCode.ENUM_TYPE_NAME_NOT_FOUND,
|
WorkspaceMigrationExceptionCode.ENUM_TYPE_NAME_NOT_FOUND,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const enumTypeName =
|
||||||
|
result.data_type === 'ARRAY'
|
||||||
|
? result.udt_name.replace(/^_/, '')
|
||||||
|
: result.udt_name;
|
||||||
|
|
||||||
return enumTypeName;
|
return enumTypeName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user