<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
  <title>Mohamed Elgohary — writing</title>
  <subtitle>Notes from building and releasing mobile apps and full-stack products, in English and Arabic.</subtitle>
  <link rel="self" type="application/atom+xml" href="https://mohamedelgohary.dev/feed.xml"/>
  <link rel="alternate" type="text/html" href="https://mohamedelgohary.dev/writing/"/>
  <id>https://mohamedelgohary.dev/feed.xml</id>
  <updated>2026-11-18T05:21:49+02:00</updated>
  <author><name>Mohamed Abdelazim Elgohary</name><uri>https://mohamedelgohary.dev/</uri></author>
  <icon>https://mohamedelgohary.dev/images/favicon-32.png</icon>
  <entry xml:lang="ar">
    <title>هوية واحدة وأدوار متعددة: أين أخطأتُ في تصميم حسابات السوق الإلكتروني</title>
    <link rel="alternate" type="text/html" href="https://mohamedelgohary.dev/ar/writing/one-identity-many-roles-marketplace-accounts/"/>
    <id>https://mohamedelgohary.dev/ar/writing/one-identity-many-roles-marketplace-accounts/</id>
    <published>2026-11-10T00:00:00Z</published>
    <updated>2026-11-18T05:17:54+02:00</updated>
    <summary>تخصيص بريد إلكتروني لكل دور يعاقب أنشط مستخدمي السوق. يشرح المقال كيف ينتقل تصميم EgyGomla إلى هوية واحدة ترتبط بها مؤسسة للشراء وأخرى للتوريد.</summary>
    <category term="system-design"/>
    <category term="marketplace"/>
    <category term="authentication"/>
    <category term="oidc"/>
    <category term="postgresql"/>
    <category term="egygomla"/>
    <content type="html">&lt;aside class=&quot;callout&quot; aria-labelledby=&quot;الخلاصة&quot;&gt;&lt;p class=&quot;callout__label&quot; id=&quot;الخلاصة&quot;&gt;الخلاصة&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;بنيت EgyGomla، منصة توريد B2B تربط التجار المصريين بالمصانع والموردين، وجعلت لكل جانب من السوق بريدًا وحسابًا وكلمة مرور مستقلة: المشترون على نطاق فرعي، والموردون على آخر.&lt;/li&gt;&lt;li&gt;تاجر الجملة يشتري من المصنع ويبيع لتاجر التجزئة، أي أنه على طرفي السوق معًا، وكان تصميمي يعاقبه.&lt;/li&gt;&lt;li&gt;الأصح أن البريد الإلكتروني يمثّل الشخص (الهوية)، وأن «مشترٍ» و«مورّد» أدوار. في الـ backend يعني ذلك مستخدمًا واحدًا له مؤسسة شراء واحدة ومؤسسة توريد واحدة على الأكثر، مرتبطتين لا مدمجتين، وقاعدة البيانات نفسها تمنع أن يبيع أحد لنفسه.&lt;/li&gt;&lt;li&gt;هذا قرار موثّق (ADR-0013، بحالة Accepted بتاريخ 14 أغسطس 2026)، وكُتبت له migrations في الكود، لكنه لم يصل بعد إلى التجار في بيئة الإنتاج.&lt;/li&gt;&lt;/ul&gt;
