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

order から register, placement(s) から order(s) へ命名を変更する #104

Merged
merged 6 commits into from
Dec 27, 2024

Conversation

exflikt
Copy link
Collaborator

@exflikt exflikt commented Dec 27, 2024

Closes #88

placement(s) という単語の使用を廃止し、完了した注文はこれから order(s) を用います。"placement"という単語自体には注文の意味がなく、"place an order" というフレーズになって初めて注文の意味が現れます。このままだと混乱を招く可能性があります。そのため、元々注文ページのことを指すために使用していた"order" を "register"に言い換えることでorderを完了した注文に当てはめるよう命名を変更しました。

以下、変更前の命名と変更後の命名の対応表です。

order (注文ページ)から register (注文を受け付けるレジ) への命名変更:

種類 変更前 変更後
Pyファイル routers/order.py routers/register.py
パス操作 '/order' '/regiser'
Jinjaファイル tepmlates/order.html template/register.html
Jinjaマクロ order(products, session) register(products, session)

placement(s) (確定注文) から order(s) (注文) への命名変更:

種類 変更前 変更後
Pyファイル routers/placements.py routers/orders.py
パス操作 '/placements' '/orders'
Pyファイル store/placement.py store/order.py
DBテーブル "placements" "orders"
DBコラム "placements.placement_id" "orders.order_id"
DBコラム "placements.placed_at" "orders.ordered_at"
Jinjaファイル templates/incoming-placements.html routers/incoming-orders.py
Jinjaマクロ incoming_placements(placements) incoming_orders(orders)
Jinjaファイル templates/resolved-placements.html routers/resolved-orders.py
Jinjaマクロ resolved_placements(placements) resolved_orders(orders)

placed_item(s) (確定したアイテム) から ordered_item(s) (注文されたアイテム) への命名変更:

種類 変更前 変更後
Pyファイル routers/placements.py routers/orders.py
パス操作 '/placed-items' '/ordered-items'
Pyファイル store/placed_item.py store/ordered_item.py
DBテーブル "placed_items" "ordered_items"
DBコラム "placed_items.placement_id" "ordered_items.order_id"
Jinjaファイル templates/placed-items-incoming.html routers/ordered-items-incoming.py
Jinjaマクロ placed_items_incoming(placed_items) ordered_items_incoming(ordered_items)

"Order" has become a pretty overloaded term in this project. In the
following commits, I introduce a few renames in hope to reduce various
terminology confusions.

This first commit renames the `/order` path operations to `/register`. I
chose the term "register" because the page acts kind of like a cash
register: the page presents various buttons to properly handle incoming
order requests. This clears up the distinction between the register as a
machine and order sessions as intermediate states.
Although we could say "place an order" to mean registering an order,
"placement," in and of itself, does not have the notion of product
orders. Yet, I have been using "placement" to mean registered orders.
As such, I decided to rename "placement" to simply "order." This
renaming revolves around mainly four things:

- Path operations and Jinja macros
- `placement_t` dictionary
- SQLModel definitions
- Database tables

This commit addresses the first piece.

Changes to path operation names are:

- `s#/placements/(incoming|resolved)#/orders/&1#`
- `s#/placed-items/incoming#/ordered-items/incoming#`
- `s#/placements#/orders`
Constraint names are required to properly downgrade foreign key constraints:
https://alembic.sqlalchemy.org/en/latest/naming.html

In order to make Alembic migrations work in tandem with SQLModel, I had to
modify the metadata object managed internally in the SQLModel namespace.

The code is partially inspired by this comment (by the way, who's Dan?):
https://www.github.com/fastapi/sqlmodel/issues/85#issuecomment-1380418653
I should have named these "orders" and "ordered_items" from the start.
Also, "placement_id" and "placed_at" columns are renamed to "order_id"
and "ordered_at," respectively.

Alembic provides operations for renaming tables, columns, and
constraints. That said, I had to write down the migration functions
myself because Alembic does not recognize the previous name corresponds
to the changed name so automatic script generation did not help much.
The execution order is important, and very subtle.

The lesson learned: renaming stringly-typed things is hard.
@exflikt exflikt merged commit 94b4927 into tut-cc:main Dec 27, 2024
3 checks passed
@exflikt exflikt deleted the dev/renames branch December 27, 2024 13:59
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.

orderregister に、placementsorders に命名を変更する
1 participant