Skip to content

fix: Fix partition constraint errors in PostgreSQL and MySQL schemas#1

Closed
shinnyeonki wants to merge 1 commit intocivilian7:mainfrom
shinnyeonki:main
Closed

fix: Fix partition constraint errors in PostgreSQL and MySQL schemas#1
shinnyeonki wants to merge 1 commit intocivilian7:mainfrom
shinnyeonki:main

Conversation

@shinnyeonki
Copy link
Copy Markdown

문제 발생

$ uv run generate.py \
  --locale ko \
  --target postgresql \
  --size medium \
  --apply \
  --host localhost \
  --port 5432 \
  --user shopuser \
  --password shoppassword \
  --database shopdb
=== E-commerce Test DB Generator ===
Scale: medium (1.0x)
Period: 2016-01-01 ~ 2025-06-30
Seed: 42
Targets: postgresql

[1/13] Generating categories, suppliers, products...
  Categories: 53, Suppliers: 60, Products: 2800
[2/13] Generating price history...
  Price history: 8466 records
[3/13] Generating product images...
  Images: 7284 records
[4/13] Generating staff...
  Staff: 50
[5/13] Generating customers, addresses...
  Customers: 52300, Addresses: 86153
[6/13] Generating coupons...
  Coupons: 200
[7/13] Generating orders, order items...
  Orders: 387667, Order items: 941728
[8/13] Generating payments...
  Payments: 387667
[9/13] Generating shipping...
  Shipping: 367457
[10/13] Generating reviews...
  Reviews: 88674
[11/13] Generating inventory, carts, coupon usage...
  Inventory: 147774, Carts: 30000/90133 items, Coupons: 1407, Wishlists: 19999
[12/13] Generating customer inquiries/complaints...
  Complaints: 38818
[13/13] Generating returns/exchanges...
  Returns: 11122

[Extra] Generating date dimension, grade history, tags...
  Dates: 3469, Grade history: 103402, Tags: 46/12498
  Views: 3323274, Points: 1436341, Promos: 128/71175, Q&A: 9438

Data generation complete: 7,629,583 total records (368.1s)

Exporting to PostgreSQL...
  -> ./output/postgresql/
  Applying to PostgreSQL shopuser@localhost:5432/shopdb...
  Applying schema...
  [ERROR] PostgreSQL: unique constraint on partitioned table must include all partitioning columns
DETAIL:  UNIQUE constraint on table "orders" lacks column "ordered_at" which is part of the partition key.


Export complete (17.3s)
Total elapsed time: 385.4s

postgresql 및 MySQL 환경에서 파티셔닝된 orders 테이블에 데이터를 주입하거나 스키마를 생성할 때 다음과 같은 에러가 발생합니다.

PostgreSQL: unique constraint on partitioned table must include all partitioning columns
MySQL: A UNIQUE INDEX must include all columns in the table's partitioning function

파티셔닝시 고유 제약 조건(PRIMARY KEY, UNIQUE KEY)에 파티션 키(본 프로젝트에서는 ordered_at)가 포함될 것을 강제하므로
컬럼 레벨의 UNIQUE 제약을 제거하고 테이블 레벨 복합 유니크 제약 추가하였습니다

@civilian7 civilian7 closed this in 36d8d67 Apr 12, 2026
@civilian7
Copy link
Copy Markdown
Owner

감사합니다! 동일한 수정을 36d8d67 커밋에 직접 반영했습니다.

  • PostgreSQL: UNIQUE (order_number, ordered_at) 복합 유니크
  • MySQL: UNIQUE KEY uq_order_number (order_number, ordered_at) 복합 유니크

파티션 테이블 제약조건 문제를 정확히 짚어주셔서 감사합니다. README 기여자 섹션에도 등록했습니다.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants