Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/storefront-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
cd services/common/data
ln -s ./secrets_template.json ./secrets.json
cd ../../store
pipenv run alembic --config ./alembic_app.ini upgrade 000002
pipenv run alembic --config ./alembic_app.ini upgrade 000004

- name: run linter
run: |
Expand Down
220 changes: 110 additions & 110 deletions services/store/Pipfile.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions services/store/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ pipenv run pip uninstall my-c-extention-lib

### Database Migration
```bash

// generate migration script template (not stable)
APP_SETTINGS="settings.test" pipenv run alembic --config alembic_app.ini revision --autogenerate \
--rev-id <VERSION_NUMBER> --depends-on <PREVIOUS_VERSION_NUMBER> -m "whatever_message"

// update
APP_SETTINGS="settings.test" pipenv run alembic --config alembic_app.ini upgrade <VERSION_NUMBER>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""remove_product_type

Revision ID: 000003
Revises: 000002
Create Date: 2025-01-25 14:46:59.897373

"""

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = "000003"
down_revision = "000002"
branch_labels = None
depends_on = "000002"

CSTR_NAME = "store_product_available_ibfk_1"
table_name = "store_product_available"


def upgrade():
op.drop_constraint(CSTR_NAME, table_name, type_="foreignkey")
op.drop_constraint(None, table_name, type_="primary")
op.drop_column(table_name, "product_type")

op.create_primary_key(None, table_name, columns=["store_id", "product_id"])
op.create_foreign_key(
constraint_name=CSTR_NAME,
source_table=table_name,
referent_table="store_profile",
local_cols=["store_id"],
remote_cols=["id"],
ondelete="CASCADE",
)


def downgrade():
op.drop_constraint(CSTR_NAME, table_name, type_="foreignkey")
op.drop_constraint(None, table_name, type_="primary")
op.add_column(
table_name,
sa.Column("product_type", mysql.ENUM("ITEM", "PACKAGE"), nullable=False),
)
op.create_primary_key(
None, table_name, columns=["store_id", "product_type", "product_id"]
)
op.create_foreign_key(
constraint_name=CSTR_NAME,
source_table=table_name,
referent_table="store_profile",
local_cols=["store_id"],
remote_cols=["id"],
ondelete="CASCADE",
)
45 changes: 45 additions & 0 deletions services/store/migrations/app/versions/000004_add_attris_charge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""add_attris_charge

Revision ID: 000004
Revises: 000003
Create Date: 2025-01-26 00:11:12.225822

"""

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = "000004"
down_revision = "000003"
branch_labels = None
depends_on = "000003"


def upgrade():
conn = op.get_bind()
conn.execute(
sa.sql.text(
"ALTER TABLE `store_product_available` RENAME COLUMN `price` TO `base_price`"
)
)
op.add_column(
"store_product_available",
sa.Column("attrs_charge", mysql.JSON(), nullable=False),
)
op.add_column(
"store_product_available",
sa.Column("attrs_last_update", sa.DateTime(), nullable=False),
)


def downgrade():
op.drop_column("store_product_available", "attrs_last_update")
op.drop_column("store_product_available", "attrs_charge")
conn = op.get_bind()
conn.execute(
sa.sql.text(
"ALTER TABLE `store_product_available` RENAME COLUMN `base_price` TO `price`"
)
)
4 changes: 4 additions & 0 deletions services/store/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
DEINIT_SHARED_CONTEXT_FN = "store.shared.app_shared_context_destroy"

ROUTERS = ["store.api.web.router"]
EXCEPTION_HANDLERS = [
("store.api.web.request_error_handler", "store.dto.StoreDtoError"),
("store.api.web.rpc_error_handler", "store.shared.AppRpcError"),
]

KEYSTORE = {
"keystore": "ecommerce_common.auth.keystore.BaseAuthKeyStore",
Expand Down
1 change: 1 addition & 0 deletions services/store/settings/development.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .common import * # noqa: F403
from .celeryconfig import * # noqa: F403

# change to dev / production server admin for database schema migration
DB_USER_ALIAS = "store_service"
8 changes: 5 additions & 3 deletions services/store/src/api/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@

from ..dto import StoreProfileDto
from ..models import StoreProfile
from ..shared import init_shared_context
from ..shared import app_shared_context_start

_logger = logging.getLogger(__name__)

_shr_ctx = init_shared_context()
evloop = asyncio.new_event_loop()

_shr_ctx["evt_loop"] = asyncio.new_event_loop()
_shr_ctx = evloop.run_until_complete(app_shared_context_start(None))

_shr_ctx["evt_loop"] = evloop

# NOTE:
# Celery currently does not support async task-handling function,
Expand Down
Loading