Skip to content

Commit

Permalink
M2-4180: Fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ibogretsov committed May 6, 2024
2 parents 56039bb + fb15565 commit 0545135
Show file tree
Hide file tree
Showing 48 changed files with 2,747 additions and 2,702 deletions.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ run_local:
test:
${TEST_COMMAND} ./

.PHONY: migrate
migrate:
./compose/fastapi/migrate

.PHONY: migrate-arbitrary
migrate-arbitrary:
./compose/fastapi/migrate arbitrary

# NOTE: cq == "Code quality"
.PHONY: cq
cq:
Expand Down
4 changes: 2 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name = "pypi"
[packages]
aioredis = "~=2.0.1"
alembic = "~=1.8.1"
asyncpg = "~=0.27.0"
asyncpg = "~=0.29.0"
boto3 = "==1.26.10"
fastapi = "==0.110.0"
# The latest version of the fastapi is not taken because of the issue
Expand Down Expand Up @@ -89,7 +89,7 @@ greenlet = "~=2.0.1"
# JSONLD deps only for dev
reproschema = "*"
cachetools = "==5.3.0"
pyld = "==2.0.3"
pyld = "==2.0.4"


[requires]
Expand Down
109 changes: 59 additions & 50 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions compose/fastapi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ RUN sed -i 's/\r$//g' /fastapi-entrypoint && chmod +x /fastapi-entrypoint
COPY --chown=code:code ./compose/fastapi/start /fastapi-start
RUN sed -i 's/\r$//g' /fastapi-start && chmod +x /fastapi-start

COPY --chown=code:code ./compose/fastapi/migrate /fastapi-migrate
RUN sed -i 's/\r$//g' /fastapi-migrate && chmod +x /fastapi-migrate

# Select internal user
USER code

Expand Down
3 changes: 3 additions & 0 deletions compose/fastapi/Dockerfile.app
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ RUN sed -i 's/\r$//g' /fastapi-entrypoint && chmod +x /fastapi-entrypoint
COPY --chown=code:code ./compose/fastapi/start /fastapi-start
RUN sed -i 's/\r$//g' /fastapi-start && chmod +x /fastapi-start

COPY --chown=code:code ./compose/fastapi/migrate /fastapi-migrate
RUN sed -i 's/\r$//g' /fastapi-migrate && chmod +x /fastapi-migrate

# Select internal user
USER code
39 changes: 39 additions & 0 deletions compose/fastapi/migrate
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

set -eo pipefail
set -o nounset

usage() {
cat <<EOF
Usage:
$(basename "$0") [ARGS]
Run migrations for the Mindlogger backend and (or) for the Mindlogger arbitrary servers.
NOTE: If no ARGS provided, apply migrations only for Mindlogger backend.
ARGS:
arbitrary Apply migrations only for arbitrary servers
all Apply migrations both for Mindlogger backend and for arbitrary servers
Help:
--help Print this message and exit
EOF
}

case "${1:-}" in
--help)
usage
exit 0
;;
arbitrary)
echo 'Applying migrations for arbitrary servers'
alembic -c alembic_arbitrary.ini upgrade head
;;
all)
echo 'Applying migrations for Mindlogger backend'
alembic upgrade head
echo 'Applying migrations for arbitrary servers'
alembic -c alembic_arbitrary.ini upgrade head
;;
*)
echo 'Applying migrations for Mindlogger backend'
alembic upgrade head
;;
esac
2 changes: 0 additions & 2 deletions compose/fastapi/start
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ set -o nounset
export UVICORN_HOST="0.0.0.0"
export UVICORN_PORT=80

alembic upgrade head && \
alembic -c alembic_arbitrary.ini upgrade head && \
opentelemetry-instrument \
--logs_exporter otlp \
uvicorn src.main:app --reload --host ${UVICORN_HOST} --port ${UVICORN_PORT} --proxy-headers
21 changes: 20 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
from sqlalchemy.orm import Session, SessionTransaction

