question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding an enum field does not generate a migration

See original GitHub issue

Issue Description

When I add an enum item to an existing enum field on an Entity and run migration:generate, a blank migration is created

Expected Behavior

I expect a migration to be created to add add the field to the Postgres database

Actual Behavior

An empty migration is created

Steps to Reproduce

  1. Add an entity with an enum field:
export enum Status {
  Live = 'live',
  Draft = 'draft',
  Archived = 'archived',
}

@Entity({ name: 'something' })
export class Something {

  @Column({
    type: 'enum',
    enum: Status,
    default: Status.Draft,
  })
  status: OrganisationVersionStatus;
}
  1. Generate and run the migrations
  2. Add another enum field:
export enum Status {
  Live = 'live',
  Draft = 'draft',
  Archived = 'archived',
  Unconfirmed = 'unconfirmed',
}

@Entity({ name: 'something' })
export class Something {

  @Column({
    type: 'enum',
    enum: Status,
    default: Status.Draft,
  })
  status: OrganisationVersionStatus;
}
  1. Generate the migrations
  2. Result:
export class AddUnconfirmedStatusToSomething643119746947 implements MigrationInterface
{
  name = 'AddUnconfirmedStatusToSomething1643119746947';

  public async up(queryRunner: QueryRunner): Promise<void> {}

  public async down(queryRunner: QueryRunner): Promise<void> {}
}

My Environment

Dependency Version
Operating System Mac OS
Node.js version 16.13.0
Typescript version 4.4.4
TypeORM version 0.2.40

Additional Context

Relevant Database Driver(s)

DB Type Reproducible
aurora-data-api no
aurora-data-api-pg no
better-sqlite3 no
cockroachdb no
cordova no
expo no
mongodb no
mysql no
nativescript no
oracle no
postgres yes
react-native no
sap no
sqlite no
sqlite-abstract no
sqljs no
sqlserver no

Are you willing to resolve this issue by submitting a Pull Request?

  • ✖️ Yes, I have the time, and I know how to start.
  • ✖️ Yes, I have the time, but I don’t know how to start. I would need guidance.
  • ✖️ No, I don’t have the time, but I can support (using donations) development.
  • ✅ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
pezholiocommented, Jan 25, 2022

@Ginden I’m using NestJS, but I think this is the pertinent bit of my config:

{
    type: 'postgres',
    url: process.env.DATABASE_URL,
    entities: ['./dist/**/*.entity.js'],
    synchronize: false,
    migrations: ['./dist/db/migrate/*.js'],
    migrationsRun: true,
    dropSchema: process.env.NODE_ENV == 'test',
    cli: {
      migrationsDir: 'src/db/migrate',
    },
    extra: {
      ssl:
        process.env.NODE_ENV === 'production'
          ? { rejectUnauthorized: false }
          : false,
    },
  }
0reactions
Ahmad-RWcommented, Jan 26, 2022

can you share your entity after the latest change you made?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add new enum column during migration - Stack Overflow
Modify your schema and don't build yet the model. run doctrine schema diff then a migration class will be generated for you. Finally...
Read more >
How to Use Enums in Rails | Saeloun Blog
We run the migration using rake db:migrate and in our Post model, we need to define the enum as shown in the below...
Read more >
Migrations uses value of enum object instead of its name.
When using Enum object as a default value for a CharField, the generated migration file uses the value of the Enum object instead...
Read more >
Postgres: Enum type fields | Hasura GraphQL Docs
New values cannot be added to an enum inside a transaction (that is, ALTER TYPE ... ADD VALUE is not supported by transactional...
Read more >
Upgrading PostgreSQL's Enum type with SQLAlchemy using ...
In this tutorial we've successfully generated the migration file which can automatically upgrade enum types on PostgreSQL server. If you want to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found