diff --git a/CHANGELOG.md b/CHANGELOG.md index a3bac56bf..3c0b05980 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/doc/data-storage.md b/doc/data-storage.md index 2e46dfdfa..e6285f269 100644 --- a/doc/data-storage.md +++ b/doc/data-storage.md @@ -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). @@ -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). diff --git a/src/layman/common/prime_db_schema/publications.py b/src/layman/common/prime_db_schema/publications.py index 816c99f9b..d0b90a152 100644 --- a/src/layman/common/prime_db_schema/publications.py +++ b/src/layman/common/prime_db_schema/publications.py @@ -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, @@ -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, @@ -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} @@ -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 ;''' @@ -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'), @@ -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), @@ -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'], diff --git a/src/layman/layer/__init__.py b/src/layman/layer/__init__.py index 81ff51807..8a317190e 100644 --- a/src/layman/layer/__init__.py +++ b/src/layman/layer/__init__.py @@ -67,7 +67,7 @@ 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=[]),), @@ -75,8 +75,8 @@ def get_layer_patch_keys(): ('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', ]),), diff --git a/src/layman/layer/prime_db_schema/table.py b/src/layman/layer/prime_db_schema/table.py index d8eef67a1..eb6615246 100644 --- a/src/layman/layer/prime_db_schema/table.py +++ b/src/layman/layer/prime_db_schema/table.py @@ -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, @@ -83,6 +85,7 @@ def post_layer(workspace, layername, access_rights, title, + description, uuid, actor_name, geodata_type, @@ -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, diff --git a/src/layman/map/__init__.py b/src/layman/map/__init__.py index daa326e69..493973a58 100644 --- a/src/layman/map/__init__.py +++ b/src/layman/map/__init__.py @@ -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', ]),), diff --git a/src/layman/map/prime_db_schema/table.py b/src/layman/map/prime_db_schema/table.py index e9a421611..eb1321cd1 100644 --- a/src/layman/map/prime_db_schema/table.py +++ b/src/layman/map/prime_db_schema/table.py @@ -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, } @@ -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, diff --git a/src/layman/upgrade/__init__.py b/src/layman/upgrade/__init__.py index 623d68eeb..b79151d15 100644 --- a/src/layman/upgrade/__init__.py +++ b/src/layman/upgrade/__init__.py @@ -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 @@ -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), [ diff --git a/src/layman/upgrade/upgrade_v1_16_test.py b/src/layman/upgrade/upgrade_v1_16_test.py index 76b82561a..faf8a7861 100644 --- a/src/layman/upgrade/upgrade_v1_16_test.py +++ b/src/layman/upgrade/upgrade_v1_16_test.py @@ -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) diff --git a/src/layman/upgrade/upgrade_v1_17_test.py b/src/layman/upgrade/upgrade_v1_17_test.py index 57bb6b852..8a7b7e758 100644 --- a/src/layman/upgrade/upgrade_v1_17_test.py +++ b/src/layman/upgrade/upgrade_v1_17_test.py @@ -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) diff --git a/src/layman/upgrade/upgrade_v2_0.py b/src/layman/upgrade/upgrade_v2_0.py new file mode 100644 index 000000000..5a5a45e7b --- /dev/null +++ b/src/layman/upgrade/upgrade_v2_0.py @@ -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 null;''' + db_util.run_statement(statement)