-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Closed
Description
Issue type:
[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)
Steps to reproduce or a small repository showing the problem:
When writing migrations by hand using the migration API to create a new table that has an enum column 3 things happen that shouldn't:
- The generated SQL does not sets the column's type to enum.
- Worse, it sets the column's type to "[Tablename]_[column]_enum".
- The "enum" TableColumnOptions parameter gets ignored.
A simple example:
// == The entity
export enum RatingType {
low = 'bad',
neutral = 'neutral',
good = 'good'
}
@Entity({ name: 'Ratings' })
export default class Rating extends BaseEntity {
@PrimaryGeneratedColumn('uuid')
id: string
@Column({ type: 'enum', enum: RatingType })
rating: RatingType
}
// == The migration
import { MigrationInterface, QueryRunner, Table } from 'typeorm'
export class CreateRatings1569818629816 implements MigrationInterface {
private ratingsTable = new Table({
name: 'Ratings',
columns: [
{
name: 'id',
type: 'uuid',
isPrimary: true,
isGenerated: true,
generationStrategy: 'uuid',
},
{
name: 'rating',
type: 'enum',
enum: ['bad', 'neutral', 'good'],
isNullable: true
}
],
})
async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(this.ratingsTable, true)
}
async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable(this.ratingsTable)
}
}The generated SQL looks like this:
CREATE TABLE "Ratings" (
"id" uuid NOT NULL DEFAULT uuid_generate_v4(),
"rating" "Ratings_rating_enum",
CONSTRAINT "PK_ee6436ff188c9bb00cc70fc447a" PRIMARY KEY ("id")
)
Reactions are currently unavailable