from apps.answers.deps.preprocess_arbitrary import get_answer_session
from apps.mailing.services import TestMail
from apps.shared.test.client import TestClient
from broker import broker
from config import settings
from infrastructure.app import create_app
from infrastructure.database.core import build_engine
from infrastructure.database.deps import get_session
from infrastructure.utility import FCMNotificationTest
from infrastructure.utility import FCMNotificationTest, RedisCacheTest

pytest_plugins = [
"apps.activities.tests.fixtures.configs",
Expand Down Expand Up @@ -288,6 +289,24 @@ def fcm_client() -> FCMNotificationTest:
return client


@pytest.fixture
def redis() -> RedisCacheTest:
redis = RedisCacheTest()
redis._storage.clear()
return redis


@pytest.fixture
def mailbox() -> TestMail:
class Connection:
pass

connection = Connection()
box = TestMail(connection)
box.clear_mails()
return box


@pytest.fixture
def mock_activity_log(mocker: MockerFixture) -> Generator:
mock = mocker.patch("apps.logs.services.UserActivityLogService.create_log")
Expand Down
17 changes: 17 additions & 0 deletions src/apps/activity_flows/crud/flow_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from apps.activity_flows.db.schemas import ActivityFlowHistoriesSchema, ActivityFlowItemHistorySchema
from apps.activity_flows.domain.flow_full import FlowHistoryWithActivityFull
from apps.applets.db.schemas import AppletHistorySchema
from apps.applets.domain.applet_history import Version
from infrastructure.database import BaseCRUD

__all__ = ["FlowsHistoryCRUD"]
Expand Down Expand Up @@ -95,3 +96,19 @@ async def get_last_histories_by_applet(self, applet_id: uuid.UUID) -> list[Activ
query = query.distinct(ActivityFlowHistoriesSchema.id)
db_result = await self._execute(query)
return db_result.scalars().all()

async def get_versions_data(self, flow_id: uuid.UUID) -> list[Version]:
query: Query = (
select(
AppletHistorySchema.version,
AppletHistorySchema.created_at,
)
.select_from(ActivityFlowHistoriesSchema)
.join(AppletHistorySchema, AppletHistorySchema.id_version == ActivityFlowHistoriesSchema.applet_id)
.where(ActivityFlowHistoriesSchema.id == flow_id)
.order_by(AppletHistorySchema.created_at)
)
result = await self._execute(query)
data = result.all()

return parse_obj_as(list[Version], data)
6 changes: 5 additions & 1 deletion src/apps/activity_flows/service/flow.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import uuid

from apps.activity_flows.crud import FlowItemsCRUD, FlowsCRUD
from apps.activity_flows.crud import FlowItemsCRUD, FlowsCRUD, FlowsHistoryCRUD
from apps.activity_flows.db.schemas import ActivityFlowSchema
from apps.activity_flows.domain.flow import Flow, FlowBaseInfo, FlowDuplicate, FlowSingleLanguageDetail
from apps.activity_flows.domain.flow_create import FlowCreate, PreparedFlowItemCreate
from apps.activity_flows.domain.flow_full import FlowFull
from apps.activity_flows.domain.flow_update import ActivityFlowReportConfiguration, FlowUpdate, PreparedFlowItemUpdate
from apps.activity_flows.service.flow_item import FlowItemService
from apps.applets.crud import UserAppletAccessCRUD
from apps.applets.domain.applet_history import Version
from apps.schedule.crud.events import EventCRUD, FlowEventsCRUD
from apps.schedule.service.schedule import ScheduleService
from apps.workspaces.domain.constants import Role
Expand Down Expand Up @@ -283,3 +284,6 @@ async def get_info_by_applet_id(self, applet_id: uuid.UUID, language: str) -> li
for schema in schemas:
flow_map[schema.activity_flow_id].activity_ids.append(schema.activity_id)
return flows

async def get_versions(self, flow_id: uuid.UUID) -> list[Version]:
return await FlowsHistoryCRUD(self.session).get_versions_data(flow_id)
Loading

0 comments on commit 0545135

Please sign in to comment.