
from ....database import db
from ....util.instances import ReprBuilder

from ..sequence.transfer.models import NumberSequenceID
from ..shop.transfer.models import ShopID

from .transfer.models import StorefrontID


class Storefront(db.Model):
    """A storefront.

    The entrypoint from a site to a shop.
    """

    __tablename__ = 'shop_storefronts'

    id = db.Column(db.UnicodeText, primary_key=True)
    shop_id = db.Column(db.UnicodeText, db.ForeignKey('shops.id'), nullable=False)
    order_number_sequence_id = db.Column(db.Uuid, db.ForeignKey('shop_sequences.id'), nullable=False)
    closed = db.Column(db.Boolean, nullable=False)

    def __init__(
        self,
        storefront_id: StorefrontID,
        shop_id: ShopID,
        order_number_sequence_id: NumberSequenceID,
        closed: bool,
    ) -> None:
        self.id = storefront_id
        self.shop_id = shop_id
        self.order_number_sequence_id = order_number_sequence_id
        self.closed = closed

    def __repr__(self) -> str:
        return ReprBuilder(self) \
            .add_with_lookup('id') \
            .add_with_lookup('shop_id') \
            .build()


from ....database import db
from ....util.instances import ReprBuilder

from ..sequence.transfer.models import NumberSequenceID
from ..shop.transfer.models import ShopID

from .transfer.models import StorefrontID


class Storefront(db.Model):
    """A storefront.

    The entrypoint from a site to a shop.
    """

    __tablename__ = 'shop_storefronts'

    id = db.Column(db.UnicodeText, primary_key=True)
    shop_id = db.Column(db.UnicodeText, db.ForeignKey('shops.id'), index=True, nullable=False)
    order_number_sequence_id = db.Column(db.Uuid, db.ForeignKey('shop_sequences.id'), nullable=False)
    closed = db.Column(db.Boolean, nullable=False)

    def __init__(
        self,
        storefront_id: StorefrontID,
        shop_id: ShopID,
        order_number_sequence_id: NumberSequenceID,
        closed: bool,
    ) -> None:
        self.id = storefront_id
        self.shop_id = shop_id
        self.order_number_sequence_id = order_number_sequence_id
        self.closed = closed

    def __repr__(self) -> str:
        return ReprBuilder(self) \
            .add_with_lookup('id') \
            .add_with_lookup('shop_id') \
            .build()

Add index for storefront's shop ID
Add index for storefront's shop ID

DDL:

    CREATE INDEX ix_shop_storefronts_shop_id ON shop_storefronts (shop_id);

  
  from ....database import db
  from ....util.instances import ReprBuilder
  
  from ..sequence.transfer.models import NumberSequenceID
  from ..shop.transfer.models import ShopID
  
  from .transfer.models import StorefrontID
  
  
  class Storefront(db.Model):
      """A storefront.
  
      The entrypoint from a site to a shop.
      """
  
      __tablename__ = 'shop_storefronts'
  
      id = db.Column(db.UnicodeText, primary_key=True)
-     shop_id = db.Column(db.UnicodeText, db.ForeignKey('shops.id'), nullable=False)
+     shop_id = db.Column(db.UnicodeText, db.ForeignKey('shops.id'), index=True, nullable=False)
      order_number_sequence_id = db.Column(db.Uuid, db.ForeignKey('shop_sequences.id'), nullable=False)
      closed = db.Column(db.Boolean, nullable=False)
  
      def __init__(
          self,
          storefront_id: StorefrontID,
          shop_id: ShopID,
          order_number_sequence_id: NumberSequenceID,
          closed: bool,
      ) -> None:
          self.id = storefront_id
          self.shop_id = shop_id
          self.order_number_sequence_id = order_number_sequence_id
          self.closed = closed
  
      def __repr__(self) -> str:
          return ReprBuilder(self) \
              .add_with_lookup('id') \
              .add_with_lookup('shop_id') \
              .build()
  
Add index for storefront's shop ID
## Code Before:

from ....database import db
from ....util.instances import ReprBuilder

from ..sequence.transfer.models import NumberSequenceID
from ..shop.transfer.models import ShopID

from .transfer.models import StorefrontID


class Storefront(db.Model):
    """A storefront.

    The entrypoint from a site to a shop.
    """

    __tablename__ = 'shop_storefronts'

    id = db.Column(db.UnicodeText, primary_key=True)
    shop_id = db.Column(db.UnicodeText, db.ForeignKey('shops.id'), nullable=False)
    order_number_sequence_id = db.Column(db.Uuid, db.ForeignKey('shop_sequences.id'), nullable=False)
    closed = db.Column(db.Boolean, nullable=False)

    def __init__(
        self,
        storefront_id: StorefrontID,
        shop_id: ShopID,
        order_number_sequence_id: NumberSequenceID,
        closed: bool,
    ) -> None:
        self.id = storefront_id
        self.shop_id = shop_id
        self.order_number_sequence_id = order_number_sequence_id
        self.closed = closed

    def __repr__(self) -> str:
        return ReprBuilder(self) \
            .add_with_lookup('id') \
            .add_with_lookup('shop_id') \
            .build()

## Instruction:
Add index for storefront's shop ID
## Code After:

from ....database import db
from ....util.instances import ReprBuilder

from ..sequence.transfer.models import NumberSequenceID
from ..shop.transfer.models import ShopID

from .transfer.models import StorefrontID


class Storefront(db.Model):
    """A storefront.

    The entrypoint from a site to a shop.
    """

    __tablename__ = 'shop_storefronts'

    id = db.Column(db.UnicodeText, primary_key=True)
    shop_id = db.Column(db.UnicodeText, db.ForeignKey('shops.id'), index=True, nullable=False)
    order_number_sequence_id = db.Column(db.Uuid, db.ForeignKey('shop_sequences.id'), nullable=False)
    closed = db.Column(db.Boolean, nullable=False)

    def __init__(
        self,
        storefront_id: StorefrontID,
        shop_id: ShopID,
        order_number_sequence_id: NumberSequenceID,
        closed: bool,
    ) -> None:
        self.id = storefront_id
        self.shop_id = shop_id
        self.order_number_sequence_id = order_number_sequence_id
        self.closed = closed

    def __repr__(self) -> str:
        return ReprBuilder(self) \
            .add_with_lookup('id') \
            .add_with_lookup('shop_id') \
            .build()
