Cellar リレーション
Cellar DB のリレーション定義です。Drizzle ORM v1.0 beta の Relations V2 (defineRelations) を使用しています。
リレーションマップ
Section titled “リレーションマップ”Shop 中心のリレーション
Section titled “Shop 中心のリレーション”Contact 中心のリレーション
Section titled “Contact 中心のリレーション”Chat 中心のリレーション
Section titled “Chat 中心のリレーション”リレーション定義一覧
Section titled “リレーション定義一覧”one-to-many
Section titled “one-to-many”| 親テーブル | 子テーブル | リレーション名 | FK |
|---|---|---|---|
| shop | contact | contacts | contact.shopId → shop.id |
| shop | chat_room | chatRooms | chat_room.shopId → shop.id |
| shop | broadcast | broadcasts | broadcast.shopId → shop.id |
| shop | label | labels | label.shopId → shop.id |
| shop | shop_line_account | lineAccounts | shop_line_account.shopId → shop.id |
| shop | shop_transfer | transfers | shop_transfer.shopId → shop.id |
| shop | shop_purelovers | shopPurelovers | shop_purelovers.shopId → shop.id |
| shop | shop_push_subscription | pushSubscriptions | shop_push_subscription.shopId → shop.id |
| shop | shop_email_recipient | emailRecipients | shop_email_recipient.shopId → shop.id |
| shop | domain_blacklist | domainBlacklists | domain_blacklist.shopId → shop.id |
| contact | chat_room | chatRooms | chat_room.contactId → contact.id |
| contact | contact_purelovers | contactPurelovers | contact_purelovers.userId → contact.userId |
| contact | contact_chat_ng | chatNgStatuses | contact_chat_ng.contactId → contact.id |
| contact | contact_chat_ng_history | chatNgHistories | contact_chat_ng_history.contactId → contact.id |
| chat_room | chat_message | messages | chat_message.roomId → chat_room.id |
| chat_room | user_room_state | userRoomStates | user_room_state.roomId → chat_room.id |
| chat_message | chat_attachment | attachments | chat_attachment.messageId → chat_message.id |
one-to-one
Section titled “one-to-one”| 親テーブル | 子テーブル | リレーション名 | FK |
|---|---|---|---|
| shop | shop_notification_setting | notificationSetting | shop_notification_setting.shopId → shop.id |
many-to-one(逆方向)
Section titled “many-to-one(逆方向)”| 子テーブル | 親テーブル | リレーション名 | FK |
|---|---|---|---|
| contact | shop | shop | contact.shopId → shop.id |
| chat_room | shop | shop | chat_room.shopId → shop.id |
| chat_room | contact | contact | chat_room.contactId → contact.id |
| chat_message | chat_room | room | chat_message.roomId → chat_room.id |
| chat_attachment | chat_message | message | chat_attachment.messageId → chat_message.id |
| user_room_state | chat_room | room | user_room_state.roomId → chat_room.id |
| broadcast | shop | shop | broadcast.shopId → shop.id |
| label | shop | shop | label.shopId → shop.id |
| shop_line_account | shop | shop | shop_line_account.shopId → shop.id |
| shop_transfer | shop | shop / toOrganization | shop_transfer.shopId / toOrganizationId → shop.id |
| shop_purelovers | shop | shop | shop_purelovers.shopId → shop.id |
| contact_purelovers | contact | contacts | contact_purelovers.userId → contact.userId |
| contact_chat_ng | contact | contact | contact_chat_ng.contactId → contact.id |
| contact_chat_ng_history | contact | contact | contact_chat_ng_history.contactId → contact.id |
| shop_notification_setting | shop | shop | shop_notification_setting.shopId → shop.id |
| shop_push_subscription | shop | shop | shop_push_subscription.shopId → shop.id |
| shop_email_recipient | shop | shop | shop_email_recipient.shopId → shop.id |
| domain_blacklist | shop | shop | domain_blacklist.shopId → shop.id |
ソースコード
Section titled “ソースコード”リレーション定義は packages/cellar/src/relations.ts で defineRelations を使用して宣言されています。
import { defineRelations } from 'drizzle-orm';import * as schema from './schema';
export const relations = defineRelations(schema, (r) => ({ shop: { contacts: r.many.contact(), chatRooms: r.many.chatRoom(), broadcasts: r.many.broadcast() // ... }, contact: { shop: r.one.shop({ from: r.contact.shopId, to: r.shop.id }) // ... } // ...}));