Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# pylint: disable=no-member,invalid-name,missing-function-docstring,too-many-statements
"""cron delete copy uod

Revision ID: dbc310a03ce1
Revises: 2efcf46bb693
Create Date: 2024-10-29 17:54:16.220414

"""
from textwrap import dedent
from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "dbc310a03ce1"
down_revision: Union[str, None] = "21b28a319b43"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade():
op.execute("CREATE EXTENSION IF NOT EXISTS pg_cron;")
delete_duplicates_sql = sa.text(
dedent(
"""
DO $$
BEGIN
DELETE FROM urban_objects_data uo
WHERE uo.urban_object_id NOT IN (
SELECT MIN(uo_inner.urban_object_id)
FROM urban_objects_data uo_inner
WHERE uo_inner.service_id IS NULL
GROUP BY uo_inner.physical_object_id, uo_inner.object_geometry_id
)
AND uo.service_id IS NULL;
END $$;
"""
)
)
op.execute(sa.text(dedent(f"SELECT cron.schedule('0 */6 * * *', $$ {delete_duplicates_sql} $$);")))


def downgrade():
op.execute("SELECT cron.unschedule('0 0 * * *');")
op.execute("DROP EXTENSION IF EXISTS pg_cron;")
19 changes: 11 additions & 8 deletions idu_api/urban_api/logic/impl/helpers/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,19 +304,22 @@ async def add_service_to_object_in_db(
raise EntityNotFoundById(service_id, "service")

flag = False
urban_object_id = None
for urban_object in urban_objects:
if urban_object.service_id is None:
statement = (
update(urban_objects_data)
.where(urban_objects_data.c.urban_object_id == urban_object.urban_object_id)
.values(service_id=service_id)
.returning(urban_objects_data.c.urban_object_id)
)
if urban_object.service_id is None and not flag:
flag = True
urban_object_id = urban_object.urban_object_id
if urban_object.service_id == service_id:
raise EntityAlreadyExists("urban object", physical_object_id, object_geometry_id, service_id)

if not flag:
if flag:
statement = (
update(urban_objects_data)
.where(urban_objects_data.c.urban_object_id == urban_object_id)
.values(service_id=service_id)
.returning(urban_objects_data.c.urban_object_id)
)
else:
statement = (
insert(urban_objects_data)
.values(
Expand Down
4 changes: 2 additions & 2 deletions idu_api/urban_api/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Version constants are defined here and should be updated on release."""

VERSION = "0.22.3"
LAST_UPDATE = "2024-10-28"
VERSION = "0.22.4"
LAST_UPDATE = "2024-10-29"
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "idu-api"
version = "1.14.3"
version = "1.14.4"
description = "This is a Digital Territories Platform API in two versions to access and manipulate basic territories data."
authors = ["Babayev Ruslan <rus.babaef@yandex.ru>"]
readme = "README.md"
Expand Down Expand Up @@ -57,7 +57,7 @@ target-version = ['py311']

[tool.pylint.format]
max-line-length = 120
expected-line-ending-format = "CRLF"
expected-line-ending-format = "LF"
max-locals = 20
max-attributes = 10
max-args = 9
Expand Down