Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default values in a jsonb column do not generate migrations correctly #10831

Open
1 of 18 tasks
ntnz opened this issue Apr 15, 2024 · 0 comments
Open
1 of 18 tasks

Default values in a jsonb column do not generate migrations correctly #10831

ntnz opened this issue Apr 15, 2024 · 0 comments

Comments

@ntnz
Copy link

ntnz commented Apr 15, 2024

Issue description

Default values in a jsonb column do not migrate correctly

Expected Behavior

When generating a migration, the default value for the jsonb column should be created and migrated in that migration. Subsequent migrations should not migrate this jsonb column default value, because it has already been migrated in a previous migration.

Actual Behavior

When generating a migration, the default value for the jsonb column is created in that migration. Every subsequent migration also attempts to migrate this column default value. This implies the migration is failing to correctly set the default value.

Strangely, the default value for the column appears to be created correctly in the database. Perhaps there is something wrong when checking for equivalence?

Steps to reproduce

Create a model with a jsonb column:

@Entity()
export class Example extends BaseEntity {
  @PrimaryGeneratedColumn('uuid')
  id: string

  @Column({
    type: 'jsonb',
    default: JSON.stringify({
      entityA: { attributeA: 'required' },
      attributeB: 'required',
      dateAttribute: 'required',
      itemDetails: {
        identifier: 'preferred',
        narrative: 'preferred',
        conditionCheck: 'preferred',
        sumValidation: 'preferred',
      },
      documentReference: 'preferred',
      entityB: { attributeC: 'required' },
      overallValidation: 'preferred',
    }),
  })
  rules: Rules
}

Generate a migration:
node typeorm migration:generate ExampleMigration1

Run the migration.

Generate another migration:
node typeorm migration:generate ExampleMigration2

Notice ExampleMigration2 includes the default value migration for the rules column of Example.

My Environment

Dependency Version
Operating System Fedora Linux 39 (Workstation Edition)
Node.js version 20.9.0
Typescript version 5.4.2
TypeORM version 0.3.20

Additional Context

No response

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

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

No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant