Skip to content

Commit

Permalink
Store description in prime_db
Browse files Browse the repository at this point in the history
  • Loading branch information
index-git committed Dec 19, 2024
1 parent 7cab949 commit c12d0f2
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
```
### Migrations and checks
#### Schema migrations
- [#1009](https://github.com/LayerManager/layman/issues/1009) Add column `description` to table `publications` in prime DB schema.
#### Data migrations
### Changes
- [#1009](https://github.com/LayerManager/layman/issues/1009) PATCH Workspace [Layer](doc/rest.md#patch-workspace-layer)/[Map](doc/rest.md#patch-workspace-map) returns same response as POST Workspace [Layers](doc/rest.md#post-workspace-layers)/[Maps](doc/rest.md#post-workspace-maps) with only `name`, `uuid`, `url` and for Layer also optional `files_to_upload` keys.
Expand Down
4 changes: 2 additions & 2 deletions doc/data-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Information about [layers](models.md#layer) includes vector or raster data and v

When user [publishes new layer](rest.md#post-workspace-layers)
- UUID and name is saved to [Redis](#redis) and [filesystem](#filesystem),
- UUID, name, title and access rights are to [PostgreSQL](#postgresql),
- UUID, name, title, description and access rights are to [PostgreSQL](#postgresql),
- data files and visualization file is saved to [filesystem](#filesystem) (if uploaded [synchronously](async-file-upload.md)),
- and asynchronous [tasks](#tasks) are saved in [Redis](#redis).

Expand All @@ -51,7 +51,7 @@ Information about [maps](models.md#map) includes JSON definition.

When user [publishes new map](rest.md#post-workspace-maps)
- UUID and name is saved to [Redis](#redis) and [filesystem](#filesystem),
- UUID, name, title, and access rights are saved to [PostgreSQL](#postgresql),
- UUID, name, title, description and access rights are saved to [PostgreSQL](#postgresql),
- JSON file is saved to [filesystem](#filesystem),
- and asynchronous [tasks](#tasks) are saved in [Redis](#redis).

Expand Down
11 changes: 8 additions & 3 deletions src/layman/common/prime_db_schema/publications.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def get_publication_infos_with_metainfo(workspace_name=None, pub_type=None, styl
p.type,
p.name,
p.title,
p.description,
p.uuid::text,
p.geodata_type,
p.style_type,
Expand Down Expand Up @@ -266,6 +267,7 @@ def get_publication_infos_with_metainfo(workspace_name=None, pub_type=None, styl
publication_name,): {'id': id_publication,
'name': publication_name,
'title': title,
'description': description,
'uuid': uuid,
'type': publication_type,
'geodata_type': geodata_type,
Expand All @@ -288,7 +290,7 @@ def get_publication_infos_with_metainfo(workspace_name=None, pub_type=None, styl
'_layer_maps': layer_maps or [],
'_wfs_wms_status': settings.EnumWfsWmsStatus(wfs_wms_status) if wfs_wms_status else None,
}
for id_publication, workspace_name, publication_type, publication_name, title, uuid, geodata_type, style_type, image_mosaic, updated_at, xmin, ymin, xmax, ymax,
for id_publication, workspace_name, publication_type, publication_name, title, description, uuid, geodata_type, style_type, image_mosaic, updated_at, xmin, ymin, xmax, ymax,
srid, external_table_uri, read_users_roles, write_users_roles, map_layers, layer_maps, wfs_wms_status, _
in values}

Expand Down Expand Up @@ -475,8 +477,8 @@ def insert_publication(workspace_name, info):
check_publication_info(workspace_name, info)

insert_publications_sql = f'''insert into {DB_SCHEMA}.publications as p
(id_workspace, name, title, type, uuid, style_type, geodata_type, everyone_can_read, everyone_can_write, updated_at, image_mosaic, external_table_uri, wfs_wms_status) values
(%s, %s, %s, %s, %s, %s, %s, %s, %s, current_timestamp, %s, PGP_SYM_ENCRYPT(%s::text, %s::text), %s )
(id_workspace, name, title, description, type, uuid, style_type, geodata_type, everyone_can_read, everyone_can_write, updated_at, image_mosaic, external_table_uri, wfs_wms_status) values
(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, current_timestamp, %s, PGP_SYM_ENCRYPT(%s::text, %s::text), %s )
returning id
;'''

Expand All @@ -491,6 +493,7 @@ def insert_publication(workspace_name, info):
data = (id_workspace,
info.get("name"),
info.get("title"),
info.get("description"),
info.get("publ_type_name"),
info.get("uuid"),
info.get('style_type'),
Expand Down Expand Up @@ -562,6 +565,7 @@ def update_publication(workspace_name, info):

update_publications_sql = f'''update {DB_SCHEMA}.publications set
title = coalesce(%s, title),
description = coalesce(%s, description),
style_type = coalesce(%s, style_type),
everyone_can_read = coalesce(%s, everyone_can_read),
everyone_can_write = coalesce(%s, everyone_can_write),
Expand All @@ -576,6 +580,7 @@ def update_publication(workspace_name, info):
;'''

data = (info.get("title"),
info.get("description"),
info.get('style_type'),
access_rights_changes['read']['EVERYONE'],
access_rights_changes['write']['EVERYONE'],
Expand Down
6 changes: 3 additions & 3 deletions src/layman/layer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ def get_layer_patch_keys():
('layman.layer.prime_db_schema.table', InternalSourceTypeDef(info_items=[
'access_rights', 'name', 'title', 'uuid', 'bounding_box', 'style_type', 'native_crs',
'native_bounding_box', 'geodata_type', 'updated_at', 'id', 'type', 'image_mosaic', 'table_uri',
'original_data_source', 'wfs_wms_status', 'layer_maps']),),
'original_data_source', 'wfs_wms_status', 'layer_maps', 'description', ]),),
('layman.layer.filesystem.input_chunk', InternalSourceTypeDef(info_items=['file', ]),),
('layman.layer.filesystem.input_file', InternalSourceTypeDef(info_items=['file', ]),),
('layman.layer.filesystem.input_style', InternalSourceTypeDef(info_items=[]),),
('layman.layer.filesystem.gdal', InternalSourceTypeDef(info_items=['file', ]),),
('layman.layer.db.table', InternalSourceTypeDef(info_items=['db', ]),),
('layman.layer.prime_db_schema.file_data', InternalSourceTypeDef(info_items=[]),),
('layman.layer.qgis.wms', InternalSourceTypeDef(info_items=['style', 'wms', ]),),
('layman.layer.geoserver.wfs', InternalSourceTypeDef(info_items=['wfs', 'description', ]),),
('layman.layer.geoserver.wms', InternalSourceTypeDef(info_items=['wms', 'description', ]),),
('layman.layer.geoserver.wfs', InternalSourceTypeDef(info_items=['wfs', ]),),
('layman.layer.geoserver.wms', InternalSourceTypeDef(info_items=['wms', ]),),
('layman.layer.geoserver.sld', InternalSourceTypeDef(info_items=['style', ]),),
('layman.layer.prime_db_schema.wfs_wms_status', InternalSourceTypeDef(info_items=[]),),
('layman.layer.filesystem.thumbnail', InternalSourceTypeDef(info_items=['thumbnail', ]),),
Expand Down
4 changes: 4 additions & 0 deletions src/layman/layer/prime_db_schema/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ def patch_layer(workspace,
external_table_uri,
style_type=None,
title=None,
description=None,
access_rights=None,
image_mosaic=None,
geodata_type=None,
):
db_info = {"name": layername,
"title": title,
"description": description,
"publ_type_name": LAYER_TYPE,
"actor_name": actor_name,
'image_mosaic': image_mosaic,
Expand Down Expand Up @@ -83,6 +85,7 @@ def post_layer(workspace,
layername,
access_rights,
title,
description,
uuid,
actor_name,
geodata_type,
Expand All @@ -92,6 +95,7 @@ def post_layer(workspace,
):
db_info = {"name": layername,
"title": title,
"description": description,
"publ_type_name": LAYER_TYPE,
"uuid": uuid,
"access_rights": access_rights,
Expand Down
4 changes: 2 additions & 2 deletions src/layman/map/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ def get_map_patch_keys():
# see also .util.TASKS_TO_MAP_INFO_KEYS
'internal_sources': OrderedDict([
('layman.map.filesystem.uuid', InternalSourceTypeDef(info_items=[]),),
('layman.map.prime_db_schema.table', InternalSourceTypeDef(info_items=['access_rights', 'name', 'title', 'uuid',
('layman.map.prime_db_schema.table', InternalSourceTypeDef(info_items=['access_rights', 'name', 'title', 'description', 'uuid',
'bounding_box', 'native_crs', 'native_bounding_box',
'updated_at', 'type', 'id', 'image_mosaic',
'map_layers']),),
('layman.map.filesystem.input_file', InternalSourceTypeDef(info_items=['description', 'file']),),
('layman.map.filesystem.input_file', InternalSourceTypeDef(info_items=['file']),),
('layman.map.prime_db_schema.file_data', InternalSourceTypeDef(info_items=[]),),
('layman.map.filesystem.thumbnail', InternalSourceTypeDef(info_items=['thumbnail', ]),),
('layman.map.micka.soap', InternalSourceTypeDef(info_items=['metadata', ]),),
Expand Down
4 changes: 4 additions & 0 deletions src/layman/map/prime_db_schema/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ def patch_map(workspace,
mapname,
actor_name,
title=None,
description=None,
access_rights=None):
db_info = {"name": mapname,
"title": title,
"description": description,
"publ_type_name": MAP_TYPE,
"actor_name": actor_name,
}
Expand Down Expand Up @@ -61,12 +63,14 @@ def post_map(workspace,
mapname,
uuid,
title,
description,
access_rights,
actor_name,
):
# store into Layman DB
db_info = {"name": mapname,
"title": title,
"description": description,
"publ_type_name": MAP_TYPE,
"uuid": uuid,
"access_rights": access_rights,
Expand Down
5 changes: 4 additions & 1 deletion src/layman/upgrade/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from db import util as db_util
from layman.upgrade import upgrade_v1_8, upgrade_v1_9, upgrade_v1_10, upgrade_v1_12, upgrade_v1_16, upgrade_v1_17, upgrade_v1_18, \
upgrade_v1_20, upgrade_v1_21, upgrade_v1_22, upgrade_v1_23
upgrade_v1_20, upgrade_v1_21, upgrade_v1_22, upgrade_v1_23, upgrade_v2_0
from layman import settings
from . import consts

Expand Down Expand Up @@ -47,6 +47,9 @@
upgrade_v1_23.create_role_service_schema,
upgrade_v1_23.remove_right_types_table,
]),
((2, 0, 0), [
upgrade_v2_0.adjust_db_for_image_mosaic,
]),
],
consts.MIGRATION_TYPE_DATA: [
((1, 16, 0), [
Expand Down
3 changes: 2 additions & 1 deletion src/layman/upgrade/upgrade_v1_16_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ def provide_map(workspace, map, *, file_path):
map,
uuid_str,
map,
None,
access_rights,
None
None,
)
uuid_common.assign_publication_uuid(MAP_TYPE, workspace, map, uuid_str=uuid_str)

Expand Down
3 changes: 2 additions & 1 deletion src/layman/upgrade/upgrade_v1_17_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,13 @@ def publish_layer(workspace, layer, *, file_path, style_type, style_file, ):
layer,
access_rights=access_rights,
title=layer,
description=None,
uuid=uuid_str,
actor_name=None,
geodata_type=settings.GEODATA_TYPE_VECTOR,
style_type=style_type_def,
image_mosaic=False,
external_table_uri=None
external_table_uri=None,
)
uuid_common.assign_publication_uuid(LAYER_TYPE, workspace, layer, uuid_str=uuid_str)

Expand Down
16 changes: 16 additions & 0 deletions src/layman/upgrade/upgrade_v2_0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import logging

from db import util as db_util
from layman import settings

logger = logging.getLogger(__name__)
DB_SCHEMA = settings.LAYMAN_PRIME_SCHEMA


def adjust_db_for_image_mosaic():
logger.info(f' Alter DB prime schema for description')

statement = f'''
ALTER TABLE {DB_SCHEMA}.publications ADD COLUMN IF NOT EXISTS
description varchar(1024) default '';'''
db_util.run_statement(statement)

0 comments on commit c12d0f2

Please sign in to comment.