&lt;/aside&gt;
&lt;h2 id=&quot;ما-بنيته-أولا&quot;&gt;ما بنيته أولًا&lt;/h2&gt;
&lt;p&gt;تساعد EgyGomla التجار المصريين على إيجاد المصانع والموردين وطلب عروض الأسعار. بنيتها من البداية إلى النهاية: واجهات الويب ولوحات التحكم والـ backend وتطبيقات Flutter. الموقع العام منشور، وتطبيقات الجوال لم تُنشر على المتاجر بعد.&lt;/p&gt;
&lt;p&gt;طبقة الـ edge في بيئة الإنتاج إعداد Caddy واحد، ولكل واجهة hostname خاص بها:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;code&gt;egygomla.com&lt;/code&gt;: الموقع العام&lt;/li&gt;&lt;li&gt;&lt;code&gt;app.egygomla.com&lt;/code&gt;: تطبيق المشتري&lt;/li&gt;&lt;li&gt;&lt;code&gt;factory.egygomla.com&lt;/code&gt;: بوابة المورّد (المصنع)&lt;/li&gt;&lt;li&gt;&lt;code&gt;admin.egygomla.com&lt;/code&gt;: لوحة الإدارة&lt;/li&gt;&lt;li&gt;&lt;code&gt;api.egygomla.com&lt;/code&gt;: الـ API&lt;/li&gt;&lt;li&gt;&lt;code&gt;id.egygomla.com&lt;/code&gt;: Keycloak، وهو الـ OIDC issuer&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;وفوق هذا الفصل قررت أن يكون لكل دور بريد إلكتروني مستقل. بدا لي ذلك الحل الأنظف.&lt;/p&gt;
&lt;h2 id=&quot;لماذا-كان-ذلك-خطأ&quot;&gt;لماذا كان ذلك خطأً&lt;/h2&gt;
&lt;p&gt;جمهور المنتج هم المصانع والمستوردون وتجار الجملة والتجزئة، وتاجر الجملة يشتري من المصنع ويبيع للتاجر الأصغر، أي أنه على طرفي السوق معًا.&lt;/p&gt;
&lt;p&gt;في التصميم الأول يحتاج هذا التاجر إلى بريد ثانٍ وحساب ثانٍ وكلمة مرور ثانية، ويظل يتنقّل بينها. أي أنني كنت أعاقب أنشط مستخدمي المنصة على نشاطهم.&lt;/p&gt;
&lt;p&gt;والكلفة ليست الإزعاج وحده: الحسابان لا يتشاركان كتالوجًا ولا محادثات ولا تقييمات، والمنصة لا تعرف أنهما نشاط تجاري واحد.&lt;/p&gt;
&lt;h2 id=&quot;كيف-تفعلها-amazon-وnoon&quot;&gt;كيف تفعلها Amazon وnoon&lt;/h2&gt;
&lt;p&gt;راجعت المنصتين. على Amazon تشتري من الموقع الرئيسي، ويقول دليل تسجيل البائعين لديها إنك تستطيع البيع بالبريد الإلكتروني وكلمة المرور نفسيهما اللذين تستخدمهما في حساب الشراء. وnoon على النمط نفسه: الشراء من الموقع الرئيسي، ولوحة البائع بوابة مستقلة على نطاق آخر (&lt;code&gt;login.noon.partners&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;النمط إذن تسجيل دخول واحد، والشراء هو الباب الرئيسي، والبيع واجهة ثانية.&lt;/p&gt;
&lt;h2 id=&quot;البريد-الإلكتروني-ليس-دورا&quot;&gt;البريد الإلكتروني ليس دورًا&lt;/h2&gt;
&lt;p&gt;الدرس الذي تعلّمته: البريد الإلكتروني يمثّل الشخص، أما «مشترٍ» و«مورّد» فهما ما يفعله هذا الشخص. وإذا ربطت الهوية بالدور، فسيدفع الثمن كل من له أكثر من دور.&lt;/p&gt;
&lt;h2 id=&quot;أين-كانت-المشكلة-فعلا&quot;&gt;أين كانت المشكلة فعلًا&lt;/h2&gt;
&lt;p&gt;ظننت أن المشكلة في الـ data model. فـ &lt;code&gt;OrganizationType&lt;/code&gt; لديّ يأخذ القيم &lt;code&gt;BUYER | SUPPLIER | PLATFORM&lt;/code&gt;، وفي الـ schema تعليق يقول إن المؤسسة الواحدة لا يمكن أن تكون الاثنين معًا. فافترضت أن الـ enum هو العائق. لكن تبيّن أنه ليس كذلك، فمعظم ما يلزم كان موجودًا:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;العضوية (membership) بين المستخدم والمؤسسة، فيمكن أن يكون الشخص عضوًا في مؤسسة مشترية ومؤسسة موردة معًا.&lt;/li&gt;&lt;li&gt;وهناك endpoint يعيد قائمة بمؤسسات الشخص، والـ guard يحدد المؤسسة من header في كل طلب، ويتحقق من العضوية ونوعها.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;ما كان يمنع التاجر فعلًا قاعدة واحدة في مرحلة التسجيل الأولي (onboarding):&lt;/p&gt;
&lt;div class=&quot;codeblock&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;codeblock__lang&quot; aria-hidden=&quot;true&quot;&gt;ts&lt;/span&gt;&lt;pre class=&quot;code&quot; dir=&quot;ltr&quot; tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;Code: ts&quot;&gt;&lt;code class=&quot;language-ts&quot;&gt;// مختصرة من الـ ADR
if (onboarding.kind === &amp;quot;PROVISIONED&amp;quot;) {
  throw new DomainValidationError(
    &amp;quot;This account already exists. Use an invitation to join another organization.&amp;quot;,
  );
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;وكانت هذه القاعدة مقصودة. فقرار سابق اعتمد &lt;code&gt;(issuer, subject)&lt;/code&gt; القادم من مزوّد الهوية مفتاحَ idempotency طبيعيًا لتأسيس المؤسسة، و«تأسيس واحد لكل هوية» هو ما يضمنه هذا المفتاح، وثمنه موثّق: لا مؤسسة ثانية عبر الخدمة الذاتية.&lt;/p&gt;
&lt;p&gt;إذن لم تكن المشكلة في الـ type، بل في قاعدة التأسيس، ومعرفة ذلك وفّرت عليّ تغييرًا أكبر بكثير.&lt;/p&gt;
&lt;h2 id=&quot;التصميم-ربط-لا-دمج&quot;&gt;التصميم: ربط لا دمج&lt;/h2&gt;
&lt;p&gt;يُبقي القرار الـ enum ثلاث قيم متنافية، ويضيّق قاعدة التأسيس بدل أن يلغيها: تأسيس واحد لكل هوية في كل جانب من السوق.&lt;/p&gt;
&lt;div class=&quot;codeblock&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;codeblock__lang&quot; aria-hidden=&quot;true&quot;&gt;sql&lt;/span&gt;&lt;pre class=&quot;code&quot; dir=&quot;ltr&quot; tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;Code: sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;-- توضيحي ومبسّط من التصميم، وليس الـ schema الفعلية
ALTER TABLE organizations
  ADD CONSTRAINT organizations_one_founding_per_side
  UNIQUE (founder_user_id, type);&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;أي أن الشخص يؤسس مؤسسة مشترية واحدة ومؤسسة موردة واحدة، ويُرفض تأسيس مؤسسة مشترية ثانية. ويبقى المفتاح طبيعيًا وداخل قاعدة البيانات.&lt;/p&gt;
&lt;p&gt;كان البديل الواضح أن أحذف الـ type وأضع flags مثل &lt;code&gt;can_buy&lt;/code&gt; و&lt;code&gt;can_sell&lt;/code&gt;، وقد رفضه الـ ADR لسببين. الأول أن لدينا ثلاثة عشر مفتاحًا أجنبيًا مركّبًا (composite foreign keys) تثبّت كل خانة طرف على مؤسسة من النوع الصحيح، والـ flags تعني تفكيك هذه الشبكة كلها في تغيير واحد. والثاني أن إضافة نوع رابع اسمه &lt;code&gt;BOTH&lt;/code&gt; أسوأ: يتحول كل &lt;code&gt;CHECK&lt;/code&gt; إلى &lt;code&gt;IN (&apos;SUPPLIER&apos;,&apos;BOTH&apos;)&lt;/code&gt;، وتختفي الضمانة دون أن يفشل اختبار واحد.&lt;/p&gt;
&lt;p&gt;لذلك تبقى المؤسستان صفّين منفصلين يجمعهما رابط معلن. والتوثيق لا يعبر هذا الرابط: شارة التوثيق تخص مؤسسة المورّد وحدها، والتقييم شهادة على المورّد، لا شيء يرثه جانب الشراء.&lt;/p&gt;
&lt;h2 id=&quot;منع-البيع-للنفس&quot;&gt;منع البيع للنفس&lt;/h2&gt;
&lt;p&gt;هذا أهم جزء. اليوم لا تستطيع أي مؤسسة أن تدعو نفسها كمورّد، لأنها لا تكون من النوعين معًا. ثم إن العرض يحتاج إلى صف دعوة، والترسية تحتاج إلى عرض، والتقييم مرتبط بالترسية. وتصمد هذه السلسلة كلها لأن النوعين متنافيان على الصف الواحد.&lt;/p&gt;
&lt;p&gt;فإذا صار لشخص واحد صف في كل جانب، لم تعد السلسلة تحمي شيئًا: صف المشتري يدعو صف المورّد، ويرسي عليه، ويمنحه خمس نجوم. لذا يجب أن يعيد التصميم بناء هذه الحماية صراحةً:&lt;/p&gt;
&lt;div class=&quot;codeblock&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;codeblock__lang&quot; aria-hidden=&quot;true&quot;&gt;sql&lt;/span&gt;&lt;pre class=&quot;code&quot; dir=&quot;ltr&quot; tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;Code: sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;-- توضيحي. شكل القيد، وليس الـ DDL الفعلي
ALTER TABLE rfq_recipients
  ADD CONSTRAINT rfq_recipients_not_self_dealing
  CHECK (buyer_link_group_id &amp;lt;&amp;gt; supplier_link_group_id);&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;وتغيّرت تفصيلة بين المسودة والتنفيذ. في المسودة كان الـ link group يقبل NULL. لكن الـ foreign key في PostgreSQL يكون &lt;code&gt;MATCH SIMPLE&lt;/code&gt; افتراضيًا: إذا كانت قيمة أي عمود NULL، يُعدّ القيد متحققًا دون فحص. أي أن أي كود يكتب البيانات وينسى هذا العمود سيعطّل القاعدة سهوًا دون أن يلاحظ أحد. لذلك صارت المؤسسة التي لا رابط معلنًا لها مجموعةً من عضو واحد، معرّفها هو الـ group، وصار القيد &lt;code&gt;&amp;lt;&amp;gt;&lt;/code&gt; بسيطًا على عمودين &lt;code&gt;NOT NULL&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;ويوثّق التصميم حدوده أيضًا:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;القيد يلتقط الرابط المعلن فقط. فلو أنشأ شخص مؤسستين ببريدين مختلفين دون إعلان الرابط، ستمرّان كما تمرّان اليوم.&lt;/li&gt;&lt;li&gt;أن يطّلع تاجر على أسعار منافسيه عبر طلب عرض أسعار حقيقي يرسله بنفسه سلوكُ سوق، لا مشكلة في الـ schema. لا يوجد مفتاح يمنعه، لكن المنصة تستطيع على الأقل أن تراه حين يوجد الرابط.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;والرابط للعرض فقط، ولا يوسّع أي قراءة. فالقراءات محصورة بمعرّف المؤسسة الذي استخرجه الـ guard من العضوية، وهناك اختبار في الـ architecture يُفشل الـ build إذا وصل عمود الرابط إلى query أو authorization أو presenter.&lt;/p&gt;
&lt;h2 id=&quot;تسجيل-الدخول-والجلسات-عبر-النطاقات-الفرعية&quot;&gt;تسجيل الدخول والجلسات عبر النطاقات الفرعية&lt;/h2&gt;
&lt;p&gt;قد توحي «هوية واحدة عبر عدة hostnames» بالحاجة إلى cookies مشتركة. لكن الأمر ليس كذلك.&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;كل hostname هو origin مستقل. وcookies من نوع &lt;code&gt;__Host-&lt;/code&gt; لا تحمل &lt;code&gt;Domain&lt;/code&gt;، فلا تُشارَك الجلسة على واجهة مع واجهة أخرى، ولو بالخطأ.&lt;/li&gt;&lt;li&gt;ما يُشارَك هو الهوية، عبر الـ issuer. فـ Keycloak على &lt;code&gt;id.&lt;/code&gt; هو الـ OIDC issuer، والهويات الخارجية مخزّنة بـ &lt;code&gt;(issuer, subject)&lt;/code&gt;، أي أن عنوان الـ issuer حدّ في الـ data model، لا مجرد اسم تجاري.&lt;/li&gt;&lt;li&gt;كل تطبيق OIDC client بعناوين redirect حرفية، والـ wildcards ممنوعة.&lt;/li&gt;&lt;li&gt;المؤسسة الفاعلة تُحدَّد مع كل طلب وتُطابَق مع العضوية. الـ header يسمّيها، والخادم هو الذي يقرر.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;ويتبع الانتقال بين البوابتين نمط OIDC المعتاد: يحوّلك التطبيق الثاني إلى الـ issuer، والـ issuer يعرفك بالفعل، فتعود مسجّل الدخول. أصف هذا من الإعدادات (config) والـ ADRs، لا من اختبار مسجّل. ويتطلب التصميم رابطًا صريحًا بين البوابتين، دون تبديل صامت.&lt;/p&gt;
&lt;h2 id=&quot;إذا-كانت-لديك-حسابات-مكررة-بالفعل&quot;&gt;إذا كانت لديك حسابات مكررة بالفعل&lt;/h2&gt;
&lt;p&gt;لم أنفّذ دمجًا لحسابات مكررة في EgyGomla، فما يلي إرشادات عامة:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;ابدأ بالعدّ قبل أن تغيّر أي شيء. الـ migrations عندي تعدّ الصفوف التي تخالف القاعدة الجديدة، ثم تتوقف وتسمّيها، بدل أن تعدّلها أو تحذفها. افعل الشيء نفسه مع التكرار: البريد الإلكتروني، والهاتف، والرقم الضريبي، واسم الشركة.&lt;/li&gt;&lt;li&gt;لا تدمج تلقائيًا عند التطابق. تشابه البيانات لا يثبت أنه الشخص نفسه، والتراجع عن الدمج صعب.&lt;/li&gt;&lt;li&gt;دع الشخص يؤكد الحسابين: يسجّل الدخول إلى كلٍّ منهما، ثم اربط المؤسستين بهوية واحدة. اربطهما، ولا تدمجهما في صف واحد.&lt;/li&gt;&lt;li&gt;اترك الكتالوج والسجل في مكانهما، ونفّذ expand ثم backfill ثم الـ constraints.&lt;/li&gt;&lt;li&gt;إذا كان العمود الجديد &lt;code&gt;NOT NULL&lt;/code&gt; بلا قيمة default، فيجب على كل ما يكتب البيانات (حتى الـ seed والـ scripts) أن يرسل قيمته قبل الـ migration.&lt;/li&gt;&lt;li&gt;سيبقى في النهاية من لن يربط حسابيه أبدًا، وهذا مقبول ما دام هذا الحدّ موثّقًا.&lt;/li&gt;&lt;/ol&gt;
&lt;h2 id=&quot;لو-عاد-بي-الزمن&quot;&gt;لو عاد بي الزمن&lt;/h2&gt;
&lt;ul&gt;&lt;li&gt;أبدأ من يوم المستخدم الذي يستعمل المنصة كل يوم، قبل أن أقرر ما تحتاجه كل صفحة.&lt;/li&gt;&lt;li&gt;أحدد أين يقع القيد فعلًا قبل أن أبني حوله. لُمتُ الـ enum، والعائق كان قاعدة onboarding اخترتها بنفسي.&lt;/li&gt;&lt;li&gt;أكتب سلسلة إساءة الاستخدام قبل المسار المثالي. كان نظام التقييم يستند إلى خاصية لا ينصّ عليها أي قيد صراحةً.&lt;/li&gt;&lt;li&gt;لا أطلق مسار المؤسسة الثانية وحده. فالـ ADR يشترط إطلاقه مع قيود منع البيع للنفس، وإلا صار التحايل الذي كان يتطلب «بريدًا ثانيًا» لا يحتاج إلا «نقرة واحدة».&lt;/li&gt;&lt;li&gt;أفصل بين ما تقرّر وما أُطلق. هذا المقال يصف قرارًا، لا ميزة متاحة للتجار.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;محمد الجوهري (Mohamed Elgohary)، مهندس برمجيات، القاهرة. mohamedelgohary.dev&lt;/p&gt;</content>
  </entry>
  <entry xml:lang="en">
    <title>One identity, many roles: what I got wrong about marketplace accounts</title>
    <link rel="alternate" type="text/html" href="https://mohamedelgohary.dev/writing/one-identity-many-roles-marketplace-accounts/"/>
    <id>https://mohamedelgohary.dev/writing/one-identity-many-roles-marketplace-accounts/</id>
    <published>2026-11-10T00:00:00Z</published>
    <updated>2026-11-18T02:51:41+02:00</updated>
    <summary>Separate emails per role punish a marketplace&apos;s busiest users. How EgyGomla&apos;s design moves to one identity with linked buyer and supplier organizations.</summary>
    <category term="system-design"/>
    <category term="marketplace"/>
    <category term="authentication"/>
    <category term="oidc"/>
    <category term="postgresql"/>
    <category term="egygomla"/>
    <content type="html">&lt;aside class=&quot;callout&quot; aria-labelledby=&quot;tldr&quot;&gt;&lt;p class=&quot;callout__label&quot; id=&quot;tldr&quot;&gt;TL;DR&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;I built EgyGomla, a B2B sourcing platform for Egyptian traders, with a separate email, account and password for each side of the market: buyers on one subdomain, suppliers on another.&lt;/li&gt;&lt;li&gt;A wholesaler buys from factories and sells to retailers. My &amp;quot;clean&amp;quot; design made the people the product is for pay the most.&lt;/li&gt;&lt;li&gt;The better model: the email is the person, and &amp;quot;buyer&amp;quot; and &amp;quot;supplier&amp;quot; are roles. In the data model that is one user with at most one buyer organization and one supplier organization, linked but never merged, with self-dealing blocked in the database.&lt;/li&gt;&lt;li&gt;This is a decided design (ADR-0013, status Accepted, 14 August 2026), and the migrations for it are written in the repo. It is not a claim that traders can do this in production today.&lt;/li&gt;&lt;/ul&gt;
&lt;/aside&gt;
&lt;h2 id=&quot;what-i-built-first&quot;&gt;What I built first&lt;/h2&gt;
&lt;p&gt;EgyGomla helps Egyptian traders find manufacturers and suppliers, browse wholesale catalogues and request quotations. I built it end to end: web apps, dashboards, backend and Flutter apps. The public website is live; the mobile apps are not on the stores yet.&lt;/p&gt;
&lt;p&gt;The production edge is one Caddy config, a hostname per surface:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;code&gt;egygomla.com&lt;/code&gt;: the public marketing site&lt;/li&gt;&lt;li&gt;&lt;code&gt;app.egygomla.com&lt;/code&gt;: the buyer application&lt;/li&gt;&lt;li&gt;&lt;code&gt;factory.egygomla.com&lt;/code&gt;: the supplier portal&lt;/li&gt;&lt;li&gt;&lt;code&gt;admin.egygomla.com&lt;/code&gt;: the platform console&lt;/li&gt;&lt;li&gt;&lt;code&gt;api.egygomla.com&lt;/code&gt;: the HTTP API&lt;/li&gt;&lt;li&gt;&lt;code&gt;id.egygomla.com&lt;/code&gt;: Keycloak, the OIDC issuer&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;On top of that split I decided every role gets its own email. It felt tidy: each role in its own place, the data separate.&lt;/p&gt;
&lt;h2 id=&quot;where-it-breaks-the-wholesaler&quot;&gt;Where it breaks: the wholesaler&lt;/h2&gt;
&lt;p&gt;The product&apos;s own audience line names factories, importers, and wholesale and retail traders. A wholesaler, by definition of the trade, buys from the factory and sells to the retailer. That person is both sides of the market.&lt;/p&gt;
&lt;p&gt;Under my first design, that trader needs a second email, a second account, a second password, and keeps switching between them. I was penalising my best users for being my best users.&lt;/p&gt;
&lt;p&gt;The cost is not only friction. Two accounts share no catalogue, conversations, reviews or history, and the platform cannot know they are one business, which matters once you think about abuse.&lt;/p&gt;
&lt;h2 id=&quot;what-the-big-marketplaces-do&quot;&gt;What the big marketplaces do&lt;/h2&gt;
&lt;p&gt;On Amazon you buy on the main site, and Amazon&apos;s own seller registration guide says you can sell with the same email and password as your customer account. noon follows the same shape: you shop on its main site, and the seller portal is a separate surface on its own domain (&lt;code&gt;login.noon.partners&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;The pattern in both: one login, the buyer experience as the front door, selling as a second surface you opt into.&lt;/p&gt;
&lt;h2 id=&quot;identity-is-not-a-role&quot;&gt;Identity is not a role&lt;/h2&gt;
&lt;p&gt;An email represents a person. &amp;quot;Buyer&amp;quot; and &amp;quot;supplier&amp;quot; are things that person does. Tie identity to role and anyone with more than one role pays for it, while everyone else never notices.&lt;/p&gt;
&lt;h2 id=&quot;where-the-constraint-actually-lived&quot;&gt;Where the constraint actually lived&lt;/h2&gt;
&lt;p&gt;I assumed the data model was the problem. &lt;code&gt;OrganizationType&lt;/code&gt; is &lt;code&gt;BUYER | SUPPLIER | PLATFORM&lt;/code&gt;, and a schema comment says one organization row cannot be both at once. But the enum was not what blocked wholesalers. Most of the multi-role machinery already existed:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;Membership is many-to-many in practice, with a unique key on &lt;code&gt;(userId, organizationId)&lt;/code&gt;, so one person can belong to a buyer organization and a supplier organization at once.&lt;/li&gt;&lt;li&gt;An endpoint returns a list of the person&apos;s organizations, not one.&lt;/li&gt;&lt;li&gt;The guard resolves the acting organization on every request from a header, then checks the membership, its status, and that the organization&apos;s type matches the route.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;What blocked the wholesaler was one rule in onboarding:&lt;/p&gt;
&lt;div class=&quot;codeblock&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;codeblock__lang&quot; aria-hidden=&quot;true&quot;&gt;ts&lt;/span&gt;&lt;pre class=&quot;code&quot; dir=&quot;ltr&quot; tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;Code: ts&quot;&gt;&lt;code class=&quot;language-ts&quot;&gt;// onboarding service (paraphrased from the ADR)
if (onboarding.kind === &amp;quot;PROVISIONED&amp;quot;) {
  throw new DomainValidationError(
    &amp;quot;This account already exists. Use an invitation to join another organization.&amp;quot;,
  );
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;That rule was deliberate. An earlier decision used &lt;code&gt;(issuer, subject)&lt;/code&gt; from the identity provider as the natural idempotency key for founding an organization, so &amp;quot;one founding per identity&amp;quot; was what that key bought, and the price was written down: no second organization through self-service.&lt;/p&gt;
&lt;p&gt;So I did not have a type problem. I had a founding-rule problem, and knowing that spared me a much bigger change.&lt;/p&gt;
&lt;h2 id=&quot;the-design-one-identity-two-linked-organizations&quot;&gt;The design: one identity, two linked organizations&lt;/h2&gt;
&lt;p&gt;The decision keeps the enum as three mutually exclusive values and narrows the founding rule instead of deleting it: one self-service founding per identity per side. Illustrative SQL, simplified:&lt;/p&gt;
&lt;div class=&quot;codeblock&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;codeblock__lang&quot; aria-hidden=&quot;true&quot;&gt;sql&lt;/span&gt;&lt;pre class=&quot;code&quot; dir=&quot;ltr&quot; tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;Code: sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Illustrative. Simplified from the design, not the production schema.
ALTER TABLE organizations
  ADD CONSTRAINT organizations_one_founding_per_side
  UNIQUE (founder_user_id, type);&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;A person can found one buyer organization and one supplier organization; a second buyer organization is refused. The idempotency key stays natural and stays in the database, not in a header the client sends.&lt;/p&gt;
&lt;h3 id=&quot;link-not-merge&quot;&gt;Link, not merge&lt;/h3&gt;
&lt;p&gt;I considered the obvious alternative: replace the type with capability flags like &lt;code&gt;can_buy&lt;/code&gt; and &lt;code&gt;can_sell&lt;/code&gt;. The ADR rejects it for two reasons.&lt;/p&gt;
&lt;p&gt;First, thirteen composite foreign keys pin each party column to an organization of the right type, so a supplier can never sit in a buyer&apos;s slot. Flags mean rebuilding that network in one change. Second, a shortcut like a fourth &lt;code&gt;BOTH&lt;/code&gt; type is worse: every &lt;code&gt;CHECK&lt;/code&gt; turns into &lt;code&gt;IN (&apos;SUPPLIER&apos;,&apos;BOTH&apos;)&lt;/code&gt;, and the guarantee that one row is not both sides disappears without a constraint failing or a test going red.&lt;/p&gt;
&lt;p&gt;So the two organizations stay separate rows joined by a declared link. Verification does not cross it: a verified badge belongs to the supplier organization, and reviews are testimony about the supplier, not something the buying side inherits.&lt;/p&gt;
&lt;h3 id=&quot;block-self-dealing&quot;&gt;Block self-dealing&lt;/h3&gt;
&lt;p&gt;Today an organization cannot invite itself as a supplier, because it is never both types. After that, a quote needs an invited recipient row, an award needs a quote, and a review is anchored to an award. The whole chain holds because the two types are disjoint on a single row.&lt;/p&gt;
&lt;p&gt;Give one person a row on each side and the chain protects nothing: the buyer row invites the supplier row, awards it, and rates it five stars. The design has to re-derive that protection explicitly:&lt;/p&gt;
&lt;div class=&quot;codeblock&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;codeblock__lang&quot; aria-hidden=&quot;true&quot;&gt;sql&lt;/span&gt;&lt;pre class=&quot;code&quot; dir=&quot;ltr&quot; tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;Code: sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Illustrative. The shape of the constraint, not the exact production DDL.
-- Each row carries a denormalised copy of each party&apos;s link group,
-- held honest by a composite foreign key to organizations.
ALTER TABLE rfq_recipients
  ADD CONSTRAINT rfq_recipients_not_self_dealing
  CHECK (buyer_link_group_id &amp;lt;&amp;gt; supplier_link_group_id);&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;One detail changed between the sketch and the implementation. The sketch had a nullable link group with &lt;code&gt;IS NULL&lt;/code&gt; branches. But a PostgreSQL foreign key is &lt;code&gt;MATCH SIMPLE&lt;/code&gt; by default: if any referencing column is NULL, the constraint is satisfied without being checked. A writer that forgot the column would switch the rule off by omission, and nothing would report it. So an organization with no declared link is a group of one, its own id, and the check becomes a plain &lt;code&gt;&amp;lt;&amp;gt;&lt;/code&gt; over two &lt;code&gt;NOT NULL&lt;/code&gt; columns.&lt;/p&gt;
&lt;p&gt;The design writes its limits down too:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;Only a declared link is caught. Two organizations created with two emails and no declaration pass, as they do today.&lt;/li&gt;&lt;li&gt;Harvesting competitors&apos; prices through your own legitimate request for quotation is market behaviour, not a schema problem. No key closes it, though the platform can at least see it once the link exists.&lt;/li&gt;&lt;/ul&gt;
&lt;h3 id=&quot;the-link-must-never-widen-a-read&quot;&gt;The link must never widen a read&lt;/h3&gt;
&lt;p&gt;Reads are scoped by the organization id the guard resolved from the membership. A supplier acting as a buyer is just a different buyer and gets the same not-found as anyone else. The link is presentational only: no query may use it to widen a tenant filter, and an architecture test fails the build if the column reaches a query condition, an ordering, an authorization path or a presenter.&lt;/p&gt;
&lt;h2 id=&quot;auth-and-sessions-across-subdomains&quot;&gt;Auth and sessions across subdomains&lt;/h2&gt;
&lt;p&gt;One identity across several hostnames sounds like it needs shared cookies. It does not.&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;Each hostname is its own origin. &lt;code&gt;__Host-&lt;/code&gt; cookies carry no &lt;code&gt;Domain&lt;/code&gt; attribute, so a session on one surface is never shared with another, even by accident.&lt;/li&gt;&lt;li&gt;Identity is shared through the issuer. Keycloak at &lt;code&gt;id.&lt;/code&gt; is the OIDC issuer, and external identities are keyed by &lt;code&gt;(issuer, subject)&lt;/code&gt;, so the issuer&apos;s hostname is a data-model boundary, not branding.&lt;/li&gt;&lt;li&gt;Each application is an OIDC client with literal redirect and post-logout URLs. Wildcards are forbidden, so renaming a host is a two-place change, and the second place is the identity provider.&lt;/li&gt;&lt;li&gt;Application session material lives in Redis behind an opaque cookie.&lt;/li&gt;&lt;li&gt;The acting organization is chosen per request and verified against a membership. A header names it; the server decides whether the person may act as it. A client-sent &amp;quot;act as&amp;quot; role would be a worse design.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;The cross-portal hop follows the usual OIDC pattern: the second application redirects to the issuer, the issuer already knows the person, and the person returns. I am describing that from the config and the ADRs, not from a recorded test. The design also calls for an explicit link between the buyer app and the supplier portal, with no silent switching, and every screen that changes something names the acting organization and its side.&lt;/p&gt;
&lt;h2 id=&quot;if-you-already-have-duplicate-accounts&quot;&gt;If you already have duplicate accounts&lt;/h2&gt;
&lt;p&gt;I have not run a merge of duplicate accounts in EgyGomla, and nothing here claims that. This is general guidance.&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;strong&gt;Count before you change anything.&lt;/strong&gt; The migrations in this repo count rows that violate a new rule and refuse to continue, naming them, instead of coercing or deleting them. Do the same for duplicates, using signals you trust: normalised email, phone, tax id, company name.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Never auto-merge on a match.&lt;/strong&gt; Similar details do not prove the same person, and a merge is hard to undo.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Let the person confirm both.&lt;/strong&gt; Ask them to sign in to each account, then attach both organizations to one identity and link them. Do not collapse them into one row.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Keep catalogues and history where they are.&lt;/strong&gt; The link is for understanding, not for combining data.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Expand, backfill, contract.&lt;/strong&gt; Add nullable columns, backfill, then add constraints, and build unique indexes concurrently on a live database.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Ship writers first.&lt;/strong&gt; If a new column is &lt;code&gt;NOT NULL&lt;/code&gt; with no default, every writer, including seeds and scripts, must supply it before the migration runs.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Expect a tail.&lt;/strong&gt; Some people will never link. They behave as they do today, which is acceptable if the limit is written down.&lt;/li&gt;&lt;/ol&gt;
&lt;h2 id=&quot;what-id-do-differently&quot;&gt;What I&apos;d do differently&lt;/h2&gt;
&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Start from the heaviest user&apos;s day.&lt;/strong&gt; Ask who the person is before deciding what each page needs, and walk through a day for the user who touches both sides.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Find where the constraint lives first.&lt;/strong&gt; I blamed the enum; the blocker was an onboarding rule I had chosen on purpose.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Write the abuse chain before the happy path.&lt;/strong&gt; The review system leaned on a property no constraint stated. Making it explicit was the most important part of the design.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Do not ship the second-organization path alone.&lt;/strong&gt; The ADR says it must not go out without the anti-self-dealing constraints, or self-dealing drops from &amp;quot;needs a second email&amp;quot; to &amp;quot;one click&amp;quot;.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Keep marketing behind the feature.&lt;/strong&gt; The ADR forbids copy like &amp;quot;one account buys and sells&amp;quot; until the feature exists, and a copy test guards the site&apos;s other promises.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Say what is decided and what is shipped.&lt;/strong&gt; This article describes a decision, not something in front of traders.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Mohamed Elgohary, Software Engineer, Cairo. mohamedelgohary.dev&lt;/p&gt;</content>
  </entry>
  <entry xml:lang="ar">
    <title>بعقلية مهندس QA: كيف أنشر تطبيقات الجوال</title>
    <link rel="alternate" type="text/html" href="https://mohamedelgohary.dev/ar/writing/tested-like-a-qa-engineer-how-i-release-mobile-apps/"/>
    <id>https://mohamedelgohary.dev/ar/writing/tested-like-a-qa-engineer-how-i-release-mobile-apps/</id>
    <published>2026-11-10T00:00:00Z</published>
    <updated>2026-11-18T05:21:49+02:00</updated>
    <summary>قائمة نشر بخبرة QA/SDET قبل رفع تطبيق على App Store أو Google Play: اختبر نسخة الـ release، وارفض الأذونات، واقطع الشبكة، وحدّث من نسخة المتجر، واحمِ الـ API.</summary>
    <category term="mobile"/>
    <category term="qa"/>
    <category term="sdet"/>
    <category term="release-management"/>
    <category term="flutter"/>
    <category term="android"/>
    <category term="ios"/>
    <category term="testing"/>
    <content type="html">&lt;aside class=&quot;callout&quot; aria-labelledby=&quot;الخلاصة&quot;&gt;&lt;p class=&quot;callout__label&quot; id=&quot;الخلاصة&quot;&gt;الخلاصة&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;إلى جانب عملي في تطوير تطبيقات الجوال، لديّ خلفية في QA/SDET (اختبار البرمجيات وأتمتته)، وأنشر التطبيقات كما يفعل المختبِر: أفترض أن المسار المثالي يعمل، وأصرف الجهد على كل ما حوله.&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;https://mohamedelgohary.dev/ar/release-checklist/&quot;&gt;قائمتي العامة للمراجعة قبل النشر&lt;/a&gt; فيها 34 بندًا في ستة أقسام: تجهيز النسخة (build)، والاختبار، والـ backend (الخادم)، وApp Store، وGoogle Play، ويوم النشر. وقد رُوجعت قواعد المتاجر فيها على الصفحات الرسمية في 28 سبتمبر 2026.&lt;/li&gt;&lt;li&gt;أهم العادات: اختبر النسخة نفسها التي ستُنشر، وارفض كل إذن، واقطع الشبكة عمدًا، وحدّث من النسخة الموجودة لدى المستخدمين، وأبقِ الـ API، أي الواجهة التي يتصل عبرها التطبيق بالخادم، متوافقًا مع النسخ القديمة المثبّتة.&lt;/li&gt;&lt;li&gt;قائمة المراجعة ليست مجموعة اختبارات (test suite). هي تخبرك بما يجب اختباره، وبما يجب الاحتفاظ به من أدلة.&lt;/li&gt;&lt;/ul&gt;
&lt;/aside&gt;
&lt;h2 id=&quot;من-أين-جاءت-هذه-الطريقة&quot;&gt;من أين جاءت هذه الطريقة&lt;/h2&gt;
&lt;p&gt;من أغسطس 2024 إلى أغسطس 2025 عملت Software Development Engineer in Test، أي مهندس برمجيات متخصصًا في الاختبار وأتمتته، لدى TAKADOM AL-IRAQ (TTech) بنظام العمل الحر. كنت مسؤولًا عن اختبار تطبيقات الجوال والويب والـ APIs في منتجات خدمات عامة، وبنيت أتمتة الاختبارات بـ Kotlin وSelenium لمشروع نفطكم (Naftcom)، مع تغطية للـ API واختبارات regression (إعادة اختبار ما كان يعمل بعد كل تغيير) حول مسار المواطن ومسار المحطة فيه. وهذا الكود في مستودع خاص، لذا لن أتناوله بالتفصيل هنا.&lt;/p&gt;
&lt;p&gt;وأنا أبني تطبيقات الجوال أيضًا. ففي Apps Square أنا مسؤول عن تطبيقات الجوال لعدة منتجات، من إنشاء المشروع والـ architecture حتى الاختبار والتسليم. وفي Inside Tech بنيت تطبيق العميل وتطبيق التاجر في &lt;a href=&quot;https://mohamedelgohary.dev/ar/project/bismar/&quot;&gt;بسمار&lt;/a&gt; بـ Kotlin Multiplatform، وكنت مهندس الجوال الوحيد فيهما، ولكلٍّ منهما صفحة عامة على App Store وGoogle Play. وتجد تفاصيل مشاريعي في &lt;a href=&quot;https://mohamedelgohary.dev/ar/projects/&quot;&gt;صفحة المشاريع&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;وعادة الاختبار ترافقني. فحين أقرأ وصف أي ميزة اليوم، يظل سؤالي الأول: ماذا يحدث إذا فشلت؟&lt;/p&gt;
&lt;h2 id=&quot;اختبر-النسخة-التي-ستنشر-فعلا&quot;&gt;اختبر النسخة التي ستُنشر فعلًا&lt;/h2&gt;
&lt;p&gt;نسخة الـ debug، أي نسخة التطوير التي يعمل عليها المبرمج، لا تثبت الكثير عن الإصدار الفعلي. والقائمة صريحة هنا: أختبر نسخة الـ release الموقّعة بإعدادات الإنتاج، لأن تقليص الكود (code shrinking) وإعدادات الـ release قد يعطّلان أشياء لا تظهر أبدًا في نسخة الـ debug.&lt;/p&gt;
&lt;p&gt;وبجانب هذا البند بنود أخرى، لأنها تفشل بالطريقة الصامتة نفسها:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;strong&gt;رقم الإصدار ورقم الـ build.&lt;/strong&gt; كل رفع إلى المتجر يحتاج رقم build أعلى من السابق (&lt;code&gt;versionCode&lt;/code&gt; على Android، ورقم الـ build على iOS)، ويجب أن يطابق الإصدار الظاهر للمستخدمين ملاحظات الإصدار.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;مفاتيح التوقيع.&lt;/strong&gt; استخدم Play App Signing حتى يمكن إعادة تعيين الـ upload key إذا فُقد. واحتفظ بنسخة احتياطية من المفاتيح وكلمات المرور خارج المستودع.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;ملفات الـ symbols للأعطال.&lt;/strong&gt; ارفع ملف الـ mapping الخاص بـ R8/ProGuard وملفات dSYM لـ iOS إلى أداة تقارير الأعطال؛ فهذه الملفات هي التي تحوّل تقرير العطل إلى كود مقروء. ومن دونها تبقى الـ stack traces القادمة من الإنتاج غير مفهومة، ويصبح أول عطل حقيقي لعبة تخمين.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;لا بقايا من الـ debug.&lt;/strong&gt; راجع في إعدادات الـ release عناوين الخادم (base URLs)، والـ feature flags، وأي logs مفصّلة تطبع بيانات شخصية، وقوائم الاختبار المخفية.&lt;/li&gt;&lt;/ul&gt;
&lt;h2 id=&quot;الأجهزة-ومسار-التحديث&quot;&gt;الأجهزة ومسار التحديث&lt;/h2&gt;
&lt;p&gt;تطلب القائمة أجهزة حقيقية من الطرفين: على الأقل أقدم إصدار نظام تشغيل تدعمه وأحدث إصدار، وشاشة صغيرة وأخرى كبيرة.&lt;/p&gt;
&lt;p&gt;واختبار التحديث هو آخر اختبار أقبل أن أتخطاه. ثبّت النسخة الموجودة على المتجر اليوم، وأنشئ بعض البيانات، ثم حدّث. يجب أن تبقى الجلسات والإعدادات المحفوظة والبيانات المحلية كما هي. فقد يكون التثبيت الجديد مثاليًا، بينما يفقد من يستخدم التطبيق منذ عام جلسته.&lt;/p&gt;
&lt;h2 id=&quot;مسارات-الفشل-أولا&quot;&gt;مسارات الفشل أولًا&lt;/h2&gt;
&lt;p&gt;هنا تظهر خلفية الـ QA أكثر من أي مكان آخر. بند الشبكة في القائمة يقول: اختبر الاتصال البطيء والمقطوع والمتقطّع، وتأكد أن حالات التحميل وإعادة المحاولة والأخطاء تعمل، وأن إرسال الـ request نفسه مرة ثانية لا يُنشئ أبدًا طلبًا مكررًا أو دفعة مكررة.&lt;/p&gt;
&lt;p&gt;والجزء الأخير هو الأهم. فإعادة المحاولة التي تعمل هي نصف الميزة فقط، والنصف الآخر أن تكون آمنة: من ضغط زر الدفع مرتين لأن الشبكة ضعيفة، ينبغي ألا يُخصم منه المبلغ مرتين.&lt;/p&gt;
&lt;p&gt;وهذا مثال صغير من تطبيق Flutter عملت عليه، هو Fueler. كانت الشاشة الرئيسية تحمّل بيانات الحساب والمحفظة والمنتجات بالتوازي، وتحدد موقع المستخدم أيضًا لإيجاد المحطات القريبة. وكان الكود الأصلي ينتظر كل ذلك قبل عرض الصفحة، فإذا تأخر تحديد الموقع اختفى رصيد المحفظة خلف حالة التحميل، مع أن المحفظة لا تحتاج إلى الإحداثيات أصلًا.&lt;/p&gt;
&lt;p&gt;والاختبار الذي يحمي الإصلاح يفعل ما يفعله أي مختبِر: يؤخّر عمدًا شيئًا واحدًا تعتمد عليه الشاشة.&lt;/p&gt;
&lt;div class=&quot;codeblock&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;codeblock__lang&quot; aria-hidden=&quot;true&quot;&gt;dart&lt;/span&gt;&lt;pre class=&quot;code&quot; dir=&quot;ltr&quot; tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;Code: dart&quot;&gt;&lt;code class=&quot;language-dart&quot;&gt;// مبسّط من ملف الاختبار في المشروع.
locationResolver.delay = const Duration(seconds: 3); // تحديد موقع يبدأ من الصفر فعلًا
final loading = cubit.load();
await Future&amp;lt;void&amp;gt;.delayed(const Duration(milliseconds: 400));

// الشاشة قابلة للاستخدام قبل أن يصل تحديد الموقع:
expect(cubit.state.status, HomeStatus.loaded);
expect(cubit.state.profile, _profile);
expect(cubit.state.products, _products);
// ...والأقسام التي تحتاج إلى الإحداثيات تقول ذلك بصدق:
expect(cubit.state.locationAccess, LocationAccess.unknown);
expect(cubit.state.stations, isEmpty);&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;وفي المجموعة نفسها اختبار ثانٍ يتحقق من أن تحديد الموقع السريع (warm fix) يُصدر حالة واحدة بالضبط مع كل تحديث للشاشة، حتى لا يعود قسم المحطات فجأة إلى «جارٍ تحديد الموقع». لم أقِس التوقيت على الأجهزة ولا أي أثر على معدلات التحويل، فالفكرة هنا في شكل الاختبار: أبطئ شيئًا واحدًا، ثم تحقق مما يُسمح لبقية الشاشة بفعله.&lt;/p&gt;
&lt;h2 id=&quot;الأذونات-واللغة-التي-تقرأ-بها&quot;&gt;الأذونات واللغة التي تقرأ بها&lt;/h2&gt;
&lt;p&gt;الكاميرا والموقع والإشعارات، لكلٍّ منها اختبار للحالة التي تُنسى: أن يضغط المستخدم «عدم السماح» (Don&apos;t Allow). يجب أن يظل التطبيق يعمل، وأن يوضّح لماذا يحتاج إلى الإذن.&lt;/p&gt;
&lt;p&gt;وتتعامل القائمة مع العربية كإعداد اختبار، لا كمهمة ترجمة: واجهات معكوسة، ونص عربي وإنجليزي متداخل، وحجم خط النظام في أقصى درجاته. فأخطاء الاتجاه من اليمين إلى اليسار (RTL) يسهل أن تفوتك إذا كنت تقرأ الواجهة بلغة واحدة فقط، وهذا بند يهمّ كل تطبيق يخاطب مستخدمين عربًا.&lt;/p&gt;
&lt;h2 id=&quot;الـ-api-جزء-من-الإصدار&quot;&gt;الـ API جزء من الإصدار&lt;/h2&gt;
&lt;p&gt;إصدار تطبيق الجوال نصفه إصدار للـ backend، والنصف الذي يُنسى هو التطبيق القديم. فالمستخدمون يحدّثون ببطء، ولذلك تطلب القائمة أن يظل الـ API يخدم النسخة المثبّتة لديهم: تبقى الـ endpoints القديمة وشكل الردود تعمل، أو تُطلق آلية التحديث الإجباري أولًا.&lt;/p&gt;
&lt;p&gt;وفحص أدنى إصدار مدعوم يتيح لك إيقاف نسخة معطوبة دون انتظار أن يحدّث الجميع. وعلى جانب البيانات: جرّب الـ migrations (تعديلات بنية قاعدة البيانات) على نسخة من بيانات الإنتاج أولًا، وخذ نسخة احتياطية قبل الإصدار.&lt;/p&gt;
&lt;p&gt;وأنقل العادة نفسها إلى أدواتي. فـ &lt;a href=&quot;https://mohamedelgohary.dev/ar/product/postsyncpro/&quot;&gt;PostSync Pro&lt;/a&gt; أداة Compose Desktop مفتوحة المصدر بنيتها، ترسل طلبات REST، وتشغّل assertions محدودة النطاق (bounded assertions)، وتتحقق من الردود مقابل مواصفة OpenAPI. وهي منشورة كنسخة Beta، والشاشات التي ما زالت تستخدم بيانات محاكاة معلَّمة بأنها معاينات (previews).&lt;/p&gt;
&lt;h2 id=&quot;إعادة-اختبار-ما-يؤلم-أكثر&quot;&gt;إعادة اختبار ما يؤلم أكثر&lt;/h2&gt;
&lt;p&gt;لا أحاول إعادة اختبار كل شيء. تقول القائمة: أجرِ اختبار regression على أهم المسارات، وهي التسجيل، وتسجيل الدخول، والدفع أو الحجز، وكل ما قد يدفع مستخدمًا إلى الاتصال بالدعم. وللإشعارات والـ deep links (روابط تفتح شاشة محددة داخل التطبيق) فحص خاص: يجب أن تفتح الشاشة الصحيحة والتطبيق مغلق، وهو في الخلفية، والمستخدم غير مسجّل الدخول.&lt;/p&gt;
&lt;h2 id=&quot;قواعد-المتاجر-حالات-اختبار-أيضا&quot;&gt;قواعد المتاجر حالات اختبار أيضًا&lt;/h2&gt;
&lt;p&gt;ينشر المتجران قواعد تُقرأ كأنها متطلبات، فتتحول إلى بنود فحص. وإذا كنت تستعد لرفع تطبيق على App Store أو نشر تطبيق على Google Play، فهذه بعض بنود القائمة:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;strong&gt;App Store:&lt;/strong&gt; ابنِ التطبيق بالـ SDK المطلوب (iOS 26 SDK أو أحدث، منذ 28 أبريل 2026)؛ واجعل بيانات App Privacy مطابقة لما يجمعه التطبيق والـ SDKs التي يستخدمها؛ وامنح فريق المراجعة في Apple (App Review) حسابًا تجريبيًا يعمل، وأبقِ الـ backend يعمل طوال فترة المراجعة؛ ووفّر حذف الحساب من داخل التطبيق؛ وإذا قدّمت تسجيل دخول عبر طرف ثالث، فقدّم خيارًا مكافئًا مثل Sign in with Apple؛ وأجب عن سؤال التشفير في &lt;code&gt;Info.plist&lt;/code&gt;.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Google Play:&lt;/strong&gt; اجعل نموذج Data safety مطابقًا للتطبيق؛ والتزم بشرط الـ target API؛ وقدّم للمراجعة بيانات دخول تبقى صالحة (قابلة لإعادة الاستخدام، دون رمز لمرة واحدة، وغير منتهية الصلاحية)؛ وإذا كان حساب المطوّر شخصيًا وجديدًا، فأجرِ الـ closed test (اختبار مغلق مع مجموعة من المختبِرين) قبل التقديم على الإنتاج (production).&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;التواريخ والحدود تتغير، لذلك تربط &lt;a href=&quot;https://mohamedelgohary.dev/ar/release-checklist/&quot;&gt;القائمة&lt;/a&gt; كل قاعدة بصفحتها الرسمية، وتسجّل تاريخ آخر مراجعة لها. راجعها من جديد قبل أن تعتمد على أي منها.&lt;/p&gt;
&lt;p&gt;ومراجعة المتجر بوابة منفصلة لها قواعدها. فهي لا تخبرني إن كان الدفع سيصمد أمام اتصال متقطّع، ولذلك لا تحل أبدًا محل اختباري أنا.&lt;/p&gt;
&lt;h2 id=&quot;أدلة-مكتوبة-لا-ذاكرة&quot;&gt;أدلة مكتوبة، لا ذاكرة&lt;/h2&gt;
&lt;p&gt;بعد أي إصدار أريد أن أجيب: ما الذي اختُبر، وعلى ماذا، وماذا حدث. ويكفي لذلك سجل قصير. هذا قالب توضيحي، وليس ملفًا من مشروع بعينه:&lt;/p&gt;
&lt;div class=&quot;codeblock&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;codeblock__lang&quot; aria-hidden=&quot;true&quot;&gt;yaml&lt;/span&gt;&lt;pre class=&quot;code&quot; dir=&quot;ltr&quot; tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;Code: yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;release: 2.4.0 (build 118)
artifact: signed release build, production config
devices: [oldest supported OS, newest OS, small screen, large screen]
upgrade_from_live: passed, session and local data kept
network: slow / offline / flaky checked, repeated request created no duplicate
permissions: camera, location, notifications denied once each
arabic_rtl_large_text: checked
regression: sign-in, checkout, support-call flows
backend: old endpoints still served, min-version check in place
symbols: mapping file and dSYMs uploaded
rollout: staged, halt criteria agreed
owner_first_72h: named&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;والكتابة نفسها تغيّر السلوك: البند المتروك يصبح ظاهرًا، ولا تعود عبارة «ظننت أننا فحصنا ذلك» إجابة.&lt;/p&gt;
&lt;h2 id=&quot;يوم-النشر-وما-بعده&quot;&gt;يوم النشر وما بعده&lt;/h2&gt;
&lt;p&gt;لا ينتهي الإصدار حين يصبح الـ build متاحًا للمستخدمين. فالقسم الأخير من القائمة يطلب:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;ملاحظات إصدار مكتوبة للمستخدمين، بكل لغات المتجر، تقول ما الذي تغيّر وهل عليهم فعل أي شيء؛&lt;/li&gt;&lt;li&gt;شخصًا يتابع أول 72 ساعة، مع مسؤول عن تقارير الأعطال وتقييمات المستخدمين على المتجر ورسائل الدعم؛&lt;/li&gt;&lt;li&gt;خطة لإصدار به خلل، لأن التحديث المثبّت يبقى لدى المستخدمين حتى تنشر إصلاحًا: جهّز مسارًا للـ hotfix (الإصلاح العاجل) ومفاتيح تحكم من جهة الخادم؛&lt;/li&gt;&lt;li&gt;التحقق من تحليلات الإصدار في الإنتاج: تُرسل الأحداث مرة واحدة، وبالقيم الصحيحة، وتحترم اختيار المستخدم بشأن جمع بياناته (consent).&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;وعلى Google Play تطلب القائمة أيضًا staged rollout، أي نشرًا تدريجيًا: انشر لنسبة صغيرة من المستخدمين أولًا، وأوقف النشر إذا ارتفع معدل الأعطال أو الـ ANR (توقف التطبيق عن الاستجابة). وهذا للتحديثات، لا للنشر الأول.&lt;/p&gt;
&lt;h2 id=&quot;ما-سأفعله-بشكل-مختلف&quot;&gt;ما سأفعله بشكل مختلف&lt;/h2&gt;
&lt;ul&gt;&lt;li&gt;&lt;strong&gt;تحويل مزيد من البنود إلى فحوص آلية.&lt;/strong&gt; بعض البنود، مثل مسار التحديث واختبار تكرار الـ request، تتكرر بما يكفي حتى لا يُترك تذكّرها لشخص.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;ربط كل بند بمسؤول وبدليل.&lt;/strong&gt; علامة الصح تقول إن أحدًا نظر، لكنها لا تقول ماذا رأى.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;التعامل مع القائمة كنقطة بداية.&lt;/strong&gt; فهي مكتوبة لتطبيقات الجوال التي لها backend. بعض المشاريع ستتخطى بنودًا، والمشروع الذي فيه مدفوعات سيحتاج إلى أكثر منها.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;إبقاء قواعد المتاجر محدّثة.&lt;/strong&gt; فهي تتغير، وتاريخ «آخر مراجعة» لا يكون صادقًا إلا إذا حدّثه أحد.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;الدقة في وصف القائمة.&lt;/strong&gt; هي قائمتي العامة، وليست سجلًا بأن كل بند نُفّذ في كل إصدار.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;وإذا كان لديك تطبيق جوال متوقف قبل النشر، فيمكنك أن تبدأ بـ &lt;a href=&quot;https://mohamedelgohary.dev/ar/release-checklist/&quot;&gt;قائمة المراجعة كاملة&lt;/a&gt;، أو أن تخبرني عنه من &lt;a href=&quot;https://mohamedelgohary.dev/ar/start/&quot;&gt;صفحة ابدأ مشروعك&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;محمد الجوهري (Mohamed Elgohary)، مهندس برمجيات، القاهرة. mohamedelgohary.dev&lt;/p&gt;</content>
  </entry>
  <entry xml:lang="en">
    <title>Tested like a QA engineer: how I release mobile apps</title>
    <link rel="alternate" type="text/html" href="https://mohamedelgohary.dev/writing/tested-like-a-qa-engineer-how-i-release-mobile-apps/"/>
    <id>https://mohamedelgohary.dev/writing/tested-like-a-qa-engineer-how-i-release-mobile-apps/</id>
    <published>2026-11-10T00:00:00Z</published>
    <updated>2026-11-18T05:17:54+02:00</updated>
    <summary>A mobile release checklist shaped by QA/SDET work: test the release build, refuse permissions, break the network, upgrade from live, keep the API safe.</summary>
    <category term="mobile"/>
    <category term="qa"/>
    <category term="sdet"/>
    <category term="release-management"/>
    <category term="flutter"/>
    <category term="android"/>
    <category term="ios"/>
    <category term="testing"/>
    <content type="html">&lt;aside class=&quot;callout&quot; aria-labelledby=&quot;tldr&quot;&gt;&lt;p class=&quot;callout__label&quot; id=&quot;tldr&quot;&gt;TL;DR&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;I have a QA/SDET background alongside my mobile engineering work, and I release apps the way a tester would: assume the happy path works and spend the effort on everything around it.&lt;/li&gt;&lt;li&gt;My public release checklist has 34 items in six sections: build, testing, backend, App Store, Google Play, and launch day. Store rules on it were checked against the official pages on 28 September 2026.&lt;/li&gt;&lt;li&gt;The habits that matter most: test the exact artifact you ship, refuse every permission, break the network on purpose, upgrade from the version people already have, and keep the API compatible with old installs.&lt;/li&gt;&lt;li&gt;A checklist is not a test suite. It tells you what to test and what evidence to keep.&lt;/li&gt;&lt;/ul&gt;
&lt;/aside&gt;
&lt;h2 id=&quot;where-this-comes-from&quot;&gt;Where this comes from&lt;/h2&gt;
&lt;p&gt;From August 2024 to August 2025 I worked as a Software Development Engineer in Test for TAKADOM AL-IRAQ (TTech), on a freelance basis. I was responsible for mobile, web and API testing on public-service products, and I built the Kotlin and Selenium automation for the Naftcom project, with API and regression coverage around its citizen and station workflows. That code is in a private repository, so I will not describe it in detail here.&lt;/p&gt;
&lt;p&gt;I also build mobile apps. At Apps Square I am responsible for the mobile apps of several products, from setup and architecture through testing and delivery. At Inside Tech I built Bismar&apos;s customer and seller apps on Kotlin Multiplatform as the only mobile engineer on them, and both have public App Store and Google Play listings.&lt;/p&gt;
&lt;p&gt;The testing habit comes with me. When I read a feature now, my first question is still what happens when this fails.&lt;/p&gt;
&lt;h2 id=&quot;test-the-thing-you-ship&quot;&gt;Test the thing you ship&lt;/h2&gt;
&lt;p&gt;A debug build proves very little about a release. The checklist is explicit that I test the signed release build with production settings, because code shrinking and release configuration can break things a debug build never shows.&lt;/p&gt;
&lt;p&gt;A few items sit next to that one because they fail in the same quiet way:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Version and build number.&lt;/strong&gt; Every upload needs a higher build number than the last (&lt;code&gt;versionCode&lt;/code&gt; on Android, the build number on iOS), and the visible version must match the release notes.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Signing keys.&lt;/strong&gt; Use Play App Signing so a lost upload key can be reset. Back up keys and passwords outside the repository.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Crash symbols.&lt;/strong&gt; Upload the R8/ProGuard mapping file and the iOS dSYMs to the crash reporter. Without them, production stack traces are unreadable and the first real crash is a guessing game.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;No debug leftovers.&lt;/strong&gt; Check base URLs, feature flags, verbose logging of personal data and hidden test menus in the release configuration.&lt;/li&gt;&lt;/ul&gt;
&lt;h2 id=&quot;devices-and-the-upgrade-path&quot;&gt;Devices and the upgrade path&lt;/h2&gt;
&lt;p&gt;The checklist asks for real devices at both ends: at least the oldest OS version you support and the newest, a small screen and a large one.&lt;/p&gt;
&lt;p&gt;The upgrade test is the one I would least like to skip. Install the version on the store today, create some data, then update. Sessions, saved settings and local data must survive. A fresh install can be perfect while the person who has used the app for a year loses their session.&lt;/p&gt;
&lt;h2 id=&quot;failure-paths-first&quot;&gt;Failure paths first&lt;/h2&gt;
&lt;p&gt;This is where the QA background shows most. The checklist&apos;s network item reads: test slow, offline and flaky connections, confirm loading, retry and error states work, and make sure a repeated request never creates a duplicate order or payment.&lt;/p&gt;
&lt;p&gt;That last clause is the important one. A retry that works is only half of the feature. The other half is that the retry is safe.&lt;/p&gt;
&lt;p&gt;Here is a small example from a Flutter app I worked on, Fueler. The home screen loaded account, wallet and product data in parallel, and also resolved the user&apos;s location to find nearby stations. The original code waited for all of it before showing the page, so a slow location fix hid the wallet balance behind a loading state, even though the wallet never needed coordinates.&lt;/p&gt;
&lt;p&gt;The test that guards the fix does what a tester would do: it delays one dependency on purpose.&lt;/p&gt;
&lt;div class=&quot;codeblock&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;codeblock__lang&quot; aria-hidden=&quot;true&quot;&gt;dart&lt;/span&gt;&lt;pre class=&quot;code&quot; dir=&quot;ltr&quot; tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;Code: dart&quot;&gt;&lt;code class=&quot;language-dart&quot;&gt;// Simplified from the project&apos;s test file.
locationResolver.delay = const Duration(seconds: 3); // a genuinely cold fix
final loading = cubit.load();
await Future&amp;lt;void&amp;gt;.delayed(const Duration(milliseconds: 400));

// The screen is already usable before the location fix lands:
expect(cubit.state.status, HomeStatus.loaded);
expect(cubit.state.profile, _profile);
expect(cubit.state.products, _products);
// ...and the sections that need coordinates say so honestly:
expect(cubit.state.locationAccess, LocationAccess.unknown);
expect(cubit.state.stations, isEmpty);&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;A second test in the same group asserts that a warm fix emits exactly one state per refresh, so the stations section does not flash back to &amp;quot;locating&amp;quot;. I did not measure device timing or any conversion effect, and I am not claiming one. The point is the shape of the test: slow down one thing, and check what the rest of the screen is allowed to do.&lt;/p&gt;
&lt;h2 id=&quot;permissions-and-the-language-you-read-in&quot;&gt;Permissions and the language you read in&lt;/h2&gt;
&lt;p&gt;Camera, location and notifications each need a test for the case people forget: the person taps Don&apos;t Allow. The app should keep working and explain why it needs the permission.&lt;/p&gt;
&lt;p&gt;The checklist also treats Arabic as a test configuration, not a translation task: mirrored layouts, mixed Arabic and English text, and the system font size at its largest. Right-to-left bugs are easy to miss when you read the interface in only one language.&lt;/p&gt;
&lt;h2 id=&quot;the-api-is-part-of-the-release&quot;&gt;The API is part of the release&lt;/h2&gt;
&lt;p&gt;A mobile release is half a backend release, and the half people forget is the old app. People update slowly, so the checklist asks that the API keep serving the installed version: old endpoints and response shapes keep working, or a forced-update path ships first.&lt;/p&gt;
&lt;p&gt;A minimum-supported-version check lets you retire a broken build without waiting for everyone to update. And on the data side: run migrations on a copy of production data first, and take a backup before the release.&lt;/p&gt;
&lt;p&gt;I carry the same habit into my own tooling. PostSync Pro, an open-source Compose Desktop toolkit I built, sends REST requests, runs bounded assertions and validates responses against an OpenAPI specification. It is published as a beta, and the screens that still use simulated data are labelled as previews.&lt;/p&gt;
&lt;h2 id=&quot;a-regression-pass-on-what-hurts-most&quot;&gt;A regression pass on what hurts most&lt;/h2&gt;
&lt;p&gt;I do not try to retest everything. The checklist says to run a regression pass on the flows that matter most: sign-up, sign-in, checkout or booking, and anything a support call would be about. Notifications and deep links get their own check: they should open the right screen from a closed app, from the background and when signed out.&lt;/p&gt;
&lt;h2 id=&quot;store-rules-are-test-cases-too&quot;&gt;Store rules are test cases too&lt;/h2&gt;
&lt;p&gt;Both stores publish rules that read like requirements, so they become checks. A few from the checklist:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;strong&gt;App Store:&lt;/strong&gt; build with the required SDK (iOS 26 SDK or later, since 28 April 2026); keep App Privacy details in line with what the app and its SDKs collect; give App Review a working demo account and keep the backend on during review; offer account deletion inside the app; if you offer a third-party sign-in, offer an equivalent option such as Sign in with Apple; answer the encryption question in &lt;code&gt;Info.plist&lt;/code&gt;.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Google Play:&lt;/strong&gt; keep the Data safety form in line with the app; meet the target API requirement; provide sign-in details for review that keep working (reusable, no one-time code, not expiring); and for a new personal developer account, run the closed test before applying for production.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Dates and thresholds change, so the checklist links each rule to the official page and records when it was last checked. Re-check before you rely on any of it.&lt;/p&gt;
&lt;p&gt;A store review is a separate gate with its own rules. It does not tell me whether checkout survives a flaky connection, so it never replaces my own testing.&lt;/p&gt;
&lt;h2 id=&quot;evidence-not-memory&quot;&gt;Evidence, not memory&lt;/h2&gt;
&lt;p&gt;After a release I want to answer what was tested, on what, and what happened. A short record is enough. This is an illustrative template, not a file from a specific project:&lt;/p&gt;
&lt;div class=&quot;codeblock&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;codeblock__lang&quot; aria-hidden=&quot;true&quot;&gt;yaml&lt;/span&gt;&lt;pre class=&quot;code&quot; dir=&quot;ltr&quot; tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;Code: yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;release: 2.4.0 (build 118)
artifact: signed release build, production config
devices: [oldest supported OS, newest OS, small screen, large screen]
upgrade_from_live: passed, session and local data kept
network: slow / offline / flaky checked, repeated request created no duplicate
permissions: camera, location, notifications denied once each
arabic_rtl_large_text: checked
regression: sign-in, checkout, support-call flows
backend: old endpoints still served, min-version check in place
symbols: mapping file and dSYMs uploaded
rollout: staged, halt criteria agreed
owner_first_72h: named&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Writing it down changes behaviour: a skipped line is visible, and &amp;quot;I thought we checked that&amp;quot; stops being an answer.&lt;/p&gt;
&lt;h2 id=&quot;launch-day-and-after&quot;&gt;Launch day and after&lt;/h2&gt;
&lt;p&gt;The release is not over when the build is live. The last section of the checklist asks for:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;release notes written for people, in every store language, saying what changed and whether they need to do anything;&lt;/li&gt;&lt;li&gt;someone who watches the first 72 hours, with an owner for crash reports, store reviews and support messages;&lt;/li&gt;&lt;li&gt;a plan for a bad release, since an installed update stays until you ship a fix: keep a hotfix path and server-side switches ready;&lt;/li&gt;&lt;li&gt;release analytics verified in production, firing once with the right values and respecting consent.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;On Google Play the checklist also asks for a staged rollout: release to a small percentage first and halt if the crash or ANR rate rises. That applies to updates, not to a first release.&lt;/p&gt;
&lt;h2 id=&quot;what-id-do-differently&quot;&gt;What I&apos;d do differently&lt;/h2&gt;
&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Turn more of the list into automated checks.&lt;/strong&gt; Some items, like the upgrade path and the repeated-request test, are repeatable enough that a person should not have to remember them.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Attach an owner and evidence to each item.&lt;/strong&gt; A checkbox says someone looked. It does not say what they saw.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Treat the list as a starting point.&lt;/strong&gt; It is written for mobile apps with a backend. Some projects will skip items, and a project with payments will need more.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Keep the store rules fresh.&lt;/strong&gt; They change, and the &amp;quot;reviewed on&amp;quot; date is only honest if someone updates it.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Be precise about what the list is.&lt;/strong&gt; It is my public checklist, not a record that every item was done on every release.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Mohamed Elgohary, Software Engineer, Cairo. mohamedelgohary.dev&lt;/p&gt;</content>
  </entry>
  <entry xml:lang="en">
    <title>Valid product, wrong supplier: moving an ownership rule into the database</title>
    <link rel="alternate" type="text/html" href="https://mohamedelgohary.dev/writing/valid-product-wrong-supplier-composite-foreign-key/"/>
    <id>https://mohamedelgohary.dev/writing/valid-product-wrong-supplier-composite-foreign-key/</id>
    <published>2026-11-10T00:00:00Z</published>
    <updated>2026-11-18T02:51:41+02:00</updated>
    <summary>A foreign key proved a product existed, not that it belonged to the named supplier. How a composite foreign key made the wrong pair unstorable.</summary>
    <category term="postgresql"/>
    <category term="data-integrity"/>
    <category term="foreign-keys"/>
    <category term="multi-tenancy"/>
    <category term="prisma"/>
    <category term="egygomla"/>
    <content type="html">&lt;aside class=&quot;callout&quot; aria-labelledby=&quot;tldr&quot;&gt;&lt;p class=&quot;callout__label&quot; id=&quot;tldr&quot;&gt;TL;DR&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;In EgyGomla, a request for a sample could name supplier A and a product that belonged to supplier B. Every constraint in the database accepted it.&lt;/li&gt;&lt;li&gt;The only thing refusing that pair was one &lt;code&gt;if&lt;/code&gt; in one repository method. It protected that code path and no other.&lt;/li&gt;&lt;li&gt;A composite foreign key on &lt;code&gt;(product_id, supplier_organization_id)&lt;/code&gt; moved the rule into the database. I kept the application check so callers still get a clear error.&lt;/li&gt;&lt;li&gt;No production incident is behind this. I found it while reviewing the schema. The fix enforces one stored relationship, not authorization in general.&lt;/li&gt;&lt;/ul&gt;
&lt;/aside&gt;
&lt;h2 id=&quot;the-shape-of-the-problem&quot;&gt;The shape of the problem&lt;/h2&gt;
&lt;p&gt;EgyGomla is a B2B sourcing platform I built for Egyptian traders. Two of its tables hold sample requests and private-label requests. Each row carries a supplier and, optionally, a catalogue product.&lt;/p&gt;
&lt;p&gt;The foreign key from the request to the product named only &lt;code&gt;catalog_products(id)&lt;/code&gt;. So the database asked one question: does this product exist? It never asked whether the product belongs to the supplier written on the same row.&lt;/p&gt;
&lt;p&gt;That means a row pairing supplier A with supplier B&apos;s product satisfied every constraint. The product is real and the supplier is real. The relationship is wrong.&lt;/p&gt;
&lt;p&gt;There was a check. The service verified that the product belonged to the supplier, so requests arriving through the API were covered. My own migration comment describes the weakness better than I would paraphrase it: that check protects the path that runs it and no other, &amp;quot;not a repair script, not a future module, not a bulk import&amp;quot;.&lt;/p&gt;
&lt;p&gt;I want to be exact about the scope here. I did not find corrupted data, and no customer was affected. This was a gap between what the application enforced and what the database enforced, and the cheapest time to close it is before something writes a bad row.&lt;/p&gt;
&lt;h2 id=&quot;the-fix&quot;&gt;The fix&lt;/h2&gt;
&lt;p&gt;The rule moves into the key itself. First, the parent table gets a unique constraint over the pair, so the pair can be referenced:&lt;/p&gt;
&lt;div class=&quot;codeblock&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;codeblock__lang&quot; aria-hidden=&quot;true&quot;&gt;sql&lt;/span&gt;&lt;pre class=&quot;code&quot; dir=&quot;ltr&quot; tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;Code: sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;ALTER TABLE &amp;quot;catalog_products&amp;quot;
  ADD CONSTRAINT &amp;quot;catalog_products_id_supplier_organization_id_key&amp;quot;
  UNIQUE (&amp;quot;id&amp;quot;, &amp;quot;supplier_organization_id&amp;quot;);&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This adds no real restriction. &lt;code&gt;id&lt;/code&gt; is already the primary key, so any &lt;code&gt;(id, supplier)&lt;/code&gt; pair is already unique. The constraint exists only so that something can point at the pair.&lt;/p&gt;
&lt;p&gt;Then the child tables swap their single-column key for a composite one:&lt;/p&gt;
&lt;div class=&quot;codeblock&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;codeblock__lang&quot; aria-hidden=&quot;true&quot;&gt;sql&lt;/span&gt;&lt;pre class=&quot;code&quot; dir=&quot;ltr&quot; tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;Code: sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;ALTER TABLE &amp;quot;sample_requests&amp;quot;
  DROP CONSTRAINT &amp;quot;sample_requests_product_id_fkey&amp;quot;;

ALTER TABLE &amp;quot;sample_requests&amp;quot;
  ADD CONSTRAINT &amp;quot;sample_requests_product_id_supplier_organization_id_fkey&amp;quot;
  FOREIGN KEY (&amp;quot;product_id&amp;quot;, &amp;quot;supplier_organization_id&amp;quot;)
  REFERENCES &amp;quot;catalog_products&amp;quot; (&amp;quot;id&amp;quot;, &amp;quot;supplier_organization_id&amp;quot;)
  ON DELETE RESTRICT ON UPDATE CASCADE;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The same change is applied to &lt;code&gt;private_label_requests&lt;/code&gt;. Now the database checks the whole pair against the catalogue. In plain terms: the pair &lt;code&gt;(P42, A)&lt;/code&gt; must exist as a row in the products table, and the row says P42 belongs to B, so the insert is rejected.&lt;/p&gt;
&lt;p&gt;The pairing becomes a fact the database keeps rather than an invariant the application remembers.&lt;/p&gt;
&lt;p&gt;In a LinkedIn post I called the column &lt;code&gt;supplier_id&lt;/code&gt; to keep the example simple. The real column is &lt;code&gt;supplier_organization_id&lt;/code&gt;, because suppliers are organizations in this schema.&lt;/p&gt;
&lt;h2 id=&quot;the-detail-that-is-easy-to-get-wrong-null&quot;&gt;The detail that is easy to get wrong: NULL&lt;/h2&gt;
&lt;p&gt;A request can name no product at all. In that case &lt;code&gt;product_id&lt;/code&gt; is NULL, and the request should be valid.&lt;/p&gt;
&lt;p&gt;PostgreSQL foreign keys default to &lt;code&gt;MATCH SIMPLE&lt;/code&gt;: if any referencing column is NULL, the constraint is not checked. That is exactly what &amp;quot;this request names no product&amp;quot; should mean, so the default is what I want here. With &lt;code&gt;MATCH FULL&lt;/code&gt;, a request with no product would also have to null out its supplier, which is wrong.&lt;/p&gt;
&lt;p&gt;I mention it because the same rule cuts the other way. When a column must always be checked, &lt;code&gt;MATCH SIMPLE&lt;/code&gt; plus a nullable column means a writer that forgets to fill it in switches the check off without any error. The same trap came up again on a different constraint, and the answer there was to make the column &lt;code&gt;NOT NULL&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;keep-the-service-check&quot;&gt;Keep the service check&lt;/h2&gt;
&lt;p&gt;I did not delete the application validation. The database is the backstop and the service is the user interface of the rule.&lt;/p&gt;
&lt;p&gt;If the composite key rejects an insert, the driver surfaces a foreign-key error. The repository translates it:&lt;/p&gt;
&lt;div class=&quot;codeblock&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;codeblock__lang&quot; aria-hidden=&quot;true&quot;&gt;ts&lt;/span&gt;&lt;pre class=&quot;code&quot; dir=&quot;ltr&quot; tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;Code: ts&quot;&gt;&lt;code class=&quot;language-ts&quot;&gt;// Simplified from the repository.
if (errorCode(error) === &amp;quot;P2003&amp;quot;) {
  throw new DomainValidationError(
    &amp;quot;The linked product is not available for this supplier.&amp;quot;,
  );
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The message is deliberately vague. It does not confirm whether the product exists or who owns it. A buyer probing product ids should not be able to learn another supplier&apos;s catalogue from the difference between two error messages.&lt;/p&gt;
&lt;h2 id=&quot;what-this-does-not-do&quot;&gt;What this does not do&lt;/h2&gt;
&lt;p&gt;It would be easy to oversell this, so here are the limits:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;It enforces one stored relationship: this product belongs to this supplier. It is not an authorization system and it is not tenant isolation. Something still has to decide who may create a request in the first place.&lt;/li&gt;&lt;li&gt;It does not fix a wrong row by changing the supplier. It rejects the pair.&lt;/li&gt;&lt;li&gt;It cannot see anything outside the columns it covers. A different table with a similar mismatch needs its own key.&lt;/li&gt;&lt;/ul&gt;
&lt;h2 id=&quot;how-i-would-test-it&quot;&gt;How I would test it&lt;/h2&gt;
&lt;p&gt;A constraint that is never exercised is a comment. The test I want is at the database level, with direct inserts that skip the application entirely:&lt;/p&gt;
&lt;div class=&quot;codeblock&quot; dir=&quot;ltr&quot;&gt;&lt;span class=&quot;codeblock__lang&quot; aria-hidden=&quot;true&quot;&gt;sql&lt;/span&gt;&lt;pre class=&quot;code&quot; dir=&quot;ltr&quot; tabindex=&quot;0&quot; role=&quot;region&quot; aria-label=&quot;Code: sql&quot;&gt;&lt;code class=&quot;language-sql&quot;&gt;-- Illustrative test cases, not from the repository.
-- 1. Valid pair: product P42 owned by B, request names (P42, B)  -&amp;gt; accepted
-- 2. Wrong pair: product P42 owned by B, request names (P42, A)  -&amp;gt; rejected
-- 3. No product: request names (NULL, A)                         -&amp;gt; accepted&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The three cases cover the intended path, the bug, and the NULL semantics. If all three behave, the rule lives in the schema and a future import script cannot bypass it by forgetting to call the service.&lt;/p&gt;
&lt;h2 id=&quot;the-same-pattern-applied-wider&quot;&gt;The same pattern, applied wider&lt;/h2&gt;
&lt;p&gt;The same mechanism shows up again in a later migration that makes a wrong-type tenant unrepresentable. Without it, the database would store a buyer organization as the owner of a catalogue product, or a supplier in the buyer slot of a request. Only whichever query remembered to filter on type would refuse it. The fix has three parts: a denormalised type column on the child row, a composite foreign key that forces it to agree with the organization row, and a &lt;code&gt;CHECK&lt;/code&gt; that pins it to the one legal value for that slot.&lt;/p&gt;
&lt;p&gt;The schema now has thirteen composite keys on &lt;code&gt;organizations(id, type)&lt;/code&gt;. A later design decision about marketplace accounts, which I describe in another article, refuses to disturb that network.&lt;/p&gt;
&lt;p&gt;Two practical habits came out of that migration:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;&lt;strong&gt;Count the violators first.&lt;/strong&gt; Before adding the constraints, the migration counts existing rows that would break them and refuses to continue, naming the table and the number, rather than failing on a bare constraint name or silently changing data. A violation there is a real finding and gets reconciled by hand.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Mind the deploy order.&lt;/strong&gt; The new columns are &lt;code&gt;NOT NULL&lt;/code&gt; with no default, so every writer has to supply them before the migration runs. An older release cannot insert into those tables once the migration is applied.&lt;/li&gt;&lt;/ol&gt;
&lt;h2 id=&quot;the-costs&quot;&gt;The costs&lt;/h2&gt;
&lt;p&gt;Composite keys are not free:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;The parent needs a unique constraint over the extra pair, and every referencing table carries a copy of the owning column.&lt;/li&gt;&lt;li&gt;Every writer must supply the extra columns, including seeds, scripts and old app versions.&lt;/li&gt;&lt;li&gt;&lt;code&gt;ON UPDATE CASCADE&lt;/code&gt; means a change to the referenced column ripples down. That is intended, and it also means ownership changes need thought.&lt;/li&gt;&lt;li&gt;Error handling needs work, because a raw foreign-key violation is a poor message.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;I accept those costs for rules where a silent wrong row is expensive and the data is shared across tenants.&lt;/p&gt;
&lt;h2 id=&quot;a-review-you-can-run-on-your-own-schema&quot;&gt;A review you can run on your own schema&lt;/h2&gt;
&lt;p&gt;Look for tables that store a tenant or owner id next to a resource id. For each one, ask whether the database proves that the resource belongs to that tenant, or only proves that both exist. If it is the second, write down which code paths currently enforce the rule, and which could write around them: imports, repair scripts, admin tools, new services.&lt;/p&gt;
&lt;h2 id=&quot;what-id-do-differently&quot;&gt;What I&apos;d do differently&lt;/h2&gt;
&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Add the composite key when the table is created.&lt;/strong&gt; Retrofitting it took a separate migration that dropped and recreated the key. A new table can have it from the first commit.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Test at the database level from the start.&lt;/strong&gt; I would write the three insert cases as part of the migration review.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Look for the pattern earlier.&lt;/strong&gt; The same shape existed in other tables, and a wider migration followed two days later.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Say what the fix covers.&lt;/strong&gt; It closes one gap. Calling it tenant isolation would be wrong.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Mohamed Elgohary, Software Engineer, Cairo. mohamedelgohary.dev&lt;/p&gt;</content>
  </entry>
</feed>
