Skip to content

Unique index is generating for existing table with OneToOne relationship and primary column #8485

@IvanYur4enk0

Description

@IvanYur4enk0

Issue Description

Expected Behavior

  1. First Test1.sql is generating with primary key and without unique index. Because unique index is not needed for primary key column.
  2. Second Test2.sql is do not generating changes by companyId that is not needed, because companyId is primary key.

Actual Behavior

  1. First Test1.sql is generating primary key without unique index.
  2. Second Test2.sql is generating unique index by companyId column that is not needed, because companyId is primary key.

Steps to Reproduce

Database: PostgreSQL

  1. Create Company and CompanyReport tables with entities.
@Entity()
export class Company {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @OneToOne(() => CompanyReport, (report) => report.company)
  report: CompanyReport | null;
}

@Entity()
export class CompanyReport {
  @PrimaryColumn()
  companyId: string;

  @OneToOne(
    () => Company,
    (company) => company.report,
    { nullable: false, onDelete: 'CASCADE' },
  )
  @JoinColumn({
    name: 'companyId',
  })
  company: Company;
}
  1. Run typeorm migration:generate -c default -n Test1.
  2. Run typeorm migration:generate -c default -n Test2.

My Environment

| Dependency | Version |
| Database | PostgreSQL 12.9 |
| Node.js version | 14.16.0 |
| Typescript version | 4.4.3 |
| TypeORM version | 0.2.41 |

Relevant Database Driver(s)

DB Type Reproducible
postgres yes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions