From f82d1efa9d2d526705005967f12162cd3251883b Mon Sep 17 00:00:00 2001 From: Alexey Shtykov Date: Thu, 23 Jan 2025 12:37:09 +0300 Subject: [PATCH] single step migration cropped previously inherited migrations into a single step, add custom (software) migrations template --- qubership-apihub-service/Service.go | 1 + .../migration/service/DBMigrationService.go | 35 +- .../service/OperationsMigrationUtils.go | 4 +- .../migration/service/SoftMigrations.go | 386 +---- .../migrations/100_transition.down.sql | 1 - .../migrations/100_transition.up.sql | 54 - .../101_integration_refresh_token.down.sql | 4 - .../101_integration_refresh_token.up.sql | 6 - ...der_version_in_version_comparison.down.sql | 1 - ...ilder_version_in_version_comparison.up.sql | 1 - .../103_personal_workspaces.down.sql | 1 - .../migrations/103_personal_workspaces.up.sql | 6 - .../104_transformed_documents.down.sql | 2 - .../104_transformed_documents.up.sql | 13 - .../105_models_for_operations.down.sql | 1 - .../105_models_for_operations.up.sql | 1 - .../106_operation_custom_tag.down.sql | 1 - .../106_operation_custom_tag.up.sql | 1 - .../migrations/107_business_metrics.down.sql | 1 - .../migrations/107_business_metrics.up.sql | 8 - .../migrations/108_build_tracking.down.sql | 2 - .../migrations/108_build_tracking.up.sql | 2 - .../migrations/109_split_jsonPath.down.sql | 6 - .../migrations/109_split_jsonPath.up.sql | 40 - .../migrations/10_content_messages.down.sql | 2 - .../migrations/10_content_messages.up.sql | 11 - .../110_moved_pkg_comparisons.up.sql | 21 - .../migrations/111_update_build.down.sql | 17 - .../migrations/111_update_build.up.sql | 9 - .../112_migration_validation.down.sql | 2 - .../112_migration_validation.up.sql | 10 - .../113_default_last_active.down.sql | 2 - .../migrations/113_default_last_active.up.sql | 2 - .../114_remove_old_checksum.down.sql | 14 - .../migrations/114_remove_old_checksum.up.sql | 4 - .../115_add_build_status_index.down.sql | 3 - .../115_add_build_status_index.up.sql | 3 - .../116_jsonb_arr_to_jsonb.down.sql | 14 - .../migrations/116_jsonb_arr_to_jsonb.up.sql | 3 - .../117_package_transition.down.sql | 1 - .../migrations/117_package_transition.up.sql | 12 - .../118_transition_activity_sequence.down.sql | 2 - .../118_transition_activity_sequence.up.sql | 10 - .../119_workspace_services.down.sql | 27 - .../migrations/119_workspace_services.up.sql | 14 - .../11_content_labels_metadata.down.sql | 6 - .../11_content_labels_metadata.up.sql | 5 - .../120_release_version_pattern.down.sql | 3 - .../120_release_version_pattern.up.sql | 3 - .../121_remove_version_permissions.up.sql | 2 - .../migrations/122_endpoint_calls.down.sql | 1 - .../migrations/122_endpoint_calls.up.sql | 7 - .../migrations/123_versions_cleanup.down.sql | 1 - .../migrations/123_versions_cleanup.up.sql | 16 - .../124_api_key_created_for.down.sql | 1 - .../migrations/124_api_key_created_for.up.sql | 1 - .../migrations/125_build_metadata.down.sql | 1 - .../migrations/125_build_metadata.up.sql | 1 - .../126_transformed_documents_rework.down.sql | 9 - .../126_transformed_documents_rework.up.sql | 9 - .../migrations/127_template_checksum.down.sql | 8 - .../migrations/127_template_checksum.up.sql | 11 - .../128_remove_ghost_operations.down.sql | 1 - .../128_remove_ghost_operations.up.sql | 2 - .../129_business_metrics_user_id.down.sql | 6 - .../129_business_metrics_user_id.up.sql | 5 - .../migrations/12_shared_content.down.sql | 2 - .../migrations/12_shared_content.up.sql | 18 - .../130_operation_group_history.down.sql | 1 - .../130_operation_group_history.up.sql | 25 - .../migrations/131_gitlab_webhook.down.sql | 2 - .../migrations/131_gitlab_webhook.up.sql | 2 - .../132_operaion_data_cleanup.up.sql | 7 - .../132_operation_data_cleanup.down.sql | 7 - .../133_editor_draft_redesign.down.sql | 11 - .../133_editor_draft_redesign.up.sql | 17 - ...134_migration_validation_overview.down.sql | 2 - .../134_migration_validation_overview.up.sql | 5 - .../migrations/135_api_key_id.down.sql | 2 - .../migrations/135_api_key_id.up.sql | 2 - .../136_latest_revision_func_fix.down.sql | 16 - .../136_latest_revision_func_fix.up.sql | 16 - .../137_index_for_op_comparison.down.sql | 1 - .../137_index_for_op_comparison.up.sql | 2 - .../migrations/138_agent_version.down.sql | 1 - .../migrations/138_agent_version.up.sql | 1 - .../139_search_tables_cleanup.down.sql | 44 - .../139_search_tables_cleanup.up.sql | 5 - .../migrations/13_branch_editors.down.sql | 1 - .../migrations/13_branch_editors.up.sql | 7 - .../migrations/140_audience.down.sql | 1 - .../resources/migrations/140_audience.up.sql | 1 - .../migrations/141_group_publish.down.sql | 1 - .../migrations/141_group_publish.up.sql | 6 - .../migrations/142_metrics_fix.up.sql | 7 - ..._clean_deleted_previous_version_ref.up.sql | 31 - .../144_deprecated_info_to_string.down.sql | 2 - .../144_deprecated_info_to_string.up.sql | 2 - .../migrations/145_csv_publish.down.sql | 1 - .../migrations/145_csv_publish.up.sql | 7 - .../migrations/14_fix_published_path.down.sql | 2 - .../migrations/14_fix_published_path.up.sql | 2 - .../15_branch_operations_draft_reset.down.sql | 10 - .../15_branch_operations_draft_reset.up.sql | 13 - .../16_nullable_content_type.down.sql | 2 - .../16_nullable_content_type.up.sql | 2 - .../migrations/17_published_src.down.sql | 3 - .../migrations/17_published_src.up.sql | 25 - .../18_drop_branch_editors.down.sql | 7 - .../migrations/18_drop_branch_editors.up.sql | 1 - .../19_drafted_branch_draft_reset.down.sql | 1 - .../19_drafted_branch_draft_reset.up.sql | 12 - .../resources/migrations/1_init.down.sql | 26 - .../resources/migrations/1_init.up.sql | 1268 +++++++++++++---- .../20_drafted_branch_constraint.down.sql | 1 - .../20_drafted_branch_constraint.up.sql | 3 - .../migrations/21_cascade_deletion.down.sql | 43 - .../migrations/21_cascade_deletion.up.sql | 43 - .../migrations/22_previous_version.down.sql | 1 - .../migrations/22_previous_version.up.sql | 2 - .../migrations/23_media_type_datafix.down.sql | 6 - .../migrations/23_media_type_datafix.up.sql | 12 - .../24_fill_versions_repository_url.down.sql | 2 - .../24_fill_versions_repository_url.up.sql | 4 - .../migrations/25_package_group.up.sql | 40 - .../migrations/26_naming_refactoring.down.sql | 47 - .../migrations/26_naming_refactoring.up.sql | 47 - .../27_previous_package_id.down.sql | 2 - .../migrations/27_previous_package_id.up.sql | 2 - .../migrations/28_title_field.down.sql | 2 - .../migrations/28_title_field.up.sql | 2 - .../migrations/29_agent_config.down.sql | 1 - .../migrations/29_agent_config.up.sql | 10 - .../migrations/2_projectsRepoAndUrl.down.sql | 3 - .../migrations/2_projectsRepoAndUrl.up.sql | 3 - .../migrations/30_published_fields.down.sql | 5 - .../migrations/30_published_fields.up.sql | 17 - .../migrations/31_unknown_type_datafix.up.sql | 2 - .../migrations/32_version_folder.down.sql | 2 - .../migrations/32_version_folder.up.sql | 2 - .../33_included_draft_flag.down.sql | 2 - .../migrations/33_included_draft_flag.up.sql | 4 - .../34_package_service_name.down.sql | 1 - .../migrations/34_package_service_name.up.sql | 12 - .../migrations/35_search_tables.down.sql | 3 - .../migrations/35_search_tables.up.sql | 23 - .../36_search_table_gin_index.down.sql | 2 - .../36_search_table_gin_index.up.sql | 9 - .../migrations/37_build_tables.down.sql | 3 - .../migrations/37_build_tables.up.sql | 42 - .../migrations/38_version_changelog.down.sql | 1 - .../migrations/38_version_changelog.up.sql | 15 - .../migrations/39_build_result.down.sql | 1 - .../migrations/39_build_result.up.sql | 8 - .../migrations/3_draftActions.down.sql | 9 - .../migrations/3_draftActions.up.sql | 9 - .../migrations/40_add_rev_pk.down.sql | 2 - .../resources/migrations/40_add_rev_pk.up.sql | 3 - .../migrations/41_nullable_included.down.sql | 1 - .../migrations/41_nullable_included.up.sql | 1 - .../migrations/42_use_zero_pg.down.sql | 4 - .../migrations/42_use_zero_pg.up.sql | 4 - .../migrations/43_builder_task.down.sql | 1 - .../migrations/43_builder_task.up.sql | 10 - .../migrations/44_config_folders.down.sql | 6 - .../migrations/44_config_folders.up.sql | 5 - .../migrations/45_user_avatar_table.down.sql | 2 - .../migrations/45_user_avatar_table.up.sql | 11 - .../migrations/46_access_control.down.sql | 3 - .../migrations/46_access_control.up.sql | 21 - .../migrations/47_version_labels.down.sql | 2 - .../migrations/47_version_labels.up.sql | 2 - .../48_access_control_constraint.down.sql | 2 - .../48_access_control_constraint.up.sql | 4 - .../migrations/49_api_key_roles.down.sql | 1 - .../migrations/49_api_key_roles.up.sql | 2 - .../migrations/4_intKeyRevoked.down.sql | 2 - .../migrations/4_intKeyRevoked.up.sql | 2 - .../migrations/50_oauth_token.up.sql | 1 - .../migrations/51_internal_users.down.sql | 3 - .../migrations/51_internal_users.up.sql | 23 - .../migrations/52_workspaces.down.sql | 1 - .../resources/migrations/52_workspaces.up.sql | 1 - .../migrations/53_packageId.down.sql | 2 - .../resources/migrations/53_packageId.up.sql | 6 - .../migrations/54_version_folders.down.sql | 1 - .../migrations/54_version_folders.up.sql | 11 - .../55_default_released_version.down.sql | 2 - .../55_default_released_version.up.sql | 2 - .../migrations/56_remove_api_keys_fk.up.sql | 2 - .../migrations/57_rest_operations.down.sql | 4 - .../migrations/57_rest_operations.up.sql | 45 - .../migrations/58_operations_search.down.sql | 2 - .../migrations/58_operations_search.up.sql | 28 - .../migrations/59_version_createdby.down.sql | 1 - .../migrations/59_version_createdby.up.sql | 1 - .../5_draft_file_commit_id.down.sql | 2 - .../migrations/5_draft_file_commit_id.up.sql | 2 - .../migrations/60_ref_relation_type.down.sql | 22 - .../migrations/60_ref_relation_type.up.sql | 7 - .../migrations/61_agent_reg.down.sql | 1 - .../resources/migrations/61_agent_reg.up.sql | 12 - .../62_package_group_service.down.sql | 1 - .../62_package_group_service.up.sql | 4 - .../migrations/63_open_count.down.sql | 3 - .../resources/migrations/63_open_count.up.sql | 25 - .../migrations/64_metadata_migration.down.sql | 8 - .../migrations/64_metadata_migration.up.sql | 8 - .../resources/migrations/65_filename.down.sql | 3 - .../resources/migrations/65_filename.up.sql | 2 - .../migrations/66_add_src_index.down.sql | 1 - .../migrations/66_add_src_index.up.sql | 2 - .../67_add_release_version_pattern.down.sql | 1 - .../67_add_release_version_pattern.up.sql | 1 - .../migrations/68_activity_tracking.down.sql | 1 - .../migrations/68_activity_tracking.up.sql | 12 - .../69_builder_notifications.down.sql | 1 - .../69_builder_notifications.up.sql | 7 - .../migrations/6_content_path.down.sql | 2 - .../migrations/6_content_path.up.sql | 2 - .../migrations/70_role_redesign.down.sql | 6 - .../migrations/70_role_redesign.up.sql | 36 - .../71_builder_notifications_fix.up.sql | 2 - .../72_old_editor_role_permissions.down.sql | 3 - .../72_old_editor_role_permissions.up.sql | 3 - .../migrations/73_delete_sources.up.sql | 2 - .../74_sources_deduplication.down.sql | 2 - .../74_sources_deduplication.up.sql | 5 - .../migrations/75_nullable_sources.down.sql | 2 - .../migrations/75_nullable_sources.up.sql | 1 - .../migrations/76_unbind_services.up.sql | 2 - .../77_operation_type_lower_case.down.sql | 5 - .../77_operation_type_lower_case.up.sql | 5 - .../migrations/78_version_deleted_by.down.sql | 1 - .../migrations/78_version_deleted_by.up.sql | 3 - .../79_parent_package_names_func.down.sql | 1 - .../79_parent_package_names_func.up.sql | 31 - .../migrations/7_apihub_api_keys.down.sql | 1 - .../migrations/7_apihub_api_keys.up.sql | 16 - .../80_at_table_remove_version.down.sql | 2 - .../80_at_table_remove_version.up.sql | 2 - .../81_remove_ref_relation_type.down.sql | 4 - .../81_remove_ref_relation_type.up.sql | 4 - .../82_frontend_version_delete.down.sql | 1 - .../82_frontend_version_delete.up.sql | 1 - .../migrations/83_cleaning_job_lock.down.sql | 1 - .../migrations/83_cleaning_job_lock.up.sql | 1 - .../migrations/84_migrations_table.up.sql | 9 - .../migrations/85_excludeFromSearch.down.sql | 1 - .../migrations/85_excludeFromSearch.up.sql | 1 - .../migrations/86_grouping_prefix.down.sql | 3 - .../migrations/86_grouping_prefix.up.sql | 16 - .../migrations/87_comparison_table.down.sql | 9 - .../migrations/87_comparison_table.up.sql | 26 - .../migrations/88_refs_redesign.down.sql | 16 - .../migrations/88_refs_redesign.up.sql | 58 - .../89_deprecated_operation.down.sql | 3 - .../migrations/89_deprecated_operation.up.sql | 3 - .../migrations/8_draft_publish_flag.down.sql | 2 - .../migrations/8_draft_publish_flag.up.sql | 5 - .../migrations/90_split_favorites.down.sql | 19 - .../migrations/90_split_favorites.up.sql | 51 - .../migrations/91_add_package_id_fks.down.sql | 21 - .../migrations/91_add_package_id_fks.up.sql | 54 - .../migrations/92_excluded_refs.down.sql | 1 - .../migrations/92_excluded_refs.up.sql | 22 - .../93_operation_comparison_fk.up.sql | 1 - .../94_manual_operation_grouping.down.sql | 17 - .../94_manual_operation_grouping.up.sql | 33 - .../resources/migrations/95_src_fix.down.sql | 22 - .../resources/migrations/95_src_fix.up.sql | 17 - .../96_latest_revision_func.down.sql | 1 - .../migrations/96_latest_revision_func.up.sql | 16 - .../97_activity_event_revision.down.sql | 3 - .../97_activity_event_revision.up.sql | 7 - .../98_deleted_grouped_operations.down.sql | 2 - .../98_deleted_grouped_operations.up.sql | 1 - .../migrations/99_gql_search_scopes.down.sql | 14 - .../migrations/99_gql_search_scopes.up.sql | 32 - .../migrations/9_published_metadata.down.sql | 25 - .../migrations/9_published_metadata.up.sql | 26 - qubership-apihub-service/service.txt | 723 ++++++++++ 282 files changed, 1772 insertions(+), 2926 deletions(-) delete mode 100644 qubership-apihub-service/resources/migrations/100_transition.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/100_transition.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/101_integration_refresh_token.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/101_integration_refresh_token.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/102_builder_version_in_version_comparison.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/102_builder_version_in_version_comparison.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/103_personal_workspaces.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/103_personal_workspaces.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/104_transformed_documents.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/104_transformed_documents.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/105_models_for_operations.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/105_models_for_operations.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/106_operation_custom_tag.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/106_operation_custom_tag.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/107_business_metrics.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/107_business_metrics.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/108_build_tracking.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/108_build_tracking.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/109_split_jsonPath.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/109_split_jsonPath.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/10_content_messages.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/10_content_messages.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/110_moved_pkg_comparisons.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/111_update_build.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/111_update_build.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/112_migration_validation.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/112_migration_validation.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/113_default_last_active.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/113_default_last_active.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/114_remove_old_checksum.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/114_remove_old_checksum.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/115_add_build_status_index.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/115_add_build_status_index.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/116_jsonb_arr_to_jsonb.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/116_jsonb_arr_to_jsonb.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/117_package_transition.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/117_package_transition.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/118_transition_activity_sequence.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/118_transition_activity_sequence.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/119_workspace_services.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/119_workspace_services.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/11_content_labels_metadata.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/11_content_labels_metadata.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/120_release_version_pattern.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/120_release_version_pattern.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/121_remove_version_permissions.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/122_endpoint_calls.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/122_endpoint_calls.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/123_versions_cleanup.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/123_versions_cleanup.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/124_api_key_created_for.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/124_api_key_created_for.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/125_build_metadata.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/125_build_metadata.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/126_transformed_documents_rework.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/126_transformed_documents_rework.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/127_template_checksum.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/127_template_checksum.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/128_remove_ghost_operations.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/128_remove_ghost_operations.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/129_business_metrics_user_id.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/129_business_metrics_user_id.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/12_shared_content.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/12_shared_content.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/130_operation_group_history.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/130_operation_group_history.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/131_gitlab_webhook.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/131_gitlab_webhook.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/132_operaion_data_cleanup.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/132_operation_data_cleanup.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/133_editor_draft_redesign.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/133_editor_draft_redesign.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/134_migration_validation_overview.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/134_migration_validation_overview.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/135_api_key_id.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/135_api_key_id.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/136_latest_revision_func_fix.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/136_latest_revision_func_fix.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/137_index_for_op_comparison.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/137_index_for_op_comparison.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/138_agent_version.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/138_agent_version.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/139_search_tables_cleanup.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/139_search_tables_cleanup.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/13_branch_editors.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/13_branch_editors.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/140_audience.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/140_audience.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/141_group_publish.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/141_group_publish.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/142_metrics_fix.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/143_clean_deleted_previous_version_ref.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/144_deprecated_info_to_string.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/144_deprecated_info_to_string.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/145_csv_publish.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/145_csv_publish.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/14_fix_published_path.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/14_fix_published_path.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/15_branch_operations_draft_reset.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/15_branch_operations_draft_reset.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/16_nullable_content_type.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/16_nullable_content_type.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/17_published_src.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/17_published_src.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/18_drop_branch_editors.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/18_drop_branch_editors.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/19_drafted_branch_draft_reset.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/19_drafted_branch_draft_reset.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/1_init.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/20_drafted_branch_constraint.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/20_drafted_branch_constraint.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/21_cascade_deletion.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/21_cascade_deletion.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/22_previous_version.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/22_previous_version.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/23_media_type_datafix.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/23_media_type_datafix.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/24_fill_versions_repository_url.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/24_fill_versions_repository_url.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/25_package_group.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/26_naming_refactoring.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/26_naming_refactoring.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/27_previous_package_id.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/27_previous_package_id.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/28_title_field.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/28_title_field.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/29_agent_config.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/29_agent_config.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/2_projectsRepoAndUrl.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/2_projectsRepoAndUrl.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/30_published_fields.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/30_published_fields.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/31_unknown_type_datafix.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/32_version_folder.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/32_version_folder.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/33_included_draft_flag.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/33_included_draft_flag.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/34_package_service_name.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/34_package_service_name.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/35_search_tables.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/35_search_tables.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/36_search_table_gin_index.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/36_search_table_gin_index.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/37_build_tables.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/37_build_tables.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/38_version_changelog.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/38_version_changelog.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/39_build_result.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/39_build_result.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/3_draftActions.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/3_draftActions.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/40_add_rev_pk.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/40_add_rev_pk.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/41_nullable_included.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/41_nullable_included.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/42_use_zero_pg.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/42_use_zero_pg.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/43_builder_task.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/43_builder_task.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/44_config_folders.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/44_config_folders.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/45_user_avatar_table.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/45_user_avatar_table.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/46_access_control.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/46_access_control.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/47_version_labels.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/47_version_labels.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/48_access_control_constraint.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/48_access_control_constraint.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/49_api_key_roles.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/49_api_key_roles.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/4_intKeyRevoked.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/4_intKeyRevoked.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/50_oauth_token.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/51_internal_users.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/51_internal_users.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/52_workspaces.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/52_workspaces.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/53_packageId.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/53_packageId.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/54_version_folders.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/54_version_folders.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/55_default_released_version.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/55_default_released_version.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/56_remove_api_keys_fk.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/57_rest_operations.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/57_rest_operations.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/58_operations_search.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/58_operations_search.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/59_version_createdby.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/59_version_createdby.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/5_draft_file_commit_id.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/5_draft_file_commit_id.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/60_ref_relation_type.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/60_ref_relation_type.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/61_agent_reg.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/61_agent_reg.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/62_package_group_service.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/62_package_group_service.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/63_open_count.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/63_open_count.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/64_metadata_migration.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/64_metadata_migration.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/65_filename.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/65_filename.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/66_add_src_index.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/66_add_src_index.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/67_add_release_version_pattern.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/67_add_release_version_pattern.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/68_activity_tracking.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/68_activity_tracking.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/69_builder_notifications.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/69_builder_notifications.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/6_content_path.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/6_content_path.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/70_role_redesign.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/70_role_redesign.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/71_builder_notifications_fix.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/72_old_editor_role_permissions.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/72_old_editor_role_permissions.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/73_delete_sources.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/74_sources_deduplication.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/74_sources_deduplication.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/75_nullable_sources.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/75_nullable_sources.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/76_unbind_services.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/77_operation_type_lower_case.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/77_operation_type_lower_case.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/78_version_deleted_by.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/78_version_deleted_by.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/79_parent_package_names_func.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/79_parent_package_names_func.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/7_apihub_api_keys.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/7_apihub_api_keys.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/80_at_table_remove_version.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/80_at_table_remove_version.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/81_remove_ref_relation_type.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/81_remove_ref_relation_type.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/82_frontend_version_delete.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/82_frontend_version_delete.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/83_cleaning_job_lock.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/83_cleaning_job_lock.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/84_migrations_table.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/85_excludeFromSearch.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/85_excludeFromSearch.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/86_grouping_prefix.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/86_grouping_prefix.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/87_comparison_table.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/87_comparison_table.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/88_refs_redesign.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/88_refs_redesign.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/89_deprecated_operation.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/89_deprecated_operation.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/8_draft_publish_flag.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/8_draft_publish_flag.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/90_split_favorites.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/90_split_favorites.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/91_add_package_id_fks.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/91_add_package_id_fks.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/92_excluded_refs.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/92_excluded_refs.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/93_operation_comparison_fk.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/94_manual_operation_grouping.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/94_manual_operation_grouping.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/95_src_fix.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/95_src_fix.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/96_latest_revision_func.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/96_latest_revision_func.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/97_activity_event_revision.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/97_activity_event_revision.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/98_deleted_grouped_operations.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/98_deleted_grouped_operations.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/99_gql_search_scopes.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/99_gql_search_scopes.up.sql delete mode 100644 qubership-apihub-service/resources/migrations/9_published_metadata.down.sql delete mode 100644 qubership-apihub-service/resources/migrations/9_published_metadata.up.sql create mode 100644 qubership-apihub-service/service.txt diff --git a/qubership-apihub-service/Service.go b/qubership-apihub-service/Service.go index 3f8f56d..4734338 100644 --- a/qubership-apihub-service/Service.go +++ b/qubership-apihub-service/Service.go @@ -156,6 +156,7 @@ func main() { time.Sleep(time.Second * 10) // Give a chance to read the unrecoverable error panic("Failed perform DB migration: " + err.Error()) } + // to perform migrations, which could not be implemented with "pure" SQL err = dbMigrationService.SoftMigrateDb(currentVersion, newVersion, migrationRequired) if err != nil { log.Errorf("Failed to perform db migrations: %v", err.Error()) diff --git a/qubership-apihub-service/migration/service/DBMigrationService.go b/qubership-apihub-service/migration/service/DBMigrationService.go index 8f8a0a7..8bf7171 100644 --- a/qubership-apihub-service/migration/service/DBMigrationService.go +++ b/qubership-apihub-service/migration/service/DBMigrationService.go @@ -18,6 +18,7 @@ import ( "context" "fmt" "os" + "path/filepath" "sort" "strings" @@ -53,7 +54,7 @@ func NewDBMigrationService(cp db.ConnectionProvider, mRRepo mRepository.Migratio repo: mRRepo, buildCleanupRepository: bCRepo, transitionRepository: transitionRepository, - migrationsFolder: systemInfoService.GetBasePath() + "/resources/migrations", + migrationsFolder: filepath.Join(systemInfoService.GetBasePath(), "resources", "migrations"), minioStorageService: minioStorageService, } upMigrations, downMigrations, err := service.getMigrationFilenamesMap() @@ -77,29 +78,27 @@ type dbMigrationServiceImpl struct { minioStorageService service.MinioStorageService } -const storedMigrationsTableMigrationVersion = 84 +const storedMigrationsTableMigrationVersion = 1 // migration table will be created at first migration func (d *dbMigrationServiceImpl) createSchemaMigrationsTable() error { _, err := d.cp.GetConnection().Exec(` - create table if not exists schema_migrations - ( - version integer not null, - dirty boolean not null, - PRIMARY KEY(version) + CREATE TABLE IF NOT EXISTS public.schema_migrations ( + "version" int4 NOT NULL, + dirty bool NOT NULL, + CONSTRAINT schema_migrations_pkey PRIMARY KEY (version) )`) return err } func (d *dbMigrationServiceImpl) createStoredMigrationsTable() error { _, err := d.cp.GetConnection().Exec(` - create table if not exists stored_schema_migration - ( - num integer not null, - up_hash varchar not null, - sql_up varchar not null, - down_hash varchar null, - sql_down varchar null, - PRIMARY KEY(num) + CREATE TABLE IF NOT EXISTS public.stored_schema_migration ( + num int4 NOT NULL, + up_hash varchar NOT NULL, + sql_up varchar NOT NULL, + down_hash varchar NULL, + sql_down varchar NULL, + CONSTRAINT stored_schema_migration_pkey PRIMARY KEY (num) )`) return err } @@ -107,7 +106,7 @@ func (d *dbMigrationServiceImpl) createStoredMigrationsTable() error { func (d *dbMigrationServiceImpl) Migrate(basePath string) (currentMigrationNum int, newMigrationNum int, migrationRequired bool, err error) { log.Infof("Schema Migration: start") - var currentMigrationNumber int + currentMigrationNumber := 0 _, err = d.cp.GetConnection().QueryOne(pg.Scan(¤tMigrationNumber), `SELECT version FROM schema_migrations`) if err != nil { if strings.Contains(err.Error(), "does not exist") { @@ -225,12 +224,12 @@ func (d *dbMigrationServiceImpl) applyRequiredMigrations(upMigrations []mEntity. Where("version is not null"). Delete() if err != nil { - return fmt.Errorf("failed to update schema_migrations table with latest migration version %v", latestMigrationNum) + return fmt.Errorf("failed to delete schema_migrations table with latest migration version %v", latestMigrationNum) } _, err = tx.Model(&migrationEntity). Insert() if err != nil { - return fmt.Errorf("failed to update schema_migrations table with latest migration version %v", latestMigrationNum) + return fmt.Errorf("failed to insert schema_migrations table with latest migration version %v", latestMigrationNum) } return nil }) diff --git a/qubership-apihub-service/migration/service/OperationsMigrationUtils.go b/qubership-apihub-service/migration/service/OperationsMigrationUtils.go index 5e697b1..d2b25a0 100644 --- a/qubership-apihub-service/migration/service/OperationsMigrationUtils.go +++ b/qubership-apihub-service/migration/service/OperationsMigrationUtils.go @@ -625,7 +625,7 @@ func (d *dbMigrationServiceImpl) getMigrationFilenamesMap() (map[int]string, map if _, exists := upMigrations[num]; exists { return nil, nil, fmt.Errorf("found duplicate migration number, migration is not possible: %v", file) } - upMigrations[num] = d.migrationsFolder + "/" + file + upMigrations[num] = filepath.Join(d.migrationsFolder, file) if maxUpMigrationNumber < num { maxUpMigrationNumber = num } @@ -635,7 +635,7 @@ func (d *dbMigrationServiceImpl) getMigrationFilenamesMap() (map[int]string, map if _, exists := downMigrations[num]; exists { return nil, nil, fmt.Errorf("found duplicate migration number, migration is not possible: %v", file) } - downMigrations[num] = d.migrationsFolder + "/" + file + downMigrations[num] = filepath.Join(d.migrationsFolder, file) } } if maxUpMigrationNumber != len(upMigrations) { diff --git a/qubership-apihub-service/migration/service/SoftMigrations.go b/qubership-apihub-service/migration/service/SoftMigrations.go index d30f7c2..2452c46 100644 --- a/qubership-apihub-service/migration/service/SoftMigrations.go +++ b/qubership-apihub-service/migration/service/SoftMigrations.go @@ -14,20 +14,6 @@ package service -import ( - "crypto/sha1" - "encoding/hex" - "fmt" - "strconv" - "time" - - "github.com/Netcracker/qubership-apihub-backend/qubership-apihub-service/entity" - "github.com/Netcracker/qubership-apihub-backend/qubership-apihub-service/utils" - "github.com/go-pg/pg/v10" - "github.com/gosimple/slug" - log "github.com/sirupsen/logrus" -) - const typeAndTitleMigrationVersion = 28 const searchTablesMigrationVersion = 35 const filesOperationsMigrationVersion = 57 @@ -38,370 +24,12 @@ const draftBlobIds = 133 // SoftMigrateDb The function implements migrations that can't be made via SQL query. // Executes only required migrations based on current vs new versions. func (d dbMigrationServiceImpl) SoftMigrateDb(currentVersion int, newVersion int, migrationRequired bool) error { - if (currentVersion < typeAndTitleMigrationVersion && typeAndTitleMigrationVersion <= newVersion) || - (migrationRequired && typeAndTitleMigrationVersion == currentVersion && typeAndTitleMigrationVersion == newVersion) { - //async migration because it could take a lot of time to execute - utils.SafeAsync(func() { - err := d.updateTypeAndTitleForPublishedFiles() - if err != nil { - log.Error(err) - } - }) - } - if (currentVersion < searchTablesMigrationVersion && searchTablesMigrationVersion <= newVersion) || - (migrationRequired && searchTablesMigrationVersion == currentVersion && searchTablesMigrationVersion == newVersion) { - //async migration because it could take a lot of time to execute - utils.SafeAsync(func() { - err := d.fillTextSearchTables() - if err != nil { - log.Error(err) - } - }) - } - - if currentVersion < groupToDashboardVersion && groupToDashboardVersion <= newVersion || - (migrationRequired && groupToDashboardVersion == currentVersion && groupToDashboardVersion == newVersion) { - //async migration because it could take a lot of time to execute - utils.SafeAsync(func() { - err := d.groupsToDashboards() - if err != nil { - log.Error(err) - } - }) - } - - if currentVersion < personalWorkspaces && personalWorkspaces <= newVersion || - (migrationRequired && personalWorkspaces == currentVersion && personalWorkspaces == newVersion) { - //async migration because it could take a lot of time to execute - utils.SafeAsync(func() { - err := d.generatePersonalWorkspaceIds() - if err != nil { - log.Error(err) - } - }) - } - if currentVersion < draftBlobIds && draftBlobIds <= newVersion || - (migrationRequired && draftBlobIds == currentVersion && draftBlobIds == newVersion) { - //async migration because it could take a lot of time to execute - utils.SafeAsync(func() { - err := d.calculateDraftBlobIds() - if err != nil { - log.Error(err) - } - }) - } - - return nil -} - -func (d dbMigrationServiceImpl) updateTypeAndTitleForPublishedFiles() error { - err := d.validateMinRequiredVersion(typeAndTitleMigrationVersion) - if err != nil { - return err - } - allPublishedFiles := make([]entity.PublishedContentEntity, 0) - err = d.cp.GetConnection().Model(&allPublishedFiles). - Select() - if err != nil { - if err == pg.ErrNoRows { - return nil - } - return err - } - total := len(allPublishedFiles) - log.Infof("start calculating type and title for published files") - for i, fileEnt := range allPublishedFiles { - log.Infof("[%v / %v] calculating type and title..", i, total) - fileType, title := d.getTypeAndTitleFromPublishedFileData(fileEnt.Name, fileEnt.Checksum) - if title == "" { - title = getTitleFromFilename(fileEnt.Name) - } - fileEntTmp := fileEnt - fileEntTmp.Title = title - fileEntTmp.DataType = fileType - _, err = d.cp.GetConnection().Model(&fileEntTmp). - Column("title", "data_type"). - WherePK(). - Update() - if err != nil { - log.Errorf("failed to calculate type or title for file %v with checksum %v: %v", fileEnt.FileId, fileEnt.Checksum, err.Error()) - } - } - log.Infof("finished calculating type and title for published files") - return nil -} - -func (d dbMigrationServiceImpl) fillTextSearchTables() error { - err := d.validateMinRequiredVersion(searchTablesMigrationVersion) - if err != nil { - return err - } - - var filesToCalculate []entity.PublishedContentEntity - - //select files from not deleted versions that have no entries in any of ts_ tables - filesWithoutTextSearchDataQuery := ` - with maxrev as - ( - select package_id, version, max(revision) as revision - from published_version - group by package_id, version - ) - select vc.* from published_version_revision_content vc - inner join maxrev - on maxrev.package_id = vc.package_id - and maxrev.version = vc.version - and maxrev.revision = vc.revision - inner join published_version pv - on pv.package_id = vc.package_id - and pv.version = vc.version - and pv.revision = vc.revision - and pv.deleted_at is null - where vc.data_type != 'unknown' - and vc.checksum not in( - select t.checksum from ts_published_data_path_split t where t.package_id = vc.package_id - union - select t.checksum from ts_published_data_custom_split t where t.package_id = vc.package_id - union - select t.checksum from ts_published_data_errors t where t.package_id = vc.package_id - );` - _, err = d.cp.GetConnection().Query(&filesToCalculate, filesWithoutTextSearchDataQuery) - if err != nil { - if err == pg.ErrNoRows { - return nil - } - return err - } - //splits each lexem by / - //(e.g. lexem /api-v1/customerTroubleTicket_final will be split into 2 lexems: api-v1, customerTroubleTicket_final) - insertTextSearchPathSplitQuery := ` - insert into ts_published_data_path_split(package_id, checksum, search_vector) - select package_id, checksum, to_tsvector(replace(convert_from(data, 'UTF-8'),'/',' ')) as search_vector - from published_data - where package_id = ? and checksum = ? - on conflict (package_id, checksum) do update set search_vector = excluded.search_vector;` - - //splits each lexem by / and then by '-', '_' and capital letters - //(e.g. lexem /api-v1/customerTroubleTicket_final will be split into 6 lexems: api, v1, customer, trouble, ticket, final) - insertTextSearchCustomSplitQuery := ` - insert into ts_published_data_custom_split(package_id, checksum, search_vector) - select package_id, checksum, to_tsvector(regexp_replace(replace(replace(replace(convert_from(data, 'UTF-8'),'/',' '),'-',' '),'_',' '), '([A-Z])', ' \1', 'g')) as search_vector - from published_data - where package_id = ? and checksum = ? - on conflict (package_id, checksum) do update set search_vector = excluded.search_vector;` - - insertTextSearchErrorQuery := ` - insert into ts_published_data_errors(package_id, checksum, error) - values (?, ?, ?) - on conflict (package_id, checksum) do update set error = excluded.error;` - - total := len(filesToCalculate) - log.Infof("start filling text search tables") - for i, file := range filesToCalculate { - log.Infof("[%v / %v] calculating lexems..", i, total) - _, err := d.cp.GetConnection().Exec(insertTextSearchPathSplitQuery, file.PackageId, file.Checksum) - if err != nil { - log.Warnf("Failed to store text search path split vector for '%v' in version %v: %v", file.FileId, file.Version, err.Error()) - _, err = d.cp.GetConnection().Exec(insertTextSearchErrorQuery, file.PackageId, file.Checksum, err.Error()) - if err != nil { - log.Errorf("Failed to store error for '%v' in version %v: %v", file.FileId, file.Version, err.Error()) - continue - } - } - _, err = d.cp.GetConnection().Exec(insertTextSearchCustomSplitQuery, file.PackageId, file.Checksum) - if err != nil { - log.Warnf("Failed to store text search custom split vector for '%v' in version %v: %v", file.FileId, file.Version, err.Error()) - _, err = d.cp.GetConnection().Exec(insertTextSearchErrorQuery, file.PackageId, file.Checksum, err.Error()) - if err != nil { - log.Errorf("Failed to store error for '%v' in version %v: %v", file.FileId, file.Version, err.Error()) - continue - } - } - } - log.Infof("finished filling text search tables") - return nil -} - -// Actually it's custom code for agent -func (d dbMigrationServiceImpl) groupsToDashboards() error { - selectNamespaceGroupsQuery := "select distinct pv.package_id from published_version pv inner join package_group pg on pv.package_id=pg.id where pv.package_id ilike 'QS.RUNENV.%' and pg.kind='group'" - - nsGroupIds := make([]string, 0) - - _, err := d.cp.GetConnection().Query(&nsGroupIds, selectNamespaceGroupsQuery) - if err != nil { - if err == pg.ErrNoRows { - return nil - } - return err - } - if len(nsGroupIds) == 0 { - return nil - } - - insertDashboardQuery := "insert into package_group (id, kind, name, alias, parent_id, image_url, description, deleted_at, created_at, created_by, deleted_by, default_role, default_released_version, service_name, release_version_pattern, exclude_from_search, rest_grouping_prefix) " + - "values (?, 'dashboard', 'snapshot', ?, ?, '', '', null, ?, 'db migration', '', 'viewer', '', '', '', true, '') on conflict(id) do nothing;" - - log.Infof("groupsToDashboards: creating dashboards and moving data") - total := len(nsGroupIds) - for i, id := range nsGroupIds { - if (i+1)%10 == 0 { - log.Infof("groupsToDashboards: processed %d/%d", i+1, total) - } - - dashAlias := "SNAPSHOT-DASH" - dashId := id + "." + dashAlias - _, err := d.cp.GetConnection().Exec(insertDashboardQuery, dashId, dashAlias, id, time.Now()) - if err != nil { - return fmt.Errorf("failed to create snapshot dashboard %s", dashId) - } - - _, err = d.transitionRepository.MoveAllData(id, dashId) - if err != nil { - return fmt.Errorf("failed to move data from group %s to dashboard %s: %w", id, dashId, err) - } - } - log.Infof("groupsToDashboards: done") - return nil -} - -func (d dbMigrationServiceImpl) generatePersonalWorkspaceIds() error { - log.Info("Start generating personal workspace ids") - getAllUsersQuery := `select * from user_data` - userEnts := make([]entity.UserEntity, 0) - _, err := d.cp.GetConnection().Query(&userEnts, getAllUsersQuery) - if err != nil { - return fmt.Errorf("failed to get all users: %w", err) - } - for _, user := range userEnts { - privatePackageId, err := d.generateUserPrivatePackageId(user.Id) - if err != nil { - return fmt.Errorf("failed to generate privatePackageId for user: %w", err) - } - _, err = d.cp.GetConnection().Exec(`update user_data set private_package_id = ? where user_id = ?`, privatePackageId, user.Id) - if err != nil { - return fmt.Errorf("failed to update private_package_id for user: %w", err) - } - } - log.Info("Successfully generated personal workspace ids") - return nil -} - -func (d dbMigrationServiceImpl) generateUserPrivatePackageId(userId string) (string, error) { - userIdSlug := slug.Make(userId) - privatePackageId := userIdSlug - privatePackageIdTaken, err := d.privatePackageIdExists(privatePackageId, userId) - if err != nil { - return "", err - } - i := 1 - for privatePackageIdTaken { - privatePackageId = userIdSlug + "-" + strconv.Itoa(i) - privatePackageIdTaken, err = d.privatePackageIdExists(privatePackageId, userId) - if err != nil { - return "", err - } - i++ - } - packageEnt, err := d.getPackageIncludingDeleted(privatePackageId) - if err != nil { - return "", err - } - for packageEnt != nil { - i++ - privatePackageId = userIdSlug + "-" + strconv.Itoa(i) - packageEnt, err = d.getPackageIncludingDeleted(privatePackageId) - if err != nil { - return "", err - } - } - return privatePackageId, nil -} - -func (d dbMigrationServiceImpl) privatePackageIdExists(privatePackageId string, excludedUserId string) (bool, error) { - userEnt := new(entity.UserEntity) - err := d.cp.GetConnection().Model(userEnt). - Where("private_package_id = ?", privatePackageId). - Where("user_id != ?", excludedUserId). - First() - if err != nil { - if err == pg.ErrNoRows { - return false, nil - } - return false, err - } - return userEnt.PrivatePackageId == privatePackageId, nil -} - -func (d dbMigrationServiceImpl) getPackageIncludingDeleted(id string) (*entity.PackageEntity, error) { - result := new(entity.PackageEntity) - err := d.cp.GetConnection().Model(result). - Where("id = ?", id). - First() - if err != nil { - if err == pg.ErrNoRows { - return nil, nil - } - return nil, err - } - return result, nil -} - -func (d dbMigrationServiceImpl) calculateDraftBlobIds() error { - log.Info("Start calculating blobIds for all draft files") - type draftFile struct { - ProjectId string `pg:"project_id"` - BranchName string `pg:"branch_name"` - FileId string `pg:"file_id"` - Status string `pg:"status"` - Data string `pg:"data"` - } - getDraftFiles := ` - select - project_id, - branch_name, - file_id, - status, - data - from branch_draft_content - where coalesce(commit_id, '') != '' - and data is not null - and coalesce(blob_id, '') = '' - order by project_id, branch_name, file_id - limit ?; - ` - updateDraftFileBlobId := ` - update branch_draft_content set blob_id = ? - where project_id = ? - and branch_name = ? - and file_id = ? - ` - limit := 10 - for { - draftFilesWithCommitId := make([]draftFile, 0) - _, err := d.cp.GetConnection().Query(&draftFilesWithCommitId, getDraftFiles, limit) - if err != nil { - return fmt.Errorf("failed to get draft files with commitId: %w", err) - } - for _, draftFile := range draftFilesWithCommitId { - _, err := d.cp.GetConnection().Exec(updateDraftFileBlobId, calculateGitBlobId(draftFile.Data), draftFile.ProjectId, draftFile.BranchName, draftFile.FileId) - if err != nil { - return fmt.Errorf("failed to get draft files with commitId: %w", err) - } - } - if len(draftFilesWithCommitId) < limit { - break - } - } - - log.Info("Successfully calculated new blobIds") + //if (currentVersion < typeAndTitleMigrationVersion && typeAndTitleMigrationVersion <= newVersion) || + // (migrationRequired && typeAndTitleMigrationVersion == currentVersion && typeAndTitleMigrationVersion == newVersion) { + // //async migration because it could take a lot of time to execute + // utils.SafeAsync(func() { + // /* do something */ + // }) + //} return nil } - -func calculateGitBlobId(s string) string { - p := fmt.Sprintf("blob %d\x00", len(s)) - h := sha1.New() - h.Write([]byte(p)) - h.Write([]byte(s)) - return hex.EncodeToString(h.Sum([]byte(nil))) -} diff --git a/qubership-apihub-service/resources/migrations/100_transition.down.sql b/qubership-apihub-service/resources/migrations/100_transition.down.sql deleted file mode 100644 index e1b582c..0000000 --- a/qubership-apihub-service/resources/migrations/100_transition.down.sql +++ /dev/null @@ -1 +0,0 @@ -drop table activity_tracking_transition; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/100_transition.up.sql b/qubership-apihub-service/resources/migrations/100_transition.up.sql deleted file mode 100644 index da96e56..0000000 --- a/qubership-apihub-service/resources/migrations/100_transition.up.sql +++ /dev/null @@ -1,54 +0,0 @@ -create table activity_tracking_transition -( - id varchar - constraint activity_tracking_transition_pk - primary key, - tr_type varchar not null, - from_id varchar not null, - to_id varchar not null, - status varchar not null, - details varchar, - started_by varchar not null, - started_at timestamp without time zone not null, - finished_at timestamp without time zone, - progress_percent int, - affected_objects int -); - -create unique index activity_tracking_transition_id_uindex - on activity_tracking_transition (id); - - -create or replace function parent_package_names(character varying) returns character varying[] - language plpgsql -as -$$ -declare - split varchar[] := string_to_array($1, '.')::varchar[]; - parent_ids varchar[]; - parent_names varchar[]; -begin - - if coalesce(array_length(split, 1), 0) <= 1 then - return ARRAY[]::varchar[]; - end if; - - parent_ids = parent_ids || split[1]; - - for i in 2..(array_length(split, 1) - 1) - loop - parent_ids = parent_ids || (parent_ids[i-1] ||'.'|| split[i])::character varying; - end loop; - - execute ' -select array_agg(name) from ( - select name from package_group - join unnest($1) with ordinality t(id, ord) using (id) --sort by parent_ids array - order by t.ord) n' - into parent_names - using parent_ids; - - return parent_names; - -end; -$$; diff --git a/qubership-apihub-service/resources/migrations/101_integration_refresh_token.down.sql b/qubership-apihub-service/resources/migrations/101_integration_refresh_token.down.sql deleted file mode 100644 index 4193c58..0000000 --- a/qubership-apihub-service/resources/migrations/101_integration_refresh_token.down.sql +++ /dev/null @@ -1,4 +0,0 @@ -alter table user_integration drop column refresh_token; -alter table user_integration drop column expires_at; -alter table user_integration drop column redirect_uri; -alter table user_integration drop column failed_refresh_attempts; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/101_integration_refresh_token.up.sql b/qubership-apihub-service/resources/migrations/101_integration_refresh_token.up.sql deleted file mode 100644 index 30aab12..0000000 --- a/qubership-apihub-service/resources/migrations/101_integration_refresh_token.up.sql +++ /dev/null @@ -1,6 +0,0 @@ -alter table user_integration add column refresh_token varchar; -alter table user_integration add column expires_at timestamp without time zone; -alter table user_integration add column redirect_uri varchar; -alter table user_integration add column failed_refresh_attempts integer default 0; - -update user_integration set is_revoked = true; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/102_builder_version_in_version_comparison.down.sql b/qubership-apihub-service/resources/migrations/102_builder_version_in_version_comparison.down.sql deleted file mode 100644 index 6977768..0000000 --- a/qubership-apihub-service/resources/migrations/102_builder_version_in_version_comparison.down.sql +++ /dev/null @@ -1 +0,0 @@ -alter table version_comparison drop column builder_version; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/102_builder_version_in_version_comparison.up.sql b/qubership-apihub-service/resources/migrations/102_builder_version_in_version_comparison.up.sql deleted file mode 100644 index 836bd60..0000000 --- a/qubership-apihub-service/resources/migrations/102_builder_version_in_version_comparison.up.sql +++ /dev/null @@ -1 +0,0 @@ -alter table version_comparison add column builder_version varchar; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/103_personal_workspaces.down.sql b/qubership-apihub-service/resources/migrations/103_personal_workspaces.down.sql deleted file mode 100644 index e749459..0000000 --- a/qubership-apihub-service/resources/migrations/103_personal_workspaces.down.sql +++ /dev/null @@ -1 +0,0 @@ -alter table user_data drop column private_package_id; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/103_personal_workspaces.up.sql b/qubership-apihub-service/resources/migrations/103_personal_workspaces.up.sql deleted file mode 100644 index 98777ed..0000000 --- a/qubership-apihub-service/resources/migrations/103_personal_workspaces.up.sql +++ /dev/null @@ -1,6 +0,0 @@ -alter table user_data add column private_package_id varchar not null default ''; - -update user_data set private_package_id = user_id; - -ALTER TABLE user_data -ADD CONSTRAINT private_package_id_unique UNIQUE (private_package_id); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/104_transformed_documents.down.sql b/qubership-apihub-service/resources/migrations/104_transformed_documents.down.sql deleted file mode 100644 index c3daf2d..0000000 --- a/qubership-apihub-service/resources/migrations/104_transformed_documents.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table transformed_content_data drop constraint if exists "FK_transformed_content_data_operation_group"; -drop table if exists transformed_content_data; diff --git a/qubership-apihub-service/resources/migrations/104_transformed_documents.up.sql b/qubership-apihub-service/resources/migrations/104_transformed_documents.up.sql deleted file mode 100644 index a5248ff..0000000 --- a/qubership-apihub-service/resources/migrations/104_transformed_documents.up.sql +++ /dev/null @@ -1,13 +0,0 @@ -CREATE TABLE if not exists transformed_content_data ( - package_id varchar NOT NULL, - version varchar NOT NULL, - revision integer NOT NULL, - api_type varchar NOT NULL, - group_id varchar NOT NULL, - data bytea, - documents_info jsonb[], - PRIMARY KEY(package_id, version, revision, api_type, group_id) -); - -ALTER TABLE transformed_content_data ADD CONSTRAINT "FK_transformed_content_data_operation_group" - FOREIGN KEY (group_id) REFERENCES operation_group (group_id) ON DELETE Cascade ON UPDATE Cascade; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/105_models_for_operations.down.sql b/qubership-apihub-service/resources/migrations/105_models_for_operations.down.sql deleted file mode 100644 index bd89d71..0000000 --- a/qubership-apihub-service/resources/migrations/105_models_for_operations.down.sql +++ /dev/null @@ -1 +0,0 @@ -alter table operation drop column models; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/105_models_for_operations.up.sql b/qubership-apihub-service/resources/migrations/105_models_for_operations.up.sql deleted file mode 100644 index cb38ead..0000000 --- a/qubership-apihub-service/resources/migrations/105_models_for_operations.up.sql +++ /dev/null @@ -1 +0,0 @@ -alter table operation add column models jsonb; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/106_operation_custom_tag.down.sql b/qubership-apihub-service/resources/migrations/106_operation_custom_tag.down.sql deleted file mode 100644 index 62901f4..0000000 --- a/qubership-apihub-service/resources/migrations/106_operation_custom_tag.down.sql +++ /dev/null @@ -1 +0,0 @@ -alter table operation drop column if exists custom_tags; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/106_operation_custom_tag.up.sql b/qubership-apihub-service/resources/migrations/106_operation_custom_tag.up.sql deleted file mode 100644 index fe2c7ff..0000000 --- a/qubership-apihub-service/resources/migrations/106_operation_custom_tag.up.sql +++ /dev/null @@ -1 +0,0 @@ -alter table operation add column if not exists custom_tags jsonb; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/107_business_metrics.down.sql b/qubership-apihub-service/resources/migrations/107_business_metrics.down.sql deleted file mode 100644 index 3218cad..0000000 --- a/qubership-apihub-service/resources/migrations/107_business_metrics.down.sql +++ /dev/null @@ -1 +0,0 @@ -drop table business_metric; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/107_business_metrics.up.sql b/qubership-apihub-service/resources/migrations/107_business_metrics.up.sql deleted file mode 100644 index 8677bba..0000000 --- a/qubership-apihub-service/resources/migrations/107_business_metrics.up.sql +++ /dev/null @@ -1,8 +0,0 @@ -create table business_metric ( - year int not null, - month int not null, - day int not null, - metric varchar not null, - data jsonb, - PRIMARY KEY(year, month, day, metric) -); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/108_build_tracking.down.sql b/qubership-apihub-service/resources/migrations/108_build_tracking.down.sql deleted file mode 100644 index 1527d4a..0000000 --- a/qubership-apihub-service/resources/migrations/108_build_tracking.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table build drop column client_build; -alter table build drop column started_at; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/108_build_tracking.up.sql b/qubership-apihub-service/resources/migrations/108_build_tracking.up.sql deleted file mode 100644 index 14e226d..0000000 --- a/qubership-apihub-service/resources/migrations/108_build_tracking.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table build add column client_build boolean; -alter table build add column started_at timestamp; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/109_split_jsonPath.down.sql b/qubership-apihub-service/resources/migrations/109_split_jsonPath.down.sql deleted file mode 100644 index 4bfce62..0000000 --- a/qubership-apihub-service/resources/migrations/109_split_jsonPath.down.sql +++ /dev/null @@ -1,6 +0,0 @@ -update operation -set deprecated_items = merge_json_path(deprecated_items) -where deprecated_items != '{}'; - -drop function if exists split_json_path; -drop function if exists merge_json_path; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/109_split_jsonPath.up.sql b/qubership-apihub-service/resources/migrations/109_split_jsonPath.up.sql deleted file mode 100644 index 69f5669..0000000 --- a/qubership-apihub-service/resources/migrations/109_split_jsonPath.up.sql +++ /dev/null @@ -1,40 +0,0 @@ -create or replace function split_json_path(jsonb[]) returns jsonb[] -as -$$ -declare - items alias for $1; - ret jsonb[]; -begin - for i in array_lower(items, 1)..array_upper(items, 1) - loop - ret[i] := jsonb_set(items[i], '{jsonPath}', - (array_to_json(string_to_array(trim(both '"' from (items[i] -> 'jsonPath')::text), - '/')))::jsonb, false); - end loop; - return ret; -end; -$$ - language plpgsql - returns null on null input; - -create or replace function merge_json_path(jsonb[]) returns jsonb[] -as -$$ -declare - items alias for $1; - jsonpath text; - ret jsonb[]; -begin - for i in array_lower(items, 1)..array_upper(items, 1) loop - select string_agg(el, '/') into jsonpath from jsonb_array_elements_text(items[i]->'jsonPath') el; - ret[i] := jsonb_set(items[i], '{jsonPath}', to_jsonb(jsonpath), false); - end loop; - return ret; -end; -$$ - language plpgsql - RETURNS NULL ON NULL INPUT; - -update operation -set deprecated_items = split_json_path(deprecated_items) -where deprecated_items != '{}'; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/10_content_messages.down.sql b/qubership-apihub-service/resources/migrations/10_content_messages.down.sql deleted file mode 100644 index b3937aa..0000000 --- a/qubership-apihub-service/resources/migrations/10_content_messages.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP TABLE IF EXISTS published_content_messages CASCADE -; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/10_content_messages.up.sql b/qubership-apihub-service/resources/migrations/10_content_messages.up.sql deleted file mode 100644 index e787538..0000000 --- a/qubership-apihub-service/resources/migrations/10_content_messages.up.sql +++ /dev/null @@ -1,11 +0,0 @@ -DROP TABLE IF EXISTS published_content_messages CASCADE; - -create table published_content_messages -( - checksum varchar not null, - messages jsonb -); - -ALTER TABLE published_content_messages ADD CONSTRAINT "PK_published_content_messages" - PRIMARY KEY (checksum) -; diff --git a/qubership-apihub-service/resources/migrations/110_moved_pkg_comparisons.up.sql b/qubership-apihub-service/resources/migrations/110_moved_pkg_comparisons.up.sql deleted file mode 100644 index 2280539..0000000 --- a/qubership-apihub-service/resources/migrations/110_moved_pkg_comparisons.up.sql +++ /dev/null @@ -1,21 +0,0 @@ -with comp as ( - select - comparison_id, - md5(package_id||'@'||version||'@'||revision||'@'||previous_package_id||'@'||previous_version||'@'||previous_revision) as new_comparison_id - from version_comparison - where comparison_id != md5(package_id||'@'||version||'@'||revision||'@'||previous_package_id||'@'||previous_version||'@'||previous_revision) -) -update version_comparison b set refs = array_replace(refs, c.comparison_id, c.new_comparison_id::varchar) -from comp c -where c.comparison_id = any(refs); - -with comp as ( - select - comparison_id, - md5(package_id||'@'||version||'@'||revision||'@'||previous_package_id||'@'||previous_version||'@'||previous_revision) as new_comparison_id - from version_comparison - where comparison_id != md5(package_id||'@'||version||'@'||revision||'@'||previous_package_id||'@'||previous_version||'@'||previous_revision) -) -update version_comparison b set comparison_id = c.new_comparison_id::varchar -from comp c -where c.comparison_id = b.comparison_id; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/111_update_build.down.sql b/qubership-apihub-service/resources/migrations/111_update_build.down.sql deleted file mode 100644 index f32592c..0000000 --- a/qubership-apihub-service/resources/migrations/111_update_build.down.sql +++ /dev/null @@ -1,17 +0,0 @@ -create table builder_task -( - build_id varchar not null - constraint "PK_builder_task" - primary key - constraint "FK_builder_task_build_id" - references build - on update cascade on delete cascade, - builder_id varchar not null, - version integer default 1 not null -); - -insert into builder_task select build_id, builder_id from build where build.builder_id!=''; - -alter table build drop builder_id; - -alter table build drop priority; diff --git a/qubership-apihub-service/resources/migrations/111_update_build.up.sql b/qubership-apihub-service/resources/migrations/111_update_build.up.sql deleted file mode 100644 index 6bb7774..0000000 --- a/qubership-apihub-service/resources/migrations/111_update_build.up.sql +++ /dev/null @@ -1,9 +0,0 @@ -alter table build add builder_id varchar; - -update build set builder_id = (select builder_id from builder_task where builder_task.build_id=build.build_id); - -drop table builder_task; - -alter table build add priority int not null default 0; - - diff --git a/qubership-apihub-service/resources/migrations/112_migration_validation.down.sql b/qubership-apihub-service/resources/migrations/112_migration_validation.down.sql deleted file mode 100644 index 4b78713..0000000 --- a/qubership-apihub-service/resources/migrations/112_migration_validation.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -drop table migrated_version_changes; -alter table migration_run drop column skip_validation; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/112_migration_validation.up.sql b/qubership-apihub-service/resources/migrations/112_migration_validation.up.sql deleted file mode 100644 index a8f75aa..0000000 --- a/qubership-apihub-service/resources/migrations/112_migration_validation.up.sql +++ /dev/null @@ -1,10 +0,0 @@ -create table migrated_version_changes ( - package_id varchar not null, - version varchar not null, - revision varchar not null, - build_id varchar not null, - migration_id varchar not null, - changes jsonb -); - -alter table migration_run add column skip_validation boolean; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/113_default_last_active.down.sql b/qubership-apihub-service/resources/migrations/113_default_last_active.down.sql deleted file mode 100644 index 6abf5d8..0000000 --- a/qubership-apihub-service/resources/migrations/113_default_last_active.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table build alter column last_active drop default; -alter table build alter column created_at drop default; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/113_default_last_active.up.sql b/qubership-apihub-service/resources/migrations/113_default_last_active.up.sql deleted file mode 100644 index eea7df4..0000000 --- a/qubership-apihub-service/resources/migrations/113_default_last_active.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table build alter column last_active set default now(); -alter table build alter column created_at set default now(); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/114_remove_old_checksum.down.sql b/qubership-apihub-service/resources/migrations/114_remove_old_checksum.down.sql deleted file mode 100644 index fe4ef1d..0000000 --- a/qubership-apihub-service/resources/migrations/114_remove_old_checksum.down.sql +++ /dev/null @@ -1,14 +0,0 @@ -alter table published_sources - add checksum varchar; - -create table published_sources_data -( - package_id varchar not null - constraint published_sources_data_package_group_id_fk - references package_group - on update cascade on delete cascade, - checksum varchar not null, - data bytea, - constraint "PK_published_sources_data" - primary key (checksum, package_id) -); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/114_remove_old_checksum.up.sql b/qubership-apihub-service/resources/migrations/114_remove_old_checksum.up.sql deleted file mode 100644 index 5d90956..0000000 --- a/qubership-apihub-service/resources/migrations/114_remove_old_checksum.up.sql +++ /dev/null @@ -1,4 +0,0 @@ -alter table published_sources - drop column checksum; - -drop table published_sources_data; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/115_add_build_status_index.down.sql b/qubership-apihub-service/resources/migrations/115_add_build_status_index.down.sql deleted file mode 100644 index 4b6ead3..0000000 --- a/qubership-apihub-service/resources/migrations/115_add_build_status_index.down.sql +++ /dev/null @@ -1,3 +0,0 @@ -drop index build_status_index; - -drop index build_depends_index; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/115_add_build_status_index.up.sql b/qubership-apihub-service/resources/migrations/115_add_build_status_index.up.sql deleted file mode 100644 index 1053817..0000000 --- a/qubership-apihub-service/resources/migrations/115_add_build_status_index.up.sql +++ /dev/null @@ -1,3 +0,0 @@ -create index build_status_index on build (status); - -create index build_depends_index on build_depends (depend_id); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/116_jsonb_arr_to_jsonb.down.sql b/qubership-apihub-service/resources/migrations/116_jsonb_arr_to_jsonb.down.sql deleted file mode 100644 index bcc1e37..0000000 --- a/qubership-apihub-service/resources/migrations/116_jsonb_arr_to_jsonb.down.sql +++ /dev/null @@ -1,14 +0,0 @@ -alter table version_comparison add column operation_types_arr jsonb[]; -update version_comparison set operation_types_arr = array(select jsonb_array_elements(operation_types))::jsonb[]; -alter table version_comparison drop column operation_types; -alter table version_comparison rename column operation_types_arr to operation_types; - -alter table transformed_content_data add column documents_info_arr jsonb[]; -update transformed_content_data set documents_info_arr = array(select jsonb_array_elements(documents_info))::jsonb[]; -alter table transformed_content_data drop column documents_info; -alter table transformed_content_data rename column documents_info_arr to documents_info; - -alter table operation add column deprecated_items_arr jsonb[]; -update operation set deprecated_items_arr = array(select jsonb_array_elements(deprecated_items))::jsonb[]; -alter table operation drop column deprecated_items; -alter table operation rename column deprecated_items_arr to deprecated_items; diff --git a/qubership-apihub-service/resources/migrations/116_jsonb_arr_to_jsonb.up.sql b/qubership-apihub-service/resources/migrations/116_jsonb_arr_to_jsonb.up.sql deleted file mode 100644 index 272f81a..0000000 --- a/qubership-apihub-service/resources/migrations/116_jsonb_arr_to_jsonb.up.sql +++ /dev/null @@ -1,3 +0,0 @@ -alter table version_comparison alter column operation_types type jsonb using to_jsonb(operation_types); -alter table transformed_content_data alter column documents_info type jsonb using to_jsonb(documents_info); -alter table operation alter column deprecated_items type jsonb using to_jsonb(deprecated_items); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/117_package_transition.down.sql b/qubership-apihub-service/resources/migrations/117_package_transition.down.sql deleted file mode 100644 index e32b6f3..0000000 --- a/qubership-apihub-service/resources/migrations/117_package_transition.down.sql +++ /dev/null @@ -1 +0,0 @@ -drop table package_transition; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/117_package_transition.up.sql b/qubership-apihub-service/resources/migrations/117_package_transition.up.sql deleted file mode 100644 index 011b4cf..0000000 --- a/qubership-apihub-service/resources/migrations/117_package_transition.up.sql +++ /dev/null @@ -1,12 +0,0 @@ -create table package_transition -( - old_package_id varchar not null, - new_package_id varchar not null -); - -create index package_transition_old_package_id_index - on package_transition (old_package_id); - -update operation_group -set group_id=MD5(CONCAT_WS('@', package_id, version, revision, api_type, group_name))::varchar -where MD5(CONCAT_WS('@', package_id, version, revision, api_type, group_name))!= operation_group.group_id; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/118_transition_activity_sequence.down.sql b/qubership-apihub-service/resources/migrations/118_transition_activity_sequence.down.sql deleted file mode 100644 index 502af9b..0000000 --- a/qubership-apihub-service/resources/migrations/118_transition_activity_sequence.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -drop sequence activity_tracking_transition_completed_seq; -alter table activity_tracking_transition drop column completed_serial_number; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/118_transition_activity_sequence.up.sql b/qubership-apihub-service/resources/migrations/118_transition_activity_sequence.up.sql deleted file mode 100644 index e2f3b43..0000000 --- a/qubership-apihub-service/resources/migrations/118_transition_activity_sequence.up.sql +++ /dev/null @@ -1,10 +0,0 @@ -alter table activity_tracking_transition add column completed_serial_number integer; -create sequence if not exists activity_tracking_transition_completed_seq as int minvalue 0 owned by activity_tracking_transition.completed_serial_number; -with completed_att as ( - select id from activity_tracking_transition - where status = 'complete' - order by finished_at -) -update activity_tracking_transition att set completed_serial_number = nextval('activity_tracking_transition_completed_seq') -from completed_att c -where c.id = att.id; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/119_workspace_services.down.sql b/qubership-apihub-service/resources/migrations/119_workspace_services.down.sql deleted file mode 100644 index f736d64..0000000 --- a/qubership-apihub-service/resources/migrations/119_workspace_services.down.sql +++ /dev/null @@ -1,27 +0,0 @@ ---unassign duplicate service_names -with l as ( - select service_name, min(id) as id from package_group - where service_name is not null and service_name != '' - group by service_name having count(*) > 1 -) -update package_group pg set service_name = null -from l -where l.service_name = pg.service_name -and l.id != pg.id; - -delete from package_service ps -using package_group pg -where ps.package_id = pg.id -and pg.service_name is null; - -alter table package_service drop constraint "FK_package_group_workspace"; - -alter table package_service drop constraint "PK_package_service"; -alter table package_service add constraint "PK_package_service" - primary key (package_id, service_name); - -alter table package_service drop constraint package_service_workspace_id_service_name_key; - -alter table package_service add UNIQUE(service_name); - -alter table package_service drop column workspace_id; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/119_workspace_services.up.sql b/qubership-apihub-service/resources/migrations/119_workspace_services.up.sql deleted file mode 100644 index c960bca..0000000 --- a/qubership-apihub-service/resources/migrations/119_workspace_services.up.sql +++ /dev/null @@ -1,14 +0,0 @@ -alter table package_service add column workspace_id varchar; -update package_service set workspace_id = split_part(package_id, '.', 1); -alter table package_service alter column workspace_id set not null; - -alter table package_service drop constraint package_service_service_name_key; - -alter table package_service add UNIQUE(workspace_id, service_name); - -alter table package_service drop constraint "PK_package_service"; -alter table package_service add constraint "PK_package_service" - primary key (workspace_id, package_id, service_name); - -alter table package_service add constraint "FK_package_group_workspace" - foreign key (workspace_id) references package_group (id) on delete Cascade on update Cascade; diff --git a/qubership-apihub-service/resources/migrations/11_content_labels_metadata.down.sql b/qubership-apihub-service/resources/migrations/11_content_labels_metadata.down.sql deleted file mode 100644 index fea8c31..0000000 --- a/qubership-apihub-service/resources/migrations/11_content_labels_metadata.down.sql +++ /dev/null @@ -1,6 +0,0 @@ -ALTER TABLE published_version_revision_content - DROP COLUMN metadata; - -ALTER TABLE branch_draft_content - DROP COLUMN labels; - \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/11_content_labels_metadata.up.sql b/qubership-apihub-service/resources/migrations/11_content_labels_metadata.up.sql deleted file mode 100644 index 24d1965..0000000 --- a/qubership-apihub-service/resources/migrations/11_content_labels_metadata.up.sql +++ /dev/null @@ -1,5 +0,0 @@ -ALTER TABLE published_version_revision_content - ADD COLUMN metadata jsonb; - -ALTER TABLE branch_draft_content - ADD COLUMN labels varchar[]; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/120_release_version_pattern.down.sql b/qubership-apihub-service/resources/migrations/120_release_version_pattern.down.sql deleted file mode 100644 index 1fe72aa..0000000 --- a/qubership-apihub-service/resources/migrations/120_release_version_pattern.down.sql +++ /dev/null @@ -1,3 +0,0 @@ -update package_group -set release_version_pattern = null -where release_version_pattern = '^[0-9]{4}[.]{1}[1-4]{1}$' and (kind = 'package' or kind = 'dashboard'); diff --git a/qubership-apihub-service/resources/migrations/120_release_version_pattern.up.sql b/qubership-apihub-service/resources/migrations/120_release_version_pattern.up.sql deleted file mode 100644 index 3351206..0000000 --- a/qubership-apihub-service/resources/migrations/120_release_version_pattern.up.sql +++ /dev/null @@ -1,3 +0,0 @@ -update package_group -set release_version_pattern = '^[0-9]{4}[.]{1}[1-4]{1}$' -where (kind = 'package' or kind = 'dashboard') and (release_version_pattern = '' or release_version_pattern is null); diff --git a/qubership-apihub-service/resources/migrations/121_remove_version_permissions.up.sql b/qubership-apihub-service/resources/migrations/121_remove_version_permissions.up.sql deleted file mode 100644 index 913ae67..0000000 --- a/qubership-apihub-service/resources/migrations/121_remove_version_permissions.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -update role set permissions = array_remove(permissions, 'manage_release_candidate_version'); -update role set permissions = array_remove(permissions, 'manage_deprecated_version'); diff --git a/qubership-apihub-service/resources/migrations/122_endpoint_calls.down.sql b/qubership-apihub-service/resources/migrations/122_endpoint_calls.down.sql deleted file mode 100644 index 24dffc4..0000000 --- a/qubership-apihub-service/resources/migrations/122_endpoint_calls.down.sql +++ /dev/null @@ -1 +0,0 @@ -drop table endpoint_calls; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/122_endpoint_calls.up.sql b/qubership-apihub-service/resources/migrations/122_endpoint_calls.up.sql deleted file mode 100644 index c21d35e..0000000 --- a/qubership-apihub-service/resources/migrations/122_endpoint_calls.up.sql +++ /dev/null @@ -1,7 +0,0 @@ -create table endpoint_calls( - path varchar not null, - hash varchar not null, - options jsonb, - count integer, - PRIMARY KEY(path, hash) -); diff --git a/qubership-apihub-service/resources/migrations/123_versions_cleanup.down.sql b/qubership-apihub-service/resources/migrations/123_versions_cleanup.down.sql deleted file mode 100644 index e7e12ea..0000000 --- a/qubership-apihub-service/resources/migrations/123_versions_cleanup.down.sql +++ /dev/null @@ -1 +0,0 @@ -drop table if exists versions_cleanup_run; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/123_versions_cleanup.up.sql b/qubership-apihub-service/resources/migrations/123_versions_cleanup.up.sql deleted file mode 100644 index 33c1fc1..0000000 --- a/qubership-apihub-service/resources/migrations/123_versions_cleanup.up.sql +++ /dev/null @@ -1,16 +0,0 @@ -create table if not exists versions_cleanup_run ( - run_id uuid, - started_at timestamp without time zone not null default now(), - package_id varchar not null, - delete_before timestamp without time zone not null, - status varchar not null, - details varchar, - deleted_items integer -); - -alter table versions_cleanup_run add constraint PK_versions_cleanup_run primary key (run_id); - -alter table versions_cleanup_run - add constraint versions_cleanup_run_package_group_id_fk - foreign key (package_id) references package_group - on update cascade on delete cascade; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/124_api_key_created_for.down.sql b/qubership-apihub-service/resources/migrations/124_api_key_created_for.down.sql deleted file mode 100644 index 06912dc..0000000 --- a/qubership-apihub-service/resources/migrations/124_api_key_created_for.down.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE apihub_api_keys DROP COLUMN created_for; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/124_api_key_created_for.up.sql b/qubership-apihub-service/resources/migrations/124_api_key_created_for.up.sql deleted file mode 100644 index 7ce422c..0000000 --- a/qubership-apihub-service/resources/migrations/124_api_key_created_for.up.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE apihub_api_keys ADD COLUMN created_for VARCHAR; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/125_build_metadata.down.sql b/qubership-apihub-service/resources/migrations/125_build_metadata.down.sql deleted file mode 100644 index 5983478..0000000 --- a/qubership-apihub-service/resources/migrations/125_build_metadata.down.sql +++ /dev/null @@ -1 +0,0 @@ -alter table build drop column metadata; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/125_build_metadata.up.sql b/qubership-apihub-service/resources/migrations/125_build_metadata.up.sql deleted file mode 100644 index 81048ee..0000000 --- a/qubership-apihub-service/resources/migrations/125_build_metadata.up.sql +++ /dev/null @@ -1 +0,0 @@ -alter table build add column metadata jsonb; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/126_transformed_documents_rework.down.sql b/qubership-apihub-service/resources/migrations/126_transformed_documents_rework.down.sql deleted file mode 100644 index 2c8a1b7..0000000 --- a/qubership-apihub-service/resources/migrations/126_transformed_documents_rework.down.sql +++ /dev/null @@ -1,9 +0,0 @@ -alter table operation_group drop column template; -alter table operation_group drop column template_filename; - -alter table transformed_content_data drop constraint if exists transformed_content_data_pkey; -alter table transformed_content_data add constraint transformed_content_data_pkey -primary key(package_id, version, revision, api_type, group_id); - -alter table transformed_content_data drop column format; -alter table transformed_content_data drop column build_type; diff --git a/qubership-apihub-service/resources/migrations/126_transformed_documents_rework.up.sql b/qubership-apihub-service/resources/migrations/126_transformed_documents_rework.up.sql deleted file mode 100644 index 5aaa705..0000000 --- a/qubership-apihub-service/resources/migrations/126_transformed_documents_rework.up.sql +++ /dev/null @@ -1,9 +0,0 @@ -alter table transformed_content_data add column build_type varchar default 'documentGroup'; -alter table transformed_content_data add column format varchar default 'json'; - -alter table transformed_content_data drop constraint if exists transformed_content_data_pkey; -alter table transformed_content_data add constraint transformed_content_data_pkey -primary key(package_id, version, revision, api_type, group_id, build_type, format); - -alter table operation_group add column template bytea; -alter table operation_group add column template_filename varchar; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/127_template_checksum.down.sql b/qubership-apihub-service/resources/migrations/127_template_checksum.down.sql deleted file mode 100644 index 4d0dcba..0000000 --- a/qubership-apihub-service/resources/migrations/127_template_checksum.down.sql +++ /dev/null @@ -1,8 +0,0 @@ -alter table operation_group add column template bytea; - -update operation_group og set template = (select template from operation_group_template ogt where checksum = og.template_checksum) -where template_checksum != '' and template_checksum is not null; - -alter table operation_group drop column template_checksum; - -drop table operation_group_template; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/127_template_checksum.up.sql b/qubership-apihub-service/resources/migrations/127_template_checksum.up.sql deleted file mode 100644 index 9defd7e..0000000 --- a/qubership-apihub-service/resources/migrations/127_template_checksum.up.sql +++ /dev/null @@ -1,11 +0,0 @@ -create table operation_group_template ( - checksum varchar, - template bytea, - PRIMARY KEY (checksum) -); - -insert into operation_group_template -select distinct md5(template), template from operation_group where template is not null; - -alter table operation_group alter column template type varchar using md5(template); -alter table operation_group rename column template to template_checksum; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/128_remove_ghost_operations.down.sql b/qubership-apihub-service/resources/migrations/128_remove_ghost_operations.down.sql deleted file mode 100644 index 9044d33..0000000 --- a/qubership-apihub-service/resources/migrations/128_remove_ghost_operations.down.sql +++ /dev/null @@ -1 +0,0 @@ -alter table grouped_operation add column deleted boolean default false; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/128_remove_ghost_operations.up.sql b/qubership-apihub-service/resources/migrations/128_remove_ghost_operations.up.sql deleted file mode 100644 index 1ca1031..0000000 --- a/qubership-apihub-service/resources/migrations/128_remove_ghost_operations.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -delete from grouped_operation where deleted = true; -alter table grouped_operation drop column deleted; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/129_business_metrics_user_id.down.sql b/qubership-apihub-service/resources/migrations/129_business_metrics_user_id.down.sql deleted file mode 100644 index 4ebd9f8..0000000 --- a/qubership-apihub-service/resources/migrations/129_business_metrics_user_id.down.sql +++ /dev/null @@ -1,6 +0,0 @@ -delete from business_metric where user_id != 'unknown'; - -alter table business_metric drop column user_id; - -alter table business_metric add constraint business_metric_pkey -primary key(year, month, day, metric); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/129_business_metrics_user_id.up.sql b/qubership-apihub-service/resources/migrations/129_business_metrics_user_id.up.sql deleted file mode 100644 index 9b3712d..0000000 --- a/qubership-apihub-service/resources/migrations/129_business_metrics_user_id.up.sql +++ /dev/null @@ -1,5 +0,0 @@ -alter table business_metric add column user_id varchar default 'unknown'; - -alter table business_metric drop constraint if exists business_metric_pkey; -alter table business_metric add constraint business_metric_pkey -primary key(year, month, day, metric, user_id); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/12_shared_content.down.sql b/qubership-apihub-service/resources/migrations/12_shared_content.down.sql deleted file mode 100644 index e661db0..0000000 --- a/qubership-apihub-service/resources/migrations/12_shared_content.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP TABLE IF EXISTS shared_url_info CASCADE -; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/12_shared_content.up.sql b/qubership-apihub-service/resources/migrations/12_shared_content.up.sql deleted file mode 100644 index d0073e4..0000000 --- a/qubership-apihub-service/resources/migrations/12_shared_content.up.sql +++ /dev/null @@ -1,18 +0,0 @@ -DROP TABLE IF EXISTS shared_url_info CASCADE -; -CREATE TABLE shared_url_info -( - project_id varchar NOT NULL, - version varchar NOT NULL, - file_id varchar NOT NULL, - shared_id varchar NOT NULL -) -; -ALTER TABLE shared_url_info - ADD CONSTRAINT "PK_shared_url_info" - PRIMARY KEY (shared_id) -; -ALTER TABLE shared_url_info - ADD CONSTRAINT "shared_url_info__file_info" - UNIQUE (project_id, version, file_id) -; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/130_operation_group_history.down.sql b/qubership-apihub-service/resources/migrations/130_operation_group_history.down.sql deleted file mode 100644 index 07164f4..0000000 --- a/qubership-apihub-service/resources/migrations/130_operation_group_history.down.sql +++ /dev/null @@ -1 +0,0 @@ -drop table operation_group_history; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/130_operation_group_history.up.sql b/qubership-apihub-service/resources/migrations/130_operation_group_history.up.sql deleted file mode 100644 index 0e8884a..0000000 --- a/qubership-apihub-service/resources/migrations/130_operation_group_history.up.sql +++ /dev/null @@ -1,25 +0,0 @@ -create table operation_group_history( - group_id varchar, - action varchar, - data jsonb, - user_id varchar, - date timestamp without time zone, - automatic bool -); - -insert into operation_group_history -select -group_id, 'create' as action, -jsonb_build_object( - 'PackageId', package_id, - 'Version', version, - 'Revision', revision, - 'ApiType', api_type, - 'GroupName', group_name, - 'GroupId', group_id, - 'Description', coalesce(description, ''), - 'Autogenerated', coalesce(autogenerated, false), - 'TemplateChecksum', coalesce(template_checksum, ''), - 'TemplateFilename', coalesce(template_filename, '')) as data, -'unknown' as user_id, now() as date, true as automatic -from operation_group where autogenerated = false; diff --git a/qubership-apihub-service/resources/migrations/131_gitlab_webhook.down.sql b/qubership-apihub-service/resources/migrations/131_gitlab_webhook.down.sql deleted file mode 100644 index 6c17d7d..0000000 --- a/qubership-apihub-service/resources/migrations/131_gitlab_webhook.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE project DROP COLUMN secret_token; -ALTER TABLE project DROP COLUMN secret_token_user_id; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/131_gitlab_webhook.up.sql b/qubership-apihub-service/resources/migrations/131_gitlab_webhook.up.sql deleted file mode 100644 index 3f089a8..0000000 --- a/qubership-apihub-service/resources/migrations/131_gitlab_webhook.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE project ADD COLUMN secret_token VARCHAR; -ALTER TABLE project ADD COLUMN secret_token_user_id VARCHAR; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/132_operaion_data_cleanup.up.sql b/qubership-apihub-service/resources/migrations/132_operaion_data_cleanup.up.sql deleted file mode 100644 index 01b5584..0000000 --- a/qubership-apihub-service/resources/migrations/132_operaion_data_cleanup.up.sql +++ /dev/null @@ -1,7 +0,0 @@ -alter table build_cleanup_run -add column if not exists build_result integer default 0, -add column if not exists build_src integer default 0, -add column if not exists operation_data integer default 0, -add column if not exists ts_operation_data integer default 0, -add column if not exists ts_rest_operation_data integer default 0, -add column if not exists ts_gql_operation_data integer default 0; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/132_operation_data_cleanup.down.sql b/qubership-apihub-service/resources/migrations/132_operation_data_cleanup.down.sql deleted file mode 100644 index 5cd9485..0000000 --- a/qubership-apihub-service/resources/migrations/132_operation_data_cleanup.down.sql +++ /dev/null @@ -1,7 +0,0 @@ -alter table build_cleanup_run -drop column if exists build_result, -drop column if exists build_src, -drop column if exists operation_data, -drop column if exists ts_operation_data, -drop column if exists ts_rest_operation_data, -drop column if exists ts_gql_operation_data; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/133_editor_draft_redesign.down.sql b/qubership-apihub-service/resources/migrations/133_editor_draft_redesign.down.sql deleted file mode 100644 index b55091d..0000000 --- a/qubership-apihub-service/resources/migrations/133_editor_draft_redesign.down.sql +++ /dev/null @@ -1,11 +0,0 @@ -alter table drafted_branches drop column commit_id; - -alter table branch_draft_content -drop column blob_id, -drop column conflicted_blob_id; - ---next migration - --- alter table branch_draft_content --- add column commit_id varchar, --- add column conflicted_commit_id varchar; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/133_editor_draft_redesign.up.sql b/qubership-apihub-service/resources/migrations/133_editor_draft_redesign.up.sql deleted file mode 100644 index fecadec..0000000 --- a/qubership-apihub-service/resources/migrations/133_editor_draft_redesign.up.sql +++ /dev/null @@ -1,17 +0,0 @@ -alter table drafted_branches -add column commit_id varchar; - -alter table branch_draft_content -add column blob_id varchar, -add column conflicted_blob_id varchar; - ---set blob_it=commit_id for some draft files because it will be impossible to calculate blob_id for them via soft migration -update branch_draft_content set blob_id = commit_id -where coalesce(commit_id, '') != '' -and data is null; - ---next migration - --- alter table branch_draft_content --- drop column commit_id, --- drop column conflicted_commit_id; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/134_migration_validation_overview.down.sql b/qubership-apihub-service/resources/migrations/134_migration_validation_overview.down.sql deleted file mode 100644 index 9a1d56f..0000000 --- a/qubership-apihub-service/resources/migrations/134_migration_validation_overview.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table migrated_version_changes drop column unique_changes; -drop table migration_changes; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/134_migration_validation_overview.up.sql b/qubership-apihub-service/resources/migrations/134_migration_validation_overview.up.sql deleted file mode 100644 index 089b5be..0000000 --- a/qubership-apihub-service/resources/migrations/134_migration_validation_overview.up.sql +++ /dev/null @@ -1,5 +0,0 @@ -alter table migrated_version_changes add column unique_changes varchar[]; -create table migration_changes( - migration_id varchar, - changes jsonb, - PRIMARY KEY(migration_id)); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/135_api_key_id.down.sql b/qubership-apihub-service/resources/migrations/135_api_key_id.down.sql deleted file mode 100644 index a39d905..0000000 --- a/qubership-apihub-service/resources/migrations/135_api_key_id.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -update apihub_api_keys -set id = substring(id from 9); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/135_api_key_id.up.sql b/qubership-apihub-service/resources/migrations/135_api_key_id.up.sql deleted file mode 100644 index 4fdd264..0000000 --- a/qubership-apihub-service/resources/migrations/135_api_key_id.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -update apihub_api_keys -set id = 'api-key_' || id; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/136_latest_revision_func_fix.down.sql b/qubership-apihub-service/resources/migrations/136_latest_revision_func_fix.down.sql deleted file mode 100644 index f7818bb..0000000 --- a/qubership-apihub-service/resources/migrations/136_latest_revision_func_fix.down.sql +++ /dev/null @@ -1,16 +0,0 @@ -create or replace function get_latest_revision(package_id varchar, version varchar) - returns integer language plpgsql -as ' - declare - latest_revision integer; - begin - execute '' - select max(revision) - from published_version - where package_id = $1 and version = $2 and deleted_at is null;'' - into latest_revision - using package_id,version; - if latest_revision is null then return 0; - end if; - return latest_revision; - end;'; diff --git a/qubership-apihub-service/resources/migrations/136_latest_revision_func_fix.up.sql b/qubership-apihub-service/resources/migrations/136_latest_revision_func_fix.up.sql deleted file mode 100644 index 0684aef..0000000 --- a/qubership-apihub-service/resources/migrations/136_latest_revision_func_fix.up.sql +++ /dev/null @@ -1,16 +0,0 @@ -create or replace function get_latest_revision(package_id varchar, version varchar) - returns integer language plpgsql -as ' - declare - latest_revision integer; - begin - execute '' - select max(revision) - from published_version - where package_id = $1 and version = $2;'' - into latest_revision - using package_id,version; - if latest_revision is null then return 0; - end if; - return latest_revision; - end;'; diff --git a/qubership-apihub-service/resources/migrations/137_index_for_op_comparison.down.sql b/qubership-apihub-service/resources/migrations/137_index_for_op_comparison.down.sql deleted file mode 100644 index 13410c9..0000000 --- a/qubership-apihub-service/resources/migrations/137_index_for_op_comparison.down.sql +++ /dev/null @@ -1 +0,0 @@ -drop index operation_comparison_comparison_id_index; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/137_index_for_op_comparison.up.sql b/qubership-apihub-service/resources/migrations/137_index_for_op_comparison.up.sql deleted file mode 100644 index a699ed4..0000000 --- a/qubership-apihub-service/resources/migrations/137_index_for_op_comparison.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -create index operation_comparison_comparison_id_index - on operation_comparison (comparison_id); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/138_agent_version.down.sql b/qubership-apihub-service/resources/migrations/138_agent_version.down.sql deleted file mode 100644 index 244bfe5..0000000 --- a/qubership-apihub-service/resources/migrations/138_agent_version.down.sql +++ /dev/null @@ -1 +0,0 @@ -alter table agent drop column if exists agent_version; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/138_agent_version.up.sql b/qubership-apihub-service/resources/migrations/138_agent_version.up.sql deleted file mode 100644 index 26892f1..0000000 --- a/qubership-apihub-service/resources/migrations/138_agent_version.up.sql +++ /dev/null @@ -1 +0,0 @@ -alter table agent add column if not exists agent_version varchar; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/139_search_tables_cleanup.down.sql b/qubership-apihub-service/resources/migrations/139_search_tables_cleanup.down.sql deleted file mode 100644 index d06aa01..0000000 --- a/qubership-apihub-service/resources/migrations/139_search_tables_cleanup.down.sql +++ /dev/null @@ -1,44 +0,0 @@ -CREATE TABLE ts_published_data_path_split -( - package_id varchar NOT NULL, - checksum varchar NOT NULL, - search_vector tsvector, - unique(package_id, checksum) -); - -CREATE TABLE ts_published_data_custom_split -( - package_id varchar NOT NULL, - checksum varchar NOT NULL, - search_vector tsvector, - unique(package_id, checksum) -); - -CREATE TABLE ts_published_data_errors -( - package_id varchar NOT NULL, - checksum varchar NOT NULL, - error varchar, - unique(package_id, checksum) -); - -alter table ts_published_data_errors - add constraint ts_published_data_errors_package_group_id_fk - foreign key (package_id) references package_group - on update cascade on delete cascade; - -alter table ts_published_data_custom_split - add constraint ts_published_data_custom_split_package_group_id_fk - foreign key (package_id) references package_group - on update cascade on delete cascade; - - -CREATE INDEX ts_published_data_path_split_idx -ON ts_published_data_path_split -USING gin(search_vector) -with (fastupdate = true); - -CREATE INDEX ts_published_data_custom_split_idx -ON ts_published_data_custom_split -USING gin(search_vector) -with (fastupdate = true); diff --git a/qubership-apihub-service/resources/migrations/139_search_tables_cleanup.up.sql b/qubership-apihub-service/resources/migrations/139_search_tables_cleanup.up.sql deleted file mode 100644 index 40c5ece..0000000 --- a/qubership-apihub-service/resources/migrations/139_search_tables_cleanup.up.sql +++ /dev/null @@ -1,5 +0,0 @@ -drop table ts_published_data_path_split; -drop table ts_published_data_custom_split; -drop table ts_published_data_errors; -DROP INDEX IF EXISTS ts_published_data_path_split_idx; -DROP INDEX IF EXISTS ts_published_data_custom_split_idx; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/13_branch_editors.down.sql b/qubership-apihub-service/resources/migrations/13_branch_editors.down.sql deleted file mode 100644 index 6311b8c..0000000 --- a/qubership-apihub-service/resources/migrations/13_branch_editors.down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS branch_editors; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/13_branch_editors.up.sql b/qubership-apihub-service/resources/migrations/13_branch_editors.up.sql deleted file mode 100644 index 5b88aa6..0000000 --- a/qubership-apihub-service/resources/migrations/13_branch_editors.up.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE branch_editors -( - project_id varchar NOT NULL, - branch_name varchar NOT NULL, - editors varchar[], - PRIMARY KEY (project_id, branch_name) -); diff --git a/qubership-apihub-service/resources/migrations/140_audience.down.sql b/qubership-apihub-service/resources/migrations/140_audience.down.sql deleted file mode 100644 index d499af2..0000000 --- a/qubership-apihub-service/resources/migrations/140_audience.down.sql +++ /dev/null @@ -1 +0,0 @@ -alter table operation drop column api_audience; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/140_audience.up.sql b/qubership-apihub-service/resources/migrations/140_audience.up.sql deleted file mode 100644 index 94d57b2..0000000 --- a/qubership-apihub-service/resources/migrations/140_audience.up.sql +++ /dev/null @@ -1 +0,0 @@ -alter table operation add column api_audience varchar default 'external'; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/141_group_publish.down.sql b/qubership-apihub-service/resources/migrations/141_group_publish.down.sql deleted file mode 100644 index fe0d83e..0000000 --- a/qubership-apihub-service/resources/migrations/141_group_publish.down.sql +++ /dev/null @@ -1 +0,0 @@ -drop table operation_group_publication; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/141_group_publish.up.sql b/qubership-apihub-service/resources/migrations/141_group_publish.up.sql deleted file mode 100644 index e1c56b5..0000000 --- a/qubership-apihub-service/resources/migrations/141_group_publish.up.sql +++ /dev/null @@ -1,6 +0,0 @@ -create table operation_group_publication( - publish_id varchar, - status varchar, - details varchar, - PRIMARY KEY(publish_id) -); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/142_metrics_fix.up.sql b/qubership-apihub-service/resources/migrations/142_metrics_fix.up.sql deleted file mode 100644 index add4fc2..0000000 --- a/qubership-apihub-service/resources/migrations/142_metrics_fix.up.sql +++ /dev/null @@ -1,7 +0,0 @@ -with migrations as ( - select distinct started_at::date, updated_at::date from migration_run - where started_at is not null and updated_at is not null -) -delete from business_metric using migrations m -where to_date(year || '-' || month || '-' || day, 'YYYY-MM-DD') between m.started_at and m.updated_at -and metric = 'release_versions_published'; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/143_clean_deleted_previous_version_ref.up.sql b/qubership-apihub-service/resources/migrations/143_clean_deleted_previous_version_ref.up.sql deleted file mode 100644 index 72f4349..0000000 --- a/qubership-apihub-service/resources/migrations/143_clean_deleted_previous_version_ref.up.sql +++ /dev/null @@ -1,31 +0,0 @@ -update published_version pv -set previous_version = null, previous_version_package_id = null -from ( - with deleted_versions as ( - select d.deleted_version as "version", d.dv_package_id as package_id from ( - with dv as (select distinct pv2."version" as deleted_version, pv2.package_id as dv_package_id from published_version pv2 where pv2.deleted_at is not null), - ndv as (select distinct pv2."version" as not_deleted_version, pv2.package_id as ndv_package_id from published_version pv2 where pv2.deleted_at is null) - select * from dv - left join ndv - on dv.deleted_version = ndv.not_deleted_version and dv.dv_package_id = ndv.ndv_package_id - ) as d - where d.not_deleted_version is null and d.ndv_package_id is null) - select pv.package_id, pv."version", revision from published_version pv - join deleted_versions on - pv.previous_version = deleted_versions."version" - and (pv.previous_version_package_id = deleted_versions.package_id - or - (pv.package_id = deleted_versions.package_id and (pv.previous_version_package_id = '' or pv.previous_version_package_id is null))) - where pv.deleted_at is null -) d -where pv.package_id = d.package_id and pv."version" = d."version" and pv.revision = d.revision; - -update published_version pv -set previous_version = null, previous_version_package_id = null -from ( - select package_id, "version", revision from published_version pv - where pv."version" = pv.previous_version - and deleted_at is null - and (pv.package_id = pv.previous_version_package_id or pv.previous_version_package_id is null or pv.previous_version_package_id = '') -) eqv -where pv.package_id = eqv.package_id and pv."version" = eqv."version" and pv.revision = eqv.revision; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/144_deprecated_info_to_string.down.sql b/qubership-apihub-service/resources/migrations/144_deprecated_info_to_string.down.sql deleted file mode 100644 index 07588bb..0000000 --- a/qubership-apihub-service/resources/migrations/144_deprecated_info_to_string.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table operation drop column if exists deprecated_info; -alter table operation add column if not exists deprecated_info jsonb; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/144_deprecated_info_to_string.up.sql b/qubership-apihub-service/resources/migrations/144_deprecated_info_to_string.up.sql deleted file mode 100644 index 993dd58..0000000 --- a/qubership-apihub-service/resources/migrations/144_deprecated_info_to_string.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table operation drop column if exists deprecated_info; -alter table operation add column if not exists deprecated_info varchar; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/145_csv_publish.down.sql b/qubership-apihub-service/resources/migrations/145_csv_publish.down.sql deleted file mode 100644 index 9593e82..0000000 --- a/qubership-apihub-service/resources/migrations/145_csv_publish.down.sql +++ /dev/null @@ -1 +0,0 @@ -drop table csv_dashboard_publication; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/145_csv_publish.up.sql b/qubership-apihub-service/resources/migrations/145_csv_publish.up.sql deleted file mode 100644 index e42162e..0000000 --- a/qubership-apihub-service/resources/migrations/145_csv_publish.up.sql +++ /dev/null @@ -1,7 +0,0 @@ -create table csv_dashboard_publication( - publish_id varchar, - status varchar, - message varchar, - csv_report bytea, - PRIMARY KEY(publish_id) -); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/14_fix_published_path.down.sql b/qubership-apihub-service/resources/migrations/14_fix_published_path.down.sql deleted file mode 100644 index 1dacdcd..0000000 --- a/qubership-apihub-service/resources/migrations/14_fix_published_path.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE published_version_revision_content -ALTER COLUMN path SET NOT NULL; diff --git a/qubership-apihub-service/resources/migrations/14_fix_published_path.up.sql b/qubership-apihub-service/resources/migrations/14_fix_published_path.up.sql deleted file mode 100644 index 965eed3..0000000 --- a/qubership-apihub-service/resources/migrations/14_fix_published_path.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE published_version_revision_content -ALTER COLUMN path DROP NOT NULL; diff --git a/qubership-apihub-service/resources/migrations/15_branch_operations_draft_reset.down.sql b/qubership-apihub-service/resources/migrations/15_branch_operations_draft_reset.down.sql deleted file mode 100644 index b65d44b..0000000 --- a/qubership-apihub-service/resources/migrations/15_branch_operations_draft_reset.down.sql +++ /dev/null @@ -1,10 +0,0 @@ -ALTER TABLE branch_draft_content -RENAME COLUMN status TO action; - -ALTER TABLE branch_draft_content -DROP COLUMN last_status, -DROP COLUMN conflicted_commit_id, -DROP COLUMN conflicted_file_id; - -ALTER TABLE branch_draft_reference -RENAME COLUMN status TO action; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/15_branch_operations_draft_reset.up.sql b/qubership-apihub-service/resources/migrations/15_branch_operations_draft_reset.up.sql deleted file mode 100644 index cdb1772..0000000 --- a/qubership-apihub-service/resources/migrations/15_branch_operations_draft_reset.up.sql +++ /dev/null @@ -1,13 +0,0 @@ -truncate table branch_draft_content; -truncate table branch_draft_reference; - -ALTER TABLE branch_draft_content -RENAME COLUMN action TO status; - -ALTER TABLE branch_draft_content -ADD COLUMN last_status varchar, -ADD COLUMN conflicted_commit_id varchar, -ADD COLUMN conflicted_file_id varchar; - -ALTER TABLE branch_draft_reference -RENAME COLUMN action TO status; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/16_nullable_content_type.down.sql b/qubership-apihub-service/resources/migrations/16_nullable_content_type.down.sql deleted file mode 100644 index b228927..0000000 --- a/qubership-apihub-service/resources/migrations/16_nullable_content_type.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE branch_draft_content -ALTER COLUMN data_type SET NOT NULL; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/16_nullable_content_type.up.sql b/qubership-apihub-service/resources/migrations/16_nullable_content_type.up.sql deleted file mode 100644 index bb52336..0000000 --- a/qubership-apihub-service/resources/migrations/16_nullable_content_type.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE branch_draft_content -ALTER COLUMN data_type DROP NOT NULL; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/17_published_src.down.sql b/qubership-apihub-service/resources/migrations/17_published_src.down.sql deleted file mode 100644 index 151383b..0000000 --- a/qubership-apihub-service/resources/migrations/17_published_src.down.sql +++ /dev/null @@ -1,3 +0,0 @@ -DROP TABLE IF EXISTS published_sources CASCADE; - -DROP TABLE IF EXISTS published_sources_data CASCADE; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/17_published_src.up.sql b/qubership-apihub-service/resources/migrations/17_published_src.up.sql deleted file mode 100644 index ec8c94d..0000000 --- a/qubership-apihub-service/resources/migrations/17_published_src.up.sql +++ /dev/null @@ -1,25 +0,0 @@ -CREATE TABLE published_sources -( - project_id varchar NOT NULL, - version varchar NOT NULL, - revision integer NOT NULL, - checksum varchar NOT NULL -); - -CREATE TABLE published_sources_data -( - project_id varchar NOT NULL, - checksum varchar NOT NULL, - data bytea NOT NULL -); - -ALTER TABLE published_sources_data ADD CONSTRAINT "PK_published_sources_data" - PRIMARY KEY (checksum,project_id); - -ALTER TABLE published_sources ADD CONSTRAINT "FK_published_sources_data" - FOREIGN KEY (checksum,project_id) REFERENCES published_sources_data (checksum,project_id) ON DELETE Restrict ON UPDATE Cascade; - -ALTER TABLE published_sources ADD CONSTRAINT "FK_published_sources_version_revision" - FOREIGN KEY (project_id,version,revision) REFERENCES published_version (project_id,version,revision) ON DELETE Restrict ON UPDATE Cascade; - - diff --git a/qubership-apihub-service/resources/migrations/18_drop_branch_editors.down.sql b/qubership-apihub-service/resources/migrations/18_drop_branch_editors.down.sql deleted file mode 100644 index 5b88aa6..0000000 --- a/qubership-apihub-service/resources/migrations/18_drop_branch_editors.down.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE branch_editors -( - project_id varchar NOT NULL, - branch_name varchar NOT NULL, - editors varchar[], - PRIMARY KEY (project_id, branch_name) -); diff --git a/qubership-apihub-service/resources/migrations/18_drop_branch_editors.up.sql b/qubership-apihub-service/resources/migrations/18_drop_branch_editors.up.sql deleted file mode 100644 index 6311b8c..0000000 --- a/qubership-apihub-service/resources/migrations/18_drop_branch_editors.up.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS branch_editors; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/19_drafted_branch_draft_reset.down.sql b/qubership-apihub-service/resources/migrations/19_drafted_branch_draft_reset.down.sql deleted file mode 100644 index 0fba441..0000000 --- a/qubership-apihub-service/resources/migrations/19_drafted_branch_draft_reset.down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS drafted_branches; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/19_drafted_branch_draft_reset.up.sql b/qubership-apihub-service/resources/migrations/19_drafted_branch_draft_reset.up.sql deleted file mode 100644 index 4e50d30..0000000 --- a/qubership-apihub-service/resources/migrations/19_drafted_branch_draft_reset.up.sql +++ /dev/null @@ -1,12 +0,0 @@ -truncate table branch_draft_content; -truncate table branch_draft_reference; - -CREATE TABLE drafted_branches -( - project_id varchar NOT NULL, - branch_name varchar NOT NULL, - change_type varchar, - original_config bytea, - editors varchar[], - PRIMARY KEY (project_id, branch_name) -); diff --git a/qubership-apihub-service/resources/migrations/1_init.down.sql b/qubership-apihub-service/resources/migrations/1_init.down.sql deleted file mode 100644 index 7908a9b..0000000 --- a/qubership-apihub-service/resources/migrations/1_init.down.sql +++ /dev/null @@ -1,26 +0,0 @@ -DROP TABLE IF EXISTS branch_draft_content CASCADE -; - -DROP TABLE IF EXISTS branch_draft_reference CASCADE -; - -DROP TABLE IF EXISTS project CASCADE -; - -DROP TABLE IF EXISTS published_data CASCADE -; - -DROP TABLE IF EXISTS published_version CASCADE -; - -DROP TABLE IF EXISTS published_version_reference CASCADE -; - -DROP TABLE IF EXISTS published_version_revision_content CASCADE -; - -DROP TABLE IF EXISTS user_data CASCADE -; - -DROP TABLE IF EXISTS user_integration CASCADE -; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/1_init.up.sql b/qubership-apihub-service/resources/migrations/1_init.up.sql index 794d034..293bdfd 100644 --- a/qubership-apihub-service/resources/migrations/1_init.up.sql +++ b/qubership-apihub-service/resources/migrations/1_init.up.sql @@ -1,270 +1,1046 @@ -/* ---------------------------------------------------- */ -/* Generated by Enterprise Architect Version 14.1 */ -/* Created On : 28-Apr-2022 11:55:35 */ -/* DBMS : PostgreSQL */ -/* ---------------------------------------------------- */ +-- noinspection SqlNoDataSourceInspectionForFile +-- schema downgrade file +-- dropping existing functions +DROP FUNCTION IF EXISTS public.get_latest_revision CASCADE; +DROP FUNCTION IF EXISTS public.merge_json_path CASCADE; +DROP FUNCTION IF EXISTS public.parent_package_names CASCADE; +DROP FUNCTION IF EXISTS public.split_json_path CASCADE; +DROP FUNCTION IF EXISTS parent_package_names CASCADE; +DROP FUNCTION IF EXISTS merge_json_path CASCADE; -/* Drop Tables */ +-- dropping existing indexes +DROP INDEX IF EXISTS ts_published_data_custom_split_idx CASCADE; +DROP INDEX IF EXISTS ts_operation_data_idx CASCADE; +DROP INDEX IF EXISTS build_depends_index CASCADE; +DROP INDEX IF EXISTS ts_operation_data_idx CASCADE; +DROP INDEX IF EXISTS ts_graphql_operation_data_idx CASCADE; +DROP INDEX IF EXISTS activity_tracking_transition_id_uindex CASCADE; +DROP INDEX IF EXISTS package_transition_old_package_id_index CASCADE; +DROP INDEX IF EXISTS ts_published_data_path_split_idx CASCADE; +DROP INDEX IF EXISTS ts_published_data_custom_split_idx CASCADE; +DROP INDEX IF EXISTS activity_tracking_transition_id_uindex CASCADE; +DROP INDEX IF EXISTS build_depends_index CASCADE; +DROP INDEX IF EXISTS build_status_index CASCADE; +DROP INDEX IF EXISTS operation_comparison_comparison_id_index CASCADE; +DROP INDEX IF EXISTS package_transition_old_package_id_index CASCADE; +DROP INDEX IF EXISTS published_sources_package_id_version_revision_uindex CASCADE; +DROP INDEX IF EXISTS ts_graphql_operation_data_idx CASCADE; +DROP INDEX IF EXISTS ts_operation_data_idx CASCADE; +DROP INDEX IF EXISTS ts_rest_operation_data_idx CASCADE; -DROP TABLE IF EXISTS branch_draft_content CASCADE -; +-- dropping existing sequences +DROP SEQUENCE IF EXISTS public.activity_tracking_transition_completed_seq CASCADE; +DROP SEQUENCE IF EXISTS activity_tracking_transition_completed_seq CASCADE; -DROP TABLE IF EXISTS branch_draft_reference CASCADE -; +-- dropping existing tables +DROP TABLE IF EXISTS public.activity_tracking CASCADE; +DROP TABLE IF EXISTS public.activity_tracking_transition CASCADE; +DROP TABLE IF EXISTS public.agent CASCADE; +DROP TABLE IF EXISTS public.agent_config CASCADE; +DROP TABLE IF EXISTS public.apihub_api_keys CASCADE; +DROP TABLE IF EXISTS public.branch_draft_content CASCADE; +DROP TABLE IF EXISTS public.branch_draft_reference CASCADE; +DROP TABLE IF EXISTS public.build CASCADE; +DROP TABLE IF EXISTS public.build_cleanup_run CASCADE; +DROP TABLE IF EXISTS public.build_depends CASCADE; +DROP TABLE IF EXISTS public.build_result CASCADE; +DROP TABLE IF EXISTS public.build_src CASCADE; +DROP TABLE IF EXISTS public.builder_notifications CASCADE; +DROP TABLE IF EXISTS public.business_metric CASCADE; +DROP TABLE IF EXISTS public.drafted_branches CASCADE; +DROP TABLE IF EXISTS public.endpoint_calls CASCADE; +DROP TABLE IF EXISTS public.external_identity CASCADE; +DROP TABLE IF EXISTS public.favorite_packages CASCADE; +DROP TABLE IF EXISTS public.favorite_projects CASCADE; +DROP TABLE IF EXISTS public.grouped_operation CASCADE; +DROP TABLE IF EXISTS public.migrated_version CASCADE; +DROP TABLE IF EXISTS public.migrated_version_changes CASCADE; +DROP TABLE IF EXISTS public.migration_changes CASCADE; +DROP TABLE IF EXISTS public.migration_run CASCADE; +DROP TABLE IF EXISTS public.operation CASCADE; +DROP TABLE IF EXISTS public.operation_comparison CASCADE; +DROP TABLE IF EXISTS public.operation_data CASCADE; +DROP TABLE IF EXISTS public.operation_group CASCADE; +DROP TABLE IF EXISTS public.operation_group_history CASCADE; +DROP TABLE IF EXISTS public.operation_group_publication CASCADE; +DROP TABLE IF EXISTS public.operation_group_template CASCADE; +DROP TABLE IF EXISTS public.operation_open_count CASCADE; +DROP TABLE IF EXISTS public.package_group CASCADE; +DROP TABLE IF EXISTS public.package_member_role CASCADE; +DROP TABLE IF EXISTS public.package_service CASCADE; +DROP TABLE IF EXISTS public.package_transition CASCADE; +DROP TABLE IF EXISTS public.project CASCADE; +DROP TABLE IF EXISTS public.published_content_messages CASCADE; +DROP TABLE IF EXISTS public.published_data CASCADE; +DROP TABLE IF EXISTS public.published_document_open_count CASCADE; +DROP TABLE IF EXISTS public.published_sources CASCADE; +DROP TABLE IF EXISTS public.published_sources_archives CASCADE; +DROP TABLE IF EXISTS public.published_version CASCADE; +DROP TABLE IF EXISTS public.published_version_open_count CASCADE; +DROP TABLE IF EXISTS public.published_version_reference CASCADE; +DROP TABLE IF EXISTS public.published_version_revision_content CASCADE; +DROP TABLE IF EXISTS public.published_version_validation CASCADE; +DROP TABLE IF EXISTS public.role CASCADE; +DROP TABLE IF EXISTS public.shared_url_info CASCADE; +DROP TABLE IF EXISTS public.system_role CASCADE; +DROP TABLE IF EXISTS public.transformed_content_data CASCADE; +DROP TABLE IF EXISTS public.ts_graphql_operation_data CASCADE; +DROP TABLE IF EXISTS public.ts_operation_data CASCADE; +DROP TABLE IF EXISTS public.ts_rest_operation_data CASCADE; +DROP TABLE IF EXISTS public.user_avatar_data CASCADE; +DROP TABLE IF EXISTS public.user_data CASCADE; +DROP TABLE IF EXISTS public.user_integration CASCADE; +DROP TABLE IF EXISTS public.version_comparison CASCADE; +DROP TABLE IF EXISTS public.versions_cleanup_run CASCADE; +DROP TABLE IF EXISTS branch_draft_content CASCADE; +DROP TABLE IF EXISTS branch_draft_reference CASCADE; +DROP TABLE IF EXISTS project CASCADE; +DROP TABLE IF EXISTS published_data CASCADE; +DROP TABLE IF EXISTS published_version CASCADE; +DROP TABLE IF EXISTS published_version_reference CASCADE; +DROP TABLE IF EXISTS published_version_revision_content CASCADE; +DROP TABLE IF EXISTS user_data CASCADE; +DROP TABLE IF EXISTS user_integration CASCADE; +DROP TABLE IF EXISTS favorite_projects CASCADE; +DROP TABLE IF EXISTS published_content_messages CASCADE; +DROP TABLE IF EXISTS shared_url_info CASCADE; +DROP TABLE IF EXISTS published_sources_data CASCADE; +DROP TABLE IF EXISTS drafted_branches CASCADE; +DROP TABLE IF EXISTS package_group CASCADE; +DROP TABLE IF EXISTS ts_published_data_custom_split CASCADE; +DROP TABLE IF EXISTS ts_published_data_errors CASCADE; +DROP TABLE IF EXISTS build_src CASCADE; +DROP TABLE IF EXISTS build_depends CASCADE; +DROP TABLE IF EXISTS package_member_role CASCADE; +DROP TABLE IF EXISTS operation CASCADE; +DROP TABLE IF EXISTS operation_data CASCADE; +DROP TABLE IF EXISTS changed_operation CASCADE; +DROP TABLE IF EXISTS published_document_open_count CASCADE; +DROP TABLE IF EXISTS operation_open_count CASCADE; +DROP TABLE IF EXISTS published_sources_data CASCADE; +DROP TABLE IF EXISTS role CASCADE; +DROP TABLE IF EXISTS favorite_projects CASCADE; +DROP TABLE IF EXISTS favorite_packages CASCADE; +DROP TABLE IF EXISTS favorites CASCADE; +DROP TABLE IF EXISTS operation_group CASCADE; +DROP TABLE IF EXISTS grouped_operation CASCADE; +DROP TABLE IF EXISTS operations_group CASCADE; +DROP TABLE IF EXISTS ts_operation_data CASCADE; +DROP TABLE IF EXISTS ts_graphql_operation_data CASCADE; +DROP TABLE IF EXISTS migration_changes CASCADE; +DROP TABLE IF EXISTS ts_published_data_custom_split CASCADE; +DROP TABLE IF EXISTS ts_published_data_errors CASCADE; +DROP TABLE IF EXISTS csv_dashboard_publication CASCADE; -DROP TABLE IF EXISTS project CASCADE -; +-- maintain schema migration tables +CREATE TABLE IF NOT EXISTS public.schema_migrations ( + "version" int4 NOT NULL, + dirty bool NOT NULL, + CONSTRAINT schema_migrations_pkey PRIMARY KEY (version) +); -DROP TABLE IF EXISTS published_data CASCADE -; +CREATE TABLE IF NOT EXISTS public.stored_schema_migration ( + num int4 NOT NULL, + up_hash varchar NOT NULL, + sql_up varchar NOT NULL, + down_hash varchar NULL, + sql_down varchar NULL, + CONSTRAINT stored_schema_migration_pkey PRIMARY KEY (num) +); -DROP TABLE IF EXISTS published_version CASCADE -; +-- remove all the previous migrations +truncate table public.stored_schema_migration; +truncate table public.schema_migrations; -DROP TABLE IF EXISTS published_version_reference CASCADE -; +CREATE OR REPLACE FUNCTION public.get_latest_revision(package_id character varying, version character varying) RETURNS integer + LANGUAGE plpgsql +AS $_$ +declare + latest_revision integer; +begin + execute ' + select max(revision) + from published_version + where package_id = $1 and version = $2;' + into latest_revision + using package_id,version; + if latest_revision is null then return 0; + end if; + return latest_revision; +end;$_$; -DROP TABLE IF EXISTS published_version_revision_content CASCADE -; -DROP TABLE IF EXISTS user_data CASCADE -; +ALTER FUNCTION public.get_latest_revision(package_id character varying, version character varying) OWNER TO apihub; -DROP TABLE IF EXISTS user_integration CASCADE -; +-- +-- TOC entry 264 (class 1255 OID 17274) +-- Name: merge_json_path(jsonb[]); Type: FUNCTION; Schema: public; Owner: apihub +-- -/* Create Tables */ +CREATE OR REPLACE FUNCTION public.merge_json_path(jsonb[]) RETURNS jsonb[] + LANGUAGE plpgsql STRICT +AS $_$ +declare + items alias for $1; + jsonpath text; + ret jsonb[]; +begin + for i in array_lower(items, 1)..array_upper(items, 1) loop + select string_agg(el, '/') into jsonpath from jsonb_array_elements_text(items[i]->'jsonPath') el; + ret[i] := jsonb_set(items[i], '{jsonPath}', to_jsonb(jsonpath), false); + end loop; + return ret; +end; +$_$; -CREATE TABLE branch_draft_content -( - project_id varchar NOT NULL, - branch_name varchar NOT NULL, - index integer NOT NULL DEFAULT 0, - name varchar NOT NULL, - file_id varchar NOT NULL, - path varchar NOT NULL, - data_type varchar NOT NULL, -- OpenAPI / Swagger / MD + +ALTER FUNCTION public.merge_json_path(jsonb[]) OWNER TO apihub; + +-- +-- TOC entry 262 (class 1255 OID 17011) +-- Name: parent_package_names(character varying); Type: FUNCTION; Schema: public; Owner: apihub +-- + +CREATE OR REPLACE FUNCTION public.parent_package_names(character varying) RETURNS character varying[] + LANGUAGE plpgsql +AS $_$ +declare + split varchar[] := string_to_array($1, '.')::varchar[]; + parent_ids varchar[]; + parent_names varchar[]; +begin + + if coalesce(array_length(split, 1), 0) <= 1 then + return ARRAY[]::varchar[]; + end if; + + parent_ids = parent_ids || split[1]; + + for i in 2..(array_length(split, 1) - 1) + loop + parent_ids = parent_ids || (parent_ids[i-1] ||'.'|| split[i])::character varying; + end loop; + + execute ' +select array_agg(name) from ( + select name from package_group + join unnest($1) with ordinality t(id, ord) using (id) --sort by parent_ids array + order by t.ord) n' + into parent_names + using parent_ids; + + return parent_names; + +end; +$_$; + + +ALTER FUNCTION public.parent_package_names(character varying) OWNER TO apihub; + +-- +-- TOC entry 263 (class 1255 OID 17273) +-- Name: split_json_path(jsonb[]); Type: FUNCTION; Schema: public; Owner: apihub +-- + +CREATE OR REPLACE FUNCTION public.split_json_path(jsonb[]) RETURNS jsonb[] + LANGUAGE plpgsql STRICT +AS $_$ +declare + items alias for $1; + ret jsonb[]; +begin + for i in array_lower(items, 1)..array_upper(items, 1) + loop + ret[i] := jsonb_set(items[i], '{jsonPath}', + (array_to_json(string_to_array(trim(both '"' from (items[i] -> 'jsonPath')::text), + '/')))::jsonb, false); + end loop; + return ret; +end; +$_$; + + +ALTER FUNCTION public.split_json_path(jsonb[]) OWNER TO apihub; + +SET default_tablespace = ''; + +SET default_table_access_method = heap; + +CREATE TABLE IF NOT EXISTS public.package_group ( + id character varying NOT NULL, + kind character varying, + name character varying, + alias character varying, + parent_id character varying, + image_url character varying, + description text, + deleted_at timestamp without time zone, + created_at timestamp without time zone, + created_by character varying, + deleted_by character varying, + default_role character varying DEFAULT 'Viewer'::character varying NOT NULL, + default_released_version character varying, + service_name character varying, + release_version_pattern character varying, + exclude_from_search boolean DEFAULT false, + rest_grouping_prefix character varying, + CONSTRAINT "PK_project_group" PRIMARY KEY (id), + CONSTRAINT "FK_parent_package_group" FOREIGN KEY (parent_id) REFERENCES public.package_group(id) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.package_group OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.activity_tracking ( + id character varying NOT NULL, + e_type character varying NOT NULL, + data jsonb, + package_id character varying, + date timestamp without time zone, + user_id character varying, + CONSTRAINT activity_tracking_pkey PRIMARY KEY (id), + CONSTRAINT activity_tracking_package_group_id_fk FOREIGN KEY (package_id) REFERENCES public.package_group(id) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.activity_tracking OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.activity_tracking_transition ( + id character varying NOT NULL, + tr_type character varying NOT NULL, + from_id character varying NOT NULL, + to_id character varying NOT NULL, + status character varying NOT NULL, + details character varying, + started_by character varying NOT NULL, + started_at timestamp without time zone NOT NULL, + finished_at timestamp without time zone, + progress_percent integer, + affected_objects integer, + completed_serial_number integer, + CONSTRAINT activity_tracking_transition_pk PRIMARY KEY (id) +); +ALTER TABLE public.activity_tracking_transition OWNER TO apihub; + +-- create if not exists +CREATE SEQUENCE IF NOT EXISTS public.activity_tracking_transition_completed_seq + AS integer + START WITH 0 + INCREMENT BY 1 + MINVALUE 0 + NO MAXVALUE + CACHE 1; + +-- reset the value if exists +SELECT pg_catalog.setval('public.activity_tracking_transition_completed_seq', 0, false); + +-- alter ownership +ALTER SEQUENCE public.activity_tracking_transition_completed_seq OWNER TO apihub; +ALTER SEQUENCE public.activity_tracking_transition_completed_seq OWNED BY public.activity_tracking_transition.completed_serial_number; + +CREATE TABLE IF NOT EXISTS public.agent ( + agent_id character varying NOT NULL, + cloud character varying NOT NULL, + namespace character varying NOT NULL, + url character varying NOT NULL, + last_active timestamp without time zone NOT NULL, + backend_version character varying NOT NULL, + name character varying, + agent_version character varying, + CONSTRAINT agent_pkey PRIMARY KEY (agent_id) +); +ALTER TABLE public.agent OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.agent_config ( + cloud character varying NOT NULL, + namespace character varying NOT NULL, + config jsonb, + CONSTRAINT "PK_agent_config" PRIMARY KEY (cloud, namespace) +); +ALTER TABLE public.agent_config OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.apihub_api_keys ( + id character varying NOT NULL, + package_id character varying NOT NULL, + name character varying NOT NULL, + created_by character varying NOT NULL, + created_at timestamp without time zone NOT NULL, + deleted_by character varying, + deleted_at timestamp without time zone, + api_key character varying NOT NULL, + roles character varying[] DEFAULT '{}'::character varying[], + created_for character varying, + CONSTRAINT apihub_api_keys_pkey PRIMARY KEY (id) +); +ALTER TABLE public.apihub_api_keys OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.project ( + id character varying NOT NULL, + name character varying NOT NULL, + alias character varying NOT NULL, + group_id character varying, + description text, + integration_type character varying, + default_branch character varying, + default_folder character varying, + repository_id character varying, + deleted_at timestamp without time zone, + repository_name character varying, + repository_url character varying, + deleted_by character varying, + package_id character varying, + secret_token character varying, + secret_token_user_id character varying, + CONSTRAINT "PK_project" PRIMARY KEY (id) +); +ALTER TABLE public.project OWNER TO apihub; +COMMENT ON COLUMN public.project.group_id IS 'Only for the GROUP kind'; +COMMENT ON COLUMN public.project.integration_type IS 'GitLab / Local storage'; + +CREATE TABLE IF NOT EXISTS public.branch_draft_content ( + project_id character varying NOT NULL, + branch_name character varying NOT NULL, + index integer DEFAULT 0 NOT NULL, + name character varying, + file_id character varying NOT NULL, + path character varying, + data_type character varying, data bytea, - media_type varchar NOT NULL, -- HTTP media-type - is_updated boolean NOT NULL -) -; - -CREATE TABLE branch_draft_reference -( - project_id varchar NOT NULL, - branch_name varchar NOT NULL, - reference_project_id varchar NOT NULL, - reference_version varchar NOT NULL, - relation_type varchar NOT NULL -- INCLUDE / DEPEND -) -; - -CREATE TABLE project -( - id varchar NOT NULL, - kind varchar NOT NULL, -- PROJECT / GROUP - name varchar NOT NULL, - alias varchar NOT NULL, - parent_id varchar NULL, -- Only for the GROUP kind - image_url varchar NULL, - description text NULL, - integration_type varchar NULL, -- GitLab / Local storage - default_branch varchar NULL, - default_folder varchar NULL, - repository_id varchar NULL, - delete_date timestamp without time zone NULL -) -; - -CREATE TABLE published_data -( - project_id varchar NOT NULL, - checksum varchar NOT NULL, - media_type varchar NOT NULL, -- HTTP media-type + media_type character varying NOT NULL, + status character varying, + moved_from character varying, + commit_id character varying, + publish boolean, + labels character varying[], + last_status character varying, + conflicted_commit_id character varying, + conflicted_file_id character varying, + included boolean DEFAULT false, + is_folder boolean, + from_folder boolean, + blob_id character varying, + conflicted_blob_id character varying, + CONSTRAINT "PK_branch_draft_content" PRIMARY KEY (project_id, branch_name, file_id), + CONSTRAINT "FK_project" FOREIGN KEY (project_id) REFERENCES public.project(id) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.branch_draft_content OWNER TO apihub; +COMMENT ON COLUMN public.branch_draft_content.data_type IS 'OpenAPI / Swagger / MD'; +COMMENT ON COLUMN public.branch_draft_content.media_type IS 'HTTP media-type'; + + +CREATE TABLE IF NOT EXISTS public.branch_draft_reference ( + project_id character varying NOT NULL, + branch_name character varying NOT NULL, + reference_package_id character varying NOT NULL, + reference_version character varying NOT NULL, + status character varying, + CONSTRAINT "PK_branch_draft_reference" PRIMARY KEY (branch_name, project_id, reference_package_id, reference_version), + CONSTRAINT "FK_project" FOREIGN KEY (project_id) REFERENCES public.project(id) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.branch_draft_reference OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.build ( + build_id character varying NOT NULL, + status character varying NOT NULL, + details character varying, + package_id character varying NOT NULL, + version character varying NOT NULL, + created_at timestamp without time zone DEFAULT now() NOT NULL, + last_active timestamp without time zone DEFAULT now() NOT NULL, + created_by character varying NOT NULL, + restart_count integer, + client_build boolean, + started_at timestamp without time zone, + builder_id character varying, + priority integer DEFAULT 0 NOT NULL, + metadata jsonb, + CONSTRAINT "PK_build" PRIMARY KEY (build_id), + CONSTRAINT build_package_group_id_fk FOREIGN KEY (package_id) REFERENCES public.package_group(id) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.build OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.build_cleanup_run ( + run_id integer NOT NULL, + scheduled_at timestamp without time zone, + deleted_rows integer, + build_result integer DEFAULT 0, + build_src integer DEFAULT 0, + operation_data integer DEFAULT 0, + ts_operation_data integer DEFAULT 0, + ts_rest_operation_data integer DEFAULT 0, + ts_gql_operation_data integer DEFAULT 0, + CONSTRAINT build_cleanup_run_pkey PRIMARY KEY (run_id) +); +ALTER TABLE public.build_cleanup_run OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.build_depends ( + build_id character varying NOT NULL, + depend_id character varying NOT NULL, + CONSTRAINT "FK_build_depends_depend" FOREIGN KEY (depend_id) REFERENCES public.build(build_id) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT "FK_build_depends_id" FOREIGN KEY (build_id) REFERENCES public.build(build_id) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.build_depends OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.build_result ( + build_id character varying NOT NULL, data bytea NOT NULL, - commit_id varchar NOT NULL, - commit_date timestamp without time zone NOT NULL -) -; - -CREATE TABLE published_version -( - project_id varchar NOT NULL, - version varchar NOT NULL, + CONSTRAINT "FK_build_result_build_id" FOREIGN KEY (build_id) REFERENCES public.build(build_id) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.build_result OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.build_src ( + build_id character varying NOT NULL, + source bytea, + config jsonb NOT NULL, + CONSTRAINT "FK_build_src" FOREIGN KEY (build_id) REFERENCES public.build(build_id) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.build_src OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.builder_notifications ( + build_id character varying NOT NULL, + severity character varying, + message character varying, + file_id character varying, + CONSTRAINT builder_notifications_build_id_fkey FOREIGN KEY (build_id) REFERENCES public.build(build_id) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.builder_notifications OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.business_metric ( + year integer NOT NULL, + month integer NOT NULL, + day integer NOT NULL, + metric character varying NOT NULL, + data jsonb, + user_id character varying DEFAULT 'unknown'::character varying NOT NULL, + CONSTRAINT business_metric_pkey PRIMARY KEY (year, month, day, metric, user_id) +); +ALTER TABLE public.business_metric OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.drafted_branches ( + project_id character varying NOT NULL, + branch_name character varying NOT NULL, + change_type character varying, + original_config bytea, + editors character varying[], + commit_id character varying, + CONSTRAINT drafted_branches_pkey PRIMARY KEY (project_id, branch_name), + CONSTRAINT "FK_project" FOREIGN KEY (project_id) REFERENCES public.project(id) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.drafted_branches OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.endpoint_calls ( + path character varying NOT NULL, + hash character varying NOT NULL, + options jsonb, + count integer, + CONSTRAINT endpoint_calls_pkey PRIMARY KEY (path, hash) +); +ALTER TABLE public.endpoint_calls OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.user_data ( + user_id character varying NOT NULL, + email character varying, + name character varying, + avatar_url character varying, + password bytea, + private_package_id character varying DEFAULT ''::character varying NOT NULL, + CONSTRAINT "PK_user_data" PRIMARY KEY (user_id), + CONSTRAINT email_unique UNIQUE (email), + CONSTRAINT private_package_id_unique UNIQUE (private_package_id) +); +ALTER TABLE public.user_data OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.external_identity ( + provider character varying NOT NULL, + external_id character varying NOT NULL, + internal_id character varying NOT NULL, + CONSTRAINT external_identity_pkey PRIMARY KEY (provider, external_id), + CONSTRAINT "FK_user_data" FOREIGN KEY (internal_id) REFERENCES public.user_data(user_id) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.external_identity OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.favorite_packages ( + user_id character varying NOT NULL, + package_id character varying NOT NULL, + CONSTRAINT "PK_favorite_packages" PRIMARY KEY (user_id, package_id), + CONSTRAINT "FK_favorite_packages_package_group" FOREIGN KEY (package_id) REFERENCES public.package_group(id) ON DELETE CASCADE, + CONSTRAINT "FK_favorite_packages_user_data" FOREIGN KEY (user_id) REFERENCES public.user_data(user_id) ON DELETE CASCADE +); +ALTER TABLE public.favorite_packages OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.favorite_projects ( + user_id character varying NOT NULL, + project_id character varying NOT NULL, + CONSTRAINT "PK_favorite_projects" PRIMARY KEY (user_id, project_id), + CONSTRAINT "FK_favorite_projects_project" FOREIGN KEY (project_id) REFERENCES public.project(id) ON DELETE CASCADE, + CONSTRAINT "FK_favorite_projects_user_data" FOREIGN KEY (user_id) REFERENCES public.user_data(user_id) ON DELETE CASCADE +); +ALTER TABLE public.favorite_projects OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.migrated_version ( + package_id character varying, + version character varying, + revision integer, + error character varying, + build_id character varying, + migration_id character varying, + build_type character varying, + no_changelog boolean, + CONSTRAINT migrated_version_package_group_id_fk FOREIGN KEY (package_id) REFERENCES public.package_group(id) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.migrated_version OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.migrated_version_changes ( + package_id character varying NOT NULL, + version character varying NOT NULL, + revision character varying NOT NULL, + build_id character varying NOT NULL, + migration_id character varying NOT NULL, + changes jsonb, + unique_changes character varying[] +); +ALTER TABLE public.migrated_version_changes OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.migration_changes ( + migration_id character varying NOT NULL, + changes jsonb, + CONSTRAINT migration_changes_pkey PRIMARY KEY (migration_id) +); +ALTER TABLE public.migration_changes OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.migration_run ( + id character varying, + started_at timestamp without time zone, + status character varying, + stage character varying, + package_ids character varying[], + versions character varying[], + is_rebuild boolean, + is_rebuild_changelog_only boolean, + current_builder_version character varying, + error_details character varying, + finished_at timestamp without time zone, + updated_at timestamp without time zone, + skip_validation boolean +); +ALTER TABLE public.migration_run OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.operation_data ( + data_hash character varying NOT NULL, + data bytea, + search_scope jsonb, + CONSTRAINT pk_operation_data PRIMARY KEY (data_hash) +); +ALTER TABLE public.operation_data OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.published_version ( + package_id character varying NOT NULL, + version character varying NOT NULL, revision integer NOT NULL, - status varchar NOT NULL, -- DRAFT / APPROVED / RELEASED / ARCHIVE - publish_date timestamp without time zone NOT NULL, - delete_date timestamp without time zone NULL, - branch_name varchar NOT NULL -) -; - -CREATE TABLE published_version_reference -( - project_id varchar NOT NULL, - version varchar NOT NULL, + status character varying NOT NULL, + published_at timestamp without time zone NOT NULL, + deleted_at timestamp without time zone, + metadata jsonb, + previous_version character varying, + previous_version_package_id character varying, + labels character varying[], + created_by character varying, + deleted_by character varying, + CONSTRAINT "PK_published_version" PRIMARY KEY (package_id, version, revision), + CONSTRAINT "FK_package_group" FOREIGN KEY (package_id) REFERENCES public.package_group(id) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.published_version OWNER TO apihub; +COMMENT ON COLUMN public.published_version.status IS 'DRAFT / APPROVED / RELEASED / ARCHIVE'; + +CREATE TABLE IF NOT EXISTS public.operation ( + package_id character varying NOT NULL, + version character varying NOT NULL, revision integer NOT NULL, - reference_id varchar NOT NULL, - reference_version varchar NOT NULL, - relation_type varchar NOT NULL -- INCLUDE / DEPEND -) -; - -CREATE TABLE published_version_revision_content -( - project_id varchar NOT NULL, - version varchar NOT NULL, + operation_id character varying NOT NULL, + data_hash character varying NOT NULL, + deprecated boolean NOT NULL, + kind character varying, + title character varying, + metadata jsonb, + type character varying NOT NULL, + deprecated_info varchar, + deprecated_items jsonb, + previous_release_versions character varying[], + models jsonb, + custom_tags jsonb, + api_audience character varying DEFAULT 'external'::character varying, + CONSTRAINT pk_operation PRIMARY KEY (package_id, version, revision, operation_id), + CONSTRAINT "FK_operation_data" FOREIGN KEY (data_hash) REFERENCES public.operation_data(data_hash) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT "FK_published_version" FOREIGN KEY (package_id,"version",revision) REFERENCES public.published_version(package_id,"version",revision) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.operation OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.version_comparison ( + package_id character varying NOT NULL, + version character varying NOT NULL, + revision integer NOT NULL, + previous_package_id character varying NOT NULL, + previous_version character varying NOT NULL, + previous_revision integer NOT NULL, + comparison_id character varying NOT NULL, + operation_types jsonb, + refs character varying[], + open_count bigint NOT NULL, + last_active timestamp without time zone NOT NULL, + no_content boolean NOT NULL, + builder_version character varying, + CONSTRAINT version_comparison_comparison_id_key UNIQUE (comparison_id), + CONSTRAINT version_comparison_pkey PRIMARY KEY (package_id, version, revision, previous_package_id, previous_version, previous_revision) +); +ALTER TABLE public.version_comparison OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.operation_comparison ( + package_id character varying NOT NULL, + version character varying NOT NULL, + revision integer NOT NULL, + previous_package_id character varying NOT NULL, + previous_version character varying NOT NULL, + previous_revision integer NOT NULL, + operation_id character varying NOT NULL, + data_hash character varying, + previous_data_hash character varying, + changes_summary jsonb, + changes jsonb, + comparison_id character varying, + CONSTRAINT "FK_version_comparison" FOREIGN KEY (comparison_id) REFERENCES public.version_comparison(comparison_id) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.operation_comparison OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.operation_group ( + package_id character varying NOT NULL, + version character varying NOT NULL, + revision integer NOT NULL, + api_type character varying NOT NULL, + group_name character varying NOT NULL, + autogenerated boolean NOT NULL, + group_id character varying NOT NULL, + description character varying, + template_checksum character varying, + template_filename character varying, + CONSTRAINT operation_group_group_id_key UNIQUE (group_id), + CONSTRAINT operation_group_pkey PRIMARY KEY (package_id, version, revision, api_type, group_name), + CONSTRAINT "FK_published_version" FOREIGN KEY (package_id,"version",revision) REFERENCES public.published_version(package_id,"version",revision) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.operation_group OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.grouped_operation ( + group_id character varying NOT NULL, + package_id character varying NOT NULL, + version character varying NOT NULL, revision integer NOT NULL, - checksum varchar NOT NULL, - index integer NOT NULL DEFAULT 0, - file_id varchar NOT NULL, - path varchar NOT NULL, - slug varchar NOT NULL, - data_type varchar NOT NULL, -- OpenAPI / Swagger / MD - name varchar NOT NULL, - description text NULL -) -; - -CREATE TABLE user_data -( - user_id varchar NOT NULL, - email varchar NULL, - name varchar NULL, - avatar_url varchar NULL -) -; - -CREATE TABLE user_integration -( - user_id varchar NOT NULL, - integration_type varchar NOT NULL, -- GitLab - key text NULL -) -; - -CREATE TABLE favorite_projects -( - user_id varchar NOT NULL, - project_id varchar NOT NULL -) -; - -/* Create Primary Keys, Indexes, Uniques, Checks */ - -ALTER TABLE branch_draft_content ADD CONSTRAINT "PK_branch_draft_content" - PRIMARY KEY (project_id,branch_name,file_id) -; - -ALTER TABLE branch_draft_reference ADD CONSTRAINT "PK_branch_draft_reference" - PRIMARY KEY (branch_name,project_id, reference_project_id, reference_version, relation_type) -; - -ALTER TABLE project ADD CONSTRAINT "PK_project" - PRIMARY KEY (id) -; - -ALTER TABLE published_data ADD CONSTRAINT "PK_published_data" - PRIMARY KEY (checksum,project_id) -; - -ALTER TABLE published_version ADD CONSTRAINT "PK_published_version" - PRIMARY KEY (project_id,version,revision) -; - -ALTER TABLE published_version_reference ADD CONSTRAINT "PK_published_version_reference" - PRIMARY KEY (project_id,version,revision,reference_id,relation_type,reference_version) -; - -ALTER TABLE user_data ADD CONSTRAINT "PK_user_data" - PRIMARY KEY (user_id) -; - -ALTER TABLE user_integration ADD CONSTRAINT "PK_user_integration" - PRIMARY KEY (user_id, integration_type) -; - -ALTER TABLE favorite_projects ADD CONSTRAINT "PK_favorite_projects" - PRIMARY KEY (user_id, project_id) -; - -/* Create Foreign Key Constraints */ - -ALTER TABLE branch_draft_content ADD CONSTRAINT "FK_project" - FOREIGN KEY (project_id) REFERENCES project (id) ON DELETE Restrict ON UPDATE Cascade -; - -ALTER TABLE branch_draft_reference ADD CONSTRAINT "FK_project" - FOREIGN KEY (project_id) REFERENCES project (id) ON DELETE Restrict ON UPDATE Cascade -; - -ALTER TABLE project ADD CONSTRAINT "FK_parent_project_id" - FOREIGN KEY (parent_id) REFERENCES project (id) ON DELETE Restrict ON UPDATE Cascade -; - -ALTER TABLE published_version ADD CONSTRAINT "FK_project" - FOREIGN KEY (project_id) REFERENCES project (id) ON DELETE Restrict ON UPDATE Cascade -; - -ALTER TABLE published_version_reference ADD CONSTRAINT "FK_published_version" - FOREIGN KEY (project_id,version,revision) REFERENCES published_version (project_id,version,revision) ON DELETE Restrict ON UPDATE Cascade -; - -ALTER TABLE published_version_revision_content ADD CONSTRAINT "FK_published_data" - FOREIGN KEY (checksum,project_id) REFERENCES published_data (checksum,project_id) ON DELETE Restrict ON UPDATE Cascade -; - -ALTER TABLE published_version_revision_content ADD CONSTRAINT "FK_published_version_revision" - FOREIGN KEY (project_id,version,revision) REFERENCES published_version (project_id,version,revision) ON DELETE Restrict ON UPDATE Cascade -; - -/*ALTER TABLE user_integration ADD CONSTRAINT "FK_user_data" - FOREIGN KEY (user_id) REFERENCES user_data (user_id) ON DELETE Restrict ON UPDATE Cascade -;*/ - -/* Create Table Comments, Sequences for Autonumber Columns */ - -COMMENT ON COLUMN branch_draft_content.data_type - IS 'OpenAPI / Swagger / MD' -; - -COMMENT ON COLUMN branch_draft_content.media_type - IS 'HTTP media-type' -; - -COMMENT ON COLUMN branch_draft_reference.relation_type - IS 'INCLUDE / DEPEND' -; - -COMMENT ON COLUMN project.kind - IS 'PROJECT / GROUP' -; + operation_id character varying NOT NULL, + CONSTRAINT "FK_operation" FOREIGN KEY (package_id,"version",revision,operation_id) REFERENCES public.operation(package_id,"version",revision,operation_id) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT "FK_operation_group" FOREIGN KEY (group_id) REFERENCES public.operation_group(group_id) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.grouped_operation OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.operation_group_history ( + group_id character varying, + action character varying, + data jsonb, + user_id character varying, + date timestamp without time zone, + automatic boolean +); +ALTER TABLE public.operation_group_history OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.operation_group_publication ( + publish_id character varying NOT NULL, + status character varying, + details character varying, + CONSTRAINT operation_group_publication_pkey PRIMARY KEY (publish_id) +); +ALTER TABLE public.operation_group_publication OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.operation_group_template ( + checksum character varying NOT NULL, + template bytea, + CONSTRAINT operation_group_template_pkey PRIMARY KEY (checksum) +); +ALTER TABLE public.operation_group_template OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.operation_open_count ( + package_id character varying NOT NULL, + version character varying NOT NULL, + operation_id character varying NOT NULL, + open_count bigint, + CONSTRAINT operation_open_count_pkey PRIMARY KEY (package_id, version, operation_id) +); +ALTER TABLE public.operation_open_count OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.package_member_role ( + user_id character varying NOT NULL, + package_id character varying NOT NULL, + created_by character varying NOT NULL, + created_at timestamp without time zone NOT NULL, + updated_by character varying, + updated_at timestamp without time zone, + roles character varying[] DEFAULT '{}'::character varying[], + CONSTRAINT "PK_package_member_role" PRIMARY KEY (package_id, user_id), + CONSTRAINT "FK_package_group" FOREIGN KEY (package_id) REFERENCES public.package_group(id) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.package_member_role OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.package_service ( + package_id character varying NOT NULL, + service_name character varying NOT NULL, + workspace_id character varying NOT NULL, + CONSTRAINT "PK_package_service" PRIMARY KEY (workspace_id, package_id, service_name), + CONSTRAINT package_service_workspace_id_service_name_key UNIQUE (workspace_id, service_name), + CONSTRAINT "FK_package_group" FOREIGN KEY (package_id) REFERENCES public.package_group(id) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT "FK_package_group_workspace" FOREIGN KEY (workspace_id) REFERENCES public.package_group(id) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.package_service OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.package_transition ( + old_package_id character varying NOT NULL, + new_package_id character varying NOT NULL +); +ALTER TABLE public.package_transition OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.published_content_messages ( + checksum character varying NOT NULL, + messages jsonb, + CONSTRAINT "PK_published_content_messages" PRIMARY KEY (checksum) +); +ALTER TABLE public.published_content_messages OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.published_data ( + package_id character varying NOT NULL, + checksum character varying NOT NULL, + media_type character varying NOT NULL, + data bytea NOT NULL, + CONSTRAINT "PK_published_data" PRIMARY KEY (checksum, package_id), + CONSTRAINT published_data_package_group_id_fk FOREIGN KEY (package_id) REFERENCES public.package_group(id) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.published_data OWNER TO apihub; + +COMMENT ON COLUMN public.published_data.media_type IS 'HTTP media-type'; + +CREATE TABLE IF NOT EXISTS public.published_document_open_count ( + package_id character varying NOT NULL, + version character varying NOT NULL, + slug character varying NOT NULL, + open_count bigint, + CONSTRAINT published_document_open_count_pkey PRIMARY KEY (package_id, version, slug), + CONSTRAINT published_document_open_count_package_group_id_fk FOREIGN KEY (package_id) REFERENCES public.package_group(id) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.published_document_open_count OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.published_sources ( + package_id character varying NOT NULL, + version character varying NOT NULL, + revision integer NOT NULL, + config bytea, + metadata bytea, + archive_checksum character varying, + CONSTRAINT "FK_published_sources_version_revision" FOREIGN KEY (package_id,"version",revision) REFERENCES public.published_version(package_id,"version",revision) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.published_sources OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.published_sources_archives ( + checksum character varying NOT NULL, + data bytea, + CONSTRAINT published_sources_archives_pk PRIMARY KEY (checksum) +); +ALTER TABLE public.published_sources_archives OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.published_version_open_count ( + package_id character varying NOT NULL, + version character varying NOT NULL, + open_count bigint, + CONSTRAINT published_version_open_count_pkey PRIMARY KEY (package_id, version), + CONSTRAINT published_version_open_count_package_group_id_fk FOREIGN KEY (package_id) REFERENCES public.package_group(id) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.published_version_open_count OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.published_version_reference ( + package_id character varying NOT NULL, + version character varying NOT NULL, + revision integer NOT NULL, + reference_id character varying NOT NULL, + reference_version character varying NOT NULL, + reference_revision integer DEFAULT 0 NOT NULL, + parent_reference_id character varying DEFAULT ''::character varying NOT NULL, + parent_reference_version character varying DEFAULT ''::character varying NOT NULL, + parent_reference_revision integer DEFAULT 0 NOT NULL, + excluded boolean DEFAULT false, + CONSTRAINT "PK_published_version_reference" PRIMARY KEY (package_id, version, revision, reference_id, reference_version, reference_revision, parent_reference_id, parent_reference_version, parent_reference_revision), + CONSTRAINT "FK_published_version" FOREIGN KEY (package_id,"version",revision) REFERENCES public.published_version(package_id,"version",revision) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.published_version_reference OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.published_version_revision_content ( + package_id character varying NOT NULL, + version character varying NOT NULL, + revision integer NOT NULL, + checksum character varying NOT NULL, + index integer DEFAULT 0 NOT NULL, + file_id character varying NOT NULL, + path character varying, + slug character varying NOT NULL, + data_type character varying NOT NULL, + name character varying NOT NULL, + metadata jsonb, + title character varying, + format character varying, + operation_ids character varying[], + filename character varying, + CONSTRAINT published_version_revision_content_pk PRIMARY KEY (package_id, version, revision, file_id), + CONSTRAINT "FK_published_data" FOREIGN KEY (checksum,package_id) REFERENCES public.published_data(checksum,package_id) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT "FK_published_version_revision" FOREIGN KEY (package_id,"version",revision) REFERENCES public.published_version(package_id,"version",revision) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.published_version_revision_content OWNER TO apihub; +COMMENT ON COLUMN public.published_version_revision_content.data_type IS 'OpenAPI / Swagger / MD'; + +CREATE TABLE IF NOT EXISTS public.published_version_validation ( + package_id character varying NOT NULL, + version character varying NOT NULL, + revision integer NOT NULL, + changelog jsonb, + spectral jsonb, + bwc jsonb, + CONSTRAINT "PK_published_version_validation" PRIMARY KEY (package_id, version, revision), + CONSTRAINT "FK_published_version_validation" FOREIGN KEY (package_id,"version",revision) REFERENCES public.published_version(package_id,"version",revision) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.published_version_validation OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.role ( + id character varying NOT NULL, + role character varying NOT NULL, + rank integer NOT NULL, + permissions character varying[], + read_only boolean, + CONSTRAINT role_pkey PRIMARY KEY (id) +); +ALTER TABLE public.role OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.shared_url_info ( + package_id character varying NOT NULL, + version character varying NOT NULL, + file_id character varying NOT NULL, + shared_id character varying NOT NULL, + CONSTRAINT "PK_shared_url_info" PRIMARY KEY (shared_id), + CONSTRAINT shared_url_info__file_info UNIQUE (package_id, version, file_id), + CONSTRAINT shared_url_info_package_group_id_fk FOREIGN KEY (package_id) REFERENCES public.package_group(id) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.shared_url_info OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.system_role ( + user_id character varying NOT NULL, + role character varying NOT NULL, + CONSTRAINT "PK_system_role" PRIMARY KEY (user_id) +); +ALTER TABLE public.system_role OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.transformed_content_data ( + package_id character varying NOT NULL, + version character varying NOT NULL, + revision integer NOT NULL, + api_type character varying NOT NULL, + group_id character varying NOT NULL, + data bytea, + documents_info jsonb, + build_type character varying DEFAULT 'documentGroup'::character varying NOT NULL, + format character varying DEFAULT 'json'::character varying NOT NULL, + CONSTRAINT transformed_content_data_pkey PRIMARY KEY (package_id, version, revision, api_type, group_id, build_type, format), + CONSTRAINT "FK_transformed_content_data_operation_group" FOREIGN KEY (group_id) REFERENCES public.operation_group(group_id) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.transformed_content_data OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.ts_graphql_operation_data ( + data_hash character varying NOT NULL, + scope_argument tsvector, + scope_property tsvector, + scope_annotation tsvector, + CONSTRAINT pk_ts_graphql_operation_data PRIMARY KEY (data_hash) +); +ALTER TABLE public.ts_graphql_operation_data OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.ts_operation_data ( + data_hash character varying NOT NULL, + scope_all tsvector, + CONSTRAINT pk_ts_operation_data PRIMARY KEY (data_hash) +); +ALTER TABLE public.ts_operation_data OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.ts_rest_operation_data ( + data_hash character varying NOT NULL, + scope_request tsvector, + scope_response tsvector, + scope_annotation tsvector, + scope_properties tsvector, + scope_examples tsvector, + CONSTRAINT pk_ts_rest_operation_data PRIMARY KEY (data_hash), + CONSTRAINT "FK_operation_data" FOREIGN KEY (data_hash) REFERENCES public.operation_data(data_hash) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.ts_rest_operation_data OWNER TO apihub; + +CREATE TABLE IF NOT EXISTS public.user_avatar_data ( + user_id character varying NOT NULL, + avatar bytea, + checksum bytea, + CONSTRAINT "PK_user_avatar_data" PRIMARY KEY (user_id) +); +ALTER TABLE public.user_avatar_data OWNER TO apihub; -COMMENT ON COLUMN project.parent_id - IS 'Only for the GROUP kind' -; +CREATE TABLE IF NOT EXISTS public.user_integration ( + user_id character varying NOT NULL, + integration_type character varying NOT NULL, + key text, + is_revoked boolean DEFAULT false, + refresh_token character varying, + expires_at timestamp without time zone, + redirect_uri character varying, + failed_refresh_attempts integer DEFAULT 0, + CONSTRAINT "PK_user_integration" PRIMARY KEY (user_id, integration_type) +); +ALTER TABLE public.user_integration OWNER TO apihub; +COMMENT ON COLUMN public.user_integration.integration_type IS 'GitLab'; -COMMENT ON COLUMN project.integration_type - IS 'GitLab / Local storage' -; +CREATE TABLE IF NOT EXISTS public.versions_cleanup_run ( + run_id uuid NOT NULL, + started_at timestamp without time zone DEFAULT now() NOT NULL, + package_id character varying NOT NULL, + delete_before timestamp without time zone NOT NULL, + status character varying NOT NULL, + details character varying, + deleted_items integer, + CONSTRAINT pk_versions_cleanup_run PRIMARY KEY (run_id), + CONSTRAINT versions_cleanup_run_package_group_id_fk FOREIGN KEY (package_id) REFERENCES public.package_group(id) ON DELETE CASCADE ON UPDATE CASCADE +); +ALTER TABLE public.versions_cleanup_run OWNER TO apihub; -COMMENT ON COLUMN published_data.media_type - IS 'HTTP media-type' -; +CREATE TABLE IF NOT EXISTS public.csv_dashboard_publication( + publish_id varchar, + status varchar, + message varchar, + csv_report bytea, + PRIMARY KEY(publish_id) +); +ALTER TABLE public.csv_dashboard_publication OWNER TO apihub; -COMMENT ON COLUMN published_version.status - IS 'DRAFT / APPROVED / RELEASED / ARCHIVE' -; +-- initial data for apihub_api_keys table +INSERT INTO public.apihub_api_keys VALUES ('api-key_766e637d-a59d-401a-af3c-277b5204fdf7', '*', 'system_api_key', 'adminatexample-com', '2024-12-13 08:08:50.66232', NULL, NULL, 'ecda7f95b0a6907d28792346b637758294458e9f44530ad6ae4172a31836e4d5', '{"System administrator"}', NULL); -COMMENT ON COLUMN published_version_reference.relation_type - IS 'INCLUDE / DEPEND' -; +-- initial data for ROLE table +INSERT INTO public.role VALUES ('admin', 'Admin', 1000, '{read,create_and_update_package,delete_package,manage_draft_version,manage_release_version,manage_archived_version,user_access_management,access_token_management}', true); +INSERT INTO public.role VALUES ('release-manager', 'Release Manager', 4, '{read,manage_release_version}', false); +INSERT INTO public.role VALUES ('owner', 'Owner', 3, '{read,create_and_update_package,delete_package,manage_draft_version,manage_release_version,manage_archived_version}', false); +INSERT INTO public.role VALUES ('viewer', 'Viewer', 1, '{read}', true); +INSERT INTO public.role VALUES ('none', 'None', 0, '{}', true); +INSERT INTO public.role VALUES ('editor', 'Editor', 2, '{read,manage_draft_version,manage_release_version,manage_archived_version}', false); -COMMENT ON COLUMN published_version_revision_content.data_type - IS 'OpenAPI / Swagger / MD' -; -COMMENT ON COLUMN user_integration.integration_type - IS 'GitLab' -; +INSERT INTO public.schema_migrations VALUES (1, false); +INSERT INTO public.system_role VALUES ('adminatexample-com', 'System administrator'); +INSERT INTO public.user_data VALUES ('adminatexample-com', 'admin@example.com', 'admin@example.com', NULL, '\x243261243130246e7457765776544652497459327836667a517446787531374e4b6e636e4665625a384b6e324f587945466431654c2f6b712f757771', 'adminatexample-com'); +-- extra data for activity tracking +INSERT INTO public.package_group +(id, kind, "name", alias, parent_id, image_url, description, deleted_at, created_at, + created_by, deleted_by, default_role, default_released_version, service_name, release_version_pattern, + exclude_from_search, rest_grouping_prefix) +VALUES('*', 'workspace', 'Dev', 'dev', NULL, NULL, NULL, '2023-08-25 07:35:13.549', '2023-08-24 13:07:10.020', + 'aldo0322', 'aldo0322', 'viewer', NULL, NULL, NULL, + false, NULL); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/20_drafted_branch_constraint.down.sql b/qubership-apihub-service/resources/migrations/20_drafted_branch_constraint.down.sql deleted file mode 100644 index 4f7958d..0000000 --- a/qubership-apihub-service/resources/migrations/20_drafted_branch_constraint.down.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE drafted_branches DROP CONSTRAINT "FK_project"; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/20_drafted_branch_constraint.up.sql b/qubership-apihub-service/resources/migrations/20_drafted_branch_constraint.up.sql deleted file mode 100644 index 4be00cc..0000000 --- a/qubership-apihub-service/resources/migrations/20_drafted_branch_constraint.up.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE drafted_branches ADD CONSTRAINT "FK_project" - FOREIGN KEY (project_id) REFERENCES project (id) ON DELETE Cascade ON UPDATE Cascade -; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/21_cascade_deletion.down.sql b/qubership-apihub-service/resources/migrations/21_cascade_deletion.down.sql deleted file mode 100644 index 270619c..0000000 --- a/qubership-apihub-service/resources/migrations/21_cascade_deletion.down.sql +++ /dev/null @@ -1,43 +0,0 @@ - -ALTER TABLE branch_draft_content DROP CONSTRAINT "FK_project"; -ALTER TABLE branch_draft_content ADD CONSTRAINT "FK_project" - FOREIGN KEY (project_id) REFERENCES project (id) ON DELETE Restrict ON UPDATE Cascade -; - -ALTER TABLE branch_draft_reference DROP CONSTRAINT "FK_project"; -ALTER TABLE branch_draft_reference ADD CONSTRAINT "FK_project" - FOREIGN KEY (project_id) REFERENCES project (id) ON DELETE Restrict ON UPDATE Cascade -; - -ALTER TABLE project DROP CONSTRAINT "FK_parent_project_id"; -ALTER TABLE project ADD CONSTRAINT "FK_parent_project_id" - FOREIGN KEY (parent_id) REFERENCES project (id) ON DELETE Restrict ON UPDATE Cascade -; - -ALTER TABLE published_version DROP CONSTRAINT "FK_project"; -ALTER TABLE published_version ADD CONSTRAINT "FK_project" - FOREIGN KEY (project_id) REFERENCES project (id) ON DELETE Restrict ON UPDATE Cascade -; - -ALTER TABLE published_version_reference DROP CONSTRAINT "FK_published_version"; -ALTER TABLE published_version_reference ADD CONSTRAINT "FK_published_version" - FOREIGN KEY (project_id,version,revision) REFERENCES published_version (project_id,version,revision) ON DELETE Restrict ON UPDATE Cascade -; - -ALTER TABLE published_version_revision_content DROP CONSTRAINT "FK_published_data"; -ALTER TABLE published_version_revision_content ADD CONSTRAINT "FK_published_data" - FOREIGN KEY (checksum,project_id) REFERENCES published_data (checksum,project_id) ON DELETE Restrict ON UPDATE Cascade -; - -ALTER TABLE published_version_revision_content DROP CONSTRAINT "FK_published_version_revision"; -ALTER TABLE published_version_revision_content ADD CONSTRAINT "FK_published_version_revision" - FOREIGN KEY (project_id,version,revision) REFERENCES published_version (project_id,version,revision) ON DELETE Restrict ON UPDATE Cascade -; - -ALTER TABLE published_sources DROP CONSTRAINT "FK_published_sources_data"; -ALTER TABLE published_sources ADD CONSTRAINT "FK_published_sources_data" - FOREIGN KEY (checksum,project_id) REFERENCES published_sources_data (checksum,project_id) ON DELETE Restrict ON UPDATE Cascade; - -ALTER TABLE published_sources DROP CONSTRAINT "FK_published_sources_version_revision"; -ALTER TABLE published_sources ADD CONSTRAINT "FK_published_sources_version_revision" - FOREIGN KEY (project_id,version,revision) REFERENCES published_version (project_id,version,revision) ON DELETE Restrict ON UPDATE Cascade; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/21_cascade_deletion.up.sql b/qubership-apihub-service/resources/migrations/21_cascade_deletion.up.sql deleted file mode 100644 index dee9e1f..0000000 --- a/qubership-apihub-service/resources/migrations/21_cascade_deletion.up.sql +++ /dev/null @@ -1,43 +0,0 @@ - -ALTER TABLE branch_draft_content DROP CONSTRAINT "FK_project"; -ALTER TABLE branch_draft_content ADD CONSTRAINT "FK_project" - FOREIGN KEY (project_id) REFERENCES project (id) ON DELETE Cascade ON UPDATE Cascade -; - -ALTER TABLE branch_draft_reference DROP CONSTRAINT "FK_project"; -ALTER TABLE branch_draft_reference ADD CONSTRAINT "FK_project" - FOREIGN KEY (project_id) REFERENCES project (id) ON DELETE Cascade ON UPDATE Cascade -; - -ALTER TABLE project DROP CONSTRAINT "FK_parent_project_id"; -ALTER TABLE project ADD CONSTRAINT "FK_parent_project_id" - FOREIGN KEY (parent_id) REFERENCES project (id) ON DELETE Cascade ON UPDATE Cascade -; - -ALTER TABLE published_version DROP CONSTRAINT "FK_project"; -ALTER TABLE published_version ADD CONSTRAINT "FK_project" - FOREIGN KEY (project_id) REFERENCES project (id) ON DELETE Cascade ON UPDATE Cascade -; - -ALTER TABLE published_version_reference DROP CONSTRAINT "FK_published_version"; -ALTER TABLE published_version_reference ADD CONSTRAINT "FK_published_version" - FOREIGN KEY (project_id,version,revision) REFERENCES published_version (project_id,version,revision) ON DELETE Cascade ON UPDATE Cascade -; - -ALTER TABLE published_version_revision_content DROP CONSTRAINT "FK_published_data"; -ALTER TABLE published_version_revision_content ADD CONSTRAINT "FK_published_data" - FOREIGN KEY (checksum,project_id) REFERENCES published_data (checksum,project_id) ON DELETE Cascade ON UPDATE Cascade -; - -ALTER TABLE published_version_revision_content DROP CONSTRAINT "FK_published_version_revision"; -ALTER TABLE published_version_revision_content ADD CONSTRAINT "FK_published_version_revision" - FOREIGN KEY (project_id,version,revision) REFERENCES published_version (project_id,version,revision) ON DELETE Cascade ON UPDATE Cascade -; - -ALTER TABLE published_sources DROP CONSTRAINT "FK_published_sources_data"; -ALTER TABLE published_sources ADD CONSTRAINT "FK_published_sources_data" - FOREIGN KEY (checksum,project_id) REFERENCES published_sources_data (checksum,project_id) ON DELETE Cascade ON UPDATE Cascade; - -ALTER TABLE published_sources DROP CONSTRAINT "FK_published_sources_version_revision"; -ALTER TABLE published_sources ADD CONSTRAINT "FK_published_sources_version_revision" - FOREIGN KEY (project_id,version,revision) REFERENCES published_version (project_id,version,revision) ON DELETE Cascade ON UPDATE Cascade; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/22_previous_version.down.sql b/qubership-apihub-service/resources/migrations/22_previous_version.down.sql deleted file mode 100644 index e09af1b..0000000 --- a/qubership-apihub-service/resources/migrations/22_previous_version.down.sql +++ /dev/null @@ -1 +0,0 @@ -alter table published_version drop column previous_version; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/22_previous_version.up.sql b/qubership-apihub-service/resources/migrations/22_previous_version.up.sql deleted file mode 100644 index 5b14a73..0000000 --- a/qubership-apihub-service/resources/migrations/22_previous_version.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table published_version -ADD COLUMN previous_version varchar; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/23_media_type_datafix.down.sql b/qubership-apihub-service/resources/migrations/23_media_type_datafix.down.sql deleted file mode 100644 index cd3f056..0000000 --- a/qubership-apihub-service/resources/migrations/23_media_type_datafix.down.sql +++ /dev/null @@ -1,6 +0,0 @@ -update published_data -set media_type = 'text/plain' -where media_type in ('application/zip', 'image/jpeg', 'image/png'); -update published_data -set media_type = 'application/json' -where checksum in (select checksum from published_version_revision_content where file_id ilike '%.json'); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/23_media_type_datafix.up.sql b/qubership-apihub-service/resources/migrations/23_media_type_datafix.up.sql deleted file mode 100644 index 4ff3f86..0000000 --- a/qubership-apihub-service/resources/migrations/23_media_type_datafix.up.sql +++ /dev/null @@ -1,12 +0,0 @@ -update published_data -set media_type = 'application/zip' -where checksum in (select checksum from published_version_revision_content where file_id ilike '%.docx'); -update published_data -set media_type = 'image/jpeg' -where checksum in (select checksum from published_version_revision_content where file_id ilike '%.jpg'); -update published_data -set media_type = 'image/png' -where checksum in (select checksum from published_version_revision_content where file_id ilike '%.png'); -update published_data -set media_type = 'text/plain' -where checksum in (select checksum from published_version_revision_content where file_id ilike '%.json'); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/24_fill_versions_repository_url.down.sql b/qubership-apihub-service/resources/migrations/24_fill_versions_repository_url.down.sql deleted file mode 100644 index 4c01a9f..0000000 --- a/qubership-apihub-service/resources/migrations/24_fill_versions_repository_url.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -update published_version v -set metadata = metadata #- '{repository_url}'; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/24_fill_versions_repository_url.up.sql b/qubership-apihub-service/resources/migrations/24_fill_versions_repository_url.up.sql deleted file mode 100644 index e274a28..0000000 --- a/qubership-apihub-service/resources/migrations/24_fill_versions_repository_url.up.sql +++ /dev/null @@ -1,4 +0,0 @@ -update published_version v -set metadata = metadata || jsonb_build_object('repository_url', p.repository_url) -from project p -where p.id = v.project_id; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/25_package_group.up.sql b/qubership-apihub-service/resources/migrations/25_package_group.up.sql deleted file mode 100644 index 9748bd5..0000000 --- a/qubership-apihub-service/resources/migrations/25_package_group.up.sql +++ /dev/null @@ -1,40 +0,0 @@ -DROP TABLE IF EXISTS package_group; -ALTER TABLE published_version DROP CONSTRAINT "FK_project"; -ALTER TABLE apihub_api_keys DROP CONSTRAINT "FK_project"; -ALTER TABLE project DROP CONSTRAINT "FK_parent_project_id"; - -CREATE TABLE package_group as SELECT * FROM project; - -delete from project where kind = 'group'; - -ALTER TABLE package_group ADD CONSTRAINT "PK_project_group" - PRIMARY KEY (id) -; - -UPDATE package_group SET kind = 'package' where kind = 'project'; - -ALTER TABLE package_group - DROP COLUMN repository_url, - DROP COLUMN repository_name, - DROP COLUMN repository_id, - DROP COLUMN integration_type, - DROP COLUMN default_branch, - DROP COLUMN default_folder; - -ALTER TABLE package_group - ADD COLUMN created_at timestamp without time zone, - ADD COLUMN created_by varchar, - ADD COLUMN deleted_by varchar; - -ALTER TABLE package_group - RENAME COLUMN delete_date to deleted_at; - -ALTER TABLE package_group ADD CONSTRAINT "FK_parent_package_group" - FOREIGN KEY (parent_id) REFERENCES package_group (id) ON DELETE Cascade ON UPDATE Cascade -; -ALTER TABLE published_version ADD CONSTRAINT "FK_package_group" - FOREIGN KEY (project_id) REFERENCES package_group (id) ON DELETE Cascade ON UPDATE Cascade -; -ALTER TABLE apihub_api_keys ADD CONSTRAINT "FK_package_group" - FOREIGN KEY (project_id) REFERENCES package_group (id) ON DELETE Cascade ON UPDATE Cascade -; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/26_naming_refactoring.down.sql b/qubership-apihub-service/resources/migrations/26_naming_refactoring.down.sql deleted file mode 100644 index dd751a1..0000000 --- a/qubership-apihub-service/resources/migrations/26_naming_refactoring.down.sql +++ /dev/null @@ -1,47 +0,0 @@ -ALTER TABLE project - ADD COLUMN kind varchar, - ADD COLUMN image_url varchar; - -ALTER TABLE project - DROP COLUMN deleted_by; - -ALTER TABLE project - RENAME COLUMN group_id to parent_id; -ALTER TABLE project - RENAME COLUMN deleted_at to delete_date; - -ALTER TABLE branch_draft_reference - RENAME COLUMN reference_package_id to reference_project_id; - -ALTER TABLE favorites RENAME to favorite_projects; - -ALTER TABLE favorite_projects - RENAME COLUMN id to project_id; - -ALTER TABLE published_version - RENAME COLUMN package_id to project_id; -ALTER TABLE published_version - RENAME COLUMN published_at to publish_date; -ALTER TABLE published_version - RENAME COLUMN deleted_at to delete_date; - -ALTER TABLE published_version_revision_content - RENAME COLUMN package_id to project_id; - -ALTER TABLE published_data - RENAME COLUMN package_id to project_id; - -ALTER TABLE published_version_reference - RENAME COLUMN package_id to project_id; - -ALTER TABLE shared_url_info - RENAME COLUMN package_id to project_id; - -ALTER TABLE published_sources - RENAME COLUMN package_id to project_id; - -ALTER TABLE published_sources_data - RENAME COLUMN package_id to project_id; - -ALTER TABLE apihub_api_keys - RENAME COLUMN package_id to project_id; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/26_naming_refactoring.up.sql b/qubership-apihub-service/resources/migrations/26_naming_refactoring.up.sql deleted file mode 100644 index 8c0cba4..0000000 --- a/qubership-apihub-service/resources/migrations/26_naming_refactoring.up.sql +++ /dev/null @@ -1,47 +0,0 @@ -ALTER TABLE project - DROP COLUMN kind, - DROP COLUMN image_url; - -ALTER TABLE project - ADD COLUMN deleted_by varchar; - -ALTER TABLE project - RENAME COLUMN parent_id to group_id; -ALTER TABLE project - RENAME COLUMN delete_date to deleted_at; - -ALTER TABLE branch_draft_reference - RENAME COLUMN reference_project_id to reference_package_id; - -ALTER TABLE favorite_projects RENAME to favorites; - -ALTER TABLE favorites - RENAME COLUMN project_id to id; - -ALTER TABLE published_version - RENAME COLUMN project_id to package_id; -ALTER TABLE published_version - RENAME COLUMN publish_date to published_at; -ALTER TABLE published_version - RENAME COLUMN delete_date to deleted_at; - -ALTER TABLE published_version_revision_content - RENAME COLUMN project_id to package_id; - -ALTER TABLE published_data - RENAME COLUMN project_id to package_id; - -ALTER TABLE published_version_reference - RENAME COLUMN project_id to package_id; - -ALTER TABLE shared_url_info - RENAME COLUMN project_id to package_id; - -ALTER TABLE published_sources - RENAME COLUMN project_id to package_id; - -ALTER TABLE published_sources_data - RENAME COLUMN project_id to package_id; - -ALTER TABLE apihub_api_keys - RENAME COLUMN project_id to package_id; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/27_previous_package_id.down.sql b/qubership-apihub-service/resources/migrations/27_previous_package_id.down.sql deleted file mode 100644 index 2115572..0000000 --- a/qubership-apihub-service/resources/migrations/27_previous_package_id.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE published_version - DROP COLUMN previous_version_package_id; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/27_previous_package_id.up.sql b/qubership-apihub-service/resources/migrations/27_previous_package_id.up.sql deleted file mode 100644 index 94af14e..0000000 --- a/qubership-apihub-service/resources/migrations/27_previous_package_id.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE published_version - ADD COLUMN previous_version_package_id varchar; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/28_title_field.down.sql b/qubership-apihub-service/resources/migrations/28_title_field.down.sql deleted file mode 100644 index d4d98b9..0000000 --- a/qubership-apihub-service/resources/migrations/28_title_field.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE published_version_revision_content - DROP COLUMN title; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/28_title_field.up.sql b/qubership-apihub-service/resources/migrations/28_title_field.up.sql deleted file mode 100644 index 723b3bd..0000000 --- a/qubership-apihub-service/resources/migrations/28_title_field.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE published_version_revision_content - ADD COLUMN title varchar; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/29_agent_config.down.sql b/qubership-apihub-service/resources/migrations/29_agent_config.down.sql deleted file mode 100644 index 94a537f..0000000 --- a/qubership-apihub-service/resources/migrations/29_agent_config.down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS agent_config CASCADE; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/29_agent_config.up.sql b/qubership-apihub-service/resources/migrations/29_agent_config.up.sql deleted file mode 100644 index 17ab4f0..0000000 --- a/qubership-apihub-service/resources/migrations/29_agent_config.up.sql +++ /dev/null @@ -1,10 +0,0 @@ -CREATE TABLE agent_config -( - cloud varchar NOT NULL, - namespace varchar NOT NULL, - config jsonb -); - -ALTER TABLE agent_config ADD CONSTRAINT "PK_agent_config" - PRIMARY KEY (cloud, namespace) -; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/2_projectsRepoAndUrl.down.sql b/qubership-apihub-service/resources/migrations/2_projectsRepoAndUrl.down.sql deleted file mode 100644 index 37e3c18..0000000 --- a/qubership-apihub-service/resources/migrations/2_projectsRepoAndUrl.down.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE project -DROP COLUMN repository_name, -DROP COLUMN repository_url; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/2_projectsRepoAndUrl.up.sql b/qubership-apihub-service/resources/migrations/2_projectsRepoAndUrl.up.sql deleted file mode 100644 index e882dc1..0000000 --- a/qubership-apihub-service/resources/migrations/2_projectsRepoAndUrl.up.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE project -ADD COLUMN repository_name VARCHAR, -ADD COLUMN repository_url VARCHAR; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/30_published_fields.down.sql b/qubership-apihub-service/resources/migrations/30_published_fields.down.sql deleted file mode 100644 index 7988ecc..0000000 --- a/qubership-apihub-service/resources/migrations/30_published_fields.down.sql +++ /dev/null @@ -1,5 +0,0 @@ -ALTER TABLE published_version_revision_content -DROP COLUMN format; - -ALTER TABLE published_version_revision_content -ADD COLUMN description text; diff --git a/qubership-apihub-service/resources/migrations/30_published_fields.up.sql b/qubership-apihub-service/resources/migrations/30_published_fields.up.sql deleted file mode 100644 index b57dbff..0000000 --- a/qubership-apihub-service/resources/migrations/30_published_fields.up.sql +++ /dev/null @@ -1,17 +0,0 @@ -ALTER TABLE published_version_revision_content -DROP COLUMN description; - -ALTER TABLE published_version_revision_content -ADD COLUMN format varchar; - -update published_version_revision_content -set format = 'json' where file_id ilike '%.json'; - -update published_version_revision_content -set format = 'yaml' where file_id ilike '%.yaml' or file_id ilike '%.yml'; - -update published_version_revision_content -set format = 'md' where file_id ilike '%.md' or file_id ilike '%.markdown'; - -update published_version_revision_content -set format = 'unknown' where format is null; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/31_unknown_type_datafix.up.sql b/qubership-apihub-service/resources/migrations/31_unknown_type_datafix.up.sql deleted file mode 100644 index c1a7d32..0000000 --- a/qubership-apihub-service/resources/migrations/31_unknown_type_datafix.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -update published_version_revision_content -set data_type = 'unknown' where data_type = 'unknown-yaml' or data_type = 'unknown-json' or data_type = 'unknown-text'; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/32_version_folder.down.sql b/qubership-apihub-service/resources/migrations/32_version_folder.down.sql deleted file mode 100644 index 14a81b4..0000000 --- a/qubership-apihub-service/resources/migrations/32_version_folder.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE published_version -DROP COLUMN folder; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/32_version_folder.up.sql b/qubership-apihub-service/resources/migrations/32_version_folder.up.sql deleted file mode 100644 index 2b1dabb..0000000 --- a/qubership-apihub-service/resources/migrations/32_version_folder.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE published_version -ADD COLUMN folder varchar; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/33_included_draft_flag.down.sql b/qubership-apihub-service/resources/migrations/33_included_draft_flag.down.sql deleted file mode 100644 index a2300b7..0000000 --- a/qubership-apihub-service/resources/migrations/33_included_draft_flag.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE branch_draft_content -DROP COLUMN included; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/33_included_draft_flag.up.sql b/qubership-apihub-service/resources/migrations/33_included_draft_flag.up.sql deleted file mode 100644 index 9550b66..0000000 --- a/qubership-apihub-service/resources/migrations/33_included_draft_flag.up.sql +++ /dev/null @@ -1,4 +0,0 @@ -ALTER TABLE branch_draft_content -ADD COLUMN included boolean NOT NULL default false; - -update branch_draft_content set included = true where status = 'included'; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/34_package_service_name.down.sql b/qubership-apihub-service/resources/migrations/34_package_service_name.down.sql deleted file mode 100644 index eddce16..0000000 --- a/qubership-apihub-service/resources/migrations/34_package_service_name.down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS package_service CASCADE; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/34_package_service_name.up.sql b/qubership-apihub-service/resources/migrations/34_package_service_name.up.sql deleted file mode 100644 index 2bd6c2e..0000000 --- a/qubership-apihub-service/resources/migrations/34_package_service_name.up.sql +++ /dev/null @@ -1,12 +0,0 @@ -CREATE TABLE package_service -( - package_id varchar NOT NULL, - service_name varchar NOT NULL, - UNIQUE (service_name) -); - -ALTER TABLE package_service ADD CONSTRAINT "PK_package_service" - PRIMARY KEY (package_id, service_name); - -ALTER TABLE package_service ADD CONSTRAINT "FK_package_group" - FOREIGN KEY (package_id) REFERENCES package_group (id) ON DELETE Cascade ON UPDATE Cascade; diff --git a/qubership-apihub-service/resources/migrations/35_search_tables.down.sql b/qubership-apihub-service/resources/migrations/35_search_tables.down.sql deleted file mode 100644 index 55897e4..0000000 --- a/qubership-apihub-service/resources/migrations/35_search_tables.down.sql +++ /dev/null @@ -1,3 +0,0 @@ -DROP TABLE IF EXISTS ts_published_data_path_split CASCADE; -DROP TABLE IF EXISTS ts_published_data_custom_split CASCADE; -DROP TABLE IF EXISTS ts_published_data_errors CASCADE; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/35_search_tables.up.sql b/qubership-apihub-service/resources/migrations/35_search_tables.up.sql deleted file mode 100644 index 165551f..0000000 --- a/qubership-apihub-service/resources/migrations/35_search_tables.up.sql +++ /dev/null @@ -1,23 +0,0 @@ -CREATE TABLE ts_published_data_path_split -( - package_id varchar NOT NULL, - checksum varchar NOT NULL, - search_vector tsvector, - unique(package_id, checksum) -); - -CREATE TABLE ts_published_data_custom_split -( - package_id varchar NOT NULL, - checksum varchar NOT NULL, - search_vector tsvector, - unique(package_id, checksum) -); - -CREATE TABLE ts_published_data_errors -( - package_id varchar NOT NULL, - checksum varchar NOT NULL, - error varchar, - unique(package_id, checksum) -); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/36_search_table_gin_index.down.sql b/qubership-apihub-service/resources/migrations/36_search_table_gin_index.down.sql deleted file mode 100644 index 792e886..0000000 --- a/qubership-apihub-service/resources/migrations/36_search_table_gin_index.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP INDEX IF EXISTS ts_published_data_path_split_idx; -DROP INDEX IF EXISTS ts_published_data_custom_split_idx; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/36_search_table_gin_index.up.sql b/qubership-apihub-service/resources/migrations/36_search_table_gin_index.up.sql deleted file mode 100644 index 4fb3dd0..0000000 --- a/qubership-apihub-service/resources/migrations/36_search_table_gin_index.up.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE INDEX ts_published_data_path_split_idx -ON ts_published_data_path_split -USING gin(search_vector) -with (fastupdate = true); - -CREATE INDEX ts_published_data_custom_split_idx -ON ts_published_data_custom_split -USING gin(search_vector) -with (fastupdate = true); diff --git a/qubership-apihub-service/resources/migrations/37_build_tables.down.sql b/qubership-apihub-service/resources/migrations/37_build_tables.down.sql deleted file mode 100644 index bf36eb6..0000000 --- a/qubership-apihub-service/resources/migrations/37_build_tables.down.sql +++ /dev/null @@ -1,3 +0,0 @@ -DROP TABLE IF EXISTS build CASCADE; -DROP TABLE IF EXISTS build_src CASCADE; -DROP TABLE IF EXISTS build_depends CASCADE; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/37_build_tables.up.sql b/qubership-apihub-service/resources/migrations/37_build_tables.up.sql deleted file mode 100644 index ebf9b6d..0000000 --- a/qubership-apihub-service/resources/migrations/37_build_tables.up.sql +++ /dev/null @@ -1,42 +0,0 @@ -CREATE TABLE build -( - build_id varchar NOT NULL, - status varchar NOT NULL, - details varchar NULL, - package_id varchar NOT NULL, - version varchar NOT NULL, - created_at timestamp without time zone NOT NULL, - last_active timestamp without time zone NOT NULL, - created_by varchar NOT NULL, - restart_count integer -); -ALTER TABLE build ADD CONSTRAINT "PK_build" PRIMARY KEY (build_id); - - -CREATE TABLE build_src -( - build_id varchar NOT NULL, - source bytea NULL, - config jsonb NOT NULL -); - -ALTER TABLE build_src - ADD CONSTRAINT "FK_build_src" - FOREIGN KEY (build_id) REFERENCES build (build_id) ON DELETE Cascade ON UPDATE Cascade -; - - -CREATE TABLE build_depends -( - build_id varchar NOT NULL, - depend_id varchar NOT NULL -); - -ALTER TABLE build_depends - ADD CONSTRAINT "FK_build_depends_id" - FOREIGN KEY (build_id) REFERENCES build (build_id) ON DELETE Cascade ON UPDATE Cascade -; -ALTER TABLE build_depends - ADD CONSTRAINT "FK_build_depends_depend" - FOREIGN KEY (depend_id) REFERENCES build (build_id) ON DELETE Cascade ON UPDATE Cascade -; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/38_version_changelog.down.sql b/qubership-apihub-service/resources/migrations/38_version_changelog.down.sql deleted file mode 100644 index 258bbca..0000000 --- a/qubership-apihub-service/resources/migrations/38_version_changelog.down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS published_version_validation; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/38_version_changelog.up.sql b/qubership-apihub-service/resources/migrations/38_version_changelog.up.sql deleted file mode 100644 index ed5c1bf..0000000 --- a/qubership-apihub-service/resources/migrations/38_version_changelog.up.sql +++ /dev/null @@ -1,15 +0,0 @@ -CREATE TABLE published_version_validation -( - package_id varchar NOT NULL, - version varchar NOT NULL, - revision integer NOT NULL, - changelog jsonb, - spectral jsonb, - bwc jsonb -); - -ALTER TABLE published_version_validation ADD CONSTRAINT "PK_published_version_validation" - PRIMARY KEY (package_id,version,revision); - -ALTER TABLE published_version_validation ADD CONSTRAINT "FK_published_version_validation" - FOREIGN KEY (package_id,version,revision) REFERENCES published_version (package_id,version,revision) ON DELETE Cascade ON UPDATE Cascade; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/39_build_result.down.sql b/qubership-apihub-service/resources/migrations/39_build_result.down.sql deleted file mode 100644 index 81ba880..0000000 --- a/qubership-apihub-service/resources/migrations/39_build_result.down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS build_result; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/39_build_result.up.sql b/qubership-apihub-service/resources/migrations/39_build_result.up.sql deleted file mode 100644 index 8ed2ed8..0000000 --- a/qubership-apihub-service/resources/migrations/39_build_result.up.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE build_result -( - build_id varchar NOT NULL, - data bytea NOT NULL -); - -ALTER TABLE build_result ADD CONSTRAINT "FK_build_result_build_id" - FOREIGN KEY (build_id) REFERENCES build (build_id) ON DELETE Cascade ON UPDATE Cascade; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/3_draftActions.down.sql b/qubership-apihub-service/resources/migrations/3_draftActions.down.sql deleted file mode 100644 index 7c3f16a..0000000 --- a/qubership-apihub-service/resources/migrations/3_draftActions.down.sql +++ /dev/null @@ -1,9 +0,0 @@ -ALTER TABLE branch_draft_content -DROP COLUMN moved_from, -DROP COLUMN action; - -ALTER TABLE branch_draft_reference -DROP COLUMN action; - -ALTER TABLE branch_draft_content -ADD COLUMN is_updated BOOLEAN; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/3_draftActions.up.sql b/qubership-apihub-service/resources/migrations/3_draftActions.up.sql deleted file mode 100644 index bae37ec..0000000 --- a/qubership-apihub-service/resources/migrations/3_draftActions.up.sql +++ /dev/null @@ -1,9 +0,0 @@ -ALTER TABLE branch_draft_content -DROP COLUMN is_updated; - -ALTER TABLE branch_draft_content -ADD COLUMN action VARCHAR, -ADD COLUMN moved_from VARCHAR; - -ALTER TABLE branch_draft_reference -ADD COLUMN action VARCHAR; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/40_add_rev_pk.down.sql b/qubership-apihub-service/resources/migrations/40_add_rev_pk.down.sql deleted file mode 100644 index 61e1840..0000000 --- a/qubership-apihub-service/resources/migrations/40_add_rev_pk.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table published_version_revision_content - drop constraint published_version_revision_content_pk; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/40_add_rev_pk.up.sql b/qubership-apihub-service/resources/migrations/40_add_rev_pk.up.sql deleted file mode 100644 index b4a52f4..0000000 --- a/qubership-apihub-service/resources/migrations/40_add_rev_pk.up.sql +++ /dev/null @@ -1,3 +0,0 @@ -alter table published_version_revision_content - add constraint published_version_revision_content_pk - primary key (package_id, version, revision, file_id); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/41_nullable_included.down.sql b/qubership-apihub-service/resources/migrations/41_nullable_included.down.sql deleted file mode 100644 index 405b9a1..0000000 --- a/qubership-apihub-service/resources/migrations/41_nullable_included.down.sql +++ /dev/null @@ -1 +0,0 @@ -alter table branch_draft_content alter column included set not null; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/41_nullable_included.up.sql b/qubership-apihub-service/resources/migrations/41_nullable_included.up.sql deleted file mode 100644 index 11fd53e..0000000 --- a/qubership-apihub-service/resources/migrations/41_nullable_included.up.sql +++ /dev/null @@ -1 +0,0 @@ -alter table branch_draft_content alter column included drop not null; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/42_use_zero_pg.down.sql b/qubership-apihub-service/resources/migrations/42_use_zero_pg.down.sql deleted file mode 100644 index 8214e54..0000000 --- a/qubership-apihub-service/resources/migrations/42_use_zero_pg.down.sql +++ /dev/null @@ -1,4 +0,0 @@ -update branch_draft_content set included = null where included = false; -update branch_draft_content set publish = null where publish = false; -update user_integration set is_revoked = null where is_revoked = false; -update build set restart_count = null where restart_count = 0; diff --git a/qubership-apihub-service/resources/migrations/42_use_zero_pg.up.sql b/qubership-apihub-service/resources/migrations/42_use_zero_pg.up.sql deleted file mode 100644 index 077fdc6..0000000 --- a/qubership-apihub-service/resources/migrations/42_use_zero_pg.up.sql +++ /dev/null @@ -1,4 +0,0 @@ -update branch_draft_content set included = false where included is null; -update branch_draft_content set publish = false where publish is null; -update user_integration set is_revoked = false where is_revoked is null; -update build set restart_count = 0 where restart_count is null; diff --git a/qubership-apihub-service/resources/migrations/43_builder_task.down.sql b/qubership-apihub-service/resources/migrations/43_builder_task.down.sql deleted file mode 100644 index a205dab..0000000 --- a/qubership-apihub-service/resources/migrations/43_builder_task.down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS builder_task; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/43_builder_task.up.sql b/qubership-apihub-service/resources/migrations/43_builder_task.up.sql deleted file mode 100644 index 5abdf52..0000000 --- a/qubership-apihub-service/resources/migrations/43_builder_task.up.sql +++ /dev/null @@ -1,10 +0,0 @@ -CREATE TABLE builder_task -( - build_id varchar NOT NULL, - builder_id varchar NOT NULL -); - -ALTER TABLE builder_task ADD CONSTRAINT "FK_builder_task_build_id" - FOREIGN KEY (build_id) REFERENCES build (build_id) ON DELETE Cascade ON UPDATE Cascade; - -ALTER TABLE builder_task ADD CONSTRAINT "PK_builder_task" PRIMARY KEY (build_id); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/44_config_folders.down.sql b/qubership-apihub-service/resources/migrations/44_config_folders.down.sql deleted file mode 100644 index cecc4dc..0000000 --- a/qubership-apihub-service/resources/migrations/44_config_folders.down.sql +++ /dev/null @@ -1,6 +0,0 @@ -ALTER TABLE branch_draft_content -DROP COLUMN is_folder; -ALTER TABLE branch_draft_content -DROP COLUMN from_folder; -ALTER TABLE branch_draft_content -ALTER COLUMN name set not null; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/44_config_folders.up.sql b/qubership-apihub-service/resources/migrations/44_config_folders.up.sql deleted file mode 100644 index 76660c8..0000000 --- a/qubership-apihub-service/resources/migrations/44_config_folders.up.sql +++ /dev/null @@ -1,5 +0,0 @@ -ALTER TABLE branch_draft_content -ADD COLUMN is_folder bool, -ADD COLUMN from_folder bool; -ALTER TABLE branch_draft_content -ALTER COLUMN name DROP not null; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/45_user_avatar_table.down.sql b/qubership-apihub-service/resources/migrations/45_user_avatar_table.down.sql deleted file mode 100644 index 702ee7a..0000000 --- a/qubership-apihub-service/resources/migrations/45_user_avatar_table.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP TABLE IF EXISTS user_avatar_data CASCADE -; diff --git a/qubership-apihub-service/resources/migrations/45_user_avatar_table.up.sql b/qubership-apihub-service/resources/migrations/45_user_avatar_table.up.sql deleted file mode 100644 index 2d11064..0000000 --- a/qubership-apihub-service/resources/migrations/45_user_avatar_table.up.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE TABLE user_avatar_data -( - user_id varchar NOT NULL, - avatar bytea NULL, - checksum bytea NULL -) -; - -ALTER TABLE user_avatar_data ADD CONSTRAINT "PK_user_avatar_data" - PRIMARY KEY (user_id) -; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/46_access_control.down.sql b/qubership-apihub-service/resources/migrations/46_access_control.down.sql deleted file mode 100644 index 0556a52..0000000 --- a/qubership-apihub-service/resources/migrations/46_access_control.down.sql +++ /dev/null @@ -1,3 +0,0 @@ -drop table if exists system_role; -drop table if exists package_member_role; -alter table package_group drop column default_role; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/46_access_control.up.sql b/qubership-apihub-service/resources/migrations/46_access_control.up.sql deleted file mode 100644 index 75c8280..0000000 --- a/qubership-apihub-service/resources/migrations/46_access_control.up.sql +++ /dev/null @@ -1,21 +0,0 @@ -CREATE TABLE system_role -( - user_id varchar NOT NULL, - role varchar NOT NULL -); -CREATE TABLE package_member_role -( - user_id varchar NOT NULL, - package_id varchar NOT NULL, - role varchar NOT NULL, - created_by varchar NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_by varchar NULL, - updated_at timestamp without time zone NULL -); - -ALTER TABLE package_group -ADD COLUMN default_role varchar NOT NULL default 'Viewer'; - -ALTER TABLE package_member_role ADD CONSTRAINT "PK_package_member_role" - PRIMARY KEY (package_id, user_id); diff --git a/qubership-apihub-service/resources/migrations/47_version_labels.down.sql b/qubership-apihub-service/resources/migrations/47_version_labels.down.sql deleted file mode 100644 index d8a0319..0000000 --- a/qubership-apihub-service/resources/migrations/47_version_labels.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table published_version - drop column labels; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/47_version_labels.up.sql b/qubership-apihub-service/resources/migrations/47_version_labels.up.sql deleted file mode 100644 index 3f75e8d..0000000 --- a/qubership-apihub-service/resources/migrations/47_version_labels.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table published_version - add labels varchar array; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/48_access_control_constraint.down.sql b/qubership-apihub-service/resources/migrations/48_access_control_constraint.down.sql deleted file mode 100644 index 47e18dc..0000000 --- a/qubership-apihub-service/resources/migrations/48_access_control_constraint.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE package_member_role DROP CONSTRAINT "FK_package_group"; -ALTER TABLE system_role DROP CONSTRAINT "PK_system_role"; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/48_access_control_constraint.up.sql b/qubership-apihub-service/resources/migrations/48_access_control_constraint.up.sql deleted file mode 100644 index 534e60e..0000000 --- a/qubership-apihub-service/resources/migrations/48_access_control_constraint.up.sql +++ /dev/null @@ -1,4 +0,0 @@ -ALTER TABLE package_member_role ADD CONSTRAINT "FK_package_group" - FOREIGN KEY (package_id) REFERENCES package_group (id) ON DELETE Cascade ON UPDATE Cascade; -ALTER TABLE system_role ADD CONSTRAINT "PK_system_role" - PRIMARY KEY (user_id); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/49_api_key_roles.down.sql b/qubership-apihub-service/resources/migrations/49_api_key_roles.down.sql deleted file mode 100644 index 38ae687..0000000 --- a/qubership-apihub-service/resources/migrations/49_api_key_roles.down.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE apihub_api_keys DROP COLUMN role; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/49_api_key_roles.up.sql b/qubership-apihub-service/resources/migrations/49_api_key_roles.up.sql deleted file mode 100644 index 74fa247..0000000 --- a/qubership-apihub-service/resources/migrations/49_api_key_roles.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE apihub_api_keys -ADD COLUMN role varchar NOT NULL default 'Admin'; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/4_intKeyRevoked.down.sql b/qubership-apihub-service/resources/migrations/4_intKeyRevoked.down.sql deleted file mode 100644 index 72e2ff1..0000000 --- a/qubership-apihub-service/resources/migrations/4_intKeyRevoked.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE user_integration -DROP COLUMN is_revoked; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/4_intKeyRevoked.up.sql b/qubership-apihub-service/resources/migrations/4_intKeyRevoked.up.sql deleted file mode 100644 index 88497cb..0000000 --- a/qubership-apihub-service/resources/migrations/4_intKeyRevoked.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE user_integration - ADD COLUMN is_revoked boolean DEFAULT false; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/50_oauth_token.up.sql b/qubership-apihub-service/resources/migrations/50_oauth_token.up.sql deleted file mode 100644 index 9de4d7e..0000000 --- a/qubership-apihub-service/resources/migrations/50_oauth_token.up.sql +++ /dev/null @@ -1 +0,0 @@ -DELETE FROM user_integration \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/51_internal_users.down.sql b/qubership-apihub-service/resources/migrations/51_internal_users.down.sql deleted file mode 100644 index 89c0924..0000000 --- a/qubership-apihub-service/resources/migrations/51_internal_users.down.sql +++ /dev/null @@ -1,3 +0,0 @@ -DROP TABLE IF EXISTS external_identity; -ALTER TABLE user_data DROP COLUMN password; -ALTER TABLE user_data DROP CONSTRAINT email_unique; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/51_internal_users.up.sql b/qubership-apihub-service/resources/migrations/51_internal_users.up.sql deleted file mode 100644 index 2e08d9a..0000000 --- a/qubership-apihub-service/resources/migrations/51_internal_users.up.sql +++ /dev/null @@ -1,23 +0,0 @@ -CREATE TABLE external_identity -( - provider varchar NOT NULL, - external_id varchar NOT NULL, - internal_id varchar NOT NULL, - PRIMARY KEY(provider, external_id) -); - -ALTER TABLE user_data -ADD COLUMN password bytea; - -ALTER TABLE external_identity ADD CONSTRAINT "FK_user_data" - FOREIGN KEY (internal_id) REFERENCES user_data (user_id) ON DELETE Cascade ON UPDATE Cascade; - -update user_data set email = LOWER(email); - -delete from user_data -where email in ( - select email from user_data - group by email having count(email) > 1); - -ALTER TABLE user_data -ADD CONSTRAINT email_unique UNIQUE (email); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/52_workspaces.down.sql b/qubership-apihub-service/resources/migrations/52_workspaces.down.sql deleted file mode 100644 index 77d21f1..0000000 --- a/qubership-apihub-service/resources/migrations/52_workspaces.down.sql +++ /dev/null @@ -1 +0,0 @@ -update package_group set kind = 'group' where parent_id is null; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/52_workspaces.up.sql b/qubership-apihub-service/resources/migrations/52_workspaces.up.sql deleted file mode 100644 index d0f1996..0000000 --- a/qubership-apihub-service/resources/migrations/52_workspaces.up.sql +++ /dev/null @@ -1 +0,0 @@ -update package_group set kind = 'workspace' where parent_id is null; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/53_packageId.down.sql b/qubership-apihub-service/resources/migrations/53_packageId.down.sql deleted file mode 100644 index dbe3047..0000000 --- a/qubership-apihub-service/resources/migrations/53_packageId.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE project -DROP COLUMN package_id \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/53_packageId.up.sql b/qubership-apihub-service/resources/migrations/53_packageId.up.sql deleted file mode 100644 index 2489df1..0000000 --- a/qubership-apihub-service/resources/migrations/53_packageId.up.sql +++ /dev/null @@ -1,6 +0,0 @@ -ALTER TABLE project - ADD COLUMN package_id varchar; - -update project p -set package_id = id -where (select count(id) from package_group where id = p.id and kind = 'package') > 0 \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/54_version_folders.down.sql b/qubership-apihub-service/resources/migrations/54_version_folders.down.sql deleted file mode 100644 index cfdf587..0000000 --- a/qubership-apihub-service/resources/migrations/54_version_folders.down.sql +++ /dev/null @@ -1 +0,0 @@ -alter table published_version add column folder varchar; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/54_version_folders.up.sql b/qubership-apihub-service/resources/migrations/54_version_folders.up.sql deleted file mode 100644 index 1c5f106..0000000 --- a/qubership-apihub-service/resources/migrations/54_version_folders.up.sql +++ /dev/null @@ -1,11 +0,0 @@ -update published_version -set labels = labels || folder -where folder is not null -and folder != any(labels); - -update published_version -set labels = ARRAY[folder] -where folder is not null -and labels is null; - -alter table published_version drop column folder; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/55_default_released_version.down.sql b/qubership-apihub-service/resources/migrations/55_default_released_version.down.sql deleted file mode 100644 index c21add5..0000000 --- a/qubership-apihub-service/resources/migrations/55_default_released_version.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE package_group - DROP COLUMN default_released_version; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/55_default_released_version.up.sql b/qubership-apihub-service/resources/migrations/55_default_released_version.up.sql deleted file mode 100644 index 9346ab3..0000000 --- a/qubership-apihub-service/resources/migrations/55_default_released_version.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE package_group - ADD COLUMN default_released_version VARCHAR; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/56_remove_api_keys_fk.up.sql b/qubership-apihub-service/resources/migrations/56_remove_api_keys_fk.up.sql deleted file mode 100644 index a21c08c..0000000 --- a/qubership-apihub-service/resources/migrations/56_remove_api_keys_fk.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table apihub_api_keys - drop constraint "FK_package_group"; diff --git a/qubership-apihub-service/resources/migrations/57_rest_operations.down.sql b/qubership-apihub-service/resources/migrations/57_rest_operations.down.sql deleted file mode 100644 index 51530df..0000000 --- a/qubership-apihub-service/resources/migrations/57_rest_operations.down.sql +++ /dev/null @@ -1,4 +0,0 @@ -ALTER TABLE published_version_revision_content DROP COLUMN operation_ids; -DROP TABLE IF EXISTS operation; -DROP TABLE IF EXISTS operation_data; -DROP TABLE IF EXISTS changed_operation; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/57_rest_operations.up.sql b/qubership-apihub-service/resources/migrations/57_rest_operations.up.sql deleted file mode 100644 index 38f4880..0000000 --- a/qubership-apihub-service/resources/migrations/57_rest_operations.up.sql +++ /dev/null @@ -1,45 +0,0 @@ -ALTER TABLE published_version_revision_content -ADD COLUMN operation_ids varchar[]; - -CREATE TABLE operation -( -package_id varchar NOT NULL, -version varchar NOT NULL, -revision integer NOT NULL, -operation_id varchar NOT NULL, -data_hash varchar NOT NULL, -deprecated boolean NOT NULL, -kind varchar NULL, -title varchar NULL, -metadata jsonb NULL, -type varchar NOT NULL, -CONSTRAINT pk_operation PRIMARY KEY (package_id, version, revision, operation_id) -); - -CREATE TABLE operation_data -( -data_hash varchar NOT NULL, -data bytea NULL, -search_scope jsonb NULL, -CONSTRAINT pk_operation_data PRIMARY KEY (data_hash) -); - -ALTER TABLE operation ADD CONSTRAINT "FK_published_version" - FOREIGN KEY (package_id,version,revision) REFERENCES published_version (package_id,version,revision) ON DELETE Cascade ON UPDATE Cascade; - -ALTER TABLE operation ADD CONSTRAINT "FK_operation_data" - FOREIGN KEY (data_hash) REFERENCES operation_data (data_hash) ON DELETE Cascade ON UPDATE Cascade; - -CREATE TABLE changed_operation -( -package_id varchar NOT NULL, -version varchar NOT NULL, -revision integer NOT NULL, -previous_package_id varchar NOT NULL, -previous_version varchar NOT NULL, -previous_revision integer NOT NULL, -operation_id varchar NOT NULL, -data_hash varchar NULL, -previous_data_hash varchar NULL, -changes_summary jsonb NULL, -changes jsonb NULL); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/58_operations_search.down.sql b/qubership-apihub-service/resources/migrations/58_operations_search.down.sql deleted file mode 100644 index 5f9e9b4..0000000 --- a/qubership-apihub-service/resources/migrations/58_operations_search.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP TABLE ts_operation_data; -DROP INDEX IF EXISTS ts_operation_data_idx; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/58_operations_search.up.sql b/qubership-apihub-service/resources/migrations/58_operations_search.up.sql deleted file mode 100644 index 411f627..0000000 --- a/qubership-apihub-service/resources/migrations/58_operations_search.up.sql +++ /dev/null @@ -1,28 +0,0 @@ -CREATE TABLE ts_operation_data( - data_hash varchar NOT NULL, - scope_all tsvector, - scope_request tsvector, - scope_response tsvector, - scope_annotation tsvector, - scope_properties tsvector, - scope_examples tsvector, - CONSTRAINT pk_ts_operation_data PRIMARY KEY(data_hash) -); - -ALTER TABLE ts_operation_data ADD CONSTRAINT "FK_operation_data" - FOREIGN KEY (data_hash) REFERENCES operation_data (data_hash) ON DELETE Cascade ON UPDATE Cascade; - -insert into ts_operation_data -select data_hash, -to_tsvector(jsonb_extract_path_text(search_scope, 'all')) scope_all, -to_tsvector(jsonb_extract_path_text(search_scope, 'request')) scope_request, -to_tsvector(jsonb_extract_path_text(search_scope, 'response')) scope_response, -to_tsvector(jsonb_extract_path_text(search_scope, 'annotation')) scope_annotation, -to_tsvector(jsonb_extract_path_text(search_scope, 'properties')) scope_properties, -to_tsvector(jsonb_extract_path_text(search_scope, 'examples')) scope_examples -from operation_data; - -CREATE INDEX ts_operation_data_idx -ON ts_operation_data -USING gin(scope_request,scope_response,scope_annotation,scope_properties,scope_examples) -with (fastupdate = true); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/59_version_createdby.down.sql b/qubership-apihub-service/resources/migrations/59_version_createdby.down.sql deleted file mode 100644 index 36c81b8..0000000 --- a/qubership-apihub-service/resources/migrations/59_version_createdby.down.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE published_version DROP COLUMN created_by; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/59_version_createdby.up.sql b/qubership-apihub-service/resources/migrations/59_version_createdby.up.sql deleted file mode 100644 index d580e7f..0000000 --- a/qubership-apihub-service/resources/migrations/59_version_createdby.up.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE published_version ADD COLUMN created_by varchar; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/5_draft_file_commit_id.down.sql b/qubership-apihub-service/resources/migrations/5_draft_file_commit_id.down.sql deleted file mode 100644 index d947b42..0000000 --- a/qubership-apihub-service/resources/migrations/5_draft_file_commit_id.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE branch_draft_content - DROP COLUMN commit_id; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/5_draft_file_commit_id.up.sql b/qubership-apihub-service/resources/migrations/5_draft_file_commit_id.up.sql deleted file mode 100644 index eff821c..0000000 --- a/qubership-apihub-service/resources/migrations/5_draft_file_commit_id.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE branch_draft_content - ADD COLUMN commit_id varchar; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/60_ref_relation_type.down.sql b/qubership-apihub-service/resources/migrations/60_ref_relation_type.down.sql deleted file mode 100644 index e19b0b3..0000000 --- a/qubership-apihub-service/resources/migrations/60_ref_relation_type.down.sql +++ /dev/null @@ -1,22 +0,0 @@ -ALTER TABLE published_version_reference ADD COLUMN relation_type varchar; - -with pkggroup as ( - select id as package_id from package_group where kind = 'group' -) -update published_version_reference pvr -set relation_type = 'import' - from pkggroup - where pvr.package_id = pkggroup.package_id; - -with pkgnotgroup as ( - select id as package_id from package_group where kind != 'group' -) -update published_version_reference pvr -set relation_type = 'depend' - from pkgnotgroup -where pvr.package_id = pkgnotgroup.package_id; - -ALTER TABLE published_version_reference DROP CONSTRAINT "PK_published_version_reference"; -ALTER TABLE published_version_reference ADD CONSTRAINT "PK_published_version_reference" - PRIMARY KEY (package_id,version,revision,reference_id,relation_type,reference_version) -; diff --git a/qubership-apihub-service/resources/migrations/60_ref_relation_type.up.sql b/qubership-apihub-service/resources/migrations/60_ref_relation_type.up.sql deleted file mode 100644 index d5d1f54..0000000 --- a/qubership-apihub-service/resources/migrations/60_ref_relation_type.up.sql +++ /dev/null @@ -1,7 +0,0 @@ -DELETE FROM published_version_reference WHERE relation_type = 'depend'; - -ALTER TABLE published_version_reference DROP CONSTRAINT "PK_published_version_reference"; -ALTER TABLE published_version_reference DROP COLUMN relation_type; -ALTER TABLE published_version_reference ADD CONSTRAINT "PK_published_version_reference" - PRIMARY KEY (package_id,version,revision,reference_id,reference_version) -; diff --git a/qubership-apihub-service/resources/migrations/61_agent_reg.down.sql b/qubership-apihub-service/resources/migrations/61_agent_reg.down.sql deleted file mode 100644 index 4e47c68..0000000 --- a/qubership-apihub-service/resources/migrations/61_agent_reg.down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE agent; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/61_agent_reg.up.sql b/qubership-apihub-service/resources/migrations/61_agent_reg.up.sql deleted file mode 100644 index b7f34fc..0000000 --- a/qubership-apihub-service/resources/migrations/61_agent_reg.up.sql +++ /dev/null @@ -1,12 +0,0 @@ -CREATE TABLE agent -( - agent_id varchar NOT NULL, - cloud varchar NOT NULL, - namespace varchar NOT NULL, - url varchar NOT NULL, - last_active timestamp without time zone NOT NULL, - backend_version varchar NOT NULL, - frontend_version varchar NOT NULL, - name varchar, - PRIMARY KEY (agent_id) -); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/62_package_group_service.down.sql b/qubership-apihub-service/resources/migrations/62_package_group_service.down.sql deleted file mode 100644 index 35885a4..0000000 --- a/qubership-apihub-service/resources/migrations/62_package_group_service.down.sql +++ /dev/null @@ -1 +0,0 @@ -alter table package_group drop column service_name; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/62_package_group_service.up.sql b/qubership-apihub-service/resources/migrations/62_package_group_service.up.sql deleted file mode 100644 index fd184f9..0000000 --- a/qubership-apihub-service/resources/migrations/62_package_group_service.up.sql +++ /dev/null @@ -1,4 +0,0 @@ -alter table package_group add column service_name varchar; -update package_group pg set service_name = s.service_name -from package_service s -where s.package_id = pg.id; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/63_open_count.down.sql b/qubership-apihub-service/resources/migrations/63_open_count.down.sql deleted file mode 100644 index 3f31b25..0000000 --- a/qubership-apihub-service/resources/migrations/63_open_count.down.sql +++ /dev/null @@ -1,3 +0,0 @@ -drop table published_version_open_count; -drop table published_document_open_count; -drop table operation_open_count; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/63_open_count.up.sql b/qubership-apihub-service/resources/migrations/63_open_count.up.sql deleted file mode 100644 index ac96a6b..0000000 --- a/qubership-apihub-service/resources/migrations/63_open_count.up.sql +++ /dev/null @@ -1,25 +0,0 @@ -create table published_version_open_count -( - package_id varchar not null, - version varchar not null, - open_count bigint, - PRIMARY KEY(package_id, version) -); - -create table published_document_open_count -( - package_id varchar not null, - version varchar not null, - slug varchar not null, - open_count bigint, - PRIMARY KEY(package_id, version, slug) -); - -create table operation_open_count -( - package_id varchar not null, - version varchar not null, - operation_id varchar not null, - open_count bigint, - PRIMARY KEY(package_id, version, operation_id) -); diff --git a/qubership-apihub-service/resources/migrations/64_metadata_migration.down.sql b/qubership-apihub-service/resources/migrations/64_metadata_migration.down.sql deleted file mode 100644 index a29cb59..0000000 --- a/qubership-apihub-service/resources/migrations/64_metadata_migration.down.sql +++ /dev/null @@ -1,8 +0,0 @@ -ALTER TABLE published_data - ADD COLUMN metadata jsonb; - -UPDATE published_data AS pd -SET metadata = JSONB_SET(metadata, '{commitId}',(select metadata -> 'commitId' from published_version_revision_content as pvrc WHERE pd.package_id = pvrc.package_id AND pd.checksum = pvrc.checksum LIMIT 1)); - -UPDATE published_data AS pd -SET metadata = JSONB_SET(metadata, '{commitDate}',(select metadata -> 'commitDate' from published_version_revision_content as pvrc WHERE pd.package_id = pvrc.package_id AND pd.checksum = pvrc.checksum LIMIT 1)); diff --git a/qubership-apihub-service/resources/migrations/64_metadata_migration.up.sql b/qubership-apihub-service/resources/migrations/64_metadata_migration.up.sql deleted file mode 100644 index 997b34e..0000000 --- a/qubership-apihub-service/resources/migrations/64_metadata_migration.up.sql +++ /dev/null @@ -1,8 +0,0 @@ -UPDATE published_version_revision_content AS pvrc -SET metadata = JSONB_SET(metadata, '{commitId}',(select metadata -> 'commitId' from published_data as pd WHERE pd.package_id = pvrc.package_id AND pd.checksum = pvrc.checksum LIMIT 1)); - -UPDATE published_version_revision_content AS pvrc -SET metadata = JSONB_SET(metadata, '{commitDate}',(select metadata -> 'commitDate' from published_data as pd WHERE pd.package_id = pvrc.package_id AND pd.checksum = pvrc.checksum LIMIT 1)); - -ALTER TABLE published_data - DROP COLUMN metadata; diff --git a/qubership-apihub-service/resources/migrations/65_filename.down.sql b/qubership-apihub-service/resources/migrations/65_filename.down.sql deleted file mode 100644 index 715543f..0000000 --- a/qubership-apihub-service/resources/migrations/65_filename.down.sql +++ /dev/null @@ -1,3 +0,0 @@ -alter table published_version_revision_content - drop column filename; - diff --git a/qubership-apihub-service/resources/migrations/65_filename.up.sql b/qubership-apihub-service/resources/migrations/65_filename.up.sql deleted file mode 100644 index a33cb8f..0000000 --- a/qubership-apihub-service/resources/migrations/65_filename.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table published_version_revision_content - add filename varchar; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/66_add_src_index.down.sql b/qubership-apihub-service/resources/migrations/66_add_src_index.down.sql deleted file mode 100644 index 5f5aedc..0000000 --- a/qubership-apihub-service/resources/migrations/66_add_src_index.down.sql +++ /dev/null @@ -1 +0,0 @@ -drop index published_sources_package_id_version_revision_uindex; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/66_add_src_index.up.sql b/qubership-apihub-service/resources/migrations/66_add_src_index.up.sql deleted file mode 100644 index 9f25ce8..0000000 --- a/qubership-apihub-service/resources/migrations/66_add_src_index.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -create unique index published_sources_package_id_version_revision_uindex - on published_sources (package_id, version, revision); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/67_add_release_version_pattern.down.sql b/qubership-apihub-service/resources/migrations/67_add_release_version_pattern.down.sql deleted file mode 100644 index f5c9974..0000000 --- a/qubership-apihub-service/resources/migrations/67_add_release_version_pattern.down.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE package_group DROP COLUMN release_version_pattern; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/67_add_release_version_pattern.up.sql b/qubership-apihub-service/resources/migrations/67_add_release_version_pattern.up.sql deleted file mode 100644 index 3823e95..0000000 --- a/qubership-apihub-service/resources/migrations/67_add_release_version_pattern.up.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE package_group ADD COLUMN release_version_pattern varchar; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/68_activity_tracking.down.sql b/qubership-apihub-service/resources/migrations/68_activity_tracking.down.sql deleted file mode 100644 index 83fd747..0000000 --- a/qubership-apihub-service/resources/migrations/68_activity_tracking.down.sql +++ /dev/null @@ -1 +0,0 @@ -drop table activity_tracking; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/68_activity_tracking.up.sql b/qubership-apihub-service/resources/migrations/68_activity_tracking.up.sql deleted file mode 100644 index 6f050fe..0000000 --- a/qubership-apihub-service/resources/migrations/68_activity_tracking.up.sql +++ /dev/null @@ -1,12 +0,0 @@ -create table activity_tracking -( - id varchar not null, - e_type varchar not null, - data jsonb, - package_id varchar, - version varchar, - date timestamp without time zone, - user_id varchar, - - PRIMARY KEY(id) -); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/69_builder_notifications.down.sql b/qubership-apihub-service/resources/migrations/69_builder_notifications.down.sql deleted file mode 100644 index 8788b31..0000000 --- a/qubership-apihub-service/resources/migrations/69_builder_notifications.down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS builder_notifications; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/69_builder_notifications.up.sql b/qubership-apihub-service/resources/migrations/69_builder_notifications.up.sql deleted file mode 100644 index 9483bf1..0000000 --- a/qubership-apihub-service/resources/migrations/69_builder_notifications.up.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE builder_notifications -( -build_id varchar NOT NULL, -severity varchar, -message varchar, -file_id integer, -FOREIGN KEY (build_id) REFERENCES build (build_id) ON DELETE Cascade ON UPDATE Cascade); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/6_content_path.down.sql b/qubership-apihub-service/resources/migrations/6_content_path.down.sql deleted file mode 100644 index b154196..0000000 --- a/qubership-apihub-service/resources/migrations/6_content_path.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE branch_draft_content -ALTER COLUMN path SET NOT NULL; diff --git a/qubership-apihub-service/resources/migrations/6_content_path.up.sql b/qubership-apihub-service/resources/migrations/6_content_path.up.sql deleted file mode 100644 index 32261a1..0000000 --- a/qubership-apihub-service/resources/migrations/6_content_path.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE branch_draft_content -ALTER COLUMN path DROP NOT NULL; diff --git a/qubership-apihub-service/resources/migrations/70_role_redesign.down.sql b/qubership-apihub-service/resources/migrations/70_role_redesign.down.sql deleted file mode 100644 index a9054b4..0000000 --- a/qubership-apihub-service/resources/migrations/70_role_redesign.down.sql +++ /dev/null @@ -1,6 +0,0 @@ ---data migration from roles array to role varchar is not possible -alter table package_member_role add column role varchar; -alter table package_member_role drop column roles; -alter table apihub_api_keys add column role varchar; -alter table apihub_api_keys drop column roles; -drop table role; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/70_role_redesign.up.sql b/qubership-apihub-service/resources/migrations/70_role_redesign.up.sql deleted file mode 100644 index 41909d8..0000000 --- a/qubership-apihub-service/resources/migrations/70_role_redesign.up.sql +++ /dev/null @@ -1,36 +0,0 @@ -alter table package_member_role add column roles varchar array default '{}'; - -update package_member_role set roles = array_append(roles, lower(role)::varchar); -update package_group set default_role = lower(default_role); - -alter table package_member_role drop column role; -delete from package_member_role where roles = ARRAY[]::varchar[]; -delete from package_member_role where roles = ARRAY[null]::varchar[]; - -create table role -( - id varchar not null, - role varchar not null, - rank int not null, - permissions varchar array, - read_only bool, - PRIMARY KEY(id) -); - -insert into role(id, role, rank, permissions, read_only) -values -('admin', 'Admin', 1000, ARRAY['read', 'create_and_update_package', 'delete_package', 'manage_draft_version', 'manage_release_candidate_version', 'manage_release_version', 'manage_archived_version', 'manage_deprecated_version', 'user_access_management', 'access_token_management'], true), -('release-manager', 'Release Manager', 4, ARRAY['read', 'manage_release_version'], false), -('owner', 'Owner', 3, ARRAY['read', 'create_and_update_package', 'delete_package', 'manage_draft_version', 'manage_release_candidate_version', 'manage_release_version', 'manage_archived_version', 'manage_deprecated_version'], false), -('editor', 'Editor', 2, ARRAY['read', 'manage_draft_version', 'manage_release_candidate_version', 'manage_archived_version', 'manage_deprecated_version'], false), -('viewer', 'Viewer', 1, ARRAY['read'], true), -('none', 'None', 0, ARRAY[]::varchar[], true); - -alter table apihub_api_keys add column roles varchar array default '{}'; -update apihub_api_keys set roles = array_append(roles, lower(role)::varchar); - -alter table apihub_api_keys drop column role; -update apihub_api_keys -set roles = ARRAY['admin']::varchar[] -where roles = ARRAY[]::varchar[] -or roles = ARRAY[null]::varchar[]; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/71_builder_notifications_fix.up.sql b/qubership-apihub-service/resources/migrations/71_builder_notifications_fix.up.sql deleted file mode 100644 index b7c61c4..0000000 --- a/qubership-apihub-service/resources/migrations/71_builder_notifications_fix.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -truncate table builder_notifications; -alter table builder_notifications alter column file_id type varchar; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/72_old_editor_role_permissions.down.sql b/qubership-apihub-service/resources/migrations/72_old_editor_role_permissions.down.sql deleted file mode 100644 index a3379b5..0000000 --- a/qubership-apihub-service/resources/migrations/72_old_editor_role_permissions.down.sql +++ /dev/null @@ -1,3 +0,0 @@ -update role -set permissions = ARRAY['read', 'manage_draft_version', 'manage_release_candidate_version', 'manage_archived_version', 'manage_deprecated_version'] -where id = 'editor'; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/72_old_editor_role_permissions.up.sql b/qubership-apihub-service/resources/migrations/72_old_editor_role_permissions.up.sql deleted file mode 100644 index 7748707..0000000 --- a/qubership-apihub-service/resources/migrations/72_old_editor_role_permissions.up.sql +++ /dev/null @@ -1,3 +0,0 @@ -update role -set permissions = ARRAY['read', 'manage_draft_version', 'manage_release_version', 'manage_archived_version', 'manage_deprecated_version'] -where id = 'editor'; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/73_delete_sources.up.sql b/qubership-apihub-service/resources/migrations/73_delete_sources.up.sql deleted file mode 100644 index 5fa3e0f..0000000 --- a/qubership-apihub-service/resources/migrations/73_delete_sources.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -truncate table published_sources_data cascade; -truncate table published_sources cascade; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/74_sources_deduplication.down.sql b/qubership-apihub-service/resources/migrations/74_sources_deduplication.down.sql deleted file mode 100644 index 832845f..0000000 --- a/qubership-apihub-service/resources/migrations/74_sources_deduplication.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table published_sources drop column config; -alter table published_sources drop column metadata; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/74_sources_deduplication.up.sql b/qubership-apihub-service/resources/migrations/74_sources_deduplication.up.sql deleted file mode 100644 index 4e347e6..0000000 --- a/qubership-apihub-service/resources/migrations/74_sources_deduplication.up.sql +++ /dev/null @@ -1,5 +0,0 @@ -truncate table published_sources_data cascade; -truncate table published_sources cascade; - -alter table published_sources add column config bytea; -alter table published_sources add column metadata bytea; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/75_nullable_sources.down.sql b/qubership-apihub-service/resources/migrations/75_nullable_sources.down.sql deleted file mode 100644 index 59f0210..0000000 --- a/qubership-apihub-service/resources/migrations/75_nullable_sources.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -delete from published_sources_data where data is null; -alter table published_sources_data alter column data set not null; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/75_nullable_sources.up.sql b/qubership-apihub-service/resources/migrations/75_nullable_sources.up.sql deleted file mode 100644 index 7ba021e..0000000 --- a/qubership-apihub-service/resources/migrations/75_nullable_sources.up.sql +++ /dev/null @@ -1 +0,0 @@ -alter table published_sources_data alter column data drop not null; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/76_unbind_services.up.sql b/qubership-apihub-service/resources/migrations/76_unbind_services.up.sql deleted file mode 100644 index 77fbb21..0000000 --- a/qubership-apihub-service/resources/migrations/76_unbind_services.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -delete from package_service where package_id in (select id from package_group where deleted_at is not null and service_name is not null); -update package_group set service_name = null where deleted_at is not null and service_name is not null; diff --git a/qubership-apihub-service/resources/migrations/77_operation_type_lower_case.down.sql b/qubership-apihub-service/resources/migrations/77_operation_type_lower_case.down.sql deleted file mode 100644 index 39d78cf..0000000 --- a/qubership-apihub-service/resources/migrations/77_operation_type_lower_case.down.sql +++ /dev/null @@ -1,5 +0,0 @@ -update operation -set type = 'Rest' where type = 'rest'; - -update operation -set type = 'GraphQL' where type = 'graphql'; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/77_operation_type_lower_case.up.sql b/qubership-apihub-service/resources/migrations/77_operation_type_lower_case.up.sql deleted file mode 100644 index 29f4956..0000000 --- a/qubership-apihub-service/resources/migrations/77_operation_type_lower_case.up.sql +++ /dev/null @@ -1,5 +0,0 @@ -update operation -set type = 'rest' where type = 'Rest'; - -update operation -set type = 'graphql' where type = 'GraphQL'; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/78_version_deleted_by.down.sql b/qubership-apihub-service/resources/migrations/78_version_deleted_by.down.sql deleted file mode 100644 index 1309245..0000000 --- a/qubership-apihub-service/resources/migrations/78_version_deleted_by.down.sql +++ /dev/null @@ -1 +0,0 @@ -alter table published_version drop column deleted_by; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/78_version_deleted_by.up.sql b/qubership-apihub-service/resources/migrations/78_version_deleted_by.up.sql deleted file mode 100644 index 76c5971..0000000 --- a/qubership-apihub-service/resources/migrations/78_version_deleted_by.up.sql +++ /dev/null @@ -1,3 +0,0 @@ -alter table published_version add column deleted_by varchar default null; - -update published_version set deleted_by = 'unknown' where deleted_at is not null; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/79_parent_package_names_func.down.sql b/qubership-apihub-service/resources/migrations/79_parent_package_names_func.down.sql deleted file mode 100644 index e7174ab..0000000 --- a/qubership-apihub-service/resources/migrations/79_parent_package_names_func.down.sql +++ /dev/null @@ -1 +0,0 @@ -drop function if exists parent_package_names; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/79_parent_package_names_func.up.sql b/qubership-apihub-service/resources/migrations/79_parent_package_names_func.up.sql deleted file mode 100644 index 8295c5d..0000000 --- a/qubership-apihub-service/resources/migrations/79_parent_package_names_func.up.sql +++ /dev/null @@ -1,31 +0,0 @@ -create or replace function parent_package_names(varchar) -returns varchar[] language plpgsql -as ' -declare -split varchar[] := string_to_array($1, ''.'')::varchar[]; -parent_ids varchar[]; -parent_names varchar[]; -begin - -if coalesce(array_length(split, 1), 0) <= 1 then - return ARRAY[]::varchar[]; -end if; - -parent_ids = parent_ids || split[1]; - -for i in 2..(array_length(split, 1) - 1) -loop - parent_ids = parent_ids || (parent_ids[i-1] ||''.''|| split[i]); -end loop; - -execute '' -select array_agg(name) from ( - select name from package_group - join unnest($1) with ordinality t(id, ord) using (id) --sort by parent_ids array - order by t.ord) n'' -into parent_names -using parent_ids; - -return parent_names; - -end;'; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/7_apihub_api_keys.down.sql b/qubership-apihub-service/resources/migrations/7_apihub_api_keys.down.sql deleted file mode 100644 index 165ff46..0000000 --- a/qubership-apihub-service/resources/migrations/7_apihub_api_keys.down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS apihub_api_keys CASCADE; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/7_apihub_api_keys.up.sql b/qubership-apihub-service/resources/migrations/7_apihub_api_keys.up.sql deleted file mode 100644 index 27f611c..0000000 --- a/qubership-apihub-service/resources/migrations/7_apihub_api_keys.up.sql +++ /dev/null @@ -1,16 +0,0 @@ -CREATE TABLE apihub_api_keys -( - id varchar PRIMARY KEY, - project_id varchar NOT NULL, - name varchar NOT NULL, - created_by varchar NOT NULL, - created_at timestamp without time zone NOT NULL, - deleted_by varchar NULL, - deleted_at timestamp without time zone NULL, - api_key varchar NOT NULL -) -; - -ALTER TABLE apihub_api_keys ADD CONSTRAINT "FK_project" - FOREIGN KEY (project_id) REFERENCES project (id) ON DELETE Cascade ON UPDATE Cascade -; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/80_at_table_remove_version.down.sql b/qubership-apihub-service/resources/migrations/80_at_table_remove_version.down.sql deleted file mode 100644 index ab90d00..0000000 --- a/qubership-apihub-service/resources/migrations/80_at_table_remove_version.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table activity_tracking - add version varchar; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/80_at_table_remove_version.up.sql b/qubership-apihub-service/resources/migrations/80_at_table_remove_version.up.sql deleted file mode 100644 index f18365d..0000000 --- a/qubership-apihub-service/resources/migrations/80_at_table_remove_version.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table activity_tracking - drop column version; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/81_remove_ref_relation_type.down.sql b/qubership-apihub-service/resources/migrations/81_remove_ref_relation_type.down.sql deleted file mode 100644 index 2b55572..0000000 --- a/qubership-apihub-service/resources/migrations/81_remove_ref_relation_type.down.sql +++ /dev/null @@ -1,4 +0,0 @@ -alter table branch_draft_reference drop constraint "PK_branch_draft_reference"; -alter table branch_draft_reference add column relation_type varchar not null default 'depend'; -alter table branch_draft_reference add constraint "PK_branch_draft_reference" - primary key (branch_name,project_id, reference_package_id, reference_version, relation_type); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/81_remove_ref_relation_type.up.sql b/qubership-apihub-service/resources/migrations/81_remove_ref_relation_type.up.sql deleted file mode 100644 index 2009645..0000000 --- a/qubership-apihub-service/resources/migrations/81_remove_ref_relation_type.up.sql +++ /dev/null @@ -1,4 +0,0 @@ -alter table branch_draft_reference drop constraint "PK_branch_draft_reference"; -alter table branch_draft_reference drop column relation_type; -alter table branch_draft_reference add constraint "PK_branch_draft_reference" - primary key (branch_name,project_id, reference_package_id, reference_version); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/82_frontend_version_delete.down.sql b/qubership-apihub-service/resources/migrations/82_frontend_version_delete.down.sql deleted file mode 100644 index 8d5d22e..0000000 --- a/qubership-apihub-service/resources/migrations/82_frontend_version_delete.down.sql +++ /dev/null @@ -1 +0,0 @@ -alter table agent add column if not exists frontend_version varchar; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/82_frontend_version_delete.up.sql b/qubership-apihub-service/resources/migrations/82_frontend_version_delete.up.sql deleted file mode 100644 index e94f5b5..0000000 --- a/qubership-apihub-service/resources/migrations/82_frontend_version_delete.up.sql +++ /dev/null @@ -1 +0,0 @@ -alter table agent drop column if exists frontend_version; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/83_cleaning_job_lock.down.sql b/qubership-apihub-service/resources/migrations/83_cleaning_job_lock.down.sql deleted file mode 100644 index e4ddb52..0000000 --- a/qubership-apihub-service/resources/migrations/83_cleaning_job_lock.down.sql +++ /dev/null @@ -1 +0,0 @@ -drop table build_cleanup_run; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/83_cleaning_job_lock.up.sql b/qubership-apihub-service/resources/migrations/83_cleaning_job_lock.up.sql deleted file mode 100644 index be960f1..0000000 --- a/qubership-apihub-service/resources/migrations/83_cleaning_job_lock.up.sql +++ /dev/null @@ -1 +0,0 @@ -create table build_cleanup_run(run_id integer primary key, scheduled_at timestamp, deleted_rows integer); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/84_migrations_table.up.sql b/qubership-apihub-service/resources/migrations/84_migrations_table.up.sql deleted file mode 100644 index 3de2f87..0000000 --- a/qubership-apihub-service/resources/migrations/84_migrations_table.up.sql +++ /dev/null @@ -1,9 +0,0 @@ -create table if not exists stored_schema_migration -( - num integer not null, - up_hash varchar not null, - sql_up varchar not null, - down_hash varchar null, - sql_down varchar null, - PRIMARY KEY(num) -); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/85_excludeFromSearch.down.sql b/qubership-apihub-service/resources/migrations/85_excludeFromSearch.down.sql deleted file mode 100644 index d29ce10..0000000 --- a/qubership-apihub-service/resources/migrations/85_excludeFromSearch.down.sql +++ /dev/null @@ -1 +0,0 @@ -alter table package_group drop column if exists exclude_from_search; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/85_excludeFromSearch.up.sql b/qubership-apihub-service/resources/migrations/85_excludeFromSearch.up.sql deleted file mode 100644 index 029701c..0000000 --- a/qubership-apihub-service/resources/migrations/85_excludeFromSearch.up.sql +++ /dev/null @@ -1 +0,0 @@ -alter table package_group add column if not exists exclude_from_search bool default false; diff --git a/qubership-apihub-service/resources/migrations/86_grouping_prefix.down.sql b/qubership-apihub-service/resources/migrations/86_grouping_prefix.down.sql deleted file mode 100644 index 2f6bc9b..0000000 --- a/qubership-apihub-service/resources/migrations/86_grouping_prefix.down.sql +++ /dev/null @@ -1,3 +0,0 @@ -drop table operations_group; - -alter table package_group drop column rest_grouping_prefix; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/86_grouping_prefix.up.sql b/qubership-apihub-service/resources/migrations/86_grouping_prefix.up.sql deleted file mode 100644 index 0c690a8..0000000 --- a/qubership-apihub-service/resources/migrations/86_grouping_prefix.up.sql +++ /dev/null @@ -1,16 +0,0 @@ -create table operations_group -( - package_id varchar not null, - version varchar not null, - revision integer not null, - group_name varchar not null, - api_type varchar not null, - operation_ids varchar array null, - autogenerated boolean not null, - PRIMARY KEY(package_id, version, revision, group_name, api_type) -); - -ALTER TABLE operations_group ADD CONSTRAINT "FK_published_version" - FOREIGN KEY (package_id, version, revision) REFERENCES published_version (package_id, version, revision) ON DELETE Cascade ON UPDATE Cascade; - -alter table package_group add column rest_grouping_prefix varchar default null; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/87_comparison_table.down.sql b/qubership-apihub-service/resources/migrations/87_comparison_table.down.sql deleted file mode 100644 index 1379b1d..0000000 --- a/qubership-apihub-service/resources/migrations/87_comparison_table.down.sql +++ /dev/null @@ -1,9 +0,0 @@ -alter table operation_comparison rename to changed_operation; - -alter table changed_operation drop constraint "FK_version_comparison"; - -alter table changed_operation drop column comparison_id; - -drop table version_comparison; - -truncate table changed_operation; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/87_comparison_table.up.sql b/qubership-apihub-service/resources/migrations/87_comparison_table.up.sql deleted file mode 100644 index eec9b94..0000000 --- a/qubership-apihub-service/resources/migrations/87_comparison_table.up.sql +++ /dev/null @@ -1,26 +0,0 @@ -create table version_comparison -( - package_id varchar not null, - version varchar not null, - revision integer not null, - previous_package_id varchar not null, - previous_version varchar not null, - previous_revision integer not null, - comparison_id varchar not null, - operation_types jsonb[] null, - refs varchar[] null, - open_count bigint not null, - last_active timestamp without time zone not null, - no_content boolean not null, - PRIMARY KEY(package_id, version, revision, previous_package_id, previous_version, previous_revision), - UNIQUE(comparison_id) -); - -truncate table changed_operation; - -alter table changed_operation RENAME TO operation_comparison; - -alter table operation_comparison add column comparison_id varchar; - -ALTER TABLE operation_comparison ADD CONSTRAINT "FK_version_comparison" - FOREIGN KEY (comparison_id) REFERENCES version_comparison (comparison_id) ON DELETE Cascade ON UPDATE Cascade; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/88_refs_redesign.down.sql b/qubership-apihub-service/resources/migrations/88_refs_redesign.down.sql deleted file mode 100644 index 32092f6..0000000 --- a/qubership-apihub-service/resources/migrations/88_refs_redesign.down.sql +++ /dev/null @@ -1,16 +0,0 @@ -delete from published_version_reference where parent_reference_id != ''; - -alter table published_version_reference -drop column reference_revision, -drop column parent_reference_id, -drop column parent_reference_version, -drop column parent_reference_revision; - -ALTER TABLE published_version_reference DROP CONSTRAINT if exists "PK_published_version_reference"; -ALTER TABLE published_version_reference ADD CONSTRAINT "PK_published_version_reference" - PRIMARY KEY ( - package_id, - version, - revision, - reference_id, - reference_version); \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/88_refs_redesign.up.sql b/qubership-apihub-service/resources/migrations/88_refs_redesign.up.sql deleted file mode 100644 index 7a9d187..0000000 --- a/qubership-apihub-service/resources/migrations/88_refs_redesign.up.sql +++ /dev/null @@ -1,58 +0,0 @@ -alter table published_version_reference -add column reference_revision integer not null default 0, -add column parent_reference_id varchar not null default '', -add column parent_reference_version varchar not null default '', -add column parent_reference_revision integer not null default 0; - -ALTER TABLE published_version_reference DROP CONSTRAINT if exists "PK_published_version_reference"; -ALTER TABLE published_version_reference ADD CONSTRAINT "PK_published_version_reference" - PRIMARY KEY ( - package_id, - version, - revision, - reference_id, - reference_version, - reference_revision, - parent_reference_id, - parent_reference_version, - parent_reference_revision) - ; - ---set latest revisions for all references -update published_version_reference r set reference_revision = maxrev.revision -from -( - select package_id, version, max(revision) as revision from published_version - group by package_id, version -) maxrev -where maxrev.package_id = r.reference_id -and maxrev.version = r.reference_version; - ---calculate references tree and store it in a flat way preserving parent link -insert into published_version_reference -with recursive rec as ( - select 0 as depth, s.package_id, s.version, s.revision, ''::varchar as parent_id, ''::varchar as parent_version, 0 as parent_revision, - s.package_id root_package_id, s.version root_version, s.revision root_revision - from published_version_reference s - inner join published_version_reference t - on s.package_id = t.package_id - and s.version = t.version - and s.revision = t.revision - where s.parent_reference_id = '' - union - select rec.depth+1 as depth, s.reference_id as package_id, s.reference_version as version, s.revision, - rec.package_id as parent_id, rec.version as parent_version, rec.revision as parent_revision, - rec.root_package_id root_package_id, rec.root_version root_version, rec.root_revision root_revision - from published_version_reference s - inner join rec - on rec.package_id = s.package_id - and rec.version = s.version - and rec.revision = s.revision - where s.parent_reference_id = '' -) -select r.root_package_id as package_id, r.root_version as version, r.root_revision as revision, -r.package_id as reference_id, r.version as reference_version, r.revision as reference_revision, -r.parent_id as parent_reference_id, r.parent_version as parent_reference_version, r.parent_revision as parent_reference_revision -from rec r -where r.depth > 0 -and not (r.parent_id = r.root_package_id and r.parent_version = r.root_version and r.parent_revision = r.root_revision); diff --git a/qubership-apihub-service/resources/migrations/89_deprecated_operation.down.sql b/qubership-apihub-service/resources/migrations/89_deprecated_operation.down.sql deleted file mode 100644 index f7eef94..0000000 --- a/qubership-apihub-service/resources/migrations/89_deprecated_operation.down.sql +++ /dev/null @@ -1,3 +0,0 @@ -alter table operation drop column if exists deprecated_info; -alter table operation drop column if exists deprecated_items; -alter table operation drop column if exists previous_release_versions; diff --git a/qubership-apihub-service/resources/migrations/89_deprecated_operation.up.sql b/qubership-apihub-service/resources/migrations/89_deprecated_operation.up.sql deleted file mode 100644 index 7bb80d3..0000000 --- a/qubership-apihub-service/resources/migrations/89_deprecated_operation.up.sql +++ /dev/null @@ -1,3 +0,0 @@ -alter table operation add column if not exists deprecated_info jsonb; -alter table operation add column if not exists deprecated_items jsonb[]; -alter table operation add column if not exists previous_release_versions varchar[]; diff --git a/qubership-apihub-service/resources/migrations/8_draft_publish_flag.down.sql b/qubership-apihub-service/resources/migrations/8_draft_publish_flag.down.sql deleted file mode 100644 index eb19ce3..0000000 --- a/qubership-apihub-service/resources/migrations/8_draft_publish_flag.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE branch_draft_content -DROP COLUMN publish; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/8_draft_publish_flag.up.sql b/qubership-apihub-service/resources/migrations/8_draft_publish_flag.up.sql deleted file mode 100644 index 3d685e1..0000000 --- a/qubership-apihub-service/resources/migrations/8_draft_publish_flag.up.sql +++ /dev/null @@ -1,5 +0,0 @@ -ALTER TABLE branch_draft_content - ADD COLUMN publish boolean; - -UPDATE branch_draft_content - SET publish = true; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/90_split_favorites.down.sql b/qubership-apihub-service/resources/migrations/90_split_favorites.down.sql deleted file mode 100644 index 94cba0d..0000000 --- a/qubership-apihub-service/resources/migrations/90_split_favorites.down.sql +++ /dev/null @@ -1,19 +0,0 @@ -ALTER TABLE favorite_projects DROP CONSTRAINT "PK_favorite_projects"; - -CREATE TABLE favorites -( - user_id varchar NOT NULL, - id varchar NOT NULL -); - -ALTER TABLE favorites ADD CONSTRAINT "PK_favorite_projects" - PRIMARY KEY (user_id, id); - -INSERT INTO favorites -(SELECT user_id, project_id from favorite_projects) ON CONFLICT DO NOTHING; - -INSERT INTO favorites -(SELECT user_id, package_id from favorite_packages) ON CONFLICT DO NOTHING; - -DROP TABLE favorite_projects; -DROP TABLE favorite_packages; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/90_split_favorites.up.sql b/qubership-apihub-service/resources/migrations/90_split_favorites.up.sql deleted file mode 100644 index 165243a..0000000 --- a/qubership-apihub-service/resources/migrations/90_split_favorites.up.sql +++ /dev/null @@ -1,51 +0,0 @@ -ALTER TABLE favorites DROP CONSTRAINT "PK_favorite_projects"; - -delete from favorites f -where f.user_id not in (select ud.user_id from user_data ud); - -CREATE TABLE favorite_projects -( - user_id varchar NOT NULL, - project_id varchar NOT NULL -); - -ALTER TABLE favorite_projects ADD CONSTRAINT "PK_favorite_projects" - PRIMARY KEY (user_id, project_id); - -ALTER TABLE favorite_projects ADD CONSTRAINT "FK_favorite_projects_project" - FOREIGN KEY (project_id) REFERENCES project(id) ON DELETE CASCADE; - -ALTER TABLE favorite_projects ADD CONSTRAINT "FK_favorite_projects_user_data" - FOREIGN KEY (user_id) REFERENCES user_data(user_id) ON DELETE CASCADE; - - -CREATE TABLE favorite_packages -( - user_id varchar NOT NULL, - package_id varchar NOT NULL -); - -ALTER TABLE favorite_packages ADD CONSTRAINT "PK_favorite_packages" - PRIMARY KEY (user_id, package_id); - -ALTER TABLE favorite_packages ADD CONSTRAINT "FK_favorite_packages_package_group" - FOREIGN KEY (package_id) REFERENCES package_group(id) ON DELETE CASCADE; - -ALTER TABLE favorite_packages ADD CONSTRAINT "FK_favorite_packages_user_data" - FOREIGN KEY (user_id) REFERENCES user_data(user_id) ON DELETE CASCADE; - -INSERT INTO favorite_projects -( - select f.* from favorites f - inner join project as p - on p.id = f.id -) ON CONFLICT DO NOTHING; - -INSERT INTO favorite_packages -( - select f.* from favorites f - inner join package_group as p - on p.id = f.id -) ON CONFLICT DO NOTHING; - -DROP TABLE favorites; diff --git a/qubership-apihub-service/resources/migrations/91_add_package_id_fks.down.sql b/qubership-apihub-service/resources/migrations/91_add_package_id_fks.down.sql deleted file mode 100644 index 752ac3a..0000000 --- a/qubership-apihub-service/resources/migrations/91_add_package_id_fks.down.sql +++ /dev/null @@ -1,21 +0,0 @@ -alter table build drop constraint if exists build_package_group_id_fk; - -alter table published_data drop constraint if exists published_data_package_group_id_fk; - -alter table published_sources_data drop constraint if exists published_sources_data_package_group_id_fk ; - -alter table shared_url_info drop constraint if exists shared_url_info_package_group_id_fk; - -alter table published_version_open_count drop constraint if exists published_version_open_count_package_group_id_fk; - -alter table activity_tracking drop constraint if exists activity_tracking_package_group_id_fk; - -alter table public.migrated_version drop constraint if exists migrated_version_package_group_id_fk; - -alter table published_document_open_count drop constraint if exists published_document_open_count_package_group_id_fk; - -alter table operation_comparison drop constraint if exists operation_comparison_package_group_id_fk; - -alter table ts_published_data_errors drop constraint if exists ts_published_data_errors_package_group_id_fk; - -alter table ts_published_data_custom_split drop constraint if exists ts_published_data_custom_split_package_group_id_fk; diff --git a/qubership-apihub-service/resources/migrations/91_add_package_id_fks.up.sql b/qubership-apihub-service/resources/migrations/91_add_package_id_fks.up.sql deleted file mode 100644 index 4722895..0000000 --- a/qubership-apihub-service/resources/migrations/91_add_package_id_fks.up.sql +++ /dev/null @@ -1,54 +0,0 @@ -alter table build - add constraint build_package_group_id_fk - foreign key (package_id) references package_group - on update cascade on delete cascade; - -alter table published_data - add constraint published_data_package_group_id_fk - foreign key (package_id) references package_group - on update cascade on delete cascade; - -alter table published_sources_data - add constraint published_sources_data_package_group_id_fk - foreign key (package_id) references package_group - on update cascade on delete cascade; - -alter table shared_url_info - add constraint shared_url_info_package_group_id_fk - foreign key (package_id) references package_group - on update cascade on delete cascade; - -alter table published_version_open_count - add constraint published_version_open_count_package_group_id_fk - foreign key (package_id) references package_group - on update cascade on delete cascade; - -alter table activity_tracking - add constraint activity_tracking_package_group_id_fk - foreign key (package_id) references package_group - on update cascade on delete cascade; - -alter table migrated_version - add constraint migrated_version_package_group_id_fk - foreign key (package_id) references package_group - on update cascade on delete cascade; - -alter table published_document_open_count - add constraint published_document_open_count_package_group_id_fk - foreign key (package_id) references package_group - on update cascade on delete cascade; - -alter table operation_comparison - add constraint operation_comparison_package_group_id_fk - foreign key (package_id) references package_group - on update cascade on delete cascade; - -alter table ts_published_data_errors - add constraint ts_published_data_errors_package_group_id_fk - foreign key (package_id) references package_group - on update cascade on delete cascade; - -alter table ts_published_data_custom_split - add constraint ts_published_data_custom_split_package_group_id_fk - foreign key (package_id) references package_group - on update cascade on delete cascade; diff --git a/qubership-apihub-service/resources/migrations/92_excluded_refs.down.sql b/qubership-apihub-service/resources/migrations/92_excluded_refs.down.sql deleted file mode 100644 index 4bd742b..0000000 --- a/qubership-apihub-service/resources/migrations/92_excluded_refs.down.sql +++ /dev/null @@ -1 +0,0 @@ -alter table published_version_reference drop column excluded; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/92_excluded_refs.up.sql b/qubership-apihub-service/resources/migrations/92_excluded_refs.up.sql deleted file mode 100644 index ec9880c..0000000 --- a/qubership-apihub-service/resources/migrations/92_excluded_refs.up.sql +++ /dev/null @@ -1,22 +0,0 @@ -alter table published_version_reference add column excluded boolean default false; - -update published_version_reference r set excluded = true -from ( - select - distinct on (package_id, version, revision, reference_id) - package_id, version, revision, reference_id, reference_version, reference_revision, parent_reference_id, parent_reference_version, parent_reference_revision - from published_version_reference - order by package_id, version, revision, reference_id, reference_version desc, reference_revision desc -) p -where r.package_id = p.package_id -and r.version = p.version -and r.revision = p.revision -and r.reference_id = p.reference_id - -and -(r.reference_version != p.reference_version -or r.reference_revision != p.reference_revision -or r.parent_reference_id != p.parent_reference_id -or r.parent_reference_version != p.parent_reference_version -or r.parent_reference_revision != p.parent_reference_revision) -; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/93_operation_comparison_fk.up.sql b/qubership-apihub-service/resources/migrations/93_operation_comparison_fk.up.sql deleted file mode 100644 index 647e5dc..0000000 --- a/qubership-apihub-service/resources/migrations/93_operation_comparison_fk.up.sql +++ /dev/null @@ -1 +0,0 @@ -alter table operation_comparison drop constraint if exists operation_comparison_package_group_id_fk; diff --git a/qubership-apihub-service/resources/migrations/94_manual_operation_grouping.down.sql b/qubership-apihub-service/resources/migrations/94_manual_operation_grouping.down.sql deleted file mode 100644 index 17aa3fe..0000000 --- a/qubership-apihub-service/resources/migrations/94_manual_operation_grouping.down.sql +++ /dev/null @@ -1,17 +0,0 @@ -drop table operation_group cascade; -drop table grouped_operation; - -create table operations_group -( - package_id varchar not null, - version varchar not null, - revision integer not null, - group_name varchar not null, - api_type varchar not null, - operation_ids varchar array null, - autogenerated boolean not null, - PRIMARY KEY(package_id, version, revision, group_name, api_type) -); - -ALTER TABLE operations_group ADD CONSTRAINT "FK_published_version" - FOREIGN KEY (package_id, version, revision) REFERENCES published_version (package_id, version, revision) ON DELETE Cascade ON UPDATE Cascade; diff --git a/qubership-apihub-service/resources/migrations/94_manual_operation_grouping.up.sql b/qubership-apihub-service/resources/migrations/94_manual_operation_grouping.up.sql deleted file mode 100644 index 05df7fb..0000000 --- a/qubership-apihub-service/resources/migrations/94_manual_operation_grouping.up.sql +++ /dev/null @@ -1,33 +0,0 @@ -drop table operations_group; - -create table operation_group -( - package_id varchar not null, - version varchar not null, - revision integer not null, - api_type varchar not null, - group_name varchar not null, - autogenerated boolean not null, - group_id varchar not null, - description varchar null, - PRIMARY KEY(package_id, version, revision, api_type, group_name), - UNIQUE(group_id) -); - -create table grouped_operation -( - group_id varchar not null, - package_id varchar not null, - version varchar not null, - revision integer not null, - operation_id varchar not null -); - -ALTER TABLE grouped_operation ADD CONSTRAINT "FK_operation_group" - FOREIGN KEY (group_id) REFERENCES operation_group (group_id) ON DELETE Cascade ON UPDATE Cascade; - -ALTER TABLE grouped_operation ADD CONSTRAINT "FK_operation" - FOREIGN KEY (package_id, version, revision, operation_id) REFERENCES operation (package_id, version, revision, operation_id) ON DELETE Cascade ON UPDATE Cascade; - -ALTER TABLE operation_group ADD CONSTRAINT "FK_published_version" - FOREIGN KEY (package_id, version, revision) REFERENCES published_version (package_id, version, revision) ON DELETE Cascade ON UPDATE Cascade; diff --git a/qubership-apihub-service/resources/migrations/95_src_fix.down.sql b/qubership-apihub-service/resources/migrations/95_src_fix.down.sql deleted file mode 100644 index af2e2ce..0000000 --- a/qubership-apihub-service/resources/migrations/95_src_fix.down.sql +++ /dev/null @@ -1,22 +0,0 @@ -alter table published_sources DROP CONSTRAINT IF EXISTS published_sources_published_sources_archives_checksum_fk; - -alter table published_sources drop column archive_checksum; - -drop table published_sources_archives; - -delete from published_sources -where (package_id, checksum) in -( - select package_id, checksum from published_sources - except - select package_id, checksum from published_sources_data -); - -delete from published_sources where checksum is null; - -alter table published_sources - add constraint "FK_published_sources_data" - foreign key (checksum, package_id) references published_sources_data; - -alter table published_sources - alter column checksum set not null; diff --git a/qubership-apihub-service/resources/migrations/95_src_fix.up.sql b/qubership-apihub-service/resources/migrations/95_src_fix.up.sql deleted file mode 100644 index c27f1b1..0000000 --- a/qubership-apihub-service/resources/migrations/95_src_fix.up.sql +++ /dev/null @@ -1,17 +0,0 @@ -create table published_sources_archives -( - checksum varchar - constraint published_sources_archives_pk - primary key, - data bytea -); - -alter table published_sources - add archive_checksum varchar; - -alter table published_sources - drop constraint "FK_published_sources_data"; - -alter table published_sources - alter column checksum drop not null; - diff --git a/qubership-apihub-service/resources/migrations/96_latest_revision_func.down.sql b/qubership-apihub-service/resources/migrations/96_latest_revision_func.down.sql deleted file mode 100644 index 9ddaf79..0000000 --- a/qubership-apihub-service/resources/migrations/96_latest_revision_func.down.sql +++ /dev/null @@ -1 +0,0 @@ -drop function if exists get_latest_revision \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/96_latest_revision_func.up.sql b/qubership-apihub-service/resources/migrations/96_latest_revision_func.up.sql deleted file mode 100644 index f7818bb..0000000 --- a/qubership-apihub-service/resources/migrations/96_latest_revision_func.up.sql +++ /dev/null @@ -1,16 +0,0 @@ -create or replace function get_latest_revision(package_id varchar, version varchar) - returns integer language plpgsql -as ' - declare - latest_revision integer; - begin - execute '' - select max(revision) - from published_version - where package_id = $1 and version = $2 and deleted_at is null;'' - into latest_revision - using package_id,version; - if latest_revision is null then return 0; - end if; - return latest_revision; - end;'; diff --git a/qubership-apihub-service/resources/migrations/97_activity_event_revision.down.sql b/qubership-apihub-service/resources/migrations/97_activity_event_revision.down.sql deleted file mode 100644 index 771ee91..0000000 --- a/qubership-apihub-service/resources/migrations/97_activity_event_revision.down.sql +++ /dev/null @@ -1,3 +0,0 @@ -update activity_tracking set data = data::jsonb - 'revision' where e_type = 'publish_new_version'; -update activity_tracking set data = data::jsonb - 'revision' where e_type = 'patch_version_meta'; -update activity_tracking set data = data::jsonb - 'revision' where e_type = 'delete_version'; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/97_activity_event_revision.up.sql b/qubership-apihub-service/resources/migrations/97_activity_event_revision.up.sql deleted file mode 100644 index 45569f5..0000000 --- a/qubership-apihub-service/resources/migrations/97_activity_event_revision.up.sql +++ /dev/null @@ -1,7 +0,0 @@ -update activity_tracking set data = jsonb_set(data, '{revision}',to_jsonb(1)) where e_type = 'publish_new_version'; - -update activity_tracking as at set data = jsonb_set(data, '{revision}',to_jsonb((select revision from published_version as pv where pv.version = at.data #>> '{version}' and pv.package_id = at.package_id order by revision desc limit 1))) -where e_type = 'patch_version_meta'; - -update activity_tracking as at set data = jsonb_set(data, '{revision}',to_jsonb((select revision from published_version as pv where pv.version = at.data #>> '{version}' and pv.package_id = at.package_id order by revision desc limit 1))) -where e_type = 'delete_version'; diff --git a/qubership-apihub-service/resources/migrations/98_deleted_grouped_operations.down.sql b/qubership-apihub-service/resources/migrations/98_deleted_grouped_operations.down.sql deleted file mode 100644 index 1ca1031..0000000 --- a/qubership-apihub-service/resources/migrations/98_deleted_grouped_operations.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -delete from grouped_operation where deleted = true; -alter table grouped_operation drop column deleted; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/98_deleted_grouped_operations.up.sql b/qubership-apihub-service/resources/migrations/98_deleted_grouped_operations.up.sql deleted file mode 100644 index 93f0072..0000000 --- a/qubership-apihub-service/resources/migrations/98_deleted_grouped_operations.up.sql +++ /dev/null @@ -1 +0,0 @@ -alter table grouped_operation add column deleted boolean default false; diff --git a/qubership-apihub-service/resources/migrations/99_gql_search_scopes.down.sql b/qubership-apihub-service/resources/migrations/99_gql_search_scopes.down.sql deleted file mode 100644 index f5bf239..0000000 --- a/qubership-apihub-service/resources/migrations/99_gql_search_scopes.down.sql +++ /dev/null @@ -1,14 +0,0 @@ -drop index ts_graphql_operation_data_idx; -drop table ts_graphql_operation_data; - -alter table ts_rest_operation_data add column scope_all tsvector; - -drop index ts_operation_data_idx; - -update ts_rest_operation_data r_od set scope_all = (select scope_all from ts_operation_data od where od.data_hash = r_od.data_hash); - -drop table ts_operation_data; - -alter table ts_rest_operation_data rename constraint pk_ts_rest_operation_data to pk_ts_operation_data; -alter index ts_rest_operation_data_idx rename to ts_operation_data_idx; -alter table ts_rest_operation_data rename to ts_operation_data; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/99_gql_search_scopes.up.sql b/qubership-apihub-service/resources/migrations/99_gql_search_scopes.up.sql deleted file mode 100644 index 1367d02..0000000 --- a/qubership-apihub-service/resources/migrations/99_gql_search_scopes.up.sql +++ /dev/null @@ -1,32 +0,0 @@ -alter table ts_operation_data rename to ts_rest_operation_data; -alter index ts_operation_data_idx rename to ts_rest_operation_data_idx; -alter table ts_rest_operation_data rename constraint pk_ts_operation_data to pk_ts_rest_operation_data; - -CREATE TABLE ts_operation_data( - data_hash varchar NOT NULL, - scope_all tsvector, - CONSTRAINT pk_ts_operation_data PRIMARY KEY(data_hash) -); - -insert into ts_operation_data -select data_hash, scope_all from ts_rest_operation_data where scope_all is not null; - -CREATE INDEX ts_operation_data_idx -ON ts_operation_data -USING gin(scope_all) -with (fastupdate = true); - -alter table ts_rest_operation_data drop column scope_all; - -CREATE TABLE ts_graphql_operation_data( - data_hash varchar NOT NULL, - scope_argument tsvector, - scope_property tsvector, - scope_annotation tsvector, - CONSTRAINT pk_ts_graphql_operation_data PRIMARY KEY(data_hash) -); - -CREATE INDEX ts_graphql_operation_data_idx -ON ts_graphql_operation_data -USING gin(scope_argument, scope_property, scope_annotation) -with (fastupdate = true); diff --git a/qubership-apihub-service/resources/migrations/9_published_metadata.down.sql b/qubership-apihub-service/resources/migrations/9_published_metadata.down.sql deleted file mode 100644 index 8358ec7..0000000 --- a/qubership-apihub-service/resources/migrations/9_published_metadata.down.sql +++ /dev/null @@ -1,25 +0,0 @@ -ALTER TABLE published_version - ADD COLUMN branch_name varchar; - -update published_version t -set branch_name = jsonb_extract_path_text(s.metadata, 'branch_name') -from published_version s -where t.project_id = s.project_id - and t.version = s.version - and t.revision = s.revision; - -ALTER TABLE published_version - DROP COLUMN metadata; - -ALTER TABLE published_data - ADD COLUMN commit_id varchar, - ADD COLUMN commit_date timestamp without time zone; - -update published_data t -set commit_id = jsonb_extract_path_text(s.metadata, 'commit_id') -from published_data s -where t.project_id = s.project_id - and t.checksum = s.checksum; - -ALTER TABLE published_data - DROP COLUMN metadata; \ No newline at end of file diff --git a/qubership-apihub-service/resources/migrations/9_published_metadata.up.sql b/qubership-apihub-service/resources/migrations/9_published_metadata.up.sql deleted file mode 100644 index aab2e27..0000000 --- a/qubership-apihub-service/resources/migrations/9_published_metadata.up.sql +++ /dev/null @@ -1,26 +0,0 @@ -ALTER TABLE published_version - ADD COLUMN metadata jsonb; - -update published_version t -set metadata = jsonb_build_object('branch_name', s.branch_name) -from published_version s -where t.project_id = s.project_id - and t.version = s.version - and t.revision = s.revision; - -ALTER TABLE published_version - DROP COLUMN branch_name; - - -ALTER TABLE published_data - ADD COLUMN metadata jsonb; - -update published_data t -set metadata = jsonb_build_object('commit_id', s.commit_id, 'commit_date', to_char(s.commit_date,'DD-MM-YYYY hh24:mi:ss')) -from published_data s -where t.project_id = s.project_id - and t.checksum = s.checksum; - -ALTER TABLE published_data - DROP COLUMN commit_id, - DROP COLUMN commit_date; diff --git a/qubership-apihub-service/service.txt b/qubership-apihub-service/service.txt new file mode 100644 index 0000000..2864b60 --- /dev/null +++ b/qubership-apihub-service/service.txt @@ -0,0 +1,723 @@ +package main + +import ( + "context" + "io" + "net/http" + _ "net/http/pprof" + "os" + "path" + "runtime/debug" + "strings" + "sync" + "time" + + "gopkg.in/natefinch/lumberjack.v2" + + "git.netcracker.com/prod.platform.apihub/apihub-backend/apihub-service/metrics" + midldleware "git.netcracker.com/prod.platform.apihub/apihub-backend/apihub-service/middleware" + "github.com/prometheus/client_golang/prometheus/promhttp" + + "git.netcracker.com/prod.platform.apihub/apihub-backend/apihub-service/exception" + mController "git.netcracker.com/prod.platform.apihub/apihub-backend/apihub-service/migration/controller" + mRepository "git.netcracker.com/prod.platform.apihub/apihub-backend/apihub-service/migration/repository" + mService "git.netcracker.com/prod.platform.apihub/apihub-backend/apihub-service/migration/service" + "git.netcracker.com/prod.platform.apihub/apihub-backend/apihub-service/utils" + + "git.netcracker.com/prod.platform.apihub/apihub-backend/apihub-service/cache" + + "git.netcracker.com/prod.platform.apihub/apihub-backend/apihub-service/db" + + "git.netcracker.com/prod.platform.apihub/apihub-backend/apihub-service/view" + + "git.netcracker.com/prod.platform.apihub/apihub-backend/apihub-service/client" + "git.netcracker.com/prod.platform.apihub/apihub-backend/apihub-service/controller" + "git.netcracker.com/prod.platform.apihub/apihub-backend/apihub-service/repository" + "git.netcracker.com/prod.platform.apihub/apihub-backend/apihub-service/security" + "git.netcracker.com/prod.platform.apihub/apihub-backend/apihub-service/service" + + "github.com/gorilla/handlers" + "github.com/gorilla/mux" + log "github.com/sirupsen/logrus" + prefixed "github.com/x-cray/logrus-prefixed-formatter" +) + +func init() { + basePath := os.Getenv("BASE_PATH") + if basePath == "" { + basePath = "." + } + mw := io.MultiWriter(os.Stderr, &lumberjack.Logger{ + Filename: basePath + "/logs/apihub.log", + MaxSize: 10, // megabytes + }) + log.SetFormatter(&prefixed.TextFormatter{ + DisableColors: true, + TimestampFormat: "2006-01-02 15:04:05", + FullTimestamp: true, + ForceFormatting: true, + }) + logLevel, err := log.ParseLevel(os.Getenv("LOG_LEVEL")) + if err != nil { + logLevel = log.InfoLevel + } + log.SetLevel(logLevel) + log.SetOutput(mw) +} + +func main() { + systemInfoService, err := service.NewSystemInfoService() + if err != nil { + panic(err) + } + basePath := systemInfoService.GetBasePath() + + gitlabUrl := systemInfoService.GetGitlabUrl() + + // Create router and server to expose live and ready endpoints during initialization + readyChan := make(chan bool) + migrationPassedChan := make(chan bool) + initSrvStoppedChan := make(chan bool) + r := mux.NewRouter() + r.Use(midldleware.PrometheusMiddleware) + r.SkipClean(true) + r.UseEncodedPath() + healthController := controller.NewHealthController(readyChan) + r.HandleFunc("/live", healthController.HandleLiveRequest).Methods(http.MethodGet) + r.HandleFunc("/ready", healthController.HandleReadyRequest).Methods(http.MethodGet) + initSrv := makeServer(systemInfoService, r) + + creds := systemInfoService.GetCredsFromEnv() + + cp := db.NewConnectionProvider(creds) + + migrationRunRepository := mRepository.NewMigrationRunRepository(cp) + buildCleanupRepository := repository.NewBuildCleanupRepository(cp) + transitionRepository := repository.NewTransitionRepository(cp) + buildResultRepository := repository.NewBuildResultRepository(cp) + publishedRepository, err := repository.NewPublishedRepositoryPG(cp) + if err != nil { + log.Error("Failed to create PublishedRepository: " + err.Error()) + panic("Failed to create PublishedRepository: " + err.Error()) + } + minioStorageCreds := systemInfoService.GetMinioStorageCreds() + minioStorageService := service.NewMinioStorageService(buildResultRepository, publishedRepository, minioStorageCreds) + dbMigrationService, err := mService.NewDBMigrationService(cp, migrationRunRepository, buildCleanupRepository, transitionRepository, systemInfoService, minioStorageService) + if err != nil { + log.Error("Failed create dbMigrationService: " + err.Error()) + panic("Failed create dbMigrationService: " + err.Error()) + } + + go func(initSrvStoppedChan chan bool) { // Do not use safe async here to enable panic + log.Debugf("Starting init srv") + _ = initSrv.ListenAndServe() + log.Debugf("Init srv closed") + initSrvStoppedChan <- true + close(initSrvStoppedChan) + }(initSrvStoppedChan) + + go func(migrationReadyChan chan bool) { // Do not use safe async here to enable panic + passed := <-migrationPassedChan + err := initSrv.Shutdown(context.Background()) + if err != nil { + log.Fatalf("Failed to shutdown initial server") + } + if !passed { + log.Fatalf("Stopping server since migration failed") + } + migrationReadyChan <- true + close(migrationReadyChan) + close(migrationPassedChan) + }(readyChan) + + wg := sync.WaitGroup{} + wg.Add(1) + + go func() { // Do not use safe async here to enable panic + defer wg.Done() + + currentVersion, newVersion, migrationRequired, err := dbMigrationService.Migrate(basePath) + if err != nil { + log.Error("Failed perform DB migration: " + err.Error()) + time.Sleep(time.Second * 10) // Give a chance to read the unrecoverable error + panic("Failed perform DB migration: " + err.Error()) + } + // to perform migrations, which could not be implemented with "pure" SQL + err = dbMigrationService.SoftMigrateDb(currentVersion, newVersion, migrationRequired) + if err != nil { + log.Errorf("Failed to perform db migrations: %v", err.Error()) + time.Sleep(time.Second * 10) // Give a chance to read the unrecoverable error + panic("Failed to perform db migrations: " + err.Error()) + } + migrationPassedChan <- true + }() + + wg.Wait() + _ = <-initSrvStoppedChan // wait for the init srv to stop to avoid multiple servers started race condition + log.Infof("Migration step passed, continue initialization") + + gitIntegrationRepository, err := repository.NewGitIntegrationRepositoryPG(cp) + if err != nil { + log.Error("Failed to create UserIntegrationsRepository: " + err.Error()) + panic("Failed to create UserIntegrationsRepository: " + err.Error()) + } + + projectRepository, err := repository.NewPrjGrpIntRepositoryPG(cp) + if err != nil { + log.Error("Failed to create PrjGrpIntRepository: " + err.Error()) + panic("Failed to create PrjGrpIntRepository: " + err.Error()) + } + + draftRepository, err := repository.NewDraftRepositoryPG(cp) + if err != nil { + log.Error("Failed to create DraftRepository: " + err.Error()) + panic("Failed to create DraftRepository: " + err.Error()) + } + + favoritesRepository, err := repository.NewFavoritesRepositoryPG(cp) + if err != nil { + log.Error("Failed to create FavoriteRepository: " + err.Error()) + panic("Failed to create FavoriteRepository: " + err.Error()) + } + + usersRepository, err := repository.NewUserRepositoryPG(cp) + if err != nil { + log.Error("Failed to create UsersRepository: " + err.Error()) + panic("Failed to create UsersRepository: " + err.Error()) + } + apihubApiKeyRepository, err := repository.NewApihubApiKeyRepositoryPG(cp) + if err != nil { + log.Error("Failed to create ApihubApiKeyRepository: " + err.Error()) + panic("Failed to create ApihubApiKeyRepository: " + err.Error()) + } + branchRepository, err := repository.NewBranchRepositoryPG(cp) + if err != nil { + log.Error("Failed to create BranchRepository: " + err.Error()) + panic("Failed to create BranchRepository: " + err.Error()) + } + buildRepository, err := repository.NewBuildRepositoryPG(cp) + if err != nil { + log.Error("Failed to create BuildRepository: " + err.Error()) + panic("Failed to create BuildRepository: " + err.Error()) + } + + roleRepository := repository.NewRoleRepository(cp) + operationRepository := repository.NewOperationRepository(cp) + agentRepository := repository.NewAgentRepository(cp) + businessMetricRepository := repository.NewBusinessMetricRepository(cp) + + activityTrackingRepository := repository.NewActivityTrackingRepository(cp) + + versionCleanupRepository := repository.NewVersionCleanupRepository(cp) + + olricProvider, err := cache.NewOlricProvider() + if err != nil { + log.Error("Failed to create olricProvider: " + err.Error()) + panic("Failed to create olricProvider: " + err.Error()) + } + + configs := []client.GitClientConfiguration{{Integration: view.GitlabIntegration, BaseUrl: gitlabUrl}} + tokenRevocationHandler := service.NewTokenRevocationHandler(gitIntegrationRepository, olricProvider) + tokenExpirationHandler := service.NewTokenExpirationHandler(gitIntegrationRepository, olricProvider, systemInfoService) + gitClientProvider, err := service.NewGitClientProvider(configs, gitIntegrationRepository, tokenRevocationHandler, tokenExpirationHandler, olricProvider) + if err != nil { + log.Error("Failed to create GitClientProvider: " + err.Error()) + panic("Failed to create GitClientProvider: " + err.Error()) + } + privateUserPackageService := service.NewPrivateUserPackageService(publishedRepository, usersRepository, roleRepository, favoritesRepository) + integrationsService := service.NewIntegrationsService(gitIntegrationRepository, gitClientProvider) + userService := service.NewUserService(usersRepository, gitClientProvider, systemInfoService, privateUserPackageService) + + projectService := service.NewProjectService(gitClientProvider, projectRepository, favoritesRepository, publishedRepository) + groupService := service.NewGroupService(projectRepository, projectService, favoritesRepository, publishedRepository, usersRepository) + + wsLoadBalancer, err := service.NewWsLoadBalancer(olricProvider) + if err != nil { + log.Error("Failed to create wsLoadBalancer: " + err.Error()) + panic("Failed to create wsLoadBalancer: " + err.Error()) + } + + templateService := service.NewTemplateService() + + cleanupService := service.NewCleanupService(cp) + monitoringService := service.NewMonitoringService(cp) + packageVersionEnrichmentService := service.NewPackageVersionEnrichmentService(publishedRepository) + activityTrackingService := service.NewActivityTrackingService(activityTrackingRepository, publishedRepository, userService) + operationService := service.NewOperationService(operationRepository, publishedRepository, packageVersionEnrichmentService) + roleService := service.NewRoleService(roleRepository, userService, activityTrackingService, publishedRepository) + wsBranchService := service.NewWsBranchService(userService, wsLoadBalancer) + branchEditorsService := service.NewBranchEditorsService(userService, wsBranchService, branchRepository, olricProvider) + branchService := service.NewBranchService(projectService, draftRepository, gitClientProvider, publishedRepository, wsBranchService, branchEditorsService, branchRepository) + projectFilesService := service.NewProjectFilesService(gitClientProvider, projectRepository, branchService) + ptHandler := service.NewPackageTransitionHandler(transitionRepository) + publishedService := service.NewPublishedService(branchService, publishedRepository, projectRepository, buildRepository, gitClientProvider, wsBranchService, favoritesRepository, operationRepository, activityTrackingService, monitoringService, minioStorageService, systemInfoService) + contentService := service.NewContentService(draftRepository, projectService, branchService, gitClientProvider, wsBranchService, templateService, systemInfoService) + refService := service.NewRefService(draftRepository, projectService, branchService, publishedRepository, wsBranchService) + wsFileEditService := service.NewWsFileEditService(userService, contentService, branchEditorsService, wsLoadBalancer) + portalService := service.NewPortalService(basePath, publishedService, publishedRepository, projectRepository) + operationGroupService := service.NewOperationGroupService(operationRepository, publishedRepository, packageVersionEnrichmentService, activityTrackingService) + versionService := service.NewVersionService(gitClientProvider, projectRepository, favoritesRepository, publishedRepository, publishedService, operationRepository, operationService, activityTrackingService, systemInfoService, packageVersionEnrichmentService, portalService, versionCleanupRepository, operationGroupService) + packageService := service.NewPackageService(gitClientProvider, projectRepository, favoritesRepository, publishedRepository, versionService, roleService, activityTrackingService, operationGroupService, usersRepository, ptHandler, systemInfoService) + + logsService := service.NewLogsService() + internalWebsocketService := service.NewInternalWebsocketService(wsLoadBalancer, olricProvider) + commitService := service.NewCommitService(draftRepository, contentService, branchService, projectService, gitClientProvider, wsBranchService, wsFileEditService, branchEditorsService) + searchService := service.NewSearchService(projectService, publishedService, branchService, gitClientProvider, contentService) + apihubApiKeyService := service.NewApihubApiKeyService(apihubApiKeyRepository, publishedRepository, activityTrackingService, userService, roleRepository, roleService.IsSysadm) + + refResolverService := service.NewRefResolverService(publishedRepository) + buildProcessorService := service.NewBuildProcessorService(buildRepository, refResolverService) + buildService := service.NewBuildService(buildRepository, buildProcessorService, publishedService, systemInfoService, packageService, refResolverService) + buildResultService := service.NewBuildResultService(buildResultRepository, systemInfoService, minioStorageService) + versionService.SetBuildService(buildService) + operationGroupService.SetBuildService(buildService) + + agentService := service.NewAgentRegistrationService(agentRepository) + excelService := service.NewExcelService(publishedRepository, versionService, operationService, packageService) + comparisonService := service.NewComparisonService(publishedRepository, operationRepository, packageVersionEnrichmentService) + businessMetricService := service.NewBusinessMetricService(businessMetricRepository) + + dbCleanupService := service.NewDBCleanupService(buildCleanupRepository, migrationRunRepository, minioStorageService, systemInfoService) + if err := dbCleanupService.CreateCleanupJob(systemInfoService.GetBuildsCleanupSchedule()); err != nil { + log.Error("Failed to start cleaning job" + err.Error()) + } + + transitionService := service.NewTransitionService(transitionRepository, publishedRepository) + transformationService := service.NewTransformationService(publishedRepository, operationRepository) + + gitHookService := service.NewGitHookService(projectRepository, branchService, buildService, userService) + + zeroDayAdminService := service.NewZeroDayAdminService(userService, roleService, usersRepository) + + integrationsController := controller.NewIntegrationsController(integrationsService) + projectController := controller.NewProjectController(projectService, groupService, searchService) + branchController := controller.NewBranchController(branchService, commitService, projectFilesService, searchService, publishedService, branchEditorsService, wsBranchService) + groupController := controller.NewGroupController(groupService, publishedService, roleService) + contentController := controller.NewContentController(contentService, branchService, searchService, wsFileEditService, wsBranchService, systemInfoService) + publishedController := controller.NewPublishedController(publishedService, portalService, searchService) + refController := controller.NewRefController(refService, wsBranchService) + branchWSController := controller.NewBranchWSController(branchService, wsLoadBalancer, internalWebsocketService) + fileWSController := controller.NewFileWSController(wsFileEditService, wsLoadBalancer, internalWebsocketService) + + logsController := controller.NewLogsController(logsService, roleService) + systemInfoController := controller.NewSystemInfoController(systemInfoService) + sysAdminController := controller.NewSysAdminController(roleService) + apihubApiKeyController := controller.NewApihubApiKeyController(apihubApiKeyService, roleService) + cleanupController := controller.NewCleanupController(cleanupService) + + agentClient := client.NewAgentClient() + agentController := controller.NewAgentController(agentService, agentClient) + agentProxyController := controller.NewAgentProxyController(agentService, systemInfoService) + playgroundProxyController := controller.NewPlaygroundProxyController(systemInfoService) + publishV2Controller := controller.NewPublishV2Controller(buildService, publishedService, buildResultService, roleService, systemInfoService) + exportController := controller.NewExportController(publishedService, portalService, searchService, roleService, excelService, versionService, monitoringService) + + packageController := controller.NewPackageController(packageService, publishedService, portalService, searchService, roleService, monitoringService, ptHandler) + versionController := controller.NewVersionController(versionService, roleService, monitoringService, ptHandler, roleService.IsSysadm) + roleController := controller.NewRoleController(roleService) + samlAuthController := security.NewSamlAuthController(userService, systemInfoService) + userController := controller.NewUserController(userService, privateUserPackageService, roleService.IsSysadm) + jwtPubKeyController := security.NewJwtPubKeyController() + oauthController := security.NewOauth20Controller(integrationsService, userService, systemInfoService) + operationController := controller.NewOperationController(roleService, operationService, buildService, monitoringService, ptHandler) + operationGroupController := controller.NewOperationGroupController(roleService, operationGroupService, versionService) + searchController := controller.NewSearchController(operationService, versionService, monitoringService) + tempMigrationController := mController.NewTempMigrationController(dbMigrationService, roleService.IsSysadm) + activityTrackingController := controller.NewActivityTrackingController(activityTrackingService, roleService, ptHandler) + comparisonController := controller.NewComparisonController(operationService, versionService, buildService, roleService, comparisonService, monitoringService, ptHandler) + buildCleanupController := controller.NewBuildCleanupController(dbCleanupService, roleService.IsSysadm) + transitionController := controller.NewTransitionController(transitionService, roleService.IsSysadm) + businessMetricController := controller.NewBusinessMetricController(businessMetricService, excelService, roleService.IsSysadm) + + apiDocsController := controller.NewApiDocsController(basePath) + + transformationController := controller.NewTransformationController(roleService, buildService, versionService, transformationService, operationGroupService) + + minioStorageController := controller.NewMinioStorageController(minioStorageCreds, minioStorageService) + + gitHookController := controller.NewGitHookController(gitHookService) + + r.HandleFunc("/api/v1/integrations/{integrationId}/apikey", security.Secure(integrationsController.GetUserApiKeyStatus)).Methods(http.MethodGet) + r.HandleFunc("/api/v1/integrations/{integrationId}/apikey", security.Secure(integrationsController.SetUserApiKey)).Methods(http.MethodPut) + r.HandleFunc("/api/v1/integrations/{integrationId}/repositories", security.Secure(integrationsController.ListRepositories)).Methods(http.MethodGet) + r.HandleFunc("/api/v1/integrations/{integrationId}/repositories/{repositoryId}/branches", security.Secure(integrationsController.ListBranchesAndTags)).Methods(http.MethodGet) + + r.HandleFunc("/api/v1/projects", security.Secure(projectController.GetFilteredProjects)).Methods(http.MethodGet) + r.HandleFunc("/api/v1/projects", security.Secure(projectController.AddProject)).Methods(http.MethodPost) + r.HandleFunc("/api/v1/projects/{projectId}", security.Secure(projectController.GetProject)).Methods(http.MethodGet) + r.HandleFunc("/api/v1/projects/{projectId}", security.Secure(projectController.UpdateProject)).Methods(http.MethodPut) + r.HandleFunc("/api/v1/projects/{projectId}", security.Secure(projectController.DeleteProject)).Methods(http.MethodDelete) + r.HandleFunc("/api/v1/projects/{projectId}/favor", security.Secure(projectController.FavorProject)).Methods(http.MethodPost) + r.HandleFunc("/api/v1/projects/{projectId}/disfavor", security.Secure(projectController.DisfavorProject)).Methods(http.MethodPost) + + r.HandleFunc("/api/v1/groups", security.Secure(groupController.AddGroup)).Methods(http.MethodPost) + r.HandleFunc("/api/v1/groups/{groupId}", security.Secure(groupController.GetGroupInfo)).Methods(http.MethodGet) + r.HandleFunc("/api/v1/groups", security.Secure(groupController.GetAllGroups)).Methods(http.MethodGet) + r.HandleFunc("/api/v1/groups/{groupId}/favor", security.Secure(groupController.FavorGroup)).Methods(http.MethodPost) + r.HandleFunc("/api/v1/groups/{groupId}/disfavor", security.Secure(groupController.DisfavorGroup)).Methods(http.MethodPost) + + r.HandleFunc("/api/v1/projects/{projectId}/branches", security.Secure(branchController.GetProjectBranches)).Methods(http.MethodGet) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}", security.Secure(branchController.GetProjectBranchDetails)).Methods(http.MethodGet) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/config", security.Secure(branchController.GetProjectBranchConfigRaw)).Methods(http.MethodGet) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/save", security.Secure(branchController.CommitBranchDraftChanges)).Methods(http.MethodPost) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/zip", security.Secure(branchController.GetProjectBranchContentZip)).Methods(http.MethodGet) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/integration/files", security.Secure(branchController.GetProjectBranchFiles)).Methods(http.MethodGet) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/history", security.Secure(branchController.GetProjectBranchCommitHistory_deprecated)).Methods(http.MethodGet) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}", security.Secure(branchController.DeleteBranch)).Methods(http.MethodDelete) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/clone", security.Secure(branchController.CloneBranch)).Methods(http.MethodPost) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/reset", security.Secure(branchController.DeleteBranchDraft)).Methods(http.MethodPost) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/conflicts", security.Secure(branchController.GetBranchConflicts)).Methods(http.MethodGet) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/integration/files", security.Secure(contentController.AddFile)).Methods(http.MethodPost) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/refs", security.Secure(refController.UpdateRefs)).Methods(http.MethodPatch) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/editors", security.Secure(branchController.AddBranchEditor)).Methods(http.MethodPost) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/editors", security.Secure(branchController.RemoveBranchEditor)).Methods(http.MethodDelete) + + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/files/{fileId}", security.Secure(contentController.GetContent)).Methods(http.MethodGet) //deprecated??? + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/files/{fileId}/file", security.Secure(contentController.GetContentAsFile)).Methods(http.MethodGet) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/files/{fileId}", security.Secure(contentController.UpdateContent)).Methods(http.MethodPut) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/upload", security.Secure(contentController.UploadContent)).Methods(http.MethodPost) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/files/{fileId}/history", security.Secure(contentController.GetContentHistory)).Methods(http.MethodGet) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/files/{fileId}/history/{commitId}", security.Secure(contentController.GetContentFromCommit)).Methods(http.MethodGet) + r.HandleFunc("/api/v1/projects/{projectId}/blobs/{blobId}", security.Secure(contentController.GetContentFromBlobId)).Methods(http.MethodGet) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/files/{fileId}/rename", security.Secure(contentController.MoveFile)).Methods(http.MethodPost) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/files/{fileId}/reset", security.Secure(contentController.ResetFile)).Methods(http.MethodPost) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/files/{fileId}/restore", security.Secure(contentController.RestoreFile)).Methods(http.MethodPost) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/files/{fileId}", security.Secure(contentController.DeleteFile)).Methods(http.MethodDelete) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/files/{fileId}/meta", security.Secure(contentController.UpdateMetadata)).Methods(http.MethodPatch) + r.HandleFunc("/api/v1/projects/{projectId}/branches/{branchName}/allfiles", security.Secure(contentController.GetAllContent)).Methods(http.MethodGet) + + r.HandleFunc("/api/v1/projects/{packageId}/versions/{version}", security.Secure(publishedController.GetVersion)).Methods(http.MethodGet) + r.HandleFunc("/api/v1/projects/{packageId}/versions/{version}/documentation", security.Secure(publishedController.GenerateVersionDocumentation)).Methods(http.MethodGet) + r.HandleFunc("/api/v1/projects/{packageId}/versions/{version}/files/{slug}/documentation", security.Secure(publishedController.GenerateFileDocumentation)).Methods(http.MethodGet) + r.HandleFunc("/api/v1/projects/{packageId}/versions/{version}/files/{fileSlug}/share", security.Secure(publishedController.SharePublishedFile)).Methods(http.MethodPost) + r.HandleFunc("/api/v1/shared/{shared_id}", security.NoSecure(publishedController.GetSharedContentFile)).Methods(http.MethodGet) + + r.HandleFunc("/api/v1/system/info", security.Secure(systemInfoController.GetSystemInfo)).Methods(http.MethodGet) + r.HandleFunc("/api/v1/system/configuration", samlAuthController.GetSystemSSOInfo).Methods(http.MethodGet) + + r.HandleFunc("/api/v1/projects/{projectId}/versions/{version}/files/{fileSlug}/share", security.Secure(publishedController.SharePublishedFile)).Methods(http.MethodPost) + r.HandleFunc("/api/v1/debug/logs", security.Secure(logsController.StoreLogs)).Methods(http.MethodPut) + r.HandleFunc("/api/v1/debug/logs/setLevel", security.Secure(logsController.SetLogLevel)).Methods(http.MethodPost) + r.HandleFunc("/api/v1/debug/logs/checkLevel", security.Secure(logsController.CheckLogLevel)).Methods(http.MethodGet) + + //websocket + r.HandleFunc("/ws/v1/projects/{projectId}/branches/{branchName}", security.SecureWebsocket(branchWSController.ConnectToProjectBranch)) + r.HandleFunc("/ws/v1/projects/{projectId}/branches/{branchName}/files/{fileId}", security.SecureWebsocket(fileWSController.ConnectToFile)) + + //Search + r.HandleFunc("/api/v2/search/{searchLevel}", security.Secure(searchController.Search_deprecated)).Methods(http.MethodPost) //deprecated + r.HandleFunc("/api/v3/search/{searchLevel}", security.Secure(searchController.Search)).Methods(http.MethodPost) + + r.HandleFunc("/api/v2/builders/{builderId}/tasks", security.Secure(publishV2Controller.GetFreeBuild)).Methods(http.MethodPost) + + r.HandleFunc("/api/v2/packages", security.Secure(packageController.CreatePackage)).Methods(http.MethodPost) + r.HandleFunc("/api/v2/packages/{packageId}", security.Secure(packageController.UpdatePackage)).Methods(http.MethodPatch) + r.HandleFunc("/api/v2/packages/{packageId}", security.Secure(packageController.DeletePackage)).Methods(http.MethodDelete) + r.HandleFunc("/api/v2/packages/{packageId}/favor", security.Secure(packageController.FavorPackage)).Methods(http.MethodPost) + r.HandleFunc("/api/v2/packages/{packageId}/disfavor", security.Secure(packageController.DisfavorPackage)).Methods(http.MethodPost) + r.HandleFunc("/api/v2/packages/{packageId}", security.Secure(packageController.GetPackage)).Methods(http.MethodGet) + r.HandleFunc("/api/v2/packages/{packageId}/status", security.Secure(packageController.GetPackageStatus)).Methods(http.MethodGet) + r.HandleFunc("/api/v2/packages", security.Secure(packageController.GetPackagesList)).Methods(http.MethodGet) + r.HandleFunc("/api/v2/packages/{packageId}/publish/availableStatuses", security.Secure(packageController.GetAvailableVersionStatusesForPublish)).Methods(http.MethodGet) + + r.HandleFunc("/api/v2/packages/{packageId}/apiKeys", security.Secure(apihubApiKeyController.GetApiKeys_deprecated)).Methods(http.MethodGet) + r.HandleFunc("/api/v3/packages/{packageId}/apiKeys", security.Secure(apihubApiKeyController.GetApiKeys_v3_deprecated)).Methods(http.MethodGet) + r.HandleFunc("/api/v4/packages/{packageId}/apiKeys", security.Secure(apihubApiKeyController.GetApiKeys)).Methods(http.MethodGet) + r.HandleFunc("/api/v2/packages/{packageId}/apiKeys", security.Secure(apihubApiKeyController.CreateApiKey_deprecated)).Methods(http.MethodPost) + r.HandleFunc("/api/v3/packages/{packageId}/apiKeys", security.Secure(apihubApiKeyController.CreateApiKey_v3_deprecated)).Methods(http.MethodPost) + r.HandleFunc("/api/v4/packages/{packageId}/apiKeys", security.Secure(apihubApiKeyController.CreateApiKey)).Methods(http.MethodPost) + r.HandleFunc("/api/v2/packages/{packageId}/apiKeys/{id}", security.Secure(apihubApiKeyController.RevokeApiKey)).Methods(http.MethodDelete) + + r.HandleFunc("/api/v2/packages/{packageId}/members", security.Secure(roleController.GetPackageMembers)).Methods(http.MethodGet) + r.HandleFunc("/api/v2/packages/{packageId}/members", security.Secure(roleController.AddPackageMembers)).Methods(http.MethodPost) + r.HandleFunc("/api/v2/packages/{packageId}/members/{userId}", security.Secure(roleController.UpdatePackageMembers)).Methods(http.MethodPatch) + r.HandleFunc("/api/v2/packages/{packageId}/members/{userId}", security.Secure(roleController.DeletePackageMember)).Methods(http.MethodDelete) + + r.HandleFunc("/api/v2/packages/{packageId}/recalculateGroups", security.Secure(packageController.RecalculateOperationGroups)).Methods(http.MethodPost) + r.HandleFunc("/api/v2/packages/{packageId}/calculateGroups", security.Secure(packageController.CalculateOperationGroups)).Methods(http.MethodGet) + + //api for agent + r.HandleFunc("/api/v2/users/{userId}/availablePackagePromoteStatuses", security.Secure(roleController.GetAvailableUserPackagePromoteStatuses)).Methods(http.MethodPost) + + r.HandleFunc("/api/v2/packages/{packageId}/publish/{publishId}/status", security.Secure(publishV2Controller.GetPublishStatus)).Methods(http.MethodGet) + r.HandleFunc("/api/v2/packages/{packageId}/publish/statuses", security.Secure(publishV2Controller.GetPublishStatuses)).Methods(http.MethodPost) + r.HandleFunc("/api/v2/packages/{packageId}/publish", security.Secure(publishV2Controller.Publish)).Methods(http.MethodPost) + r.HandleFunc("/api/v2/packages/{packageId}/publish/{publishId}/status", security.Secure(publishV2Controller.SetPublishStatus_deprecated)).Methods(http.MethodPost) + r.HandleFunc("/api/v3/packages/{packageId}/publish/{publishId}/status", security.Secure(publishV2Controller.SetPublishStatus)).Methods(http.MethodPost) + r.HandleFunc("/api/v1/packages/{packageId}/publish/withOperationsGroup", security.Secure(versionController.PublishFromCSV)).Methods(http.MethodPost) + r.HandleFunc("/api/v1/packages/{packageId}/publish/{publishId}/withOperationsGroup/status", security.Secure(versionController.GetCSVDashboardPublishStatus)).Methods(http.MethodGet) + r.HandleFunc("/api/v1/packages/{packageId}/publish/{publishId}/withOperationsGroup/report", security.Secure(versionController.GetCSVDashboardPublishReport)).Methods(http.MethodGet) + + r.HandleFunc("/api/v2/packages/{packageId}/versions/{version}", security.Secure(versionController.GetPackageVersionContent_deprecated)).Methods(http.MethodGet) + r.HandleFunc("/api/v3/packages/{packageId}/versions/{version}", security.Secure(versionController.GetPackageVersionContent)).Methods(http.MethodGet) + r.HandleFunc("/api/v2/packages/{packageId}/versions", security.Secure(versionController.GetPackageVersionsList_deprecated)).Methods(http.MethodGet) + r.HandleFunc("/api/v3/packages/{packageId}/versions", security.Secure(versionController.GetPackageVersionsList)).Methods(http.MethodGet) + r.HandleFunc("/api/v2/packages/{packageId}/versions/{version}", security.Secure(versionController.DeleteVersion)).Methods(http.MethodDelete) + r.HandleFunc("/api/v2/packages/{packageId}/versions/{version}", security.Secure(versionController.PatchVersion)).Methods(http.MethodPatch) + r.HandleFunc("/api/v2/packages/{packageId}/versions/recursiveDelete", security.Secure(versionController.DeleteVersionsRecursively)).Methods(http.MethodPost) + + r.HandleFunc("/api/v2/packages/{packageId}/versions/{version}/files/{slug}/raw", security.Secure(versionController.GetVersionedContentFileRaw)).Methods(http.MethodGet) + r.HandleFunc("/api/v2/sharedFiles/{sharedFileId}", security.NoSecure(versionController.GetSharedContentFile)).Methods(http.MethodGet) + r.HandleFunc("/api/v2/packages/{packageId}/versions/{version}/changes", security.Secure(versionController.GetVersionChanges)).Methods(http.MethodGet) + r.HandleFunc("/api/v2/packages/{packageId}/versions/{version}/problems", security.Secure(versionController.GetVersionProblems)).Methods(http.MethodGet) + r.HandleFunc("/api/v2/sharedFiles", security.Secure(versionController.SharePublishedFile)).Methods(http.MethodPost) + + r.HandleFunc("/api/v2/packages/{packageId}/versions/{version}/doc", security.Secure(exportController.GenerateVersionDoc)).Methods(http.MethodGet) + r.HandleFunc("/api/v2/packages/{packageId}/versions/{version}/files/{slug}/doc", security.Secure(exportController.GenerateFileDoc)).Methods(http.MethodGet) + + r.HandleFunc("/api/v2/auth/saml", security.NoSecure(samlAuthController.StartSamlAuthentication)).Methods(http.MethodGet) // deprecated. + r.HandleFunc("/login/sso/saml", security.NoSecure(samlAuthController.StartSamlAuthentication)).Methods(http.MethodGet) + r.HandleFunc("/saml/acs", security.NoSecure(samlAuthController.AssertionConsumerHandler)).Methods(http.MethodPost) + r.HandleFunc("/saml/metadata", security.NoSecure(samlAuthController.ServeMetadata)).Methods(http.MethodGet) + + // Required for agent to verify apihub tokens + r.HandleFunc("/api/v2/auth/publicKey", security.NoSecure(jwtPubKeyController.GetRsaPublicKey)).Methods(http.MethodGet) + // Required to verify api key for external authorization + r.HandleFunc("/api/v2/auth/apiKey", security.NoSecure(apihubApiKeyController.GetApiKeyByKey)).Methods(http.MethodGet) + r.HandleFunc("/api/v1/auth/apiKey/{apiKeyId}", security.Secure(apihubApiKeyController.GetApiKeyById)).Methods(http.MethodGet) + + r.HandleFunc("/api/v2/users/{userId}/profile/avatar", security.NoSecure(userController.GetUserAvatar)).Methods(http.MethodGet) // Should not be secured! FE renders avatar as