From df4a686d2e4a02ca04a8524e6700abbbd3544acc Mon Sep 17 00:00:00 2001 From: Jesse Sopel Date: Wed, 31 May 2023 16:01:49 -0400 Subject: [PATCH] Remove pre-bullseye migrations --- .../014b218f97dd_add_acl_to_call_logd.py | 45 - ...3d47_add_the_tenant_uuid_column_to_the_.py | 51 - .../02361b8a4b7c_rename_directory_backend.py | 36 - .../0269f5e35792_bump_version_23_02.py | 23 - .../035908ce02df_add_meeting_creation_date.py | 26 - .../035e2cb65b6d_bump_version_21_14.py | 23 - ...b69fd8297_reorder_endpoint_sip_template.py | 93 -- .../049ea24c3a0f_bump_version_22_10.py | 23 - .../0600c04fd4a6_bump_version_22_12.py | 23 - .../060e2360612f_bump_version_21_06.py | 23 - ...f25f0d_refactor_trunk_protocol_register.py | 245 --- .../06e9e3483fec_bump_version_21_11.py | 23 - ...5_change_auth_key_for_dird_wazo_backend.py | 38 - ...08a23688eaf7_add_tenant_uuid_to_outcall.py | 59 - .../0a7363700618_bump_version_19_12.py | 23 - ...0aeb61795700_rename_general_group_queue.py | 72 - ...f27e0_remove_deleted_from_groupfeatures.py | 25 - .../0c758daee631_bump_version_22_07.py | 23 - ...99_disallow_null_type_for_app_dest_node.py | 20 - .../0d74d34f7782_bump_version_18_11.py | 23 - ...1e2_meeting_add_unique_on_number_tenant.py | 25 - .../versions/0f4a7c48613c_add_zonemessages.py | 84 - .../0ffacfab7041_bump_version_22_04.py | 23 - ...06159225d65_fk_template_add_tenant_uuid.py | 111 -- ...6117e_fix_sequence_usage_on_stat_agent_.py | 20 - .../108f435e1af2_bump_version_20_04.py | 23 - ...rename_xivo_call_logd_to_wazo_call_logd.py | 41 - .../1108308b3fd7_bump_version_22_17.py | 23 - ...a2d937_add_auth_key_file_to_directories.py | 53 - ...92e6bfd226_configure_the_dhcp_interface.py | 52 - .../11b792bcc775_create_func_key_bsfilter.py | 51 - .../11cfb4ff787d_add_application_table.py | 53 - ..._add_notify_early_inuse_ringing_option_.py | 74 - ...1fddb7_fix_invalid_extension_conference.py | 49 - .../129646f8f81f_bump_version_18_09.py | 23 - ...12b81f6c229b_add_the_ingress_http_table.py | 35 - ...2f9880ae872_switchboard_add_tenant_uuid.py | 183 --- ...c2a63_fix_auth_key_file_for_directories.py | 48 - .../versions/13472f54a7_bump_version_17_09.py | 22 - .../13692a692d44_remove_mylocaldir_xlet.py | 79 - .../13917b00e63c_create_func_key_agent.py | 56 - .../13f4485996fd_remove_dundi_from_general.py | 23 - ...6c4b36_deactivate_user_login_by_default.py | 20 - .../148a96399123_add_phonebook_id_fk.py | 66 - ...493335e754b_remove_serverfeatures_table.py | 29 - .../14c0ca8a7834_update_nat_options.py | 70 - .../151d1315479b_fix_paging_duplicates.py | 93 -- ...90b21ad_remove_cel_call_log_foreign_key.py | 29 - ...6bd8060_add_fk_between_directories_and_.py | 91 -- ...1b71_queueskillrule_remove_name_unique_.py | 45 - ...0b0f8_add_tags_to_call_log_participants.py | 25 - .../160e7b3161fa_clean_features_table.py | 67 - ...632064e0441_remove_remotedirectory_xlet.py | 26 - .../1747774cead4_bump_version_18_04.py | 23 - .../17653c3f37ce_bump_version_17_10.py | 22 - ...dd_trunkfeatures_twilio_incoming_column.py | 21 - ...64_add_application_uuid_to_linefeatures.py | 29 - ...fault_cat_metric_voicemail_zonemessages.py | 29 - ...8840b2fdb03_confbridge_add_default_type.py | 91 -- ...4e08f_rename_queue_autopause_constraint.py | 32 - .../versions/18b419c519f4_add_context_id.py | 30 - .../18cb96cb384_remove_cti_options.py | 60 - .../18e40e519e1b_migrate_custom_func_keys.py | 281 ---- ...dea1085af_add_foreign_key_to_paginguser.py | 59 - .../versions/198c5bc02abf_add_parking_lot.py | 65 - .../198cf8fda9a4_remove_ami_config.py | 28 - .../19a869176d6c_bump_version_17_05.py | 22 - ...3acc6cdb0_add_confbridge_talk_detection.py | 76 - ...5b8b93e70_add_missing_features_func_key.py | 104 -- ...2baf_drop_order_column_in_schedule_path.py | 47 - .../1a730d10e4a7_add_phonebook_url.py | 46 - ...2_remove_null_constraint_exten_context_.py | 24 - ...1b6be5d5e4ac_drop_usersip_setvar_column.py | 22 - .../1c3eb7380750_replace_mobile_callable.py | 59 - .../versions/1c95890bb00d_add_pjsip_system.py | 131 -- .../1cc52186eb47_add_switchboard_table.py | 104 -- .../1d05ffb14525_remove_unused_tables.py | 53 - .../1d4b487e4d1f_add_voicemail_foreign_key.py | 23 - .../1ddfb39a066f_drop_musiconhold_table.py | 57 - ...3_remove_nullable_constraint_queueskill.py | 20 - ...4cbd713979_add_missing_entity_id_column.py | 39 - .../1f533d5f5f51_add_conference_dialaction.py | 67 - .../203129d6b213_remove_queue_info_table.py | 37 - ...f2cf0a0_remove_deprecated_incall_fields.py | 39 - .../2072c1e66aa9_drop_dialaction_event.py | 26 - ...49_replace_agent_action_by_extension_id.py | 87 - ...8e_remove_constraints_from_linefeatures.py | 26 - ...01_move_column_merging_from_display_to_.py | 128 -- .../21b72c41eb6a_bump_version_22_05.py | 23 - ...5c24210e_add_a_wizard_webservice_access.py | 34 - ...1f6963c1d35_call_filter_add_tenant_uuid.py | 56 - .../2251b5ae9e6c_add_wazo_upgrade_acl.py | 37 - ...256e488e43c_change_email_body_new_lines.py | 29 - ...32708be8a75_parking_lot_add_tenant_uuid.py | 56 - .../234745874c55_migrate_func_key_paging.py | 349 ---- ...681deb_calll_permission_add_tenant_uuid.py | 45 - .../versions/2375157ea682_add_people_xlet.py | 21 - ...241501a5f8ba_remove_queue_info_function.py | 23 - ...1ba0a6d087_fix_broken_ctidirectories_fk.py | 60 - ...2485d7c1f8e9_fix_twilio_trunk_migration.py | 68 - .../24b41ddb07d7_migrate_agent_func_keys.py | 313 ---- .../255de5d2adea_update_agid_forwards_acl.py | 54 - .../267d8bd31d11_add_xivo_auth_service_acl.py | 85 - .../27040433c098_remove_invalid_user_email.py | 80 - .../27801f8c2a80_add_direction_to_call_log.py | 21 - .../2796b8c839c5_remove_ulaw_everywhere.py | 103 -- .../27d9ea4b21d0_fix_func_key_type_ids.py | 75 - .../27f83f39e031_add_user_contact_part_2.py | 39 - ...3d1_migrate_sip_general_to_pjsip_global.py | 145 -- .../28443bfc4fb1_update_nat_options_auto.py | 72 - .../284a6962ac4e_fix_codec_migration.py | 140 -- ...8721fe085d3_add_group_member_extensions.py | 117 -- ...13d7926e6_dissociate_user_from_template.py | 31 - ...f08938_add_read_postfix_to_service_acls.py | 44 - ...ed250b7a2_drop_useriax_realtime_columns.py | 23 - ...29290c38946f_fix_queuemember_interfaces.py | 34 - .../2956eaa19c7c_remove_dialer_xlet.py | 45 - ...4e5ede175_add_mongooseim_acl_to_ctid_ng.py | 51 - ...989b8b30fe7_create_line_extension_table.py | 133 -- .../2991705be1ec_bump_version_18_02.py | 22 - ...remove_duration_and_answered_from_call_.py | 37 - ...a24c3d1d13e_call_log_add_requested_name.py | 22 - ...27e01c8070_add_greeting_sound_to_incall.py | 24 - ...02871_change_datax_columns_to_type_text.py | 30 - .../2b0f5ee268c4_remove_orphan_lines.py | 37 - ...1d388_add_the_meetingjoin_extenfeatures.py | 46 - .../2b5d68fa7ab8_bump_version_21_07.py | 23 - ..._meeting_require_authorization_not_null.py | 21 - ...2f1d009ca_add_autoprov_acl_to_xivo_agid.py | 52 - .../2bb55c201ee7_bump_version_21_01.py | 23 - ...a6_make_directory_fields_format_strings.py | 48 - .../2c004153ed7f_make_user_uuid_unique.py | 20 - ..._remove_unused_indexes_on_cel_and_qlog_.py | 22 - .../2c940e077157_add_xivo_configured.py | 33 - .../2cbd52dd69e1_bump_version_20_05.py | 23 - .../versions/2d0b0356eb76_add_cel_extra.py | 21 - .../2d3d29858d6d_create_func_key_paging.py | 50 - ...rename_enableautomon_to_enableonlinerec.py | 20 - ...4a1653fc_add_deleted_col_to_stat_tables.py | 29 - .../2f69acadecbe_create_conference_table.py | 36 - .../2f7e5c4119bc_add_xivo_directory_fields.py | 32 - ...d4231cca_remove_phonebook_configuration.py | 80 - ...580_add_user_specific_recording_options.py | 60 - ...1ab8_remove_rightcallmember_incall_enum.py | 42 - .../30564ea14542_remove_voicemail_type.py | 32 - .../3096b11582cf_group_timeout_may_be_null.py | 28 - .../30d59d9b4b6e_remove_exchange_voicemail.py | 25 - .../30d7dcbb9133_add_web_service_uuid.py | 34 - .../versions/30eebcef63ad_delete_sessions.py | 23 - ...62201_alter_queueskill_drop_printscreen.py | 22 - .../3133fb4958ef_add_acls_to_xivo_ctid_ng.py | 40 - ...15f74edddb1_remove_nullable_constraint_.py | 20 - ...196befc4753_remove_custom_moh_directory.py | 62 - ...c5c5_migrate_service_func_keys_without_.py | 299 ---- ...0d05ebad29_set_call_limit_default_to_10.py | 20 - .../324ad441b84c_add_wazo_plugind_cli_acl.py | 38 - ...a535c_remove_nullable_constraint_pwd_vm.py | 20 - .../330b1c94980d_remove_outbound_auth_key.py | 30 - .../3314b25783a2_bump_version_22_02.py | 23 - ...d1b1d31_add_dtmf_hangup_to_userfeatures.py | 35 - .../337f76c25478_update_internal_directory.py | 63 - .../33e0cdb6971d_create_func_key_features.py | 134 -- .../versions/33fa1a10428f_add_moh_table.py | 32 - .../34122e276b2_bump_version_17_03.py | 22 - .../341f7e584088_remove_old_phonebook.py | 41 - .../3420040c5650_add_confd_acls_to_agid.py | 47 - ...2497a56f8_add_tenants_acl_to_the_wizard.py | 46 - .../34748356e196_bump_version_18_07.py | 23 - .../34b2b6ca345e_bump_version_19_13.py | 23 - .../354fe6b9e819_sccpline_add_tenant_uuid.py | 64 - .../35a7f7e2dc33_create_automon_func_key.py | 174 -- .../3612e8058d92_bump_version_17_08.py | 22 - ...1b_add_call_log_requested_exten_context.py | 24 - .../36c3f75ac228_ast13_remove_adsipark.py | 29 - ...a67216_userfeatures_tenant_uuid_cascade.py | 34 - .../3770e116222d_divide_queue_waitratio.py | 34 - ...78c46e8c6fe_remove_pickupmember_invalid.py | 75 - ...e0c5e51_add_directmedia_outgoing_option.py | 62 - ...ed6d9a62_remove_acesswebservice_acl_obj.py | 20 - .../37b9ac945437_bump_version_17_04.py | 22 - ...b2b_convert_agent_status_login_to_pjsip.py | 39 - .../37c6976343d4_fix_partial_call_stats.py | 55 - ...a1a5_create_meeting_authorization_table.py | 53 - .../versions/382aaefc59ec_add_group_uuid.py | 36 - .../387d650380bd_change_defaut_cti_colors.py | 92 -- ...522e4a_add_ldapfitler_id_to_directories.py | 25 - .../versions/39f7b89af84e_randomize_uuid.py | 28 - ...2f91bc_call_log_add_internal_extensions.py | 32 - .../3a0ace87fc76_remove_contact_xlet.py | 78 - .../3ab28f25de30_reset_queue_exit_context.py | 21 - .../3ab7cf07eb66_migrate_func_key_bsfilter.py | 516 ------ .../3b2e82f0bfbe_add_the_tenant_table.py | 25 - ...edb5c_add_services_forwards_acl_to_agid.py | 45 - ...a3_add_index_on_callid_in_stat_call_on_.py | 20 - .../3c72c43e39fa_remove_cel_fields_limits.py | 55 - ...ed5c_adjust_agent_login_status_login_at.py | 22 - .../versions/3d22f40558d1_add_infos_table.py | 32 - ...184c10386_create_transfer_function_keys.py | 132 -- ...e069be_remove_constraints_agentfeatures.py | 30 - ...c9ae6158_add_xivo_call_logs_web_service.py | 38 - .../3e7dbde01837_bump_version_17_13.py | 22 - ...c983a901c_remove_usersip_registertrying.py | 21 - .../3edd3b3aac7d_bump_version_21_13.py | 23 - .../3f132402532b_bump_version_19_04.py | 23 - ...0bfa7f9a_remove_chan_sip_permaturemedia.py | 25 - .../3fe6319ce27a_create_func_key_custom.py | 48 - .../40359c5c2c92_bump_version_18_01.py | 22 - ...ove_loginclient_passwdclient_data_from_.py | 27 - .../40ba1a488aa7_phonebook_file_to_csv.py | 32 - .../40e2f31cf146_remove_orphan_func_key.py | 152 -- .../40e6d1e4c2c3_schedule_add_tenant_uuid.py | 57 - .../4123465e114e_add_agentd_acl_to_agid.py | 35 - ...b6135f650_rename_xivo_auth_to_wazo_auth.py | 40 - .../415b08ed9959_add_xivo_auth_web_service.py | 38 - .../41a523e18fdd_bump_version_18_03.py | 23 - ...41b6afe5b164_usercustom_add_tenant_uuid.py | 71 - ...missing_func_key_dest_user_pointing_to_.py | 138 -- ...2da_directories_rename_internal_to_xivo.py | 48 - .../41f6ef3f00fe_voicemail_extra_options.py | 188 --- .../425eebc346b1_bump_version_17_14.py | 22 - ...8a_add_an_external_meeting_sip_template.py | 178 --- .../42e9771685b0_bump_version_17_07.py | 22 - ...72df48_remove_paging_callnotbusy_column.py | 26 - .../43995f4ac823_fix_invalid_context_name.py | 100 -- ...1ae83_update_directory_definition_joins.py | 122 -- .../43c5188319dc_update_chan_sip_t1min.py | 34 - ...4b39e9aa32_rename_webservices_directory.py | 32 - ...ab61975_fix_queue_table_without_context.py | 18 - .../449045080bf6_bump_version_19_16.py | 23 - .../versions/44af2488e95_ast13_app_queue.py | 43 - .../44c6b8d8c196_activate_blf_by_default.py | 20 - ...4c3dfde5db_migrate_to_sip_webrtc_option.py | 62 - .../45ceb32fae06_add_uuid_to_userfeatures.py | 37 - ...40ac_remove_dangling_user_function_keys.py | 62 - .../462b92a4f5d8_add_conference_exten_enum.py | 51 - ...cd084872_remove_columns_from_ldapfilter.py | 24 - .../46dda7d0374e_bump_version_18_14.py | 23 - ...b1_remove_unused_values_dialaction_enum.py | 138 -- .../476a2700b4c2_moh_add_tenant_uuid.py | 46 - ...47920341f392_add_application_dialaction.py | 70 - ...86c0749403c_migrate_voicemail_func_keys.py | 292 ---- .../488e5a3d75_create_asterisk_file_tables.py | 53 - .../49126e9fffe2_remove_autochangestate.py | 25 - .../495accfabe9f_bump_version_22_15.py | 23 - .../4977a626c01_add_xivo_ctid_ng_acl.py | 47 - ...8f0570ffef_fix_default_display_personal.py | 56 - .../4a0281e1a826_usersip_add_tenant_uuid.py | 72 - ...a87321_add_foreignkey_on_rightcallexten.py | 23 - ...3eb52f_add_subscription_to_userfeatures.py | 34 - ...d0e24028_directories_use_dirtype_column.py | 71 - .../4aa03039dd2e_bump_version_20_13.py | 23 - .../4bb90c6c47bb_allow_email_as_username.py | 26 - ...318f6975_migrate_func_key_park_position.py | 344 ---- .../4c1cbf778770_bump_version_19_08.py | 23 - .../4c4a8eaa31e7_bump_version_19_17.py | 23 - .../4c660492b365_fix_register_transports.py | 95 -- ...6bccb_drop_useless_provisioning_columns.py | 32 - .../4ce50bcf2a0e_create_forward_func_keys.py | 50 - .../4cf59c82b51e_queue_timeout_may_be_null.py | 27 - ...4cf687f2c0eb_add_dird_xivo_backend_auth.py | 39 - .../versions/4d539700bb90_add_group_label.py | 35 - .../4d736bac41cb_bump_version_20_06.py | 23 - .../4d80d8106d1e_bump_version_19_14.py | 23 - ..._add_paused_and_paused_reason_to_agent_.py | 25 - ...a2_add_unique_constraint_queueskillrule.py | 25 - ...4ee55e5290be_directories_xivo_confd_uri.py | 46 - .../4f85f1de19b4_useriax_add_tenant_uuid.py | 64 - .../4f86216ba603_paging_add_tenant_uuid.py | 45 - ...fa0a41c0327_add_foreignkey_outcalltrunk.py | 60 - .../4fb644b564c8_bump_version_17_15.py | 22 - ...0315a61fc_allow_context_none_in_outcall.py | 20 - .../4fe20686380b_bump_version_19_10.py | 23 - ...ba3_add_unique_constraint_to_user_email.py | 48 - ...3a8_use_automixmon_features_instead_of_.py | 33 - ...3b66e26d2_add_auth_tenants_read_to_agid.py | 45 - .../501dae22d6be_ast13_update_findslot.py | 34 - .../versions/503cf85083ba_enable_starttls.py | 23 - ...047425b0f5c_add_tenant_uuid_to_call_log.py | 31 - .../versions/505c12d2ed73_add_iax_options.py | 24 - ...fa473e_force_user_to_entity_association.py | 71 - ...d295_allow_call_filter_description_none.py | 20 - .../508c5a0382dc_bump_version_17_12.py | 22 - ...0cfb10bd01d_drop_empty_recording_tables.py | 66 - .../51ebe7954da8_meeting_persistent_column.py | 26 - ...25b0cc45d2_add_context_to_trunkfeatures.py | 73 - ...5270d317f8fd_add_ldapfilter_directories.py | 40 - .../52acaaba550c_bump_version_18_05.py | 23 - .../52b66f888125_bump_version_17_16.py | 22 - .../versions/52bd5977c09d_initial_script.py | 21 - .../534d6112e879_fix_sound_file_paths.py | 166 -- ...7774d3845a_add_email_field_in_phonebook.py | 60 - ...5381b673cf2c_add_ignore_forward_columns.py | 30 - .../53ad771ac875_bump_version_21_02.py | 23 - ...f6ffe9_add_stat_switchboard_queue_table.py | 42 - .../versions/53e449192523_add_user_email.py | 22 - .../versions/53fbfa53b47c_add_user_uuid.py | 33 - ...905_remove_dialaction_n_plus_101_option.py | 59 - .../5450dd40916e_add_call_completion.py | 56 - ...5497199c082f_add_queue_id_to_stat_queue.py | 165 -- .../549c621ae619_update_musiconhold_random.py | 33 - alembic/versions/5524f5f02959_remove_ctis.py | 22 - .../55527c5cb4b1_bump_version_20_03.py | 23 - ..._queue_log_change_the_type_of_agent_to_.py | 22 - .../55cd08a0dae2_bump_version_to_22_01.py | 23 - ...5c5_create_func_key_destination_service.py | 49 - ...13454_populate_confbridge_configuration.py | 73 - ...00b4_remove_unused_provisioning_columns.py | 24 - ...bfca6cf85_rename_dhcp_field_extra_iface.py | 21 - .../564d634619bc_add_dnd_acl_to_ctid.py | 47 - .../56a75d478edc_remove_staticsip_table.py | 35 - ...6a9a83c26b3_remove_old_phonebook_tables.py | 23 - ...ce34ae9_link_default_template_to_tenant.py | 79 - ...683a865e0_add_english_presence_statuses.py | 136 -- ...emove_nullable_constraint_queuefeatures.py | 20 - ...ate_new_dird_phonebooks_cti_directories.py | 160 -- .../57461905b7e6_bump_version_17_17.py | 22 - ...7a7c7438b98_add_email_field_in_internal.py | 60 - .../57ab432bb1c3_bump_version_18_10.py | 23 - .../5863384621a1_bump_version_22_03.py | 23 - .../58cd88054523_bump_version_19_02.py | 23 - ...emove_nullable_constraint_groupfeatures.py | 22 - .../58e808b69aec_queue_autopause_option.py | 38 - .../58fc78d9f67f_bump_version_18_06.py | 23 - .../592e449b34ec_cti_displays_clean_fields.py | 45 - .../596b177ba681_bump_version_17_06.py | 22 - ...9feecbe8d13_webi_to_dird_ldap_migration.py | 300 ---- .../5a02fde67132_migrate_func_key_parking.py | 275 ---- .../5a285558e46e_trunk_add_tenant_uuid.py | 64 - .../5a4fe661486c_fix_func_key_label_empty.py | 37 - ...dc40b5c_create_missing_paging_func_keys.py | 70 - ...b427e206bdf_update_wazo_plugind_cli_acl.py | 55 - ...fix_jitter_buffer_implementation_choice.py | 32 - .../5c9f286599b6_bump_version_20_11.py | 23 - .../5dd4a73c91c2_bump_version_19_03.py | 23 - .../5f8c8a323cbe_incall_add_tenant_uuid.py | 60 - ...f5386dca8_remove_cti_directories_tables.py | 117 -- ...8db7_add_endpoint_sip_materialized_view.py | 145 -- .../60eb57605f3_bump_version_17_11.py | 22 - .../61e3d7c65755_set_all_moh_labels.py | 30 - .../62c5befaa8cf_hep_general_section.py | 78 - .../64c6bde0116c_add_date_end_to_call_log.py | 21 - ...5d103068c_add_the_asterisk_service_user.py | 38 - .../66453e75a1fd_set_a_username_on_usersip.py | 32 - .../672a6918b7f9_fix_the_reverse_directory.py | 38 - .../67cdc9dfc2d0_remove_unused_tables.py | 78 - ...181de97_add_tenant_uuid_to_userfeatures.py | 55 - .../69c55f395eb7_fix_global_trunk_template.py | 182 --- ...ba_add_default_sccp_provisioning_values.py | 37 - ...bbb_update_uniqueconstraint_queuemember.py | 29 - ...cf16a334d_add_auth_tenants_read_to_auth.py | 44 - .../6bfd932df2c_add_user_contact_table.py | 65 - ...196b7526a_drop_usersip_realtime_columns.py | 29 - ...fc79e30e8bf_add_user_external_app_table.py | 33 - ...35e_add_mark_answered_elsewhere_column_.py | 30 - ...ee6_alter_provisioning_remove_not_null_.py | 26 - .../706a7655606e_add_the_meeting_table.py | 57 - ...1c41130380e_drop_accesswebservice_table.py | 20 - ...66af50deb_fix_trunk_with_host_migration.py | 133 -- .../732a9b6500da_bump_version_19_15.py | 23 - ...9d1db031_queueskillrule_add_tenant_uuid.py | 53 - .../74a76197acaa_bump_version_18_12.py | 23 - .../7541da6ac48f_bump_version_22_09.py | 23 - .../757111d049b6_add_the_tenant_slug.py | 22 - .../7628599d48dc_pickup_add_tenant_uuid.py | 55 - ...dc763148f_add_auth_tenants_read_to_dird.py | 50 - .../785b8cb74daa_revert_version_upgrade.py | 23 - .../7b3b0ff90f0c_add_name_column_to_paging.py | 23 - .../7d342adb6ae1_bump_version_22_14.py | 23 - .../7d47aaef973a_bump_version_19_07.py | 23 - .../7d91d22133a9_bump_version_20_08.py | 23 - ...1c00662_remove_invalid_chars_from_label.py | 62 - ..._unset_context_queue_from_groupfeatures.py | 31 - ...452bc3d5d67_conferences_add_tenant_uuid.py | 64 - .../84d91026c293_add_switchboard_moh.py | 37 - ...ef5d49_add_displayname_field_in_source_.py | 66 - .../867bd9268824_bump_version_21_03.py | 23 - .../8691b32cf44e_remove_phonebook_enums.py | 29 - .../86c17bf55b92_bump_version_20_07.py | 23 - .../versions/872b869e9675_remove_entity.py | 26 - .../87b36150b613_bump_version_19_06.py | 23 - .../8a551a46dd5d_add_wazo_version_column.py | 23 - .../8bbb46a9f362_bump_version_23_05.py | 23 - .../8c21acf4e9e_bump_version_17_02.py | 22 - ...fde62d_remove_auth_from_insecure_trunks.py | 73 - .../versions/90518bf34218_back_to_19_12.py | 23 - ...47d665_call_permission_non_unique_names.py | 27 - .../90f771359c71_bump_version_19_05.py | 23 - .../versions/9142f0403c8_add_ivr_support.py | 115 -- .../92061fe1c3b8_bump_version_20_02.py | 23 - .../92928db7221_bump_version_18_08.py | 23 - .../93ea61395eef_bump_version_22_01.py | 23 - .../9442da3b20b6_bump_version_21_04.py | 23 - .../978e620de034_bump_version_21_09.py | 23 - .../99082b9c0b7b_bump_version_18_13.py | 23 - ...a818e6_add_tenant_uuid_to_agentfeatures.py | 117 -- .../9b7e32eb0a77_bump_version_19_09.py | 23 - .../9eeb96b396a7_bump_version_21_08.py | 23 - .../9f11f3abaacc_bump_version_23_03.py | 23 - ...10db8de6372_remove_unused_extenfeatures.py | 42 - .../a132daff54b_drop_column_useenum.py | 21 - .../a28974a2dc19_add_pjsip_endpoints.py | 88 -- .../a3b4e1bf633b_queue_add_tenant_uuid.py | 56 - ...e7fd7b670_create_func_key_park_position.py | 51 - .../a46c624e7f61_bump_version_22_11.py | 23 - ...af16eeecf7f_add_indices_to_foreign_keys.py | 210 --- ...8_directories_add_tenant_and_phonebook_.py | 26 - .../ae5bee40e9d2_bump_version_22_08.py | 23 - .../b0edbcc1426d_bump_version_22_16.py | 23 - .../b1c4be6f46ff_bump_version_20_16.py | 23 - ...replace_automixmon_with_dynamic_feature.py | 100 -- ...c84ad_add_a_source_field_to_all_sources.py | 40 - ...fix_contextinclude_include_for_context_.py | 72 - ...68f5505_remove_dialaction_linked_column.py | 24 - ...5_add_direction_constraints_to_call_log.py | 23 - ...5c40615bc21_context_add_the_tenant_uuid.py | 60 - ...e1e0fe_add_users_confd_acl_to_call_logd.py | 47 - .../b62e1eba7869_bump_version_20_17.py | 23 - .../b6a0f4cc7e49_remove_user_table.py | 52 - .../b6bb28f27f2_fix_schema_differences.py | 109 -- .../b78a74e69592_bump_version_20_14.py | 23 - .../b7d3c4701095_add_a_meeting_number.py | 45 - .../b8d0848e7b2_add_acls_to_xivo_ctid_ng.py | 47 - ...25_directories_migration_xivo_directory.py | 83 - ...ba7c6bb897b3_add_switchboard_dialaction.py | 74 - ...3a031fd01_remove_invalid_webrtc_options.py | 84 - .../bc9e62985a0_add_wazo_plugind_acl.py | 38 - ...f8_fix_default_pjsip_template_transport.py | 83 - .../c04ed3f6a685_fix_pjpjsip_queuemembers.py | 38 - ...e988da503_add_name_nullable_on_schedule.py | 20 - .../c193f30636ff_add_acl_to_xivo_ctid_ng.py | 45 - .../c1d845eb61b4_add_external_app_table.py | 33 - ...2356e22a13_directories_add_auth_columns.py | 32 - .../c3b40a0998c4_update_sip_realm_to_wazo.py | 38 - ...f9e78_fix_invalid_extension_parking_lot.py | 49 - ...7de783d8c8c_add_a_tenant_uuid_to_groups.py | 62 - .../c8415eb8bfb5_bump_version_23_01.py | 23 - .../c8abcc5497ef_bump_version_20_01.py | 23 - ...2541b284_meeting_authorization_required.py | 22 - ...c9af37c973_remove_deprecated_cti_tables.py | 176 --- .../cb5666745311_bump_version_21_10.py | 23 - ...add_timezone_data_to_the_cel_eventtime_.py | 28 - .../cc9063471025_registration_options.py | 66 - ...24f5d7fe2_add_auth_tenants_read_to_ctid.py | 50 - .../ce76c220eaab_bump_version_21_16.py | 23 - ...d57_add_answer_to_application_dest_node.py | 26 - .../d0f74d74eb5f_bump_version_19_11.py | 23 - .../d47f295009dd_remove_sipauthentication.py | 37 - .../d56d7434e9f4_bump_version_20_12.py | 23 - .../versions/d6be50f692dc_add_sip_options.py | 24 - .../d81a903b6d1e_ivr_add_tenant_uuid.py | 45 - .../d90ff200ae53_bump_version_20_09.py | 23 - ...7aac4970_add_call_log_participant_table.py | 32 - ...eaed7a2f42_convert_queuemember_to_pjsip.py | 32 - .../da06cfd76289_bump_version_21_15.py | 23 - .../da53b63d9433_add_missing_pjsip_options.py | 151 -- .../da58e9e49eb_add_transfers_acl_to_ctid.py | 48 - ...ba4e40979ae_add_date_answer_to_call_log.py | 21 - ...011dfbb5_remove_mohsuggest_from_usersip.py | 21 - .../dd0c465315d_migrate_forward_func_keys.py | 307 ---- ...21f_add_tenant_uuid_to_stat_agent_queue.py | 162 -- .../dfd6c02443cc_remove_deprecated_meetme.py | 177 --- ...80f8b6fc_merge_sip_templates_for_webrtc.py | 319 ---- ...fd01d4c2a_remove_dead_forward_func_keys.py | 65 - ...2ef9dd_add_auth_tenants_read_to_ctid_ng.py | 45 - .../e4f459f58795_bump_version_19_01.py | 23 - .../e507e100aa92_bump_version_23_06.py | 4 +- ..._add_answered_column_to_cdr_participant.py | 24 - .../e53b8ab083c0_bump_version_22_13.py | 23 - ...1742_refactor_line_protocol_to_endpoint.py | 150 -- ...dc5d0_add_timezone_on_call_center_stats.py | 126 -- ...6504d94e2e_update_sip_useragent_to_wazo.py | 38 - .../e6c5e0410e89_bump_version_21_05.py | 23 - ...emove_number_context_from_groupfeatures.py | 24 - .../ea74eca400ce_sip_to_pjsip_endpoint.py | 1406 ----------------- ...d59f8_add_default_template_webrtc_video.py | 257 --- ...eaffdf929dd1_queueskill_add_tenant_uuid.py | 169 -- .../ed40a90222f0_bump_version_21_12.py | 23 - ...b58b09b15_6361_missing_acl_xivo_ctid_ng.py | 50 - ...430a8373_add_the_pjsip_transport_tables.py | 48 - .../eddc1df1d57c_bump_version_20_10.py | 23 - .../ee27cd6ccd9_rtp_general_section.py | 80 - ...e773d263d87_remove_endpoint_sip_context.py | 25 - .../eee032b308b_add_xivo_confd_acl.py | 36 - ...6196_merge_ctimain_infos_general_tables.py | 99 -- ...add_extension_cascade_on_line_extension.py | 43 - ...6d9_add_priority_column_to_endpoint_sip.py | 22 - .../f207de52e7d0_bump_version_20_15.py | 23 - .../f2eae4a8353e_bump_version_22_06.py | 23 - .../f33878e11ef4_bump_version_23_04.py | 23 - ...6222b5c9_remove_dahdi_monitoring_column.py | 22 - ...5ac649eb_migrate_transfer_function_keys.py | 270 ---- .../versions/f5f2dd21819_ast13_chan_sip.py | 29 - ...emove_column_tablename_from_directories.py | 24 - .../f721d0482a3_create_new_dird_phonebooks.py | 73 - .../versions/f98e74435092_fix_pjsip_diff.py | 64 - ...c8e5_add_line_cascade_on_line_extension.py | 43 - .../fb663a210806_pjsip_transport_migration.py | 285 ---- .../versions/fbbbf7d78ed0_back_to_19_13.py | 23 - .../fd040214cccb_add_plugind_cli_read_acl.py | 47 - 499 files changed, 2 insertions(+), 28665 deletions(-) delete mode 100644 alembic/versions/014b218f97dd_add_acl_to_call_logd.py delete mode 100644 alembic/versions/01b4c79b3d47_add_the_tenant_uuid_column_to_the_.py delete mode 100644 alembic/versions/02361b8a4b7c_rename_directory_backend.py delete mode 100644 alembic/versions/0269f5e35792_bump_version_23_02.py delete mode 100644 alembic/versions/035908ce02df_add_meeting_creation_date.py delete mode 100644 alembic/versions/035e2cb65b6d_bump_version_21_14.py delete mode 100644 alembic/versions/040b69fd8297_reorder_endpoint_sip_template.py delete mode 100644 alembic/versions/049ea24c3a0f_bump_version_22_10.py delete mode 100644 alembic/versions/0600c04fd4a6_bump_version_22_12.py delete mode 100644 alembic/versions/060e2360612f_bump_version_21_06.py delete mode 100644 alembic/versions/06149af25f0d_refactor_trunk_protocol_register.py delete mode 100644 alembic/versions/06e9e3483fec_bump_version_21_11.py delete mode 100644 alembic/versions/0720419573a5_change_auth_key_for_dird_wazo_backend.py delete mode 100644 alembic/versions/08a23688eaf7_add_tenant_uuid_to_outcall.py delete mode 100644 alembic/versions/0a7363700618_bump_version_19_12.py delete mode 100644 alembic/versions/0aeb61795700_rename_general_group_queue.py delete mode 100644 alembic/versions/0b694daf27e0_remove_deleted_from_groupfeatures.py delete mode 100644 alembic/versions/0c758daee631_bump_version_22_07.py delete mode 100644 alembic/versions/0c84ec128899_disallow_null_type_for_app_dest_node.py delete mode 100644 alembic/versions/0d74d34f7782_bump_version_18_11.py delete mode 100644 alembic/versions/0dd3509ac1e2_meeting_add_unique_on_number_tenant.py delete mode 100644 alembic/versions/0f4a7c48613c_add_zonemessages.py delete mode 100644 alembic/versions/0ffacfab7041_bump_version_22_04.py delete mode 100644 alembic/versions/106159225d65_fk_template_add_tenant_uuid.py delete mode 100644 alembic/versions/108164f6117e_fix_sequence_usage_on_stat_agent_.py delete mode 100644 alembic/versions/108f435e1af2_bump_version_20_04.py delete mode 100644 alembic/versions/10bf9a42edee_rename_xivo_call_logd_to_wazo_call_logd.py delete mode 100644 alembic/versions/1108308b3fd7_bump_version_22_17.py delete mode 100644 alembic/versions/117b51a2d937_add_auth_key_file_to_directories.py delete mode 100644 alembic/versions/1192e6bfd226_configure_the_dhcp_interface.py delete mode 100644 alembic/versions/11b792bcc775_create_func_key_bsfilter.py delete mode 100644 alembic/versions/11cfb4ff787d_add_application_table.py delete mode 100644 alembic/versions/1264fdcb3e71_add_notify_early_inuse_ringing_option_.py delete mode 100644 alembic/versions/126c8c1fddb7_fix_invalid_extension_conference.py delete mode 100644 alembic/versions/129646f8f81f_bump_version_18_09.py delete mode 100644 alembic/versions/12b81f6c229b_add_the_ingress_http_table.py delete mode 100644 alembic/versions/12f9880ae872_switchboard_add_tenant_uuid.py delete mode 100644 alembic/versions/1311cd6c2a63_fix_auth_key_file_for_directories.py delete mode 100644 alembic/versions/13472f54a7_bump_version_17_09.py delete mode 100644 alembic/versions/13692a692d44_remove_mylocaldir_xlet.py delete mode 100644 alembic/versions/13917b00e63c_create_func_key_agent.py delete mode 100644 alembic/versions/13f4485996fd_remove_dundi_from_general.py delete mode 100644 alembic/versions/146ddf6c4b36_deactivate_user_login_by_default.py delete mode 100644 alembic/versions/148a96399123_add_phonebook_id_fk.py delete mode 100644 alembic/versions/1493335e754b_remove_serverfeatures_table.py delete mode 100644 alembic/versions/14c0ca8a7834_update_nat_options.py delete mode 100644 alembic/versions/151d1315479b_fix_paging_duplicates.py delete mode 100644 alembic/versions/1583f90b21ad_remove_cel_call_log_foreign_key.py delete mode 100644 alembic/versions/15b236bd8060_add_fk_between_directories_and_.py delete mode 100644 alembic/versions/15ca57fa1b71_queueskillrule_remove_name_unique_.py delete mode 100644 alembic/versions/15fb16c0b0f8_add_tags_to_call_log_participants.py delete mode 100644 alembic/versions/160e7b3161fa_clean_features_table.py delete mode 100644 alembic/versions/1632064e0441_remove_remotedirectory_xlet.py delete mode 100644 alembic/versions/1747774cead4_bump_version_18_04.py delete mode 100644 alembic/versions/17653c3f37ce_bump_version_17_10.py delete mode 100644 alembic/versions/176660b8b2c3_add_trunkfeatures_twilio_incoming_column.py delete mode 100644 alembic/versions/17ea1bc19d64_add_application_uuid_to_linefeatures.py delete mode 100644 alembic/versions/1815dcbc813f_fix_default_cat_metric_voicemail_zonemessages.py delete mode 100644 alembic/versions/18840b2fdb03_confbridge_add_default_type.py delete mode 100644 alembic/versions/1888ca44e08f_rename_queue_autopause_constraint.py delete mode 100644 alembic/versions/18b419c519f4_add_context_id.py delete mode 100644 alembic/versions/18cb96cb384_remove_cti_options.py delete mode 100644 alembic/versions/18e40e519e1b_migrate_custom_func_keys.py delete mode 100644 alembic/versions/196dea1085af_add_foreign_key_to_paginguser.py delete mode 100644 alembic/versions/198c5bc02abf_add_parking_lot.py delete mode 100644 alembic/versions/198cf8fda9a4_remove_ami_config.py delete mode 100644 alembic/versions/19a869176d6c_bump_version_17_05.py delete mode 100644 alembic/versions/1a13acc6cdb0_add_confbridge_talk_detection.py delete mode 100644 alembic/versions/1a25b8b93e70_add_missing_features_func_key.py delete mode 100644 alembic/versions/1a72b3da2baf_drop_order_column_in_schedule_path.py delete mode 100644 alembic/versions/1a730d10e4a7_add_phonebook_url.py delete mode 100644 alembic/versions/1aef8dfb5a12_remove_null_constraint_exten_context_.py delete mode 100644 alembic/versions/1b6be5d5e4ac_drop_usersip_setvar_column.py delete mode 100644 alembic/versions/1c3eb7380750_replace_mobile_callable.py delete mode 100644 alembic/versions/1c95890bb00d_add_pjsip_system.py delete mode 100644 alembic/versions/1cc52186eb47_add_switchboard_table.py delete mode 100644 alembic/versions/1d05ffb14525_remove_unused_tables.py delete mode 100644 alembic/versions/1d4b487e4d1f_add_voicemail_foreign_key.py delete mode 100644 alembic/versions/1ddfb39a066f_drop_musiconhold_table.py delete mode 100644 alembic/versions/1f272484c083_remove_nullable_constraint_queueskill.py delete mode 100644 alembic/versions/1f4cbd713979_add_missing_entity_id_column.py delete mode 100644 alembic/versions/1f533d5f5f51_add_conference_dialaction.py delete mode 100644 alembic/versions/203129d6b213_remove_queue_info_table.py delete mode 100644 alembic/versions/203f6f2cf0a0_remove_deprecated_incall_fields.py delete mode 100644 alembic/versions/2072c1e66aa9_drop_dialaction_event.py delete mode 100644 alembic/versions/2077c9fc2d49_replace_agent_action_by_extension_id.py delete mode 100644 alembic/versions/20d4630f2c8e_remove_constraints_from_linefeatures.py delete mode 100644 alembic/versions/20debb21dc01_move_column_merging_from_display_to_.py delete mode 100644 alembic/versions/21b72c41eb6a_bump_version_22_05.py delete mode 100644 alembic/versions/21d45c24210e_add_a_wizard_webservice_access.py delete mode 100644 alembic/versions/21f6963c1d35_call_filter_add_tenant_uuid.py delete mode 100644 alembic/versions/2251b5ae9e6c_add_wazo_upgrade_acl.py delete mode 100644 alembic/versions/2256e488e43c_change_email_body_new_lines.py delete mode 100644 alembic/versions/232708be8a75_parking_lot_add_tenant_uuid.py delete mode 100644 alembic/versions/234745874c55_migrate_func_key_paging.py delete mode 100644 alembic/versions/235158681deb_calll_permission_add_tenant_uuid.py delete mode 100644 alembic/versions/2375157ea682_add_people_xlet.py delete mode 100644 alembic/versions/241501a5f8ba_remove_queue_info_function.py delete mode 100644 alembic/versions/241ba0a6d087_fix_broken_ctidirectories_fk.py delete mode 100644 alembic/versions/2485d7c1f8e9_fix_twilio_trunk_migration.py delete mode 100644 alembic/versions/24b41ddb07d7_migrate_agent_func_keys.py delete mode 100644 alembic/versions/255de5d2adea_update_agid_forwards_acl.py delete mode 100644 alembic/versions/267d8bd31d11_add_xivo_auth_service_acl.py delete mode 100644 alembic/versions/27040433c098_remove_invalid_user_email.py delete mode 100644 alembic/versions/27801f8c2a80_add_direction_to_call_log.py delete mode 100644 alembic/versions/2796b8c839c5_remove_ulaw_everywhere.py delete mode 100644 alembic/versions/27d9ea4b21d0_fix_func_key_type_ids.py delete mode 100644 alembic/versions/27f83f39e031_add_user_contact_part_2.py delete mode 100644 alembic/versions/28195459f3d1_migrate_sip_general_to_pjsip_global.py delete mode 100644 alembic/versions/28443bfc4fb1_update_nat_options_auto.py delete mode 100644 alembic/versions/284a6962ac4e_fix_codec_migration.py delete mode 100644 alembic/versions/28721fe085d3_add_group_member_extensions.py delete mode 100644 alembic/versions/29013d7926e6_dissociate_user_from_template.py delete mode 100644 alembic/versions/2903faf08938_add_read_postfix_to_service_acls.py delete mode 100644 alembic/versions/291ed250b7a2_drop_useriax_realtime_columns.py delete mode 100644 alembic/versions/29290c38946f_fix_queuemember_interfaces.py delete mode 100644 alembic/versions/2956eaa19c7c_remove_dialer_xlet.py delete mode 100644 alembic/versions/2984e5ede175_add_mongooseim_acl_to_ctid_ng.py delete mode 100644 alembic/versions/2989b8b30fe7_create_line_extension_table.py delete mode 100644 alembic/versions/2991705be1ec_bump_version_18_02.py delete mode 100644 alembic/versions/29a5eab6a19b_remove_duration_and_answered_from_call_.py delete mode 100644 alembic/versions/2a24c3d1d13e_call_log_add_requested_name.py delete mode 100644 alembic/versions/2a27e01c8070_add_greeting_sound_to_incall.py delete mode 100644 alembic/versions/2acff5c02871_change_datax_columns_to_type_text.py delete mode 100644 alembic/versions/2b0f5ee268c4_remove_orphan_lines.py delete mode 100644 alembic/versions/2b51ff81d388_add_the_meetingjoin_extenfeatures.py delete mode 100644 alembic/versions/2b5d68fa7ab8_bump_version_21_07.py delete mode 100644 alembic/versions/2b65d248c2ad_meeting_require_authorization_not_null.py delete mode 100644 alembic/versions/2ba2f1d009ca_add_autoprov_acl_to_xivo_agid.py delete mode 100644 alembic/versions/2bb55c201ee7_bump_version_21_01.py delete mode 100644 alembic/versions/2bb6543883a6_make_directory_fields_format_strings.py delete mode 100644 alembic/versions/2c004153ed7f_make_user_uuid_unique.py delete mode 100644 alembic/versions/2c6c9833d839_remove_unused_indexes_on_cel_and_qlog_.py delete mode 100644 alembic/versions/2c940e077157_add_xivo_configured.py delete mode 100644 alembic/versions/2cbd52dd69e1_bump_version_20_05.py delete mode 100644 alembic/versions/2d0b0356eb76_add_cel_extra.py delete mode 100644 alembic/versions/2d3d29858d6d_create_func_key_paging.py delete mode 100644 alembic/versions/2ea8d6cb26f6_rename_enableautomon_to_enableonlinerec.py delete mode 100644 alembic/versions/2f354a1653fc_add_deleted_col_to_stat_tables.py delete mode 100644 alembic/versions/2f69acadecbe_create_conference_table.py delete mode 100644 alembic/versions/2f7e5c4119bc_add_xivo_directory_fields.py delete mode 100644 alembic/versions/2fbbd4231cca_remove_phonebook_configuration.py delete mode 100644 alembic/versions/2fe87e2b9580_add_user_specific_recording_options.py delete mode 100644 alembic/versions/30271471ab8_remove_rightcallmember_incall_enum.py delete mode 100644 alembic/versions/30564ea14542_remove_voicemail_type.py delete mode 100644 alembic/versions/3096b11582cf_group_timeout_may_be_null.py delete mode 100644 alembic/versions/30d59d9b4b6e_remove_exchange_voicemail.py delete mode 100644 alembic/versions/30d7dcbb9133_add_web_service_uuid.py delete mode 100644 alembic/versions/30eebcef63ad_delete_sessions.py delete mode 100644 alembic/versions/30f88b362201_alter_queueskill_drop_printscreen.py delete mode 100644 alembic/versions/3133fb4958ef_add_acls_to_xivo_ctid_ng.py delete mode 100644 alembic/versions/315f74edddb1_remove_nullable_constraint_.py delete mode 100644 alembic/versions/3196befc4753_remove_custom_moh_directory.py delete mode 100644 alembic/versions/31eecc16c5c5_migrate_service_func_keys_without_.py delete mode 100644 alembic/versions/320d05ebad29_set_call_limit_default_to_10.py delete mode 100644 alembic/versions/324ad441b84c_add_wazo_plugind_cli_acl.py delete mode 100644 alembic/versions/3284584a535c_remove_nullable_constraint_pwd_vm.py delete mode 100644 alembic/versions/330b1c94980d_remove_outbound_auth_key.py delete mode 100644 alembic/versions/3314b25783a2_bump_version_22_02.py delete mode 100644 alembic/versions/333cd1b1d31_add_dtmf_hangup_to_userfeatures.py delete mode 100644 alembic/versions/337f76c25478_update_internal_directory.py delete mode 100644 alembic/versions/33e0cdb6971d_create_func_key_features.py delete mode 100644 alembic/versions/33fa1a10428f_add_moh_table.py delete mode 100644 alembic/versions/34122e276b2_bump_version_17_03.py delete mode 100644 alembic/versions/341f7e584088_remove_old_phonebook.py delete mode 100644 alembic/versions/3420040c5650_add_confd_acls_to_agid.py delete mode 100644 alembic/versions/3462497a56f8_add_tenants_acl_to_the_wizard.py delete mode 100644 alembic/versions/34748356e196_bump_version_18_07.py delete mode 100644 alembic/versions/34b2b6ca345e_bump_version_19_13.py delete mode 100644 alembic/versions/354fe6b9e819_sccpline_add_tenant_uuid.py delete mode 100644 alembic/versions/35a7f7e2dc33_create_automon_func_key.py delete mode 100644 alembic/versions/3612e8058d92_bump_version_17_08.py delete mode 100644 alembic/versions/36516503ae1b_add_call_log_requested_exten_context.py delete mode 100644 alembic/versions/36c3f75ac228_ast13_remove_adsipark.py delete mode 100644 alembic/versions/374507a67216_userfeatures_tenant_uuid_cascade.py delete mode 100644 alembic/versions/3770e116222d_divide_queue_waitratio.py delete mode 100644 alembic/versions/378c46e8c6fe_remove_pickupmember_invalid.py delete mode 100644 alembic/versions/379d2e0c5e51_add_directmedia_outgoing_option.py delete mode 100644 alembic/versions/379ed6d9a62_remove_acesswebservice_acl_obj.py delete mode 100644 alembic/versions/37b9ac945437_bump_version_17_04.py delete mode 100644 alembic/versions/37c0864e0b2b_convert_agent_status_login_to_pjsip.py delete mode 100644 alembic/versions/37c6976343d4_fix_partial_call_stats.py delete mode 100644 alembic/versions/381de5b6a1a5_create_meeting_authorization_table.py delete mode 100644 alembic/versions/382aaefc59ec_add_group_uuid.py delete mode 100644 alembic/versions/387d650380bd_change_defaut_cti_colors.py delete mode 100644 alembic/versions/394edc522e4a_add_ldapfitler_id_to_directories.py delete mode 100644 alembic/versions/39f7b89af84e_randomize_uuid.py delete mode 100644 alembic/versions/3a091c2f91bc_call_log_add_internal_extensions.py delete mode 100644 alembic/versions/3a0ace87fc76_remove_contact_xlet.py delete mode 100644 alembic/versions/3ab28f25de30_reset_queue_exit_context.py delete mode 100644 alembic/versions/3ab7cf07eb66_migrate_func_key_bsfilter.py delete mode 100644 alembic/versions/3b2e82f0bfbe_add_the_tenant_table.py delete mode 100644 alembic/versions/3b7b334edb5c_add_services_forwards_acl_to_agid.py delete mode 100644 alembic/versions/3c14d64c95a3_add_index_on_callid_in_stat_call_on_.py delete mode 100644 alembic/versions/3c72c43e39fa_remove_cel_fields_limits.py delete mode 100644 alembic/versions/3c9280e9ed5c_adjust_agent_login_status_login_at.py delete mode 100644 alembic/versions/3d22f40558d1_add_infos_table.py delete mode 100644 alembic/versions/3df184c10386_create_transfer_function_keys.py delete mode 100644 alembic/versions/3e185fe069be_remove_constraints_agentfeatures.py delete mode 100644 alembic/versions/3e6bc9ae6158_add_xivo_call_logs_web_service.py delete mode 100644 alembic/versions/3e7dbde01837_bump_version_17_13.py delete mode 100644 alembic/versions/3ecc983a901c_remove_usersip_registertrying.py delete mode 100644 alembic/versions/3edd3b3aac7d_bump_version_21_13.py delete mode 100644 alembic/versions/3f132402532b_bump_version_19_04.py delete mode 100644 alembic/versions/3f310bfa7f9a_remove_chan_sip_permaturemedia.py delete mode 100644 alembic/versions/3fe6319ce27a_create_func_key_custom.py delete mode 100644 alembic/versions/40359c5c2c92_bump_version_18_01.py delete mode 100644 alembic/versions/404300b7c16d_remove_loginclient_passwdclient_data_from_.py delete mode 100644 alembic/versions/40ba1a488aa7_phonebook_file_to_csv.py delete mode 100644 alembic/versions/40e2f31cf146_remove_orphan_func_key.py delete mode 100644 alembic/versions/40e6d1e4c2c3_schedule_add_tenant_uuid.py delete mode 100644 alembic/versions/4123465e114e_add_agentd_acl_to_agid.py delete mode 100644 alembic/versions/412b6135f650_rename_xivo_auth_to_wazo_auth.py delete mode 100644 alembic/versions/415b08ed9959_add_xivo_auth_web_service.py delete mode 100644 alembic/versions/41a523e18fdd_bump_version_18_03.py delete mode 100644 alembic/versions/41b6afe5b164_usercustom_add_tenant_uuid.py delete mode 100644 alembic/versions/41d3e47edf4a_missing_func_key_dest_user_pointing_to_.py delete mode 100644 alembic/versions/41e07bde92da_directories_rename_internal_to_xivo.py delete mode 100644 alembic/versions/41f6ef3f00fe_voicemail_extra_options.py delete mode 100644 alembic/versions/425eebc346b1_bump_version_17_14.py delete mode 100644 alembic/versions/42db6d46c98a_add_an_external_meeting_sip_template.py delete mode 100644 alembic/versions/42e9771685b0_bump_version_17_07.py delete mode 100644 alembic/versions/438cb372df48_remove_paging_callnotbusy_column.py delete mode 100644 alembic/versions/43995f4ac823_fix_invalid_context_name.py delete mode 100644 alembic/versions/43a39441ae83_update_directory_definition_joins.py delete mode 100644 alembic/versions/43c5188319dc_update_chan_sip_t1min.py delete mode 100644 alembic/versions/444b39e9aa32_rename_webservices_directory.py delete mode 100644 alembic/versions/447e4ab61975_fix_queue_table_without_context.py delete mode 100644 alembic/versions/449045080bf6_bump_version_19_16.py delete mode 100644 alembic/versions/44af2488e95_ast13_app_queue.py delete mode 100644 alembic/versions/44c6b8d8c196_activate_blf_by_default.py delete mode 100644 alembic/versions/454c3dfde5db_migrate_to_sip_webrtc_option.py delete mode 100644 alembic/versions/45ceb32fae06_add_uuid_to_userfeatures.py delete mode 100644 alembic/versions/45ec6bd040ac_remove_dangling_user_function_keys.py delete mode 100644 alembic/versions/462b92a4f5d8_add_conference_exten_enum.py delete mode 100644 alembic/versions/46dbcd084872_remove_columns_from_ldapfilter.py delete mode 100644 alembic/versions/46dda7d0374e_bump_version_18_14.py delete mode 100644 alembic/versions/4722bbe519b1_remove_unused_values_dialaction_enum.py delete mode 100644 alembic/versions/476a2700b4c2_moh_add_tenant_uuid.py delete mode 100644 alembic/versions/47920341f392_add_application_dialaction.py delete mode 100644 alembic/versions/486c0749403c_migrate_voicemail_func_keys.py delete mode 100644 alembic/versions/488e5a3d75_create_asterisk_file_tables.py delete mode 100644 alembic/versions/49126e9fffe2_remove_autochangestate.py delete mode 100644 alembic/versions/495accfabe9f_bump_version_22_15.py delete mode 100644 alembic/versions/4977a626c01_add_xivo_ctid_ng_acl.py delete mode 100644 alembic/versions/498f0570ffef_fix_default_display_personal.py delete mode 100644 alembic/versions/4a0281e1a826_usersip_add_tenant_uuid.py delete mode 100644 alembic/versions/4a1c2a87321_add_foreignkey_on_rightcallexten.py delete mode 100644 alembic/versions/4a5a1c3eb52f_add_subscription_to_userfeatures.py delete mode 100644 alembic/versions/4a80d0e24028_directories_use_dirtype_column.py delete mode 100644 alembic/versions/4aa03039dd2e_bump_version_20_13.py delete mode 100644 alembic/versions/4bb90c6c47bb_allow_email_as_username.py delete mode 100644 alembic/versions/4c13318f6975_migrate_func_key_park_position.py delete mode 100644 alembic/versions/4c1cbf778770_bump_version_19_08.py delete mode 100644 alembic/versions/4c4a8eaa31e7_bump_version_19_17.py delete mode 100644 alembic/versions/4c660492b365_fix_register_transports.py delete mode 100644 alembic/versions/4c79fd76bccb_drop_useless_provisioning_columns.py delete mode 100644 alembic/versions/4ce50bcf2a0e_create_forward_func_keys.py delete mode 100644 alembic/versions/4cf59c82b51e_queue_timeout_may_be_null.py delete mode 100644 alembic/versions/4cf687f2c0eb_add_dird_xivo_backend_auth.py delete mode 100644 alembic/versions/4d539700bb90_add_group_label.py delete mode 100644 alembic/versions/4d736bac41cb_bump_version_20_06.py delete mode 100644 alembic/versions/4d80d8106d1e_bump_version_19_14.py delete mode 100644 alembic/versions/4e07e476eb0b_add_paused_and_paused_reason_to_agent_.py delete mode 100644 alembic/versions/4e2fb3cbc2a2_add_unique_constraint_queueskillrule.py delete mode 100644 alembic/versions/4ee55e5290be_directories_xivo_confd_uri.py delete mode 100644 alembic/versions/4f85f1de19b4_useriax_add_tenant_uuid.py delete mode 100644 alembic/versions/4f86216ba603_paging_add_tenant_uuid.py delete mode 100644 alembic/versions/4fa0a41c0327_add_foreignkey_outcalltrunk.py delete mode 100644 alembic/versions/4fb644b564c8_bump_version_17_15.py delete mode 100644 alembic/versions/4fd0315a61fc_allow_context_none_in_outcall.py delete mode 100644 alembic/versions/4fe20686380b_bump_version_19_10.py delete mode 100644 alembic/versions/4fe888586ba3_add_unique_constraint_to_user_email.py delete mode 100644 alembic/versions/500ca962c3a8_use_automixmon_features_instead_of_.py delete mode 100644 alembic/versions/5013b66e26d2_add_auth_tenants_read_to_agid.py delete mode 100644 alembic/versions/501dae22d6be_ast13_update_findslot.py delete mode 100644 alembic/versions/503cf85083ba_enable_starttls.py delete mode 100644 alembic/versions/5047425b0f5c_add_tenant_uuid_to_call_log.py delete mode 100644 alembic/versions/505c12d2ed73_add_iax_options.py delete mode 100644 alembic/versions/5073b1fa473e_force_user_to_entity_association.py delete mode 100644 alembic/versions/5085447dd295_allow_call_filter_description_none.py delete mode 100644 alembic/versions/508c5a0382dc_bump_version_17_12.py delete mode 100644 alembic/versions/50cfb10bd01d_drop_empty_recording_tables.py delete mode 100644 alembic/versions/51ebe7954da8_meeting_persistent_column.py delete mode 100644 alembic/versions/525b0cc45d2_add_context_to_trunkfeatures.py delete mode 100644 alembic/versions/5270d317f8fd_add_ldapfilter_directories.py delete mode 100644 alembic/versions/52acaaba550c_bump_version_18_05.py delete mode 100644 alembic/versions/52b66f888125_bump_version_17_16.py delete mode 100644 alembic/versions/52bd5977c09d_initial_script.py delete mode 100644 alembic/versions/534d6112e879_fix_sound_file_paths.py delete mode 100644 alembic/versions/537774d3845a_add_email_field_in_phonebook.py delete mode 100644 alembic/versions/5381b673cf2c_add_ignore_forward_columns.py delete mode 100644 alembic/versions/53ad771ac875_bump_version_21_02.py delete mode 100644 alembic/versions/53ce4ff6ffe9_add_stat_switchboard_queue_table.py delete mode 100644 alembic/versions/53e449192523_add_user_email.py delete mode 100644 alembic/versions/53fbfa53b47c_add_user_uuid.py delete mode 100644 alembic/versions/544f8b1e6905_remove_dialaction_n_plus_101_option.py delete mode 100644 alembic/versions/5450dd40916e_add_call_completion.py delete mode 100644 alembic/versions/5497199c082f_add_queue_id_to_stat_queue.py delete mode 100644 alembic/versions/549c621ae619_update_musiconhold_random.py delete mode 100644 alembic/versions/5524f5f02959_remove_ctis.py delete mode 100644 alembic/versions/55527c5cb4b1_bump_version_20_03.py delete mode 100644 alembic/versions/5576b5f933e6_queue_log_change_the_type_of_agent_to_.py delete mode 100644 alembic/versions/55cd08a0dae2_bump_version_to_22_01.py delete mode 100644 alembic/versions/55f3c86885c5_create_func_key_destination_service.py delete mode 100644 alembic/versions/55f7b6c13454_populate_confbridge_configuration.py delete mode 100644 alembic/versions/5600ad4c00b4_remove_unused_provisioning_columns.py delete mode 100644 alembic/versions/560bfca6cf85_rename_dhcp_field_extra_iface.py delete mode 100644 alembic/versions/564d634619bc_add_dnd_acl_to_ctid.py delete mode 100644 alembic/versions/56a75d478edc_remove_staticsip_table.py delete mode 100644 alembic/versions/56a9a83c26b3_remove_old_phonebook_tables.py delete mode 100644 alembic/versions/56a9fce34ae9_link_default_template_to_tenant.py delete mode 100644 alembic/versions/56e683a865e0_add_english_presence_statuses.py delete mode 100644 alembic/versions/570d858c41d6_remove_nullable_constraint_queuefeatures.py delete mode 100644 alembic/versions/5712e7a66baa_create_new_dird_phonebooks_cti_directories.py delete mode 100644 alembic/versions/57461905b7e6_bump_version_17_17.py delete mode 100644 alembic/versions/57a7c7438b98_add_email_field_in_internal.py delete mode 100644 alembic/versions/57ab432bb1c3_bump_version_18_10.py delete mode 100644 alembic/versions/5863384621a1_bump_version_22_03.py delete mode 100644 alembic/versions/58cd88054523_bump_version_19_02.py delete mode 100644 alembic/versions/58d561775bf3_remove_nullable_constraint_groupfeatures.py delete mode 100644 alembic/versions/58e808b69aec_queue_autopause_option.py delete mode 100644 alembic/versions/58fc78d9f67f_bump_version_18_06.py delete mode 100644 alembic/versions/592e449b34ec_cti_displays_clean_fields.py delete mode 100644 alembic/versions/596b177ba681_bump_version_17_06.py delete mode 100644 alembic/versions/59feecbe8d13_webi_to_dird_ldap_migration.py delete mode 100644 alembic/versions/5a02fde67132_migrate_func_key_parking.py delete mode 100644 alembic/versions/5a285558e46e_trunk_add_tenant_uuid.py delete mode 100644 alembic/versions/5a4fe661486c_fix_func_key_label_empty.py delete mode 100644 alembic/versions/5ace7dc40b5c_create_missing_paging_func_keys.py delete mode 100644 alembic/versions/5b427e206bdf_update_wazo_plugind_cli_acl.py delete mode 100644 alembic/versions/5c8dc069cfd7_fix_jitter_buffer_implementation_choice.py delete mode 100644 alembic/versions/5c9f286599b6_bump_version_20_11.py delete mode 100644 alembic/versions/5dd4a73c91c2_bump_version_19_03.py delete mode 100644 alembic/versions/5f8c8a323cbe_incall_add_tenant_uuid.py delete mode 100644 alembic/versions/5faf5386dca8_remove_cti_directories_tables.py delete mode 100644 alembic/versions/5ffaec7e8db7_add_endpoint_sip_materialized_view.py delete mode 100644 alembic/versions/60eb57605f3_bump_version_17_11.py delete mode 100644 alembic/versions/61e3d7c65755_set_all_moh_labels.py delete mode 100644 alembic/versions/62c5befaa8cf_hep_general_section.py delete mode 100644 alembic/versions/64c6bde0116c_add_date_end_to_call_log.py delete mode 100644 alembic/versions/6545d103068c_add_the_asterisk_service_user.py delete mode 100644 alembic/versions/66453e75a1fd_set_a_username_on_usersip.py delete mode 100644 alembic/versions/672a6918b7f9_fix_the_reverse_directory.py delete mode 100644 alembic/versions/67cdc9dfc2d0_remove_unused_tables.py delete mode 100644 alembic/versions/68507181de97_add_tenant_uuid_to_userfeatures.py delete mode 100644 alembic/versions/69c55f395eb7_fix_global_trunk_template.py delete mode 100644 alembic/versions/6a08e32fadba_add_default_sccp_provisioning_values.py delete mode 100644 alembic/versions/6aead6a54bbb_update_uniqueconstraint_queuemember.py delete mode 100644 alembic/versions/6afcf16a334d_add_auth_tenants_read_to_auth.py delete mode 100644 alembic/versions/6bfd932df2c_add_user_contact_table.py delete mode 100644 alembic/versions/6e196b7526a_drop_usersip_realtime_columns.py delete mode 100644 alembic/versions/6fc79e30e8bf_add_user_external_app_table.py delete mode 100644 alembic/versions/6ff776dde35e_add_mark_answered_elsewhere_column_.py delete mode 100644 alembic/versions/700711f75ee6_alter_provisioning_remove_not_null_.py delete mode 100644 alembic/versions/706a7655606e_add_the_meeting_table.py delete mode 100644 alembic/versions/71c41130380e_drop_accesswebservice_table.py delete mode 100644 alembic/versions/73166af50deb_fix_trunk_with_host_migration.py delete mode 100644 alembic/versions/732a9b6500da_bump_version_19_15.py delete mode 100644 alembic/versions/73889d1db031_queueskillrule_add_tenant_uuid.py delete mode 100644 alembic/versions/74a76197acaa_bump_version_18_12.py delete mode 100644 alembic/versions/7541da6ac48f_bump_version_22_09.py delete mode 100644 alembic/versions/757111d049b6_add_the_tenant_slug.py delete mode 100644 alembic/versions/7628599d48dc_pickup_add_tenant_uuid.py delete mode 100644 alembic/versions/778dc763148f_add_auth_tenants_read_to_dird.py delete mode 100644 alembic/versions/785b8cb74daa_revert_version_upgrade.py delete mode 100644 alembic/versions/7b3b0ff90f0c_add_name_column_to_paging.py delete mode 100644 alembic/versions/7d342adb6ae1_bump_version_22_14.py delete mode 100644 alembic/versions/7d47aaef973a_bump_version_19_07.py delete mode 100644 alembic/versions/7d91d22133a9_bump_version_20_08.py delete mode 100644 alembic/versions/7f1c1c00662_remove_invalid_chars_from_label.py delete mode 100644 alembic/versions/7f337d6ca187_unset_context_queue_from_groupfeatures.py delete mode 100644 alembic/versions/8452bc3d5d67_conferences_add_tenant_uuid.py delete mode 100644 alembic/versions/84d91026c293_add_switchboard_moh.py delete mode 100644 alembic/versions/86511ef5d49_add_displayname_field_in_source_.py delete mode 100644 alembic/versions/867bd9268824_bump_version_21_03.py delete mode 100644 alembic/versions/8691b32cf44e_remove_phonebook_enums.py delete mode 100644 alembic/versions/86c17bf55b92_bump_version_20_07.py delete mode 100644 alembic/versions/872b869e9675_remove_entity.py delete mode 100644 alembic/versions/87b36150b613_bump_version_19_06.py delete mode 100644 alembic/versions/8a551a46dd5d_add_wazo_version_column.py delete mode 100644 alembic/versions/8bbb46a9f362_bump_version_23_05.py delete mode 100644 alembic/versions/8c21acf4e9e_bump_version_17_02.py delete mode 100644 alembic/versions/8e09c6fde62d_remove_auth_from_insecure_trunks.py delete mode 100644 alembic/versions/90518bf34218_back_to_19_12.py delete mode 100644 alembic/versions/907d4947d665_call_permission_non_unique_names.py delete mode 100644 alembic/versions/90f771359c71_bump_version_19_05.py delete mode 100644 alembic/versions/9142f0403c8_add_ivr_support.py delete mode 100644 alembic/versions/92061fe1c3b8_bump_version_20_02.py delete mode 100644 alembic/versions/92928db7221_bump_version_18_08.py delete mode 100644 alembic/versions/93ea61395eef_bump_version_22_01.py delete mode 100644 alembic/versions/9442da3b20b6_bump_version_21_04.py delete mode 100644 alembic/versions/978e620de034_bump_version_21_09.py delete mode 100644 alembic/versions/99082b9c0b7b_bump_version_18_13.py delete mode 100644 alembic/versions/9b0892a818e6_add_tenant_uuid_to_agentfeatures.py delete mode 100644 alembic/versions/9b7e32eb0a77_bump_version_19_09.py delete mode 100644 alembic/versions/9eeb96b396a7_bump_version_21_08.py delete mode 100644 alembic/versions/9f11f3abaacc_bump_version_23_03.py delete mode 100644 alembic/versions/a10db8de6372_remove_unused_extenfeatures.py delete mode 100644 alembic/versions/a132daff54b_drop_column_useenum.py delete mode 100644 alembic/versions/a28974a2dc19_add_pjsip_endpoints.py delete mode 100644 alembic/versions/a3b4e1bf633b_queue_add_tenant_uuid.py delete mode 100644 alembic/versions/a3e7fd7b670_create_func_key_park_position.py delete mode 100644 alembic/versions/a46c624e7f61_bump_version_22_11.py delete mode 100644 alembic/versions/aaf16eeecf7f_add_indices_to_foreign_keys.py delete mode 100644 alembic/versions/ab2956a0168_directories_add_tenant_and_phonebook_.py delete mode 100644 alembic/versions/ae5bee40e9d2_bump_version_22_08.py delete mode 100644 alembic/versions/b0edbcc1426d_bump_version_22_16.py delete mode 100644 alembic/versions/b1c4be6f46ff_bump_version_20_16.py delete mode 100644 alembic/versions/b1dfaf771da8_replace_automixmon_with_dynamic_feature.py delete mode 100644 alembic/versions/b2abcc84ad_add_a_source_field_to_all_sources.py delete mode 100644 alembic/versions/b3bf380f5241_fix_contextinclude_include_for_context_.py delete mode 100644 alembic/versions/b536a68f5505_remove_dialaction_linked_column.py delete mode 100644 alembic/versions/b57ed1e30535_add_direction_constraints_to_call_log.py delete mode 100644 alembic/versions/b5c40615bc21_context_add_the_tenant_uuid.py delete mode 100644 alembic/versions/b5f230e1e0fe_add_users_confd_acl_to_call_logd.py delete mode 100644 alembic/versions/b62e1eba7869_bump_version_20_17.py delete mode 100644 alembic/versions/b6a0f4cc7e49_remove_user_table.py delete mode 100644 alembic/versions/b6bb28f27f2_fix_schema_differences.py delete mode 100644 alembic/versions/b78a74e69592_bump_version_20_14.py delete mode 100644 alembic/versions/b7d3c4701095_add_a_meeting_number.py delete mode 100644 alembic/versions/b8d0848e7b2_add_acls_to_xivo_ctid_ng.py delete mode 100644 alembic/versions/b8f8ba046d25_directories_migration_xivo_directory.py delete mode 100644 alembic/versions/ba7c6bb897b3_add_switchboard_dialaction.py delete mode 100644 alembic/versions/bba3a031fd01_remove_invalid_webrtc_options.py delete mode 100644 alembic/versions/bc9e62985a0_add_wazo_plugind_acl.py delete mode 100644 alembic/versions/bf1aaa27b7f8_fix_default_pjsip_template_transport.py delete mode 100644 alembic/versions/c04ed3f6a685_fix_pjpjsip_queuemembers.py delete mode 100644 alembic/versions/c18e988da503_add_name_nullable_on_schedule.py delete mode 100644 alembic/versions/c193f30636ff_add_acl_to_xivo_ctid_ng.py delete mode 100644 alembic/versions/c1d845eb61b4_add_external_app_table.py delete mode 100644 alembic/versions/c22356e22a13_directories_add_auth_columns.py delete mode 100644 alembic/versions/c3b40a0998c4_update_sip_realm_to_wazo.py delete mode 100644 alembic/versions/c3ecaf2f9e78_fix_invalid_extension_parking_lot.py delete mode 100644 alembic/versions/c7de783d8c8c_add_a_tenant_uuid_to_groups.py delete mode 100644 alembic/versions/c8415eb8bfb5_bump_version_23_01.py delete mode 100644 alembic/versions/c8abcc5497ef_bump_version_20_01.py delete mode 100644 alembic/versions/c9ed2541b284_meeting_authorization_required.py delete mode 100644 alembic/versions/cac9af37c973_remove_deprecated_cti_tables.py delete mode 100644 alembic/versions/cb5666745311_bump_version_21_10.py delete mode 100644 alembic/versions/cbd383662cc0_add_timezone_data_to_the_cel_eventtime_.py delete mode 100644 alembic/versions/cc9063471025_registration_options.py delete mode 100644 alembic/versions/ce624f5d7fe2_add_auth_tenants_read_to_ctid.py delete mode 100644 alembic/versions/ce76c220eaab_bump_version_21_16.py delete mode 100644 alembic/versions/d0411d361d57_add_answer_to_application_dest_node.py delete mode 100644 alembic/versions/d0f74d74eb5f_bump_version_19_11.py delete mode 100644 alembic/versions/d47f295009dd_remove_sipauthentication.py delete mode 100644 alembic/versions/d56d7434e9f4_bump_version_20_12.py delete mode 100644 alembic/versions/d6be50f692dc_add_sip_options.py delete mode 100644 alembic/versions/d81a903b6d1e_ivr_add_tenant_uuid.py delete mode 100644 alembic/versions/d90ff200ae53_bump_version_20_09.py delete mode 100644 alembic/versions/d9e7aac4970_add_call_log_participant_table.py delete mode 100644 alembic/versions/d9eaed7a2f42_convert_queuemember_to_pjsip.py delete mode 100644 alembic/versions/da06cfd76289_bump_version_21_15.py delete mode 100644 alembic/versions/da53b63d9433_add_missing_pjsip_options.py delete mode 100644 alembic/versions/da58e9e49eb_add_transfers_acl_to_ctid.py delete mode 100644 alembic/versions/dba4e40979ae_add_date_answer_to_call_log.py delete mode 100644 alembic/versions/dd011dfbb5_remove_mohsuggest_from_usersip.py delete mode 100644 alembic/versions/dd0c465315d_migrate_forward_func_keys.py delete mode 100644 alembic/versions/de624f81421f_add_tenant_uuid_to_stat_agent_queue.py delete mode 100644 alembic/versions/dfd6c02443cc_remove_deprecated_meetme.py delete mode 100644 alembic/versions/e04b80f8b6fc_merge_sip_templates_for_webrtc.py delete mode 100644 alembic/versions/e0fd01d4c2a_remove_dead_forward_func_keys.py delete mode 100644 alembic/versions/e3f5e62ef9dd_add_auth_tenants_read_to_ctid_ng.py delete mode 100644 alembic/versions/e4f459f58795_bump_version_19_01.py delete mode 100644 alembic/versions/e5281e98b300_add_answered_column_to_cdr_participant.py delete mode 100644 alembic/versions/e53b8ab083c0_bump_version_22_13.py delete mode 100644 alembic/versions/e5da3b191742_refactor_line_protocol_to_endpoint.py delete mode 100644 alembic/versions/e5e53b7dc5d0_add_timezone_on_call_center_stats.py delete mode 100644 alembic/versions/e66504d94e2e_update_sip_useragent_to_wazo.py delete mode 100644 alembic/versions/e6c5e0410e89_bump_version_21_05.py delete mode 100644 alembic/versions/e71820229900_remove_number_context_from_groupfeatures.py delete mode 100644 alembic/versions/ea74eca400ce_sip_to_pjsip_endpoint.py delete mode 100644 alembic/versions/ea9cdf2d59f8_add_default_template_webrtc_video.py delete mode 100644 alembic/versions/eaffdf929dd1_queueskill_add_tenant_uuid.py delete mode 100644 alembic/versions/ed40a90222f0_bump_version_21_12.py delete mode 100644 alembic/versions/edb58b09b15_6361_missing_acl_xivo_ctid_ng.py delete mode 100644 alembic/versions/edca430a8373_add_the_pjsip_transport_tables.py delete mode 100644 alembic/versions/eddc1df1d57c_bump_version_20_10.py delete mode 100644 alembic/versions/ee27cd6ccd9_rtp_general_section.py delete mode 100644 alembic/versions/ee773d263d87_remove_endpoint_sip_context.py delete mode 100644 alembic/versions/eee032b308b_add_xivo_confd_acl.py delete mode 100644 alembic/versions/f055e37e6196_merge_ctimain_infos_general_tables.py delete mode 100644 alembic/versions/f1518ec4da82_add_extension_cascade_on_line_extension.py delete mode 100644 alembic/versions/f1fea68b56d9_add_priority_column_to_endpoint_sip.py delete mode 100644 alembic/versions/f207de52e7d0_bump_version_20_15.py delete mode 100644 alembic/versions/f2eae4a8353e_bump_version_22_06.py delete mode 100644 alembic/versions/f33878e11ef4_bump_version_23_04.py delete mode 100644 alembic/versions/f3e76222b5c9_remove_dahdi_monitoring_column.py delete mode 100644 alembic/versions/f485ac649eb_migrate_transfer_function_keys.py delete mode 100644 alembic/versions/f5f2dd21819_ast13_chan_sip.py delete mode 100644 alembic/versions/f6dab479e74_remove_column_tablename_from_directories.py delete mode 100644 alembic/versions/f721d0482a3_create_new_dird_phonebooks.py delete mode 100644 alembic/versions/f98e74435092_fix_pjsip_diff.py delete mode 100644 alembic/versions/f9ea1046c8e5_add_line_cascade_on_line_extension.py delete mode 100644 alembic/versions/fb663a210806_pjsip_transport_migration.py delete mode 100644 alembic/versions/fbbbf7d78ed0_back_to_19_13.py delete mode 100644 alembic/versions/fd040214cccb_add_plugind_cli_read_acl.py diff --git a/alembic/versions/014b218f97dd_add_acl_to_call_logd.py b/alembic/versions/014b218f97dd_add_acl_to_call_logd.py deleted file mode 100644 index a199a751..00000000 --- a/alembic/versions/014b218f97dd_add_acl_to_call_logd.py +++ /dev/null @@ -1,45 +0,0 @@ -"""add acl to call-logd - -Revision ID: 014b218f97dd -Revises: 3e185fe069be - -""" - -from alembic import op -from sqlalchemy import sql -from sqlalchemy.dialects.postgresql import ARRAY, VARCHAR - - -# revision identifiers, used by Alembic. -revision = '014b218f97dd' -down_revision = '3e185fe069be' - - -accesswebservice = sql.table('accesswebservice', - sql.column('id'), - sql.column('name'), - sql.column('acl')) - -ACLS = ['auth.tenants.read'] - - -def upgrade(): - acls = sql.cast(ACLS, ARRAY(VARCHAR)) - query = (accesswebservice - .update() - .values( - acl=sql.func.array_cat(accesswebservice.c.acl, acls)) - .where( - accesswebservice.c.name == "wazo-call-logd")) - op.execute(query) - - -def downgrade(): - for acl in ACLS: - query = (accesswebservice - .update() - .values( - acl=sql.func.array_remove(accesswebservice.c.acl, acl)) - .where( - accesswebservice.c.name == "wazo-call-logd")) - op.execute(query) diff --git a/alembic/versions/01b4c79b3d47_add_the_tenant_uuid_column_to_the_.py b/alembic/versions/01b4c79b3d47_add_the_tenant_uuid_column_to_the_.py deleted file mode 100644 index 3595a7be..00000000 --- a/alembic/versions/01b4c79b3d47_add_the_tenant_uuid_column_to_the_.py +++ /dev/null @@ -1,51 +0,0 @@ -"""add the tenant_uuid column to the entity table - -Revision ID: 01b4c79b3d47 -Revises: 3b2e82f0bfbe - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '01b4c79b3d47' -down_revision = '3b2e82f0bfbe' - -tenant_table = sa.sql.table('tenant', sa.sql.column('uuid')) - - -def _create_tenant(): - insert_query = tenant_table.insert().returning(tenant_table.c.uuid) - return op.get_bind().execute(insert_query).scalar() - - -def associate_tenants(): - tbl = sa.sql.table('entity', sa.sql.column('id'), sa.sql.column('tenant_uuid')) - sql = "SELECT entity.id FROM entity" - entities = op.get_bind().execute(sa.sql.text(sql)) - - for entity in entities: - # The real wazo-auth tenant will be created as a post-start script. - tenant_uuid = _create_tenant() - query = tbl.update().where(tbl.c.id == entity.id).values(tenant_uuid=tenant_uuid) - op.execute(query) - - -def upgrade(): - op.add_column( - 'entity', - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid'), - nullable=True, - ), - ) - associate_tenants() - op.alter_column('entity', 'tenant_uuid', nullable=False) - - -def downgrade(): - op.drop_column('entity', 'tenant_uuid') diff --git a/alembic/versions/02361b8a4b7c_rename_directory_backend.py b/alembic/versions/02361b8a4b7c_rename_directory_backend.py deleted file mode 100644 index 2a1504d6..00000000 --- a/alembic/versions/02361b8a4b7c_rename_directory_backend.py +++ /dev/null @@ -1,36 +0,0 @@ -"""rename-directory-backend - -Revision ID: 02361b8a4b7c -Revises: 30271471ab8 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '02361b8a4b7c' -down_revision = '30271471ab8' - -directories_table = sa.sql.table( - 'directories', - sa.sql.column('dirtype'), -) - - -def _update_type(from_, to): - op.execute( - directories_table - .update() - .where(directories_table.c.dirtype == from_) - .values(dirtype=to) - ) - - -def upgrade(): - _update_type(from_='xivo', to='wazo') - - -def downgrade(): - _update_type(from_='wazo', to='xivo') diff --git a/alembic/versions/0269f5e35792_bump_version_23_02.py b/alembic/versions/0269f5e35792_bump_version_23_02.py deleted file mode 100644 index 1153c1cf..00000000 --- a/alembic/versions/0269f5e35792_bump_version_23_02.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_23_02 - -Revision ID: 0269f5e35792 -Revises: c8415eb8bfb5 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '0269f5e35792' -down_revision = 'c8415eb8bfb5' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='23.02')) - - -def downgrade(): - pass diff --git a/alembic/versions/035908ce02df_add_meeting_creation_date.py b/alembic/versions/035908ce02df_add_meeting_creation_date.py deleted file mode 100644 index ada115cd..00000000 --- a/alembic/versions/035908ce02df_add_meeting_creation_date.py +++ /dev/null @@ -1,26 +0,0 @@ -"""add meeting creation date - -Revision ID: 035908ce02df -Revises: 37c0864e0b2b - -""" - -import datetime -import sqlalchemy as sa - -from alembic import op -from sqlalchemy.types import DateTime -from sqlalchemy.schema import Column - - -# revision identifiers, used by Alembic. -revision = '035908ce02df' -down_revision = '035e2cb65b6d' - - -def upgrade(): - op.add_column('meeting', Column('created_at', DateTime(timezone=True), default=datetime.datetime.utcnow, server_default=sa.text("(now() at time zone 'utc')"))) - - -def downgrade(): - op.drop_column('meeting', 'created_at') diff --git a/alembic/versions/035e2cb65b6d_bump_version_21_14.py b/alembic/versions/035e2cb65b6d_bump_version_21_14.py deleted file mode 100644 index e2347f66..00000000 --- a/alembic/versions/035e2cb65b6d_bump_version_21_14.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_21_14 - -Revision ID: 035e2cb65b6d -Revises: 37c0864e0b2b - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '035e2cb65b6d' -down_revision = '37c0864e0b2b' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='21.14')) - - -def downgrade(): - pass diff --git a/alembic/versions/040b69fd8297_reorder_endpoint_sip_template.py b/alembic/versions/040b69fd8297_reorder_endpoint_sip_template.py deleted file mode 100644 index 5425db61..00000000 --- a/alembic/versions/040b69fd8297_reorder_endpoint_sip_template.py +++ /dev/null @@ -1,93 +0,0 @@ -"""reorder endpoint sip template - -Revision ID: 040b69fd8297 -Revises: 2485d7c1f8e9 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '040b69fd8297' -down_revision = '2485d7c1f8e9' - -endpoint_sip_template_table = sa.sql.table( - "endpoint_sip_template", - sa.sql.column("child_uuid"), - sa.sql.column("parent_uuid"), - sa.sql.column("priority"), -) -tenant_table = sa.sql.table( - "tenant", - sa.sql.column("uuid"), - sa.sql.column("global_sip_template_uuid"), - sa.sql.column("registration_trunk_sip_template_uuid"), - sa.sql.column("webrtc_sip_template_uuid"), - sa.sql.column("webrtc_video_sip_template_uuid"), -) - - -def upgrade(): - reset_endpoint_sip_template_priority() - for tenant in find_tenants(): - update_endpoint_sip_template_priority(tenant) - - -def find_tenants(): - query = sa.sql.select([ - tenant_table.c.uuid, - tenant_table.c.global_sip_template_uuid, - tenant_table.c.webrtc_sip_template_uuid, - tenant_table.c.webrtc_video_sip_template_uuid, - tenant_table.c.registration_trunk_sip_template_uuid, - ]) - return op.get_bind().execute(query) - - -def reset_endpoint_sip_template_priority(): - query = ( - endpoint_sip_template_table.update() - .values(priority=endpoint_sip_template_table.c.priority + 4) - ) - op.execute(query) - - -def update_endpoint_sip_template_priority(tenant): - global_template_uuid = tenant['global_sip_template_uuid'] - webrtc_template_uuid = tenant['webrtc_sip_template_uuid'] - webrtc_video_template_uuid = tenant['webrtc_video_sip_template_uuid'] - registration_trunk_template_uuid = tenant['registration_trunk_sip_template_uuid'] - - query = ( - endpoint_sip_template_table.update() - .values(priority=0) - .where(endpoint_sip_template_table.c.parent_uuid == global_template_uuid) - ) - op.execute(query) - - query = ( - endpoint_sip_template_table.update() - .values(priority=1) - .where(endpoint_sip_template_table.c.parent_uuid == webrtc_template_uuid) - ) - op.execute(query) - - query = ( - endpoint_sip_template_table.update() - .values(priority=2) - .where(endpoint_sip_template_table.c.parent_uuid == webrtc_video_template_uuid) - ) - op.execute(query) - - query = ( - endpoint_sip_template_table.update() - .values(priority=3) - .where(endpoint_sip_template_table.c.parent_uuid == registration_trunk_template_uuid) - ) - op.execute(query) - - -def downgrade(): - pass diff --git a/alembic/versions/049ea24c3a0f_bump_version_22_10.py b/alembic/versions/049ea24c3a0f_bump_version_22_10.py deleted file mode 100644 index 7c1e6e65..00000000 --- a/alembic/versions/049ea24c3a0f_bump_version_22_10.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_22_10 - -Revision ID: 049ea24c3a0f -Revises: 7541da6ac48f - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '049ea24c3a0f' -down_revision = '7541da6ac48f' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='22.10')) - - -def downgrade(): - pass diff --git a/alembic/versions/0600c04fd4a6_bump_version_22_12.py b/alembic/versions/0600c04fd4a6_bump_version_22_12.py deleted file mode 100644 index a1742190..00000000 --- a/alembic/versions/0600c04fd4a6_bump_version_22_12.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_22_12 - -Revision ID: 0600c04fd4a6 -Revises: a46c624e7f61 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '0600c04fd4a6' -down_revision = 'a46c624e7f61' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='22.12')) - - -def downgrade(): - pass diff --git a/alembic/versions/060e2360612f_bump_version_21_06.py b/alembic/versions/060e2360612f_bump_version_21_06.py deleted file mode 100644 index 7765a935..00000000 --- a/alembic/versions/060e2360612f_bump_version_21_06.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_21_06 - -Revision ID: 060e2360612f -Revises: 0f4a7c48613c - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '060e2360612f' -down_revision = '0f4a7c48613c' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='21.06')) - - -def downgrade(): - pass diff --git a/alembic/versions/06149af25f0d_refactor_trunk_protocol_register.py b/alembic/versions/06149af25f0d_refactor_trunk_protocol_register.py deleted file mode 100644 index 3c284ccb..00000000 --- a/alembic/versions/06149af25f0d_refactor_trunk_protocol_register.py +++ /dev/null @@ -1,245 +0,0 @@ -"""refactor_trunk_protocol_register - -Revision ID: 06149af25f0d -Revises: e5da3b191742 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '06149af25f0d' -down_revision = 'e5da3b191742' - -trunk_protocol = sa.Enum(('sip', 'iax', 'sccp', 'custom'), name='trunk_protocol') - -trunkfeatures_tbl = sa.sql.table( - 'trunkfeatures', - sa.sql.column('id'), - sa.sql.column('protocol'), - sa.sql.column('protocolid'), - sa.sql.column('registerid'), - sa.sql.column('endpoint_sip_id'), - sa.sql.column('endpoint_iax_id'), - sa.sql.column('endpoint_custom_id'), - sa.sql.column('register_sip_id'), - sa.sql.column('register_iax_id'), -) -usersip_tbl = sa.sql.table('usersip', sa.sql.column('id')) -useriax_tbl = sa.sql.table('useriax', sa.sql.column('id')) -usercustom_tbl = sa.sql.table('usercustom', sa.sql.column('id')) -staticsip_tbl = sa.sql.table('staticsip', sa.sql.column('id')) -staticiax_tbl = sa.sql.table('staticiax', sa.sql.column('id')) - - -def upgrade(): - op.add_column( - 'trunkfeatures', - sa.Column( - 'endpoint_sip_id', - sa.Integer, - sa.ForeignKey('usersip.id', ondelete='SET NULL') - ) - ) - op.add_column( - 'trunkfeatures', - sa.Column( - 'endpoint_iax_id', - sa.Integer, - sa.ForeignKey('useriax.id', ondelete='SET NULL') - ) - ) - op.add_column( - 'trunkfeatures', - sa.Column( - 'endpoint_custom_id', - sa.Integer, - sa.ForeignKey('usercustom.id', ondelete='SET NULL') - ) - ) - op.add_column( - 'trunkfeatures', - sa.Column( - 'register_sip_id', - sa.Integer, - sa.ForeignKey('staticsip.id', ondelete='SET NULL') - ) - ) - op.add_column( - 'trunkfeatures', - sa.Column( - 'register_iax_id', - sa.Integer, - sa.ForeignKey('staticiax.id', ondelete='SET NULL') - ) - ) - op.create_check_constraint( - 'trunkfeatures_endpoints_check', - 'trunkfeatures', - ''' - ( CASE WHEN endpoint_sip_id IS NULL THEN 0 ELSE 1 END - + CASE WHEN endpoint_iax_id IS NULL THEN 0 ELSE 1 END - + CASE WHEN endpoint_custom_id IS NULL THEN 0 ELSE 1 END - ) <= 1 - ''', - ) - op.create_check_constraint( - 'trunkfeatures_registers_check', - 'trunkfeatures', - ''' - ( CASE WHEN register_sip_id IS NULL THEN 0 ELSE 1 END - + CASE WHEN register_iax_id IS NULL THEN 0 ELSE 1 END - ) <= 1 - ''', - ), - op.create_check_constraint( - 'trunkfeatures_endpoint_register_check', - 'trunkfeatures', - ''' - ( - register_sip_id IS NULL AND - register_iax_id IS NULL - ) OR ( - register_sip_id IS NOT NULL AND - endpoint_iax_id IS NULL AND - endpoint_custom_id IS NULL - ) OR ( - register_iax_id IS NOT NULL AND - endpoint_sip_id IS NULL AND - endpoint_custom_id IS NULL - ) - ''', - ), - query = sa.sql.select([ - trunkfeatures_tbl.c.id, - trunkfeatures_tbl.c.protocol, - trunkfeatures_tbl.c.protocolid, - trunkfeatures_tbl.c.registerid, - ]) - for trunk in op.get_bind().execute(query): - if not trunk.protocol: - continue - - if trunk.protocol == 'sip': - if trunk.protocolid: - query = sa.sql.select([usersip_tbl.c.id]).where(usersip_tbl.c.id == trunk.protocolid) - if op.get_bind().execute(query).scalar(): - op.execute( - trunkfeatures_tbl - .update() - .where(trunkfeatures_tbl.c.id == trunk.id) - .values(endpoint_sip_id=trunk.protocolid) - ) - if trunk.registerid: - query = sa.sql.select([staticsip_tbl.c.id]).where(staticsip_tbl.c.id == trunk.registerid) - if op.get_bind().execute(query).scalar(): - op.execute( - trunkfeatures_tbl - .update() - .where(trunkfeatures_tbl.c.id == trunk.id) - .values(register_sip_id=trunk.registerid) - ) - - elif trunk.protocol == 'iax': - if trunk.protocolid: - query = sa.sql.select([useriax_tbl.c.id]).where(useriax_tbl.c.id == trunk.protocolid) - if op.get_bind().execute(query).scalar(): - op.execute( - trunkfeatures_tbl - .update() - .where(trunkfeatures_tbl.c.id == trunk.id) - .values(endpoint_iax_id=trunk.protocolid) - ) - - if trunk.registerid: - query = sa.sql.select([staticiax_tbl.c.id]).where(staticiax_tbl.c.id == trunk.registerid) - if op.get_bind().execute(query).scalar(): - op.execute( - trunkfeatures_tbl - .update() - .where(trunkfeatures_tbl.c.id == trunk.id) - .values(register_iax_id=trunk.registerid) - ) - - elif trunk.protocol == 'custom': - if trunk.protocolid: - query = sa.sql.select([usercustom_tbl.c.id]).where(usercustom_tbl.c.id == trunk.protocolid) - if op.get_bind().execute(query).scalar(): - op.execute( - trunkfeatures_tbl - .update() - .where(trunkfeatures_tbl.c.id == trunk.id) - .values(endpoint_custom_id=trunk.protocolid) - ) - - op.drop_column('trunkfeatures', 'protocol') - op.drop_column('trunkfeatures', 'protocolid') - op.drop_column('trunkfeatures', 'registerid') - - -def downgrade(): - op.add_column('trunkfeatures', sa.Column('protocol', trunk_protocol)) - op.add_column('trunkfeatures', sa.Column('protocolid', sa.Integer)) - op.add_column('trunkfeatures', sa.Column('registerid', sa.Integer, nullable=False, server_default='0')) - op.create_unique_constraint( - 'trunkfeatures_protocol_protocolid_key', - 'trunkfeatures', - ['protocol', 'protocolid'], - ) - - query = sa.sql.select([ - trunkfeatures_tbl.c.id, - trunkfeatures_tbl.c.endpoint_sip_id, - trunkfeatures_tbl.c.endpoint_iax_id, - trunkfeatures_tbl.c.endpoint_custom_id, - trunkfeatures_tbl.c.register_sip_id, - trunkfeatures_tbl.c.register_iax_id, - ]) - for trunk in op.get_bind().execute(query): - if trunk.endpoint_sip_id: - op.execute( - trunkfeatures_tbl - .update() - .where(trunkfeatures_tbl.c.id == trunk.id) - .values(protocol='sip', protocolid=trunk.endpoint_sip_id) - ) - elif trunk.endpoint_iax_id: - op.execute( - trunkfeatures_tbl - .update() - .where(trunkfeatures_tbl.c.id == trunk.id) - .values(protocol='iax', protocolid=trunk.endpoint_iax_id) - ) - elif trunk.endpoint_custom_id: - op.execute( - trunkfeatures_tbl - .update() - .where(trunkfeatures_tbl.c.id == trunk.id) - .values(protocol='custom', protocolid=trunk.endpoint_custom_id) - ) - - if trunk.register_sip_id: - op.execute( - trunkfeatures_tbl - .update() - .where(trunkfeatures_tbl.c.id == trunk.id) - .values(protocol='sip', registerid=trunk.register_sip_id) - ) - elif trunk.register_iax_id: - op.execute( - trunkfeatures_tbl - .update() - .where(trunkfeatures_tbl.c.id == trunk.id) - .values(protocol='iax', registerid=trunk.register_iax_id) - ) - - op.drop_constraint('trunkfeatures_endpoints_check', 'trunkfeatures') - op.drop_constraint('trunkfeatures_registers_check', 'trunkfeatures') - op.drop_constraint('trunkfeatures_endpoint_register_check', 'trunkfeatures') - op.drop_column('trunkfeatures', 'endpoint_sip_id') - op.drop_column('trunkfeatures', 'endpoint_iax_id') - op.drop_column('trunkfeatures', 'endpoint_custom_id') - op.drop_column('trunkfeatures', 'register_sip_id') - op.drop_column('trunkfeatures', 'register_iax_id') diff --git a/alembic/versions/06e9e3483fec_bump_version_21_11.py b/alembic/versions/06e9e3483fec_bump_version_21_11.py deleted file mode 100644 index cc45b11e..00000000 --- a/alembic/versions/06e9e3483fec_bump_version_21_11.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_21_11 - -Revision ID: 06e9e3483fec -Revises: 907d4947d665 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '06e9e3483fec' -down_revision = '907d4947d665' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='21.11')) - - -def downgrade(): - pass diff --git a/alembic/versions/0720419573a5_change_auth_key_for_dird_wazo_backend.py b/alembic/versions/0720419573a5_change_auth_key_for_dird_wazo_backend.py deleted file mode 100644 index ee53faff..00000000 --- a/alembic/versions/0720419573a5_change_auth_key_for_dird_wazo_backend.py +++ /dev/null @@ -1,38 +0,0 @@ -"""change auth key for dird wazo backend - -Revision ID: 0720419573a5 -Revises: 02361b8a4b7c - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '0720419573a5' -down_revision = '02361b8a4b7c' - -directories_table = sa.sql.table( - 'directories', - sa.sql.column('dirtype'), - sa.sql.column('auth_key_file'), -) - - -def upgrade(): - op.execute( - directories_table - .update() - .where(directories_table.c.dirtype == 'wazo') - .values(auth_key_file='/var/lib/wazo-auth-keys/wazo-dird-wazo-backend-key.yml') - ) - - -def downgrade(): - op.execute( - directories_table - .update() - .where(directories_table.c.dirtype == 'wazo') - .values(auth_key_file='/var/lib/wazo-auth-keys/wazo-dird-xivo-backend-key.yml') - ) diff --git a/alembic/versions/08a23688eaf7_add_tenant_uuid_to_outcall.py b/alembic/versions/08a23688eaf7_add_tenant_uuid_to_outcall.py deleted file mode 100644 index d6cfb4df..00000000 --- a/alembic/versions/08a23688eaf7_add_tenant_uuid_to_outcall.py +++ /dev/null @@ -1,59 +0,0 @@ -"""add tenant_uuid to outcall - -Revision ID: 08a23688eaf7 -Revises: 5f8c8a323cbe - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '08a23688eaf7' -down_revision = '5f8c8a323cbe' - -TBL = 'outcall' - - -def find_default_tenant_uuid(): - entity_table = sa.sql.table( - 'entity', - sa.sql.column('id'), - sa.sql.column('name'), - sa.sql.column('tenant_uuid'), - ) - query = sa.sql.select([entity_table.c.tenant_uuid]).order_by(entity_table.c.id) - for row in op.get_bind().execute(query): - return row.tenant_uuid - - -def associate_tenants(): - ctx_tbl = sa.sql.table('context', sa.sql.column('name'), sa.sql.column('tenant_uuid')) - outcall_tbl = sa.sql.table('outcall', sa.sql.column('context'), sa.sql.column('tenant_uuid')) - query = sa.sql.select([ctx_tbl.c.name, ctx_tbl.c.tenant_uuid]) - context_to_tenant = {row.name: row.tenant_uuid for row in op.get_bind().execute(query)} - - for name, tenant_uuid in context_to_tenant.items(): - query = outcall_tbl.update().where(outcall_tbl.c.context == name).values(tenant_uuid=tenant_uuid) - op.execute(query) - - -def upgrade(): - default_tenant_uuid = find_default_tenant_uuid() - op.add_column( - TBL, - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=False, - server_default=default_tenant_uuid, - ) - ) - associate_tenants() - op.alter_column(TBL, 'tenant_uuid', server_default=None) - - -def downgrade(): - op.drop_column(TBL, 'tenant_uuid') diff --git a/alembic/versions/0a7363700618_bump_version_19_12.py b/alembic/versions/0a7363700618_bump_version_19_12.py deleted file mode 100644 index ea48f332..00000000 --- a/alembic/versions/0a7363700618_bump_version_19_12.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_19_12 - -Revision ID: 0a7363700618 -Revises: 5047425b0f5c - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '0a7363700618' -down_revision = '5047425b0f5c' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='19.12')) - - -def downgrade(): - pass diff --git a/alembic/versions/0aeb61795700_rename_general_group_queue.py b/alembic/versions/0aeb61795700_rename_general_group_queue.py deleted file mode 100644 index 89310fee..00000000 --- a/alembic/versions/0aeb61795700_rename_general_group_queue.py +++ /dev/null @@ -1,72 +0,0 @@ -"""rename_general_group_queue - -Revision ID: 0aeb61795700 -Revises: 7d47aaef973a - -""" - -from alembic import op -from sqlalchemy import sql - - -# revision identifiers, used by Alembic. -revision = '0aeb61795700' -down_revision = '7d47aaef973a' - -groupfeatures_tbl = sql.table( - 'groupfeatures', - sql.column('name'), -) - -queuefeatures_tbl = sql.table( - 'queuefeatures', - sql.column('name'), -) - -queue_tbl = sql.table( - 'queue', - sql.column('name'), - sql.column('category'), -) - - -def find_next_available_name(name): - query = queue_tbl.select().where(queue_tbl.c.name == name) - group_exists = op.get_bind().execute(query).scalar() - if group_exists: - next_name = '{}_'.format(name) - return find_next_available_name(next_name) - return name - - -def upgrade(): - query = queue_tbl.select().where(queue_tbl.c.name == 'general') - queue = op.get_bind().execute(query).first() - if not queue: - return - - new_name = find_next_available_name('general') - op.execute( - queue_tbl - .update() - .where(queue_tbl.c.name == queue.name) - .values(name=new_name) - ) - if queue.category == 'group': - op.execute( - groupfeatures_tbl - .update() - .where(groupfeatures_tbl.c.name == queue.name) - .values(name=new_name) - ) - elif queue.category == 'queue': - op.execute( - queuefeatures_tbl - .update() - .where(queuefeatures_tbl.c.name == queue.name) - .values(name=new_name) - ) - - -def downgrade(): - pass diff --git a/alembic/versions/0b694daf27e0_remove_deleted_from_groupfeatures.py b/alembic/versions/0b694daf27e0_remove_deleted_from_groupfeatures.py deleted file mode 100644 index 8a179f59..00000000 --- a/alembic/versions/0b694daf27e0_remove_deleted_from_groupfeatures.py +++ /dev/null @@ -1,25 +0,0 @@ -"""remove_deleted_from_groupfeatures - -Revision ID: 0b694daf27e0 -Revises: e71820229900 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '0b694daf27e0' -down_revision = 'e71820229900' - - -def upgrade(): - op.drop_column('groupfeatures', 'deleted') - - -def downgrade(): - op.add_column( - 'groupfeatures', - sa.Column('deleted', sa.Integer, nullable=False, server_default='0'), - ) diff --git a/alembic/versions/0c758daee631_bump_version_22_07.py b/alembic/versions/0c758daee631_bump_version_22_07.py deleted file mode 100644 index 0671a458..00000000 --- a/alembic/versions/0c758daee631_bump_version_22_07.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_22_07 - -Revision ID: 0c758daee631 -Revises: f2eae4a8353e - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '0c758daee631' -down_revision = 'f2eae4a8353e' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='22.07')) - - -def downgrade(): - pass diff --git a/alembic/versions/0c84ec128899_disallow_null_type_for_app_dest_node.py b/alembic/versions/0c84ec128899_disallow_null_type_for_app_dest_node.py deleted file mode 100644 index d113427e..00000000 --- a/alembic/versions/0c84ec128899_disallow_null_type_for_app_dest_node.py +++ /dev/null @@ -1,20 +0,0 @@ -"""disallow_null_type_for_app_dest_node - -Revision ID: 0c84ec128899 -Revises: 11cfb4ff787d - -""" - -from alembic import op - -# revision identifiers, used by Alembic. -revision = '0c84ec128899' -down_revision = '11cfb4ff787d' - - -def upgrade(): - op.alter_column('application_dest_node', 'type', nullable=False) - - -def downgrade(): - op.alter_column('application_dest_node', 'type', nullable=True) diff --git a/alembic/versions/0d74d34f7782_bump_version_18_11.py b/alembic/versions/0d74d34f7782_bump_version_18_11.py deleted file mode 100644 index 27fdaf3e..00000000 --- a/alembic/versions/0d74d34f7782_bump_version_18_11.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_18_11 - -Revision ID: 0d74d34f7782 -Revises: 47920341f392 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '0d74d34f7782' -down_revision = '47920341f392' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='18.11')) - - -def downgrade(): - pass diff --git a/alembic/versions/0dd3509ac1e2_meeting_add_unique_on_number_tenant.py b/alembic/versions/0dd3509ac1e2_meeting_add_unique_on_number_tenant.py deleted file mode 100644 index 1f3af04c..00000000 --- a/alembic/versions/0dd3509ac1e2_meeting_add_unique_on_number_tenant.py +++ /dev/null @@ -1,25 +0,0 @@ -"""meeting-add-unique-on-number-tenant - -Revision ID: 0dd3509ac1e2 -Revises: b7d3c4701095 - -""" - -from alembic import op - - -# revision identifiers, used by Alembic. -revision = '0dd3509ac1e2' -down_revision = 'b7d3c4701095' - - -def upgrade(): - op.create_unique_constraint( - 'meeting_number_tenant_uuid_key', - 'meeting', - ['number', 'tenant_uuid'], - ) - - -def downgrade(): - op.drop_constraint('meeting_number_tenant_uuid_key', 'meeting') diff --git a/alembic/versions/0f4a7c48613c_add_zonemessages.py b/alembic/versions/0f4a7c48613c_add_zonemessages.py deleted file mode 100644 index eed1ee1d..00000000 --- a/alembic/versions/0f4a7c48613c_add_zonemessages.py +++ /dev/null @@ -1,84 +0,0 @@ -"""add zonemessages - -Revision ID: 0f4a7c48613c -Revises: e6c5e0410e89 - -""" - -from alembic import op -from pytz import country_timezones -from sqlalchemy import sql - - -# revision identifiers, used by Alembic. -revision = '0f4a7c48613c' -down_revision = 'e6c5e0410e89' - -staticvoicemail_tbl = sql.table( - 'staticvoicemail', - sql.column('cat_metric'), - sql.column('commented'), - sql.column('filename'), - sql.column('category'), - sql.column('var_name'), - sql.column('var_val'), -) - -SUPPORTED_COUNTRIES = ( - 'BE', # Belgium - 'IT', # Italy - 'CA', # Canada - 'DE', # Germany - 'FR', # France - 'IL', # Israel - 'LU', # Luxembourg - 'MY', # Malaysia - 'MC', # Monaco - 'NL', # Netherlands - 'PL', # Poland - 'PT', # Portugal - 'GB', # Britain (United Kingdom) - 'US', # America - 'ES', # Spain - 'CH', # Switzerland -) - - -def _timezone_name(timezone_name): - tz_name = timezone_name.split('/') - return "-".join(tz_name[1:]).lower() - - -def get_zones(): - for country_code in SUPPORTED_COUNTRIES: - timezones = country_timezones.get(country_code, []) - for timezone in timezones: - zone_name = f'{country_code}-{_timezone_name(timezone)}'.lower() - # IMp is the AM/PM time format. We set it by default by choice. - zone_format = f"{timezone}|'vm-received' q 'digits/at' IMp" - yield {'name': zone_name, 'format': zone_format} - - -def _zonemessage_exists(zone_format): - query = sql.select([sql.func.count(staticvoicemail_tbl.c.var_val)]).where( - staticvoicemail_tbl.c.var_val == zone_format - ) - return op.get_bind().execute(query).scalar() > 0 - - -def upgrade(): - for zone in get_zones(): - if not _zonemessage_exists(zone['format']): - query = staticvoicemail_tbl.insert().values( - cat_metric=1, - commented=0, - filename='voicemail.conf', - category='zonemessages', - var_name=zone['name'], - var_val=zone['format'], - ) - op.get_bind().execute(query) - - -def downgrade(): - pass diff --git a/alembic/versions/0ffacfab7041_bump_version_22_04.py b/alembic/versions/0ffacfab7041_bump_version_22_04.py deleted file mode 100644 index 87f87b00..00000000 --- a/alembic/versions/0ffacfab7041_bump_version_22_04.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_22_04 - -Revision ID: 0ffacfab7041 -Revises: 5863384621a1 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '0ffacfab7041' -down_revision = '5863384621a1' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='22.04')) - - -def downgrade(): - pass diff --git a/alembic/versions/106159225d65_fk_template_add_tenant_uuid.py b/alembic/versions/106159225d65_fk_template_add_tenant_uuid.py deleted file mode 100644 index 7867443b..00000000 --- a/alembic/versions/106159225d65_fk_template_add_tenant_uuid.py +++ /dev/null @@ -1,111 +0,0 @@ -"""fk_template_add_tenant_uuid - -Revision ID: 106159225d65 -Revises: 5c9f286599b6 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '106159225d65' -down_revision = '5c9f286599b6' - - -func_key_template_tbl = sa.sql.table( - 'func_key_template', - sa.sql.column('id'), - sa.sql.column('tenant_uuid'), -) -func_key_mapping_tbl = sa.sql.table( - 'func_key_mapping', - sa.sql.column('template_id'), -) -userfeatures_tbl = sa.sql.table( - 'userfeatures', - sa.sql.column('tenant_uuid'), - sa.sql.column('func_key_template_id'), - sa.sql.column('func_key_private_template_id'), -) -tenant_tbl = sa.sql.table('tenant', sa.sql.column('uuid')) - - -def associate_tenants(): - # associate tenant to public templates - filter_ = userfeatures_tbl.c.func_key_template_id == func_key_template_tbl.c.id - public_sub_query = ( - sa.sql.select([userfeatures_tbl.c.func_key_template_id]) - .where(filter_) - .limit(1) - ) - public_query = ( - sa.sql.select([userfeatures_tbl.c.tenant_uuid]) - .where(filter_) - .limit(1) - ) - query = ( - func_key_template_tbl - .update() - .where(func_key_template_tbl.c.id.in_(public_sub_query)) - .values(tenant_uuid=public_query) - ) - op.execute(query) - - # associate tenant to private templates - filter_ = userfeatures_tbl.c.func_key_private_template_id == func_key_template_tbl.c.id - private_sub_query = ( - sa.sql.select([userfeatures_tbl.c.func_key_private_template_id]) - .where(filter_) - .limit(1) - ) - private_query = ( - sa.sql.select([userfeatures_tbl.c.tenant_uuid]) - .where(filter_) - .limit(1) - ) - query = ( - func_key_template_tbl - .update() - .where(func_key_template_tbl.c.id.in_(private_sub_query)) - .values(tenant_uuid=private_query) - ) - op.execute(query) - - # Remove unassociated templates - sub_query = ( - sa.sql.select([func_key_template_tbl.c.id]) - .where(func_key_template_tbl.c.tenant_uuid == None) # noqa - ) - query = ( - func_key_mapping_tbl.delete() - .where(func_key_mapping_tbl.c.template_id.in_(sub_query)) - ) - op.execute(query) - - query = ( - func_key_template_tbl.delete() - .where(func_key_template_tbl.c.tenant_uuid == None) # noqa - ) - op.execute(query) - - -def upgrade(): - op.add_column( - 'func_key_template', - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=True, - ) - ) - - associate_tenants() - - op.alter_column('func_key_template', 'tenant_uuid', nullable=False) - - -def downgrade(): - op.drop_column('func_key_template', 'tenant_uuid') diff --git a/alembic/versions/108164f6117e_fix_sequence_usage_on_stat_agent_.py b/alembic/versions/108164f6117e_fix_sequence_usage_on_stat_agent_.py deleted file mode 100644 index 495c2739..00000000 --- a/alembic/versions/108164f6117e_fix_sequence_usage_on_stat_agent_.py +++ /dev/null @@ -1,20 +0,0 @@ -"""fix sequence usage on stat_agent_periodic - -Revision ID: 108164f6117e -Revises: 52bd5977c09d - -""" - -# revision identifiers, used by Alembic. -revision = '108164f6117e' -down_revision = '52bd5977c09d' - -from alembic import op - - -def upgrade(): - op.execute("SELECT setval('stat_agent_periodic_id_seq', (SELECT max(id) FROM stat_agent_periodic));") - - -def downgrade(): - pass diff --git a/alembic/versions/108f435e1af2_bump_version_20_04.py b/alembic/versions/108f435e1af2_bump_version_20_04.py deleted file mode 100644 index 39de40d9..00000000 --- a/alembic/versions/108f435e1af2_bump_version_20_04.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_20_04 - -Revision ID: 108f435e1af2 -Revises: 55527c5cb4b1 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '108f435e1af2' -down_revision = '55527c5cb4b1' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='20.04')) - - -def downgrade(): - pass diff --git a/alembic/versions/10bf9a42edee_rename_xivo_call_logd_to_wazo_call_logd.py b/alembic/versions/10bf9a42edee_rename_xivo_call_logd_to_wazo_call_logd.py deleted file mode 100644 index 8e2a890d..00000000 --- a/alembic/versions/10bf9a42edee_rename_xivo_call_logd_to_wazo_call_logd.py +++ /dev/null @@ -1,41 +0,0 @@ -"""rename_xivo_call_logd_to_wazo_call_logd - -Revision ID: 10bf9a42edee -Revises: 4fb644b564c8 - -""" - -# revision identifiers, used by Alembic. -revision = '10bf9a42edee' -down_revision = '4fb644b564c8' - -from alembic import op -import sqlalchemy as sa - - -webservice = sa.sql.table('accesswebservice', - sa.sql.column('name'), - sa.sql.column('login')) - -OLD_NAME = 'xivo-call-logd' -NEW_NAME = 'wazo-call-logd' - - -def rename_webservice_access(old_name, new_name): - op.execute( - webservice.update( - ).values( - name=new_name, - login=new_name, - ).where( - webservice.c.name == old_name, - ) - ) - - -def upgrade(): - rename_webservice_access(OLD_NAME, NEW_NAME) - - -def downgrade(): - rename_webservice_access(NEW_NAME, OLD_NAME) diff --git a/alembic/versions/1108308b3fd7_bump_version_22_17.py b/alembic/versions/1108308b3fd7_bump_version_22_17.py deleted file mode 100644 index b19a99b5..00000000 --- a/alembic/versions/1108308b3fd7_bump_version_22_17.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_22_17 - -Revision ID: 1108308b3fd7 -Revises: b0edbcc1426d - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '1108308b3fd7' -down_revision = 'b0edbcc1426d' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='22.17')) - - -def downgrade(): - pass diff --git a/alembic/versions/117b51a2d937_add_auth_key_file_to_directories.py b/alembic/versions/117b51a2d937_add_auth_key_file_to_directories.py deleted file mode 100644 index e02ed2d1..00000000 --- a/alembic/versions/117b51a2d937_add_auth_key_file_to_directories.py +++ /dev/null @@ -1,53 +0,0 @@ -"""add_auth_key_file_to_directories - -Revision ID: 117b51a2d937 -Revises: 46dda7d0374e - -""" - -from alembic import op -import sqlalchemy as sa -from sqlalchemy import sql - -# revision identifiers, used by Alembic. -revision = '117b51a2d937' -down_revision = '46dda7d0374e' - -TABLE = 'directories' -COLUMN = 'auth_key_file' - - -def _set_default_auth_key_file(): - directories = sa.sql.table( - TABLE, - sa.sql.column('dirtype'), - sa.sql.column('xivo_username'), - sa.sql.column('xivo_password'), - sa.sql.column('auth_host'), - sa.sql.column('auth_key_file'), - ) - - query = ( - directories.update() - .where( - sql.and_( - directories.c.dirtype == 'xivo', - directories.c.xivo_username == 'wazo-dird-xivo-backend', - directories.c.auth_host == 'localhost', - ) - ) - .values( - auth_key_file='/var/lib/wazo-auth-keys/wazo-dird-xivo-backend-key.yml', - xivo_password=None, - ) - ) - op.execute(query) - - -def upgrade(): - op.add_column(TABLE, sa.Column(COLUMN, sa.Text)) - _set_default_auth_key_file() - - -def downgrade(): - op.drop_column(TABLE, COLUMN) diff --git a/alembic/versions/1192e6bfd226_configure_the_dhcp_interface.py b/alembic/versions/1192e6bfd226_configure_the_dhcp_interface.py deleted file mode 100644 index 45c53a4c..00000000 --- a/alembic/versions/1192e6bfd226_configure_the_dhcp_interface.py +++ /dev/null @@ -1,52 +0,0 @@ -"""configure the dhcp interface - -Revision ID: 1192e6bfd226 -Revises: 700711f75ee6 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '1192e6bfd226' -down_revision = '700711f75ee6' - -netiface_table = sa.sql.table( - 'netiface', - sa.sql.column('ifname'), - sa.sql.column('networktype'), -) - -dhcp_table = sa.sql.table( - 'dhcp', - sa.sql.column('extra_ifaces'), -) - - -def upgrade(): - query = sa.sql.select( - [netiface_table.c.ifname] - ).where( - netiface_table.c.networktype == 'voip' - ) - - ifname = None - for netiface in op.get_bind().execute(query): - ifname = netiface.ifname - - if not ifname: - return - - query = sa.sql.select([dhcp_table.c.extra_ifaces]) - current_ifaces = '' - for dhcp in op.get_bind().execute(query): - current_ifaces = dhcp.extra_ifaces - - new_ifaces = '{} {}'.format(ifname, current_ifaces) - op.execute(dhcp_table.update().values(extra_ifaces=new_ifaces.strip())) - - -def downgrade(): - pass diff --git a/alembic/versions/11b792bcc775_create_func_key_bsfilter.py b/alembic/versions/11b792bcc775_create_func_key_bsfilter.py deleted file mode 100644 index 8e9941db..00000000 --- a/alembic/versions/11b792bcc775_create_func_key_bsfilter.py +++ /dev/null @@ -1,51 +0,0 @@ -"""create func key bsfilter - -Revision ID: 11b792bcc775 -Revises: 3d22f40558d1 - -""" - -# revision identifiers, used by Alembic. -revision = '11b792bcc775' -down_revision = '3d22f40558d1' - -from alembic import op -import sqlalchemy as sa - - -DESTINATION_ID = 12 -DESTINATION_NAME = 'bsfilter' - -destination_type_table = sa.sql.table('func_key_destination_type', - sa.sql.column('id'), - sa.sql.column('name')) - - -def upgrade(): - destination_type_row = {'id': DESTINATION_ID, 'name': DESTINATION_NAME} - op.bulk_insert(destination_type_table, [destination_type_row]) - - op.create_table( - 'func_key_dest_bsfilter', - sa.Column('func_key_id', sa.Integer), - sa.Column('destination_type_id', - sa.Integer, - sa.CheckConstraint('destination_type_id = %d' % DESTINATION_ID), - server_default=str(DESTINATION_ID)), - sa.Column('filtermember_id', - sa.Integer, - nullable=False), - sa.PrimaryKeyConstraint('func_key_id', 'destination_type_id', 'filtermember_id'), - sa.ForeignKeyConstraint(['func_key_id', 'destination_type_id'], - ['func_key.id', 'func_key.destination_type_id']), - sa.ForeignKeyConstraint(['filtermember_id'], ['callfiltermember.id']) - ) - - -def downgrade(): - op.drop_table('func_key_dest_bsfilter') - - delete_query = (destination_type_table - .delete() - .where(destination_type_table.c.id == DESTINATION_ID)) - op.execute(delete_query) diff --git a/alembic/versions/11cfb4ff787d_add_application_table.py b/alembic/versions/11cfb4ff787d_add_application_table.py deleted file mode 100644 index c26ad1e7..00000000 --- a/alembic/versions/11cfb4ff787d_add_application_table.py +++ /dev/null @@ -1,53 +0,0 @@ -"""add_application_table - -Revision ID: 11cfb4ff787d -Revises: 57ab432bb1c3 - -""" - -from alembic import op -import sqlalchemy as sa - -# revision identifiers, used by Alembic. -revision = '11cfb4ff787d' -down_revision = '57ab432bb1c3' - - -def upgrade(): - op.create_table( - 'application', - sa.Column( - 'uuid', - sa.String(36), - server_default=sa.text('uuid_generate_v4()'), - primary_key=True - ), - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=False, - ), - sa.Column('name', sa.String(128)), - ) - - op.create_table( - 'application_dest_node', - sa.Column( - 'application_uuid', - sa.String(36), - sa.ForeignKey('application.uuid', ondelete='CASCADE'), - primary_key=True, - ), - sa.Column( - 'type', - sa.String(32), - sa.CheckConstraint("type in ('holding', 'mixing')") - ), - sa.Column('music_on_hold', sa.String(128)), - ) - - -def downgrade(): - op.drop_table('application_dest_node') - op.drop_table('application') diff --git a/alembic/versions/1264fdcb3e71_add_notify_early_inuse_ringing_option_.py b/alembic/versions/1264fdcb3e71_add_notify_early_inuse_ringing_option_.py deleted file mode 100644 index 4ac60b56..00000000 --- a/alembic/versions/1264fdcb3e71_add_notify_early_inuse_ringing_option_.py +++ /dev/null @@ -1,74 +0,0 @@ -"""add notify_early_inuse_ringing option to global sip endoint templates - -Revision ID: 1264fdcb3e71 -Revises: f3e76222b5c9 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '1264fdcb3e71' -down_revision = 'f3e76222b5c9' - -tenant_tbl = sa.sql.table( - 'tenant', - sa.sql.column('uuid'), - sa.sql.column('global_sip_template_uuid'), -) - -endpoint_sip_tbl = sa.sql.table( - 'endpoint_sip', - sa.sql.column('uuid'), - sa.sql.column('template'), -) - -endpoint_sip_section_tbl = sa.sql.table( - 'endpoint_sip_section', - sa.sql.column('uuid'), - sa.sql.column('type'), - sa.sql.column('endpoint_sip_uuid'), -) -endpoint_sip_section_option_tbl = sa.sql.table( - 'endpoint_sip_section_option', - sa.sql.column('key'), - sa.sql.column('value'), - sa.sql.column('endpoint_sip_section_uuid'), -) - - -def find_sip_endoint_template_sections(): - query = sa.sql.select([endpoint_sip_section_tbl.c.uuid]).where( - sa.and_( - tenant_tbl.c.global_sip_template_uuid == endpoint_sip_section_tbl.c.endpoint_sip_uuid, - endpoint_sip_tbl.c.template.is_(True), - endpoint_sip_section_tbl.c.endpoint_sip_uuid == endpoint_sip_tbl.c.uuid, - endpoint_sip_section_tbl.c.type == 'endpoint', - ) - ) - return op.get_bind().execute(query) - - -def add_notify_early_inuse_ringing_option(sip_endpoint_sections): - for sip_endpoint_section in sip_endpoint_sections: - query = ( - endpoint_sip_section_option_tbl - .insert() - .values( - key='notify_early_inuse_ringing', - value='yes', - endpoint_sip_section_uuid=sip_endpoint_section.uuid, - ) - ) - op.execute(query) - - -def upgrade(): - sip_endpoint_template_sections = find_sip_endoint_template_sections() - add_notify_early_inuse_ringing_option(sip_endpoint_template_sections) - - -def downgrade(): - pass diff --git a/alembic/versions/126c8c1fddb7_fix_invalid_extension_conference.py b/alembic/versions/126c8c1fddb7_fix_invalid_extension_conference.py deleted file mode 100644 index c2ab553c..00000000 --- a/alembic/versions/126c8c1fddb7_fix_invalid_extension_conference.py +++ /dev/null @@ -1,49 +0,0 @@ -"""fix-invalid-extension-conference - -Revision ID: 126c8c1fddb7 -Revises: 0a7363700618 - -""" - -from alembic import op -import sqlalchemy as sa -from sqlalchemy import sql - - -# revision identifiers, used by Alembic. -revision = '126c8c1fddb7' -down_revision = '0a7363700618' - -conference_table = sql.table( - 'conference', - sql.column('id'), -) - -extensions_table = sql.table( - 'extensions', - sql.column('id'), - sql.column('type'), - sql.column('typeval'), -) - - -def upgrade(): - query = sql.select( - [extensions_table.c.id, extensions_table.c.typeval] - ).where(extensions_table.c.type == 'conference') - - for extension in op.get_bind().execute(query): - query = ( - sql.select([conference_table.c.id]) - .where(sql.cast(conference_table.c.id, sa.String) == extension.typeval) - ) - if not op.get_bind().execute(query).scalar(): - op.execute( - extensions_table.update() - .where(extensions_table.c.id == extension.id) - .values(type='user', typeval='0') - ) - - -def downgrade(): - pass diff --git a/alembic/versions/129646f8f81f_bump_version_18_09.py b/alembic/versions/129646f8f81f_bump_version_18_09.py deleted file mode 100644 index e9c29235..00000000 --- a/alembic/versions/129646f8f81f_bump_version_18_09.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_18_09 - -Revision ID: 129646f8f81f -Revises: 315f74edddb1 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '129646f8f81f' -down_revision = '315f74edddb1' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='18.09')) - - -def downgrade(): - pass diff --git a/alembic/versions/12b81f6c229b_add_the_ingress_http_table.py b/alembic/versions/12b81f6c229b_add_the_ingress_http_table.py deleted file mode 100644 index 9d8bcb4f..00000000 --- a/alembic/versions/12b81f6c229b_add_the_ingress_http_table.py +++ /dev/null @@ -1,35 +0,0 @@ -"""add the ingress_http table - -Revision ID: 12b81f6c229b -Revises: 035908ce02df - -""" - -from alembic import op -import sqlalchemy as sa - -from sqlalchemy.dialects.postgresql import UUID - - -# revision identifiers, used by Alembic. -revision = '12b81f6c229b' -down_revision = '035908ce02df' - - -def upgrade(): - op.create_table( - 'ingress_http', - sa.Column('uuid', UUID, server_default=sa.text('uuid_generate_v4()'), primary_key=True), - sa.Column('uri', sa.Text, nullable=False), - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - unique=True, - nullable=False, - ), - ) - - -def downgrade(): - op.drop_table('ingress_http') diff --git a/alembic/versions/12f9880ae872_switchboard_add_tenant_uuid.py b/alembic/versions/12f9880ae872_switchboard_add_tenant_uuid.py deleted file mode 100644 index cb5ad58e..00000000 --- a/alembic/versions/12f9880ae872_switchboard_add_tenant_uuid.py +++ /dev/null @@ -1,183 +0,0 @@ -"""switchboard_add_tenant_uuid - -Revision ID: 12f9880ae872 -Revises: 5576b5f933e6 - -""" - -from alembic import op -import sqlalchemy as sa - -# revision identifiers, used by Alembic. -revision = '12f9880ae872' -down_revision = '5576b5f933e6' - - -switchboard_tbl = sa.sql.table( - 'switchboard', - sa.sql.column('uuid'), - sa.sql.column('tenant_uuid'), -) -switchboard_member_user_tbl = sa.sql.table( - 'switchboard_member_user', - sa.sql.column('switchboard_uuid'), - sa.sql.column('user_uuid'), -) -incall_tbl = sa.sql.table( - 'incall', - sa.sql.column('id'), - sa.sql.column('tenant_uuid'), -) -dialaction_tbl = sa.sql.table( - 'dialaction', - sa.sql.column('category'), - sa.sql.column('categoryval'), - sa.sql.column('action'), - sa.sql.column('actionarg1'), -) -userfeatures_tbl = sa.sql.table( - 'userfeatures', - sa.sql.column('uuid'), - sa.sql.column('tenant_uuid'), -) - - -def associate_tenants(): - - query = ( - sa.sql.select([switchboard_tbl.c.uuid, incall_tbl.c.tenant_uuid]) - .where(dialaction_tbl.c.category == 'incall') - .where(dialaction_tbl.c.categoryval == sa.cast(incall_tbl.c.id, sa.String)) - .where(dialaction_tbl.c.action == 'switchboard') - .where(dialaction_tbl.c.actionarg1 == switchboard_tbl.c.uuid) - ) - switchboard_incall = op.get_bind().execute(query) - - query = ( - sa.sql.select([switchboard_tbl.c.uuid, userfeatures_tbl.c.tenant_uuid]) - .where(switchboard_member_user_tbl.c.switchboard_uuid == switchboard_tbl.c.uuid) - .where(switchboard_member_user_tbl.c.user_uuid == userfeatures_tbl.c.uuid) - ) - switchboard_user = op.get_bind().execute(query) - - for switchboard_uuid, tenant_uuid in list(switchboard_incall) + list(switchboard_user): - query = ( - switchboard_tbl.update() - .where(switchboard_tbl.c.uuid == switchboard_uuid) - .values(tenant_uuid=tenant_uuid) - ) - op.execute(query) - - -def delete_user_not_in_same_incall_tenant(): - query = ( - sa.sql.select([switchboard_tbl.c.uuid]) - .where(dialaction_tbl.c.category == 'incall') - .where(dialaction_tbl.c.categoryval == sa.cast(incall_tbl.c.id, sa.String)) - .where(dialaction_tbl.c.action == 'switchboard') - .where(dialaction_tbl.c.actionarg1 == switchboard_tbl.c.uuid) - .where(switchboard_member_user_tbl.c.switchboard_uuid == switchboard_tbl.c.uuid) - .where(switchboard_member_user_tbl.c.user_uuid == userfeatures_tbl.c.uuid) - .where(incall_tbl.c.tenant_uuid != userfeatures_tbl.c.tenant_uuid) - ) - switchboards = op.get_bind().execute(query) - - # Keep tenant from incall and delete user - for switchboard in switchboards: - query = ( - switchboard_member_user_tbl.delete() - .where(switchboard_member_user_tbl.c.switchboard_uuid == switchboard.uuid) - ) - op.execute(query) - - -def delete_next_incall_not_in_same_tenant(): - query = ( - sa.sql.select([switchboard_tbl.c.uuid, incall_tbl.c.id, incall_tbl.c.tenant_uuid]) - .where(dialaction_tbl.c.category == 'incall') - .where(dialaction_tbl.c.categoryval == sa.cast(incall_tbl.c.id, sa.String)) - .where(dialaction_tbl.c.action == 'switchboard') - .where(dialaction_tbl.c.actionarg1 == switchboard_tbl.c.uuid) - ) - result = op.get_bind().execute(query) - - # Delete dialaction if there are not in the same tenant - cache = {} - for switchboard_uuid, incall_id, tenant_uuid in result: - cache.setdefault(switchboard_uuid, tenant_uuid) - if cache[switchboard_uuid] == tenant_uuid: - continue - - query = ( - dialaction_tbl.delete() - .where(dialaction_tbl.c.category == 'incall') - .where(dialaction_tbl.c.categoryval == str(incall_id)) - ) - op.execute(query) - - -def delete_next_user_not_in_same_tenant(): - query = ( - sa.sql.select([switchboard_tbl.c.uuid, userfeatures_tbl.c.uuid, userfeatures_tbl.c.tenant_uuid]) - .where(switchboard_member_user_tbl.c.switchboard_uuid == switchboard_tbl.c.uuid) - .where(switchboard_member_user_tbl.c.user_uuid == userfeatures_tbl.c.uuid) - ) - result = op.get_bind().execute(query) - - # Delete member user if there are not in the same tenant - cache = {} - for switchboard_uuid, user_uuid, tenant_uuid in result: - cache.setdefault(switchboard_uuid, tenant_uuid) - if cache[switchboard_uuid] == tenant_uuid: - continue - - query = ( - switchboard_member_user_tbl.delete() - .where(switchboard_member_user_tbl.c.switchboard_uuid == switchboard_uuid) - .where(switchboard_member_user_tbl.c.user_uuid == user_uuid) - ) - op.execute(query) - - -def delete_no_tenants(): - query = sa.sql.select([switchboard_tbl.c.uuid]).where(switchboard_tbl.c.tenant_uuid == None) # noqa - switchboards = op.get_bind().execute(query) - for (switchboard_uuid,) in switchboards: - query = ( - switchboard_member_user_tbl.delete() - .where(switchboard_member_user_tbl.c.switchboard_uuid == switchboard_uuid) - ) - op.execute(query) - query = switchboard_tbl.delete().where(switchboard_tbl.c.uuid == switchboard_uuid) - op.execute(query) - - -def delete_unhandled_dialaction(): - query = ( - dialaction_tbl.delete() - .where(dialaction_tbl.c.category != 'incall') - .where(dialaction_tbl.c.action == 'switchboard') - ) - op.execute(query) - - -def upgrade(): - op.add_column( - 'switchboard', - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=True), - ) - delete_user_not_in_same_incall_tenant() - delete_next_incall_not_in_same_tenant() - delete_next_user_not_in_same_tenant() - associate_tenants() - delete_unhandled_dialaction() - delete_no_tenants() - op.alter_column('switchboard', 'tenant_uuid', nullable=False) - - -def downgrade(): - op.drop_column('switchboard', 'tenant_uuid') diff --git a/alembic/versions/1311cd6c2a63_fix_auth_key_file_for_directories.py b/alembic/versions/1311cd6c2a63_fix_auth_key_file_for_directories.py deleted file mode 100644 index 71fc24a3..00000000 --- a/alembic/versions/1311cd6c2a63_fix_auth_key_file_for_directories.py +++ /dev/null @@ -1,48 +0,0 @@ -"""fix-auth-key-file-for-directories - -Revision ID: 1311cd6c2a63 -Revises: 71c41130380e - -""" - -from alembic import op -import sqlalchemy as sa -from sqlalchemy import sql - - -# revision identifiers, used by Alembic. -revision = '1311cd6c2a63' -down_revision = '71c41130380e' - -directories = sa.sql.table( - 'directories', - sa.sql.column('dirtype'), - sa.sql.column('xivo_username'), - sa.sql.column('xivo_password'), - sa.sql.column('auth_key_file'), -) - - -def _set_default_auth_key_file(): - query = ( - directories.update() - .where( - sql.and_( - directories.c.dirtype == 'xivo', - directories.c.xivo_username == 'wazo-dird-xivo-backend', - ) - ) - .values( - auth_key_file='/var/lib/wazo-auth-keys/wazo-dird-xivo-backend-key.yml', - xivo_password=None, - ) - ) - op.execute(query) - - -def upgrade(): - _set_default_auth_key_file() - - -def downgrade(): - pass diff --git a/alembic/versions/13472f54a7_bump_version_17_09.py b/alembic/versions/13472f54a7_bump_version_17_09.py deleted file mode 100644 index bef4e9cf..00000000 --- a/alembic/versions/13472f54a7_bump_version_17_09.py +++ /dev/null @@ -1,22 +0,0 @@ -"""bump_version_17_09 - -Revision ID: 13472f54a7 -Revises: b57ed1e30535 - -""" - -# revision identifiers, used by Alembic. -revision = '13472f54a7' -down_revision = 'b57ed1e30535' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='17.09')) - - -def downgrade(): - pass diff --git a/alembic/versions/13692a692d44_remove_mylocaldir_xlet.py b/alembic/versions/13692a692d44_remove_mylocaldir_xlet.py deleted file mode 100644 index 5b6b5c9d..00000000 --- a/alembic/versions/13692a692d44_remove_mylocaldir_xlet.py +++ /dev/null @@ -1,79 +0,0 @@ -"""remove_mylocaldir_xlet - -Revision ID: 13692a692d44 -Revises: 44c6b8d8c196 - -""" - -# revision identifiers, used by Alembic. -revision = '13692a692d44' -down_revision = '44c6b8d8c196' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy import sql - - -MYLOCALDIR_XLET = 'mylocaldir' -PEOPLE_XLET = 'people' - -xlet_table = sa.sql.table('cti_xlet', - sa.sql.column('id'), - sa.sql.column('plugin_name')) -profile_xlet_table = sa.sql.table('cti_profile_xlet', - sa.sql.column('profile_id'), - sa.sql.column('xlet_id')) - - -def upgrade(): - replace_xlet_with_people() - remove_xlet() - - -def downgrade(): - create_xlet() - - -def replace_xlet_with_people(): - people_id = _xlet_id(PEOPLE_XLET) - mylocaldir_id = _xlet_id(MYLOCALDIR_XLET) - profiles_with_people_query = ( - sa.sql.select( - [profile_xlet_table.c.profile_id] - ).where(profile_xlet_table.c.xlet_id == people_id) - ) - - # replace mylocaldir with people if people is not already in profile - replace_query = ( - profile_xlet_table - .update() - .values(xlet_id=people_id) - .where(sa.sql.and_( - profile_xlet_table.c.xlet_id == mylocaldir_id, - ~profile_xlet_table.c.profile_id.in_(profiles_with_people_query), - )) - ) - op.execute(replace_query) - - -def _xlet_id(xlet_name): - return op.get_bind().execute( - sql.select( - [xlet_table.c.id]) - .where( - xlet_table.c.plugin_name == xlet_name) - ).scalar() - - -def remove_xlet(): - remove_xlet_query = (xlet_table - .delete() - .where(xlet_table.c.plugin_name == MYLOCALDIR_XLET)) - op.execute(remove_xlet_query) - - -def create_xlet(): - create_xlet_query = (xlet_table - .insert() - .values(plugin_name=MYLOCALDIR_XLET)) - op.execute(create_xlet_query) diff --git a/alembic/versions/13917b00e63c_create_func_key_agent.py b/alembic/versions/13917b00e63c_create_func_key_agent.py deleted file mode 100644 index c92ac152..00000000 --- a/alembic/versions/13917b00e63c_create_func_key_agent.py +++ /dev/null @@ -1,56 +0,0 @@ -"""create func key agent - -Revision ID: 13917b00e63c -Revises: 3096b11582cf - -""" - -# revision identifiers, used by Alembic. -revision = '13917b00e63c' -down_revision = '3096b11582cf' - -from alembic import op -import sqlalchemy as sa - -DESTINATION_ID = 11 -DESTINATION_NAME = 'agent' - -destination_type_table = sa.sql.table('func_key_destination_type', - sa.sql.column('id'), - sa.sql.column('name')) - - -def upgrade(): - destination_type_row = {'id': DESTINATION_ID, 'name': DESTINATION_NAME} - op.bulk_insert(destination_type_table, [destination_type_row]) - - op.create_table( - 'func_key_dest_agent', - sa.Column('func_key_id', sa.Integer), - sa.Column('destination_type_id', - sa.Integer, - sa.CheckConstraint('destination_type_id = %d' % DESTINATION_ID), - server_default=str(DESTINATION_ID)), - sa.Column('agent_id', - sa.Integer, - nullable=False), - sa.Column('action', - sa.String(10), - sa.CheckConstraint("action IN ('login', 'logoff', 'toggle')"), - nullable=False - ), - sa.PrimaryKeyConstraint('func_key_id', 'destination_type_id'), - sa.UniqueConstraint('agent_id', 'action'), - sa.ForeignKeyConstraint(['func_key_id', 'destination_type_id'], - ['func_key.id', 'func_key.destination_type_id']), - sa.ForeignKeyConstraint(['agent_id'], ['agentfeatures.id']) - ) - - -def downgrade(): - op.drop_table('func_key_dest_agent') - - delete_query = (destination_type_table - .delete() - .where(destination_type_table.c.id == DESTINATION_ID)) - op.execute(delete_query) diff --git a/alembic/versions/13f4485996fd_remove_dundi_from_general.py b/alembic/versions/13f4485996fd_remove_dundi_from_general.py deleted file mode 100644 index e0e4e7df..00000000 --- a/alembic/versions/13f4485996fd_remove_dundi_from_general.py +++ /dev/null @@ -1,23 +0,0 @@ -"""remove dundi from general - -Revision ID: 13f4485996fd -Revises: 30d59d9b4b6e - -""" - -# revision identifiers, used by Alembic. -revision = '13f4485996fd' -down_revision = '30d59d9b4b6e' - -from alembic import op - -from sqlalchemy.types import Integer -from sqlalchemy.schema import Column - - -def upgrade(): - op.drop_column('general', 'dundi') - - -def downgrade(): - op.add_column('general', Column('dundi', Integer, nullable=False, server_default='0')) diff --git a/alembic/versions/146ddf6c4b36_deactivate_user_login_by_default.py b/alembic/versions/146ddf6c4b36_deactivate_user_login_by_default.py deleted file mode 100644 index b5fb6485..00000000 --- a/alembic/versions/146ddf6c4b36_deactivate_user_login_by_default.py +++ /dev/null @@ -1,20 +0,0 @@ -"""deactivate user login by default - -Revision ID: 146ddf6c4b36 -Revises: 108164f6117e - -""" - -# revision identifiers, used by Alembic. -revision = '146ddf6c4b36' -down_revision = '108164f6117e' - -from alembic import op - - -def upgrade(): - op.alter_column('userfeatures', 'enableclient', server_default='0') - - -def downgrade(): - op.alter_column('userfeatures', 'enableclient', server_default='1') diff --git a/alembic/versions/148a96399123_add_phonebook_id_fk.py b/alembic/versions/148a96399123_add_phonebook_id_fk.py deleted file mode 100644 index 609e123b..00000000 --- a/alembic/versions/148a96399123_add_phonebook_id_fk.py +++ /dev/null @@ -1,66 +0,0 @@ -"""add phonebook id fk - -Revision ID: 148a96399123 -Revises: 1d05ffb14525 - -""" - -# revision identifiers, used by Alembic. -revision = '148a96399123' -down_revision = '1d05ffb14525' - -from alembic import op -import sqlalchemy as sa - - -phonebook_table = sa.sql.table( - 'phonebook', - sa.sql.column('id'), -) - - -def upgrade(): - _add_phonebook_fk('phonebooknumber') - _add_phonebook_fk('phonebookaddress') - - -def downgrade(): - op.drop_constraint('fk_phonebook_id', 'phonebookaddress') - op.drop_constraint('fk_phonebook_id', 'phonebooknumber') - - -def _add_phonebook_fk(table_name): - _remove_orphaned(table_name) - op.create_foreign_key( - 'fk_phonebook_id', - table_name, - 'phonebook', - ['phonebookid'], - ['id'], - ondelete='CASCADE', - ) - - -def _remove_orphaned(table_name): - table = sa.sql.table( - table_name, - sa.sql.column('id'), - sa.sql.column('phonebookid'), - ) - - existing_phonebook_ids_query = ( - sa.sql.select([phonebook_table.c.id]) - ) - - orphaned_numbers_query = ( - sa.sql.select( - [table.c.id] - ).where(~table.c.phonebookid.in_(existing_phonebook_ids_query)) - ) - - delete_query = ( - table.delete() - .where(table.c.id.in_(orphaned_numbers_query)) - ) - - op.get_bind().execute(delete_query) diff --git a/alembic/versions/1493335e754b_remove_serverfeatures_table.py b/alembic/versions/1493335e754b_remove_serverfeatures_table.py deleted file mode 100644 index 68173069..00000000 --- a/alembic/versions/1493335e754b_remove_serverfeatures_table.py +++ /dev/null @@ -1,29 +0,0 @@ -"""remove serverfeatures table - -Revision ID: 1493335e754b -Revises: 59feecbe8d13 - -""" - -# revision identifiers, used by Alembic. -revision = '1493335e754b' -down_revision = '59feecbe8d13' - -from alembic import op -from sqlalchemy import sql, Column, String, Integer, Enum, CheckConstraint, UniqueConstraint - - -def upgrade(): - op.drop_table('serverfeatures') - op.execute('DROP TYPE serverfeatures_type') - - -def downgrade(): - op.create_table('serverfeatures', - Column('id', Integer, primary_key=True), - Column('serverid', Integer, nullable=False), - Column('type', Enum('xivo', 'ldap', name='serverfeatures_type'), nullable=False), - Column('commented', Integer, nullable=False, server_default='0'), - Column('feature', String(64), nullable=False, server_default='phonebook'), - CheckConstraint("feature='phonebook'"), - UniqueConstraint('serverid', 'feature', 'type')) diff --git a/alembic/versions/14c0ca8a7834_update_nat_options.py b/alembic/versions/14c0ca8a7834_update_nat_options.py deleted file mode 100644 index 81bbbe31..00000000 --- a/alembic/versions/14c0ca8a7834_update_nat_options.py +++ /dev/null @@ -1,70 +0,0 @@ -"""update_nat_options - -Revision ID: 14c0ca8a7834 -Revises: 57461905b7e6 - -""" - -# revision identifiers, used by Alembic. -revision = '14c0ca8a7834' -down_revision = '57461905b7e6' - -import sqlalchemy as sa -from alembic import op -from sqlalchemy import sql - -old_options = ( - 'no', - 'force_rport', - 'comedia', - 'force_rport,comedia' -) -new_options = sorted(old_options + ('auto_force_rport', 'auto_comedia',)) - -new_type = sa.Enum(*new_options, name='usersip_nat') -old_type = sa.Enum(*old_options, name='usersip_nat') - -staticsip_table = sql.table('staticsip', - sql.column('var_name'), - sql.column('var_val')) - -usersip_table = sa.sql.table('usersip', - sa.sql.column('id'), - sa.sql.column('nat')) - - -def upgrade(): - _update_staticsip_nat('no', 'auto_force_rport') - _modify_type(new_type, ('usersip', 'nat')) - _update_usersip_nat('no', 'auto_force_rport') - - -def downgrade(): - _update_staticsip_nat('auto_force_rport', 'no') - _update_usersip_nat('auto_force_rport', 'no') - _modify_type(old_type, ('usersip', 'nat')) - - -def _update_staticsip_nat(val_from, val_to): - op.execute(staticsip_table.update(). - where(sql.and_( - staticsip_table.c.var_name == 'nat', - staticsip_table.c.var_val == val_from)). - values(var_val=val_to)) - - -def _update_usersip_nat(val_from, val_to): - op.execute(usersip_table.update(). - where(sql.and_( - usersip_table.c.nat == val_from)). - values(nat=val_to)) - - -def _modify_type(type_, *table_and_columns): - op.execute('ALTER TYPE {type_name} RENAME TO tmp_{type_name}'.format(type_name=type_.name)) - type_.create(op.get_bind()) - for table, column in table_and_columns: - op.execute( - 'ALTER TABLE {table_name} ALTER COLUMN {column_name} TYPE {type_name} USING {column_name}::text::{type_name}'.format( - type_name=type_.name, table_name=table, column_name=column)) - op.execute('DROP TYPE tmp_{type_name}'.format(type_name=type_.name)) diff --git a/alembic/versions/151d1315479b_fix_paging_duplicates.py b/alembic/versions/151d1315479b_fix_paging_duplicates.py deleted file mode 100644 index 2b7187ad..00000000 --- a/alembic/versions/151d1315479b_fix_paging_duplicates.py +++ /dev/null @@ -1,93 +0,0 @@ -"""fix paging duplicates - -Revision ID: 151d1315479b -Revises: f6dab479e74 - -""" - -from alembic import op - - -# revision identifiers, used by Alembic. -revision = '151d1315479b' -down_revision = 'f6dab479e74' - - -def upgrade(): - query = """ - DO $$ - - DECLARE - created_func_key_id INTEGER; - - broken_pagings CURSOR FOR - SELECT - paging_id - FROM - func_key_dest_paging - GROUP BY - paging_id - HAVING - COUNT(func_key_id) > 1 - ; - - BEGIN - FOR broken_row IN broken_pagings LOOP - - INSERT INTO func_key - (type_id, destination_type_id) - VALUES - (1, 9) - RETURNING id - INTO created_func_key_id - ; - - INSERT INTO func_key_dest_paging - (func_key_id, paging_id) - VALUES - (created_func_key_id, broken_row.paging_id) - ; - - UPDATE func_key_mapping - SET - func_key_id = created_func_key_id - WHERE - destination_type_id = 9 - AND func_key_id IN ( - SELECT - func_key_id - FROM - func_key_dest_paging - WHERE - paging_id = broken_row.paging_id - ) - ; - - DELETE FROM func_key_dest_paging - WHERE - paging_id = broken_row.paging_id - AND func_key_id != created_func_key_id - ; - - DELETE FROM func_key - WHERE - destination_type_id = 9 - AND id NOT IN ( - SELECT - func_key_id - FROM - func_key_dest_paging - ) - ; - - END LOOP; - - END - $$; - """ - - op.get_bind().execute(query) - - -def downgrade(): - pass diff --git a/alembic/versions/1583f90b21ad_remove_cel_call_log_foreign_key.py b/alembic/versions/1583f90b21ad_remove_cel_call_log_foreign_key.py deleted file mode 100644 index 6bec5c92..00000000 --- a/alembic/versions/1583f90b21ad_remove_cel_call_log_foreign_key.py +++ /dev/null @@ -1,29 +0,0 @@ -"""remove-cel-call-log-foreign-key - -Revision ID: 1583f90b21ad -Revises: 867bd9268824 - -""" - -from alembic import op - -# revision identifiers, used by Alembic. -revision = '1583f90b21ad' -down_revision = '867bd9268824' - -constraint_name = 'cel_call_log_id_fkey' - - -def upgrade(): - op.drop_constraint(constraint_name, 'cel') - - -def downgrade(): - op.create_foreign_key( - constraint_name, - 'cel', - 'call_log', - ['call_log_id'], - ['id'], - ondelete='SET NULL', - ) diff --git a/alembic/versions/15b236bd8060_add_fk_between_directories_and_.py b/alembic/versions/15b236bd8060_add_fk_between_directories_and_.py deleted file mode 100644 index a7154869..00000000 --- a/alembic/versions/15b236bd8060_add_fk_between_directories_and_.py +++ /dev/null @@ -1,91 +0,0 @@ -"""add fk between directories and ctidirectories - -Revision ID: 15b236bd8060 -Revises: 5270d317f8fd - -""" - -# revision identifiers, used by Alembic. -revision = '15b236bd8060' -down_revision = '5270d317f8fd' - -from alembic import op -import sqlalchemy as sa - -cti_directories_table = sa.sql.table('ctidirectories', - sa.Column('id'), - sa.Column('uri'), - sa.Column('directory_id')) -ldapfilter_table = sa.sql.table('ldapfilter', - sa.Column('id'), - sa.Column('name')) -directory_table = sa.sql.table('directories', - sa.Column('id'), - sa.Column('dirtype'), - sa.Column('uri'), - sa.Column('ldapfilter_id')) -ldap_prefix = 'ldapfilter://' - - -def list_associations(conn): - query = sa.sql.select([cti_directories_table]) - return [(row.id, row.uri) for row in conn.execute(query)] - -def list_ldap_filters(conn): - query = sa.sql.select([ldapfilter_table]) - return {row.name: row.id for row in conn.execute(query)} - -def list_directories(conn): - query = sa.sql.select([directory_table]) - return [directory for directory in conn.execute(query)] - - -def set_directory_id(cti_directory_id, directory_id): - query = cti_directories_table.update().where( - cti_directories_table.c.id == cti_directory_id - ).values(directory_id=directory_id) - op.execute(query) - -def upgrade(): - op.add_column('ctidirectories', - sa.Column('directory_id', - sa.Integer(), - sa.ForeignKey('directories.id', ondelete='CASCADE'))) - conn = op.get_bind() - - ldap_filters = list_ldap_filters(conn) - cti_directories = list_associations(conn) - directories = list_directories(conn) - - ldap_cti_directories = [] - normal_cti_directories = [] - - for id_, uri in cti_directories: - if uri.startswith(ldap_prefix): - ldap_cti_directories.append((id_, uri)) - else: - normal_cti_directories.append((id_, uri)) - - for id_, uri in normal_cti_directories: - for d in directories: - if d.uri != uri: - continue - set_directory_id(id_, d.id) - - for id_, uri in ldap_cti_directories: - name = uri.replace(ldap_prefix, '') - ldap_filter_id = ldap_filters.get(name) - if not ldap_filter_id: - continue - for d in directories: - if d.dirtype == 'ldapfilter' and d.ldapfilter_id == ldap_filter_id: - set_directory_id(id_, d.id) - - delete_orphans = cti_directories_table.delete().where(cti_directories_table.c.directory_id == None) - op.execute(delete_orphans) - - op.drop_column('ctidirectories', 'uri') - - -def downgrade(): - pass diff --git a/alembic/versions/15ca57fa1b71_queueskillrule_remove_name_unique_.py b/alembic/versions/15ca57fa1b71_queueskillrule_remove_name_unique_.py deleted file mode 100644 index ba010dc9..00000000 --- a/alembic/versions/15ca57fa1b71_queueskillrule_remove_name_unique_.py +++ /dev/null @@ -1,45 +0,0 @@ -"""queueskillrule remove name unique constraint - -Revision ID: 15ca57fa1b71 -Revises: 73889d1db031 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '15ca57fa1b71' -down_revision = '73889d1db031' - -queueskillrule_tbl = sa.sql.table( - 'queueskillrule', - sa.sql.column('id'), - sa.sql.column('name') -) - - -def _remove_duplicates(): - query = sa.sql.select([queueskillrule_tbl.c.id, queueskillrule_tbl.c.name]) - queueskillrules = op.get_bind().execute(query) - - unique_skillrules = set() - for rule_id, name in queueskillrules: - if name in unique_skillrules: - query = ( - queueskillrule_tbl.delete() - .where(queueskillrule_tbl.c.id == rule_id) - ) - op.execute(query) - else: - unique_skillrules.add(name) - - -def upgrade(): - op.drop_constraint('queueskillrule_name_key', 'queueskillrule') - - -def downgrade(): - _remove_duplicates() - op.create_unique_constraint('queueskillrule_name_key', 'queueskillrule', ['name']) diff --git a/alembic/versions/15fb16c0b0f8_add_tags_to_call_log_participants.py b/alembic/versions/15fb16c0b0f8_add_tags_to_call_log_participants.py deleted file mode 100644 index 50a25423..00000000 --- a/alembic/versions/15fb16c0b0f8_add_tags_to_call_log_participants.py +++ /dev/null @@ -1,25 +0,0 @@ -"""add_tags_to_call_log_participants - -Revision ID: 15fb16c0b0f8 -Revises: 27801f8c2a80 - -""" - -# revision identifiers, used by Alembic. -revision = '15fb16c0b0f8' -down_revision = '27801f8c2a80' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - op.add_column('call_log_participant', - sa.Column('tags', - sa.dialects.postgresql.ARRAY(sa.String(128)), - nullable=False, - server_default='{}')) - - -def downgrade(): - op.drop_column('call_log_participant', 'tags') diff --git a/alembic/versions/160e7b3161fa_clean_features_table.py b/alembic/versions/160e7b3161fa_clean_features_table.py deleted file mode 100644 index 8eb98961..00000000 --- a/alembic/versions/160e7b3161fa_clean_features_table.py +++ /dev/null @@ -1,67 +0,0 @@ -"""clean features table - -Revision ID: 160e7b3161fa -Revises: 45ceb32fae06 - -""" - -# revision identifiers, used by Alembic. -revision = '160e7b3161fa' -down_revision = '45ceb32fae06' - -from alembic import op -from sqlalchemy import sql - - -features_table = sql.table('features', - sql.column('var_name'), - sql.column('commented')) - - -def upgrade(): - _remove_features(( - 'pickupsound', - 'pickupfailsound', - )) - _uncomment_features(( - 'parkinghints', - 'parkingtime', - 'comebacktoorigin', - 'parkedplay', - 'parkedcalltransfers', - 'parkedcallreparking', - 'parkedcallhangup', - 'parkedcallrecording', - 'parkeddynamic', - 'adsipark', - 'findslot', - 'parkedmusicclass', - 'transferdigittimeout', - 'pickupexten', - 'pickupsound', - 'pickupfailsound', - 'featuredigittimeout', - 'atxfernoanswertimeout', - 'atxferdropcall', - 'atxferloopdelay', - 'atxfercallbackretries', - )) - - -def _uncomment_features(feature_names): - op.execute(features_table - .update() - .where(features_table.c.var_name.in_(feature_names)) - .values({'commented': 0})) - - -def _remove_features(feature_names): - delete_query = (features_table - .delete() - .where(features_table.c.var_name.in_(feature_names))) - - op.get_bind().execute(delete_query) - - -def downgrade(): - pass diff --git a/alembic/versions/1632064e0441_remove_remotedirectory_xlet.py b/alembic/versions/1632064e0441_remove_remotedirectory_xlet.py deleted file mode 100644 index c918857a..00000000 --- a/alembic/versions/1632064e0441_remove_remotedirectory_xlet.py +++ /dev/null @@ -1,26 +0,0 @@ -"""remove remotedirectory xlet - -Revision ID: 1632064e0441 -Revises: 337f76c25478 - -""" - -# revision identifiers, used by Alembic. -revision = '1632064e0441' -down_revision = '337f76c25478' - -from alembic import op -from sqlalchemy import sql - - -xlet_table = sql.table('cti_xlet', - sql.column('id'), - sql.column('plugin_name')) - - -def upgrade(): - op.execute(xlet_table.delete().where(xlet_table.c.plugin_name == 'remotedirectory')) - - -def downgrade(): - op.execute(xlet_table.insert().values(plugin_name='remotedirectory')) diff --git a/alembic/versions/1747774cead4_bump_version_18_04.py b/alembic/versions/1747774cead4_bump_version_18_04.py deleted file mode 100644 index b27d2e50..00000000 --- a/alembic/versions/1747774cead4_bump_version_18_04.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_18_04 - -Revision ID: 1747774cead4 -Revises: 28443bfc4fb1 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '1747774cead4' -down_revision = '28443bfc4fb1' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='18.04')) - - -def downgrade(): - pass diff --git a/alembic/versions/17653c3f37ce_bump_version_17_10.py b/alembic/versions/17653c3f37ce_bump_version_17_10.py deleted file mode 100644 index 1af75b10..00000000 --- a/alembic/versions/17653c3f37ce_bump_version_17_10.py +++ /dev/null @@ -1,22 +0,0 @@ -"""bump_version_17_10 - -Revision ID: 17653c3f37ce -Revises: fd040214cccb - -""" - -# revision identifiers, used by Alembic. -revision = '17653c3f37ce' -down_revision = 'fd040214cccb' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='17.10')) - - -def downgrade(): - pass diff --git a/alembic/versions/176660b8b2c3_add_trunkfeatures_twilio_incoming_column.py b/alembic/versions/176660b8b2c3_add_trunkfeatures_twilio_incoming_column.py deleted file mode 100644 index 14fb0c09..00000000 --- a/alembic/versions/176660b8b2c3_add_trunkfeatures_twilio_incoming_column.py +++ /dev/null @@ -1,21 +0,0 @@ -"""add trunkfeatures twilio_incoming column - -Revision ID: 176660b8b2c3 -Revises: 291ed250b7a2 - -""" - -# revision identifiers, used by Alembic. -revision = '176660b8b2c3' -down_revision = '291ed250b7a2' - -from alembic import op -from sqlalchemy import Column, Boolean - - -def upgrade(): - op.add_column('trunkfeatures', Column('twilio_incoming', Boolean, nullable=False, server_default='False')) - - -def downgrade(): - op.drop_column('trunkfeatures', 'twilio_incoming') diff --git a/alembic/versions/17ea1bc19d64_add_application_uuid_to_linefeatures.py b/alembic/versions/17ea1bc19d64_add_application_uuid_to_linefeatures.py deleted file mode 100644 index c96e2ab7..00000000 --- a/alembic/versions/17ea1bc19d64_add_application_uuid_to_linefeatures.py +++ /dev/null @@ -1,29 +0,0 @@ -"""add_application_uuid_to_linefeatures - -Revision ID: 17ea1bc19d64 -Revises: d0411d361d57 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '17ea1bc19d64' -down_revision = 'd0411d361d57' - - -def upgrade(): - op.add_column( - 'linefeatures', - sa.Column( - 'application_uuid', - sa.String(36), - sa.ForeignKey('application.uuid', ondelete='SET NULL'), - ) - ) - - -def downgrade(): - op.drop_column('linefeatures', 'application_uuid') diff --git a/alembic/versions/1815dcbc813f_fix_default_cat_metric_voicemail_zonemessages.py b/alembic/versions/1815dcbc813f_fix_default_cat_metric_voicemail_zonemessages.py deleted file mode 100644 index 556c0981..00000000 --- a/alembic/versions/1815dcbc813f_fix_default_cat_metric_voicemail_zonemessages.py +++ /dev/null @@ -1,29 +0,0 @@ -"""fix_default_voicemail_zonemessages - -Revision ID: 1815dcbc813f -Revises: 14c0ca8a7834 - -""" - -# revision identifiers, used by Alembic. -revision = '1815dcbc813f' -down_revision = '14c0ca8a7834' - -from alembic import op -import sqlalchemy as sa - -staticvoicemail = sa.sql.table('staticvoicemail', - sa.sql.column('cat_metric'), - sa.sql.column('category')) - - -def upgrade(): - query = (staticvoicemail - .update() - .where(staticvoicemail.c.category == 'zonemessages') - .values(cat_metric=1)) - op.execute(query) - - -def downgrade(): - pass diff --git a/alembic/versions/18840b2fdb03_confbridge_add_default_type.py b/alembic/versions/18840b2fdb03_confbridge_add_default_type.py deleted file mode 100644 index 662f30dc..00000000 --- a/alembic/versions/18840b2fdb03_confbridge_add_default_type.py +++ /dev/null @@ -1,91 +0,0 @@ -"""confbridge_add_default_type - -Revision ID: 18840b2fdb03 -Revises: 505c12d2ed73 - -""" - -# revision identifiers, used by Alembic. -revision = '18840b2fdb03' -down_revision = '505c12d2ed73' - -from alembic import op -from sqlalchemy import sql - -asterisk_file_table = sql.table('asterisk_file', - sql.column('id'), - sql.column('name')) - -asterisk_file_section_table = sql.table('asterisk_file_section', - sql.column('id'), - sql.column('name'), - sql.column('asterisk_file_id')) - -asterisk_file_variable_table = sql.table('asterisk_file_variable', - sql.column('id'), - sql.column('key'), - sql.column('value'), - sql.column('asterisk_file_section_id')) - - -def upgrade(): - file_id = _get_asterisk_file_id('confbridge.conf') - - section_id = _rename_asterisk_file_section(file_id, 'default_bridge', 'wazo_default_bridge') - _insert_asterisk_file_variable(section_id, 'type', 'bridge') - - section_id = _rename_asterisk_file_section(file_id, 'default_user', 'wazo_default_user') - _insert_asterisk_file_variable(section_id, 'type', 'user') - - -def _get_asterisk_file_id(file_name): - query = (sql.select([asterisk_file_table.c.id]) - .where(asterisk_file_table.c.name == file_name)) - for result in op.get_bind().execute(query): - return result.id - - -def _rename_asterisk_file_section(file_id, old_name, new_name): - query = (asterisk_file_section_table - .update() - .returning(asterisk_file_section_table.c.id) - .where(sql.and_( - asterisk_file_section_table.c.asterisk_file_id == file_id, - asterisk_file_section_table.c.name == old_name, - )) - .values(name=new_name)) - - for result in op.get_bind().execute(query): - return result.id - - -def _insert_asterisk_file_variable(section_id, key, value): - query = (asterisk_file_variable_table - .insert() - .values(key=key, - value=value, - asterisk_file_section_id=section_id)) - - op.get_bind().execute(query) - - -def downgrade(): - file_id = _get_asterisk_file_id('confbridge.conf') - - section_id = _rename_asterisk_file_section(file_id, 'wazo_default_bridge', 'default_bridge') - _remove_asterisk_file_variable(section_id, 'type', 'bridge') - - section_id = _rename_asterisk_file_section(file_id, 'wazo_default_user', 'default_user') - _remove_asterisk_file_variable(section_id, 'type', 'user') - - -def _remove_asterisk_file_variable(section_id, key, value): - query = (asterisk_file_variable_table - .delete() - .where(sql.and_( - asterisk_file_variable_table.c.key == key, - asterisk_file_variable_table.c.value == value, - asterisk_file_variable_table.c.asterisk_file_section_id == section_id - ))) - - op.get_bind().execute(query) diff --git a/alembic/versions/1888ca44e08f_rename_queue_autopause_constraint.py b/alembic/versions/1888ca44e08f_rename_queue_autopause_constraint.py deleted file mode 100644 index cff7ddd3..00000000 --- a/alembic/versions/1888ca44e08f_rename_queue_autopause_constraint.py +++ /dev/null @@ -1,32 +0,0 @@ -"""rename queue autopause constraint - -Revision ID: 1888ca44e08f -Revises: 50cfb10bd01d - -""" - -# revision identifiers, used by Alembic. -revision = '1888ca44e08f' -down_revision = '50cfb10bd01d' - -from alembic import op - -drop_query = "ALTER TABLE queue DROP CONSTRAINT IF EXISTS {name}" - -add_query = """ - ALTER TABLE queue - ADD CONSTRAINT {name} - CHECK (autopause IN ('no','yes','all')) -""" - - -def upgrade(): - op.execute(drop_query.format(name='queue_autopause')) - op.execute(drop_query.format(name='queue_autopause_check')) - op.execute(add_query.format(name='queue_autopause_check')) - - -def downgrade(): - op.execute(drop_query.format(name='queue_autopause')) - op.execute(drop_query.format(name='queue_autopause_check')) - op.execute(add_query.format(name='queue_autopause')) diff --git a/alembic/versions/18b419c519f4_add_context_id.py b/alembic/versions/18b419c519f4_add_context_id.py deleted file mode 100644 index 7fb944a9..00000000 --- a/alembic/versions/18b419c519f4_add_context_id.py +++ /dev/null @@ -1,30 +0,0 @@ -"""add-context-id - -Revision ID: 18b419c519f4 -Revises: a132daff54b - -""" - -# revision identifiers, used by Alembic. -revision = '18b419c519f4' -down_revision = 'a132daff54b' - -from alembic import op - - -def upgrade(): - op.drop_constraint('context_pkey', 'context') - op.execute('ALTER TABLE context ADD COLUMN id SERIAL;') - op.create_primary_key('context_pkey', 'context', ['id']) - op.create_unique_constraint('context_name_key', 'context', ['name']) - op.alter_column('context', 'description', nullable=True) - op.alter_column('context', 'displayname', nullable=True, server_default=None) - - -def downgrade(): - op.alter_column('context', 'displayname', nullable=False, server_default='') - op.alter_column('context', 'description', nullable=False) - op.drop_constraint('context_name_key', 'context') - op.drop_constraint('context_pkey', 'context') - op.drop_column('context', 'id') - op.create_primary_key('context_pkey', 'context', ['name']) diff --git a/alembic/versions/18cb96cb384_remove_cti_options.py b/alembic/versions/18cb96cb384_remove_cti_options.py deleted file mode 100644 index e27a813f..00000000 --- a/alembic/versions/18cb96cb384_remove_cti_options.py +++ /dev/null @@ -1,60 +0,0 @@ -"""remove cti options - -Revision ID: 18cb96cb384 -Revises: 3b7b334edb5c - -""" - -# revision identifiers, used by Alembic. -revision = '18cb96cb384' -down_revision = '3b7b334edb5c' - -from alembic import op - -from sqlalchemy.types import Integer, String -from sqlalchemy.schema import Column -from sqlalchemy import sql - -ctimain_table = sql.table('ctimain', - sql.column('cti_ip'), - sql.column('cti_port'), - sql.column('cti_active'), - sql.column('webi_ip'), - sql.column('webi_port'), - sql.column('webi_active'), - sql.column('info_ip'), - sql.column('info_port'), - sql.column('info_active'), - sql.column('login_timeout'), - sql.column('socket_timeout')) - - -def upgrade(): - for col in ['cti_ip', 'cti_port', 'cti_active', - 'webi_ip', 'webi_port', 'webi_active', - 'info_ip', 'info_port', 'info_active', - 'socket_timeout', 'login_timeout']: - op.drop_column('ctimain', col) - - -def downgrade(): - for col in ['cti_active', 'webi_active', 'info_active']: - op.add_column('ctimain', Column(col, Integer, nullable=False, server_default='1')) - - for col in ['cti_port', 'webi_port', 'info_port', 'socket_timeout', 'login_timeout']: - op.add_column('ctimain', Column(col, Integer)) - - for col in ['cti_ip', 'webi_ip', 'info_ip']: - op.add_column('ctimain', Column(col, String(16))) - - op.execute(ctimain_table.update().values(cti_ip='0.0.0.0', - cti_port=5003, - cti_active=1, - webi_ip='127.0.0.1', - webi_port=5004, - webi_active=1, - info_ip='127.0.0.1', - info_port=5005, - info_active=1, - socket_timeout=10, - login_timeout=5)) diff --git a/alembic/versions/18e40e519e1b_migrate_custom_func_keys.py b/alembic/versions/18e40e519e1b_migrate_custom_func_keys.py deleted file mode 100644 index 0db925cd..00000000 --- a/alembic/versions/18e40e519e1b_migrate_custom_func_keys.py +++ /dev/null @@ -1,281 +0,0 @@ -"""migrate custom func keys - -Revision ID: 18e40e519e1b -Revises: 3fe6319ce27a - -""" - -# revision identifiers, used by Alembic. -revision = '18e40e519e1b' -down_revision = '3fe6319ce27a' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy import sql - - -TYPE_SPEEDDIAL = 'speeddial' - -DESTINATION_CUSTOM_ID = 10 - - -phonefunckey_table = sql.table('phonefunckey', - sql.column('iduserfeatures'), - sql.column('fknum'), - sql.column('exten'), - sql.column('typeextenumbers'), - sql.column('typevalextenumbers'), - sql.column('typeextenumbersright'), - sql.column('typevalextenumbersright'), - sql.column('label'), - sql.column('supervision'), - sql.column('progfunckey')) - -func_key_table = sql.table('func_key', - sql.column('id'), - sql.column('type_id'), - sql.column('destination_type_id')) - -func_key_type_table = sql.table('func_key_type', - sql.column('id'), - sql.column('name')) - -destination_type_table = sql.table('func_key_destination_type', - sql.column('id'), - sql.column('name')) - -func_key_mapping_table = sql.table('func_key_mapping', - sql.column('template_id'), - sql.column('func_key_id'), - sql.column('destination_type_id'), - sql.column('label'), - sql.column('position'), - sql.column('blf')) - -dest_custom_table = sql.table('func_key_dest_custom', - sql.column('func_key_id'), - sql.column('destination_type_id'), - sql.column('exten')) - -template_table = sql.table('func_key_template', sql.column('id')) - -user_table = sql.table('userfeatures', - sql.column('id'), - sql.column('func_key_private_template_id')) - - -func_key_columns = ( - phonefunckey_table.c.iduserfeatures.label('user_id'), - phonefunckey_table.c.fknum.label('position'), - phonefunckey_table.c.label, - sql.cast(phonefunckey_table.c.supervision, sa.Boolean).label('blf'), - phonefunckey_table.c.exten.label('exten') -) - -old_func_key_columns = ( - func_key_mapping_table.c.func_key_id, - func_key_mapping_table.c.template_id, - func_key_mapping_table.c.position, - func_key_mapping_table.c.blf, - func_key_mapping_table.c.label, - dest_custom_table.c.exten, - user_table.c.id.label('user_id') -) - - -func_keys_query = (sql.select(func_key_columns) - .where( - sql.and_( - phonefunckey_table.c.typevalextenumbers == None, - phonefunckey_table.c.typevalextenumbersright == None, - phonefunckey_table.c.typeextenumbersright == None, - phonefunckey_table.c.typevalextenumbersright == None)) - ) - - -old_func_keys_query = (sql.select(old_func_key_columns, - from_obj=[ - func_key_mapping_table.join( - dest_custom_table, - func_key_mapping_table.c.func_key_id == dest_custom_table.c.func_key_id) - .join(template_table, - func_key_mapping_table.c.template_id == template_table.c.id) - .join(user_table, - template_table.c.id == user_table.c.func_key_private_template_id) - ])) - - -def upgrade(): - delete_invalid_user_func_keys() - delete_empty_customs() - migrate_func_keys() - delete_old_func_keys() - - -def delete_invalid_user_func_keys(): - query = (phonefunckey_table - .delete() - .where( - ~phonefunckey_table.c.iduserfeatures.in_(sql.select([user_table.c.id]))) - ) - - op.get_bind().execute(query) - - -def delete_empty_customs(): - template = '[MIGRATE_FK] : Deleting func key for user "%s" (fk position %s with empty custom)' - - columns = (phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.fknum) - - query = (sql.select(columns) - .where( - sql.and_( - phonefunckey_table.c.typevalextenumbers == None, - phonefunckey_table.c.typevalextenumbersright == None, - phonefunckey_table.c.typeextenumbersright == None, - phonefunckey_table.c.typevalextenumbersright == None, - sql.or_( - phonefunckey_table.c.exten == None, - phonefunckey_table.c.exten == ''))) - ) - - for row in op.get_bind().execute(query): - message = template % (row.iduserfeatures, row.fknum) - delete_fk(row, message) - - -def delete_fk(row, message): - print(message) - - query = (phonefunckey_table - .delete() - .where( - sql.and_( - phonefunckey_table.c.iduserfeatures == row.iduserfeatures, - phonefunckey_table.c.fknum == row.fknum)) - ) - - op.get_bind().execute(query) - - -def migrate_func_keys(): - for row in op.get_bind().execute(func_keys_query): - func_key_id = create_func_key() - create_custom_destination(func_key_id, row.exten) - create_mapping(func_key_id, row) - - -def create_func_key(): - speeddial_id = get_speeddial_id() - insert_query = (func_key_table - .insert() - .returning(func_key_table.c.id) - .values(type_id=speeddial_id, - destination_type_id=DESTINATION_CUSTOM_ID)) - - return op.get_bind().execute(insert_query).scalar() - - -def get_speeddial_id(): - return op.get_bind().execute( - sql.select( - [func_key_type_table.c.id]) - .where( - func_key_type_table.c.name == TYPE_SPEEDDIAL) - ).scalar() - - -def create_custom_destination(func_key_id, exten): - destination_query = (dest_custom_table - .insert() - .returning(dest_custom_table.c.func_key_id) - .values(func_key_id=func_key_id, - exten=exten)) - - op.get_bind().execute(destination_query) - - -def create_mapping(func_key_id, func_key_row): - conn = op.get_bind() - - template_id = conn.execute(sql.select( - [user_table.c.func_key_private_template_id]) - .where( - user_table.c.id == func_key_row.user_id) - ).scalar() - - mapping_query = (func_key_mapping_table - .insert() - .returning(func_key_mapping_table.c.func_key_id) - .values(func_key_id=func_key_id, - template_id=template_id, - destination_type_id=DESTINATION_CUSTOM_ID, - label=func_key_row.label, - position=func_key_row.position, - blf=func_key_row.blf)) - - conn.execute(mapping_query) - - -def delete_old_func_keys(): - delete_query = (phonefunckey_table - .delete() - .where( - sql.and_( - phonefunckey_table.c.typevalextenumbers == None, - phonefunckey_table.c.typevalextenumbersright == None, - phonefunckey_table.c.typeextenumbersright == None, - phonefunckey_table.c.typevalextenumbersright == None)) - ) - - op.get_bind().execute(delete_query) - - -def downgrade(): - for row in op.get_bind().execute(old_func_keys_query): - create_old_func_keys(row) - delete_mapping(row.func_key_id, row.template_id) - delete_dest_custom(row.func_key_id) - delete_func_key(row.func_key_id) - - -def create_old_func_keys(row): - supervision = 1 if row.blf else 0 - - row = {'iduserfeatures': row.user_id, - 'fknum': row.position, - 'typeextenumbers': None, - 'typevalextenumbers': None, - 'typeextenumbersright': None, - 'typevalextenumbersright': None, - 'label': row.label, - 'exten': row.exten, - 'supervision': supervision} - - op.bulk_insert(phonefunckey_table, [row]) - - -def delete_mapping(func_key_id, template_id): - query = (func_key_mapping_table - .delete() - .where(sql.and_( - func_key_mapping_table.c.func_key_id == func_key_id, - func_key_mapping_table.c.template_id == template_id))) - - op.get_bind().execute(query) - - -def delete_dest_custom(func_key_id): - query = (dest_custom_table - .delete()) - - op.get_bind().execute(query) - - -def delete_func_key(func_key_id): - query = (func_key_table - .delete() - .where(func_key_table.c.destination_type_id == DESTINATION_CUSTOM_ID)) - - op.get_bind().execute(query) diff --git a/alembic/versions/196dea1085af_add_foreign_key_to_paginguser.py b/alembic/versions/196dea1085af_add_foreign_key_to_paginguser.py deleted file mode 100644 index afaed79a..00000000 --- a/alembic/versions/196dea1085af_add_foreign_key_to_paginguser.py +++ /dev/null @@ -1,59 +0,0 @@ -"""add_foreign_key_to_paginguser - -Revision ID: 196dea1085af -Revises: 7b3b0ff90f0c - -""" - -# revision identifiers, used by Alembic. -revision = '196dea1085af' -down_revision = '7b3b0ff90f0c' - -from alembic import op -from sqlalchemy import sql - -user = sql.table( - 'userfeatures', - sql.column('id'), -) - -paging = sql.table( - 'paging', - sql.column('id'), -) - -paging_user = sql.table( - 'paginguser', - sql.column('userfeaturesid'), - sql.column('pagingid'), -) - - -def upgrade(): - _sanitize_paging_user() - op.create_foreign_key('paginguser_userfeaturesid_fkey', - 'paginguser', 'userfeatures', - ['userfeaturesid'], ['id']) - op.create_foreign_key('paginguser_pagingid_fkey', - 'paginguser', 'paging', - ['pagingid'], ['id']) - - -def _sanitize_paging_user(): - valid_users = sql.select([user.c.id]) - valid_pagings = sql.select([paging.c.id]) - query = ( - paging_user.delete() - .where( - sql.or_( - sql.not_(paging_user.c.pagingid.in_(valid_pagings)), - sql.not_(paging_user.c.userfeaturesid.in_(valid_users)) - ) - ) - ) - op.get_bind().execute(query) - - -def downgrade(): - op.drop_constraint('paginguser_pagingid_fkey', 'paginguser') - op.drop_constraint('paginguser_userfeaturesid_fkey', 'paginguser') diff --git a/alembic/versions/198c5bc02abf_add_parking_lot.py b/alembic/versions/198c5bc02abf_add_parking_lot.py deleted file mode 100644 index 8a53a45c..00000000 --- a/alembic/versions/198c5bc02abf_add_parking_lot.py +++ /dev/null @@ -1,65 +0,0 @@ -"""add_parking_lot - -Revision ID: 198c5bc02abf -Revises: 1f533d5f5f51 - -""" - -# revision identifiers, used by Alembic. -revision = '198c5bc02abf' -down_revision = '1f533d5f5f51' - -from alembic import op -from sqlalchemy import Column, Integer, Enum, PrimaryKeyConstraint, String - -extenumbers_type = Enum( - 'extenfeatures', - 'featuremap', - 'generalfeatures', - 'group', - 'incall', - 'meetme', - 'outcall', - 'queue', - 'user', - 'voicemenu', - 'conference', - 'parking', - name='extenumbers_type' -) - - -def upgrade(): - _create_parking_lot_table() - _modify_extenumbers_type() - - -def _create_parking_lot_table(): - op.create_table( - 'parking_lot', - Column('id', Integer), - Column('name', String(128)), - Column('slots_start', String(40), nullable=False), - Column('slots_end', String(40), nullable=False), - Column('timeout', Integer), - Column('music_on_hold', String(128)), - PrimaryKeyConstraint('id'), - ) - - -def _modify_extenumbers_type(): - _modify_type(extenumbers_type, - ('extensions', 'type')) - - -def _modify_type(type_, *table_and_columns): - op.execute('ALTER TYPE {type_name} RENAME TO tmp_{type_name}'.format(type_name=type_.name)) - type_.create(op.get_bind()) - for table, column in table_and_columns: - op.execute('ALTER TABLE {table_name} ALTER COLUMN {column_name} TYPE {type_name} USING {column_name}::text::{type_name}'.format( - type_name=type_.name, table_name=table, column_name=column)) - op.execute('DROP TYPE tmp_{type_name}'.format(type_name=type_.name)) - - -def downgrade(): - op.drop_table('parking_lot') diff --git a/alembic/versions/198cf8fda9a4_remove_ami_config.py b/alembic/versions/198cf8fda9a4_remove_ami_config.py deleted file mode 100644 index 42f78211..00000000 --- a/alembic/versions/198cf8fda9a4_remove_ami_config.py +++ /dev/null @@ -1,28 +0,0 @@ -"""remove ami config - -Revision ID: 198cf8fda9a4 -Revises: 3c72c43e39fa - -""" - -# revision identifiers, used by Alembic. -revision = '198cf8fda9a4' -down_revision = '3c72c43e39fa' - -from alembic import op -from sqlalchemy.schema import Column -from sqlalchemy.types import String, Integer - - -def upgrade(): - op.drop_column('ctimain', 'ami_ip') - op.drop_column('ctimain', 'ami_port') - op.drop_column('ctimain', 'ami_login') - op.drop_column('ctimain', 'ami_password') - - -def downgrade(): - op.add_column('ctimain', Column('ami_ip', String(16))) - op.add_column('ctimain', Column('ami_port', Integer)) - op.add_column('ctimain', Column('ami_login', String(64))) - op.add_column('ctimain', Column('ami_password', String(64))) diff --git a/alembic/versions/19a869176d6c_bump_version_17_05.py b/alembic/versions/19a869176d6c_bump_version_17_05.py deleted file mode 100644 index 0331f11c..00000000 --- a/alembic/versions/19a869176d6c_bump_version_17_05.py +++ /dev/null @@ -1,22 +0,0 @@ -"""bump_version_17_05 - -Revision ID: 19a869176d6c -Revises: 37b9ac945437 - -""" - -# revision identifiers, used by Alembic. -revision = '19a869176d6c' -down_revision = '37b9ac945437' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='17.05')) - - -def downgrade(): - pass diff --git a/alembic/versions/1a13acc6cdb0_add_confbridge_talk_detection.py b/alembic/versions/1a13acc6cdb0_add_confbridge_talk_detection.py deleted file mode 100644 index 3e049379..00000000 --- a/alembic/versions/1a13acc6cdb0_add_confbridge_talk_detection.py +++ /dev/null @@ -1,76 +0,0 @@ -"""add confbridge talk detection - -Revision ID: 1a13acc6cdb0 -Revises: 5dd4a73c91c2 - -""" - -from alembic import op -import sqlalchemy as sa -from sqlalchemy import sql - - -# revision identifiers, used by Alembic. -revision = '1a13acc6cdb0' -down_revision = '5dd4a73c91c2' - -asterisk_file_table = sa.sql.table('asterisk_file', - sa.sql.column('id'), - sa.sql.column('name')) - -asterisk_file_section_table = sa.sql.table('asterisk_file_section', - sa.sql.column('id'), - sa.sql.column('name'), - sa.sql.column('priority'), - sa.sql.column('asterisk_file_id')) - -asterisk_file_variable_table = sa.sql.table('asterisk_file_variable', - sa.sql.column('id'), - sa.sql.column('key'), - sa.sql.column('value'), - sa.sql.column('priority'), - sa.sql.column('asterisk_file_section_id')) - - -def upgrade(): - section_id = _find_asterisk_file_section('confbridge.conf', 'wazo_default_user') - if not _find_asterisk_file_variable(section_id, 'talk_detection_events'): - _insert_asterisk_file_variable(section_id, 'talk_detection_events', 'yes') - - -def _find_asterisk_file_section(file_name, section_name): - query = ( - sql.select([asterisk_file_section_table.c.id], - from_obj=[asterisk_file_section_table.join( - asterisk_file_table, - asterisk_file_table.c.id == asterisk_file_section_table.c.asterisk_file_id - )] - ).where(sql.and_( - asterisk_file_table.c.name == file_name, - asterisk_file_section_table.c.name == section_name, - )) - ) - return op.get_bind().execute(query).scalar() - - -def _find_asterisk_file_variable(section_id, variable): - query = ( - sql.select([sa.func.count(asterisk_file_variable_table.c.id)]) - .where( - asterisk_file_variable_table.c.key == variable, - ) - ) - return op.get_bind().execute(query).scalar() > 0 - - -def _insert_asterisk_file_variable(section_id, key, value): - query = (asterisk_file_variable_table - .insert() - .values(key=key, - value=value, - asterisk_file_section_id=section_id)) - op.get_bind().execute(query) - - -def downgrade(): - pass diff --git a/alembic/versions/1a25b8b93e70_add_missing_features_func_key.py b/alembic/versions/1a25b8b93e70_add_missing_features_func_key.py deleted file mode 100644 index 24885417..00000000 --- a/alembic/versions/1a25b8b93e70_add_missing_features_func_key.py +++ /dev/null @@ -1,104 +0,0 @@ -"""add_missing_features_func_key - -Revision ID: 1a25b8b93e70 -Revises: 29013d7926e6 - -""" - -from alembic import op -from sqlalchemy import sql - -# revision identifiers, used by Alembic. -revision = '1a25b8b93e70' -down_revision = '29013d7926e6' - -FEATURES_DESTINATION_NAME = 'features' -AUTOMON_FUNC_KEY_TYPE = 'dtmf' -AUTOMON_TYPE = 'automon' - -features_table = sql.table('features', - sql.column('id'), - sql.column('category'), - sql.column('var_name')) - -func_key_table = sql.table('func_key', - sql.column('id'), - sql.column('type_id'), - sql.column('destination_type_id')) - -func_key_type_table = sql.table('func_key_type', - sql.column('id'), - sql.column('name')) - -func_key_destination_type_table = sql.table('func_key_destination_type', - sql.column('id'), - sql.column('name')) - -func_key_dest_features_table = sql.table('func_key_dest_features', - sql.column('func_key_id'), - sql.column('destination_type_id'), - sql.column('features_id')) - - -def upgrade(): - features_id = find_features_id() - query = ( - sql.select([ - sql.func.count(func_key_dest_features_table.c.func_key_id)]) - .where( - func_key_dest_features_table.c.features_id == features_id)) - - count = op.get_bind().execute(query).scalar() - - if count == 0: - insert_automon_dest_features(find_func_key_type_id(), - find_destination_type_id()) - - -def downgrade(): - pass - - -def find_func_key_type_id(): - query = (sql.select([func_key_type_table.c.id]) - .where(func_key_type_table.c.name == AUTOMON_FUNC_KEY_TYPE)) - - return op.get_bind().execute(query).scalar() - - -def find_destination_type_id(): - query = (sql.select([func_key_destination_type_table.c.id]) - .where(func_key_destination_type_table.c.name == FEATURES_DESTINATION_NAME)) - - return op.get_bind().execute(query).scalar() - - -def find_features_id(): - features_query = ( - sql.select( - [features_table.c.id]) - .where( - sql.and_( - features_table.c.category == 'featuremap', - features_table.c.var_name == 'automon'))) - - return op.get_bind().execute(features_query).scalar() - - -def insert_automon_dest_features(type_id, destination_type_id): - func_key_query = (func_key_table - .insert() - .returning(func_key_table.c.id) - .values(type_id=type_id, - destination_type_id=destination_type_id)) - - func_key_id = op.get_bind().execute(func_key_query).scalar() - - dest_query = (func_key_dest_features_table - .insert() - .returning(func_key_dest_features_table.c.func_key_id) - .values(func_key_id=func_key_id, - destination_type_id=destination_type_id, - features_id=find_features_id())) - - return op.get_bind().execute(dest_query).scalar() diff --git a/alembic/versions/1a72b3da2baf_drop_order_column_in_schedule_path.py b/alembic/versions/1a72b3da2baf_drop_order_column_in_schedule_path.py deleted file mode 100644 index 7d12b637..00000000 --- a/alembic/versions/1a72b3da2baf_drop_order_column_in_schedule_path.py +++ /dev/null @@ -1,47 +0,0 @@ -"""drop_order_column_in_schedule_path - -Revision ID: 1a72b3da2baf -Revises: c18e988da503 - -""" - -# revision identifiers, used by Alembic. -revision = '1a72b3da2baf' -down_revision = 'c18e988da503' - -from alembic import op -from sqlalchemy import sql, Column, Integer - - -schedule = sql.table( - 'schedule', - sql.column('id'), -) - -schedule_path = sql.table( - 'schedule_path', - sql.column('schedule_id'), -) - - -def upgrade(): - _sanitize_schedule_path() - op.drop_column('schedule_path', 'order') - op.create_foreign_key('schedule_path_schedule_id_fkey', - 'schedule_path', 'schedule', - ['schedule_id'], ['id']) - - -def _sanitize_schedule_path(): - valid_schedules = sql.select([schedule.c.id]) - query = (schedule_path - .delete() - .where(sql.not_( - schedule_path.c.schedule_id.in_(valid_schedules) - ))) - op.get_bind().execute(query) - - -def downgrade(): - op.drop_constraint('schedule_path_schedule_id_fkey', 'schedule_path') - op.add_column('schedule_path', Column('order', Integer(), nullable=False)) diff --git a/alembic/versions/1a730d10e4a7_add_phonebook_url.py b/alembic/versions/1a730d10e4a7_add_phonebook_url.py deleted file mode 100644 index 2f07e49c..00000000 --- a/alembic/versions/1a730d10e4a7_add_phonebook_url.py +++ /dev/null @@ -1,46 +0,0 @@ -"""add phonebook url - -Revision ID: 1a730d10e4a7 -Revises: 4ee55e5290be - -""" - -# revision identifiers, used by Alembic. -revision = '1a730d10e4a7' -down_revision = '4ee55e5290be' - -from alembic import op -from sqlalchemy import sql - -phonebook_url = 'http://localhost/service/ipbx/json.php/private/pbx_services/phonebook' -directories_table = sql.table('directories', - sql.column('uri'), - sql.column('dirtype')) -cti_directories_table = sql.table('ctidirectories', - sql.column('uri')) - - -def upgrade(): - op.execute(directories_table - .update() - .where( - directories_table.c.dirtype == 'phonebook' - ).values(uri=phonebook_url)) - op.execute(cti_directories_table - .update() - .where( - cti_directories_table.c.uri == 'phonebook' - ).values(uri=phonebook_url)) - - -def downgrade(): - op.execute(directories_table - .update() - .where( - directories_table.c.uri == phonebook_url - ).values(uri='phonebook')) - op.execute(cti_directories_table - .update() - .where( - cti_directories_table.c.uri == phonebook_url - ).values(uri='phonebook')) diff --git a/alembic/versions/1aef8dfb5a12_remove_null_constraint_exten_context_.py b/alembic/versions/1aef8dfb5a12_remove_null_constraint_exten_context_.py deleted file mode 100644 index 0e6b7239..00000000 --- a/alembic/versions/1aef8dfb5a12_remove_null_constraint_exten_context_.py +++ /dev/null @@ -1,24 +0,0 @@ -"""remove_null_constraint_exten_context_from_incall - -Revision ID: 1aef8dfb5a12 -Revises: 549c621ae619 - -""" - -# revision identifiers, used by Alembic. -revision = '1aef8dfb5a12' -down_revision = '549c621ae619' - -from alembic import op - - -def upgrade(): - op.alter_column('incall', 'exten', nullable=True) - op.alter_column('incall', 'context', nullable=True) - op.alter_column('incall', 'description', nullable=True) - - -def downgrade(): - op.alter_column('incall', 'exten', nullable=False) - op.alter_column('incall', 'context', nullable=False) - op.alter_column('incall', 'description', nullable=False) diff --git a/alembic/versions/1b6be5d5e4ac_drop_usersip_setvar_column.py b/alembic/versions/1b6be5d5e4ac_drop_usersip_setvar_column.py deleted file mode 100644 index a3311778..00000000 --- a/alembic/versions/1b6be5d5e4ac_drop_usersip_setvar_column.py +++ /dev/null @@ -1,22 +0,0 @@ -"""drop usersip setvar column - -Revision ID: 1b6be5d5e4ac -Revises: 255de5d2adea - -""" - -# revision identifiers, used by Alembic. -revision = '1b6be5d5e4ac' -down_revision = '255de5d2adea' - -from alembic import op -from sqlalchemy.schema import Column -from sqlalchemy.types import String - - -def upgrade(): - op.drop_column('usersip', 'setvar') - - -def downgrade(): - op.add_column('usersip', Column('setvar', String(100), nullable=False, server_default='')) diff --git a/alembic/versions/1c3eb7380750_replace_mobile_callable.py b/alembic/versions/1c3eb7380750_replace_mobile_callable.py deleted file mode 100644 index 7bf0bf9f..00000000 --- a/alembic/versions/1c3eb7380750_replace_mobile_callable.py +++ /dev/null @@ -1,59 +0,0 @@ -"""number types migration - -Revision ID: 1c3eb7380750 -Revises: 30564ea14542 - -""" - -# revision identifiers, used by Alembic. -revision = '1c3eb7380750' -down_revision = '30564ea14542' - -import json - -from alembic import op -from sqlalchemy import sql - -cti_displays = sql.table('ctidisplays', - sql.column('id'), - sql.column('data')) - - -def _get_display_config(display): - return json.loads(display.data) if display.data else {} - - -def upgrade(): - rows = op.get_bind().execute(sql.select([cti_displays])) - for row in rows: - id_, config = row.id, _get_display_config(row) - new_config = {} - number_count = 0 - for key, value in config.items(): - new_value = list(value) - - # the type phone did not do anything but it was in the old default display - if new_value[1] == 'phone': - new_value[1] = 'number' - - # the mobile type is now callable - if new_value[1] == 'mobile': - new_value[1] = 'callable' - - # if there is more than one number, make the others callable - if new_value[1] == 'number': - number_count += 1 - if number_count > 1: - new_value[1] = 'callable' - - new_config[key] = new_value - - if new_config != config: - op.execute(cti_displays - .update() - .values(data=json.dumps(new_config)) - .where(cti_displays.c.id == id_)) - - -def downgrade(): - pass diff --git a/alembic/versions/1c95890bb00d_add_pjsip_system.py b/alembic/versions/1c95890bb00d_add_pjsip_system.py deleted file mode 100644 index 63877baa..00000000 --- a/alembic/versions/1c95890bb00d_add_pjsip_system.py +++ /dev/null @@ -1,131 +0,0 @@ -"""add-pjsip-system - -Revision ID: 1c95890bb00d -Revises: 28195459f3d1 - -""" - -from alembic import op -from sqlalchemy import sql - -# revision identifiers, used by Alembic. -revision = '1c95890bb00d' -down_revision = '28195459f3d1' - -FILENAME = 'pjsip.conf' -DEFAULTS = {} - -# Fields that are actually "translated" by wazo-confgend -SIP_TO_PJSIP_MAPPING = { - 'timert1': 'timer_t1', - 'timerb': 'timer_b', - 'compactheaders': 'compact_headers', -} - -# zcat /usr/share/doc/asterisk-doc/json/pjsip.json.gz | jq .system[].name | sort -u -VERBATIM_PJSIP_SYSTEM_OPTIONS = [ - "accept_multiple_sdp_answers", - "compact_headers", - "disable_tcp_switch", - "follow_early_media_fork", - "threadpool_auto_increment", - "threadpool_idle_timeout", - "threadpool_initial_size", - "threadpool_max_size", - "timer_b", - "timer_t1", -] - -asterisk_file_table = sql.table( - 'asterisk_file', - sql.column('id'), - sql.column('name'), -) - -asterisk_file_section_table = sql.table( - 'asterisk_file_section', - sql.column('id'), - sql.column('name'), - sql.column('priority'), - sql.column('asterisk_file_id'), -) - -asterisk_file_variable_table = sql.table( - 'asterisk_file_variable', - sql.column('id'), - sql.column('key'), - sql.column('value'), - sql.column('asterisk_file_section_id'), -) - -staticsip_table = sql.table( - 'staticsip', - sql.column('var_name'), - sql.column('var_val'), -) - - -def upgrade(): - file_id = _find_asterisk_file_id(FILENAME) - section_id = _insert_asterisk_file_section(file_id, 'system', priority=0) - current_sip_options = _get_current_sip_options() - - system_options = dict(DEFAULTS) - - for var, val in current_sip_options.items(): - # Add options mapped from sip.conf - if var in SIP_TO_PJSIP_MAPPING: - system_options[SIP_TO_PJSIP_MAPPING[var]] = val - - # If the admin used pjsip.conf keys - if var in VERBATIM_PJSIP_SYSTEM_OPTIONS: - system_options[var] = val - - for var, value in system_options.items(): - # We used to store null values in the db to match the form in the UI, not anymore. - if value is None: - continue - _insert_asterisk_file_variable(section_id, var, value) - - -def _get_current_sip_options(): - query = (sql.select([staticsip_table.c.var_name, staticsip_table.c.var_val])) - return {row[0]: row[1] for row in op.get_bind().execute(query)} - - -def _find_asterisk_file_id(name): - query = sql.select( - [asterisk_file_table.c.id] - ).where(asterisk_file_table.c.name == name) - return op.get_bind().execute(query).scalar() - - -def _insert_asterisk_file_section(file_id, name, priority=None): - query = (asterisk_file_section_table - .insert() - .returning(asterisk_file_section_table.c.id) - .values(name=name, - priority=priority, - asterisk_file_id=file_id)) - - return op.get_bind().execute(query).scalar() - - -def _insert_asterisk_file_variable(section_id, key, value): - query = (asterisk_file_variable_table - .insert() - .values(key=key, - value=value, - asterisk_file_section_id=section_id)) - - op.execute(query) - - -def downgrade(): - file_id = _find_asterisk_file_id(FILENAME) - op.execute(asterisk_file_section_table.delete().where( - sql.and_( - asterisk_file_section_table.c.asterisk_file_id == file_id, - asterisk_file_section_table.c.name == 'system', - ) - )) diff --git a/alembic/versions/1cc52186eb47_add_switchboard_table.py b/alembic/versions/1cc52186eb47_add_switchboard_table.py deleted file mode 100644 index 760c3b5a..00000000 --- a/alembic/versions/1cc52186eb47_add_switchboard_table.py +++ /dev/null @@ -1,104 +0,0 @@ -"""add switchboard table - -Revision ID: 1cc52186eb47 -Revises: 8c21acf4e9e - -""" - -# revision identifiers, used by Alembic. -revision = '1cc52186eb47' -down_revision = '8c21acf4e9e' - -from alembic import op -import sqlalchemy as sa - - -old_options = ('none', - 'endcall:busy', - 'endcall:congestion', - 'endcall:hangup', - 'user', - 'group', - 'queue', - 'meetme', - 'voicemail', - 'trunk', - 'schedule', - 'extension', - 'outcall', - 'application:callbackdisa', - 'application:disa', - 'application:directory', - 'application:faxtomail', - 'application:voicemailmain', - 'application:password', - 'sound', - 'custom', - 'ivr', - 'conference') -new_options = sorted(old_options + ('switchboard',)) - -new_type = sa.Enum(*new_options, name='dialaction_action') -old_type = sa.Enum(*old_options, name='dialaction_action') -tmp_type = sa.Enum(*new_options, name='dialaction_action_being_replaced') - -dialaction = sa.sql.table('dialaction', - sa.Column('action', new_type, nullable=False), - sa.Column('actionarg1', sa.String(255), nullable=False, server_default=''), - sa.Column('actionarg2', sa.String(255), nullable=False, server_default='')) - - -def upgrade(): - op.create_table( - 'switchboard', - sa.Column('uuid', sa.String(38), nullable=False), - sa.Column('name', sa.String(128), nullable=False), - sa.PrimaryKeyConstraint('uuid'), - ) - op.create_table( - 'switchboard_member_user', - sa.Column('switchboard_uuid', sa.String(38), nullable=False), - sa.Column('user_uuid', sa.String(38), nullable=False), - sa.PrimaryKeyConstraint('switchboard_uuid', 'user_uuid'), - sa.ForeignKeyConstraint(['switchboard_uuid'], ['switchboard.uuid']), - sa.ForeignKeyConstraint(['user_uuid'], ['userfeatures.uuid']), - sa.Index('switchboard_member_user__idx__switchboard_uuid', 'switchboard_uuid') - ) - _add_dialaction() - - -def downgrade(): - _remove_dialaction() - op.drop_table('switchboard') - - -def _add_dialaction(): - op.execute('ALTER TYPE dialaction_action RENAME TO dialaction_action_being_replaced') - - new_type.create(op.get_bind()) - op.execute('ALTER TABLE dialaction ALTER COLUMN action TYPE dialaction_action USING action::text::dialaction_action') - op.alter_column('schedule', 'fallback_action', server_default=None) - op.execute('ALTER TABLE schedule ALTER COLUMN fallback_action TYPE dialaction_action USING fallback_action::text::dialaction_action') - op.alter_column('schedule', 'fallback_action', server_default='none') - op.execute('ALTER TABLE schedule_time ALTER COLUMN action TYPE dialaction_action USING action::text::dialaction_action') - - tmp_type.drop(op.get_bind(), checkfirst=False) - - -def _remove_dialaction(): - # Convert dialaction switchboard into dialaction none - op.execute(dialaction - .update() - .where(dialaction.c.action == 'switchboard') - .values(action='none', actionarg1='', actionarg2='')) - - op.execute('ALTER TYPE dialaction_action RENAME TO dialaction_action_being_replaced') - - old_type.create(op.get_bind()) - op.execute('ALTER TABLE dialaction ALTER COLUMN action TYPE dialaction_action USING action::text::dialaction_action') - op.alter_column('schedule', 'fallback_action', server_default=None) - op.execute('ALTER TABLE schedule ALTER COLUMN fallback_action TYPE dialaction_action USING fallback_action::text::dialaction_action') - op.alter_column('schedule', 'fallback_action', server_default='none') - op.execute('ALTER TABLE schedule_time ALTER COLUMN action TYPE dialaction_action USING action::text::dialaction_action') - - tmp_type.drop(op.get_bind(), checkfirst=False) diff --git a/alembic/versions/1d05ffb14525_remove_unused_tables.py b/alembic/versions/1d05ffb14525_remove_unused_tables.py deleted file mode 100644 index 1e6db37d..00000000 --- a/alembic/versions/1d05ffb14525_remove_unused_tables.py +++ /dev/null @@ -1,53 +0,0 @@ -"""remove unused tables - -Revision ID: 1d05ffb14525 -Revises: 447e4ab61975 - -""" - -# revision identifiers, used by Alembic. -revision = '1d05ffb14525' -down_revision = '447e4ab61975' - -from alembic import op -from sqlalchemy.sql.schema import Column -from sqlalchemy.types import INTEGER, VARCHAR, TIMESTAMP - - -def upgrade(): - op.drop_table('ctilog') - op.drop_table('stats_conf_user') - op.drop_table('stats_conf_group') - op.drop_table('stats_conf_incall') - - -def downgrade(): - op.create_table( - 'ctilog', - Column('id', INTEGER, primary_key=True), - Column('eventdate', TIMESTAMP), - Column('loginclient', VARCHAR(64)), - Column('company', VARCHAR(64)), - Column('status', VARCHAR(64)), - Column('action', VARCHAR(64)), - Column('arguments', VARCHAR(255)), - Column('callduration', INTEGER) - ) - - op.create_table( - 'stats_conf_group', - Column('stats_conf_id', INTEGER, primary_key=True, autoincrement=False), - Column('groupfeatures_id', INTEGER, primary_key=True, autoincrement=False) - ) - - op.create_table( - 'stats_conf_incall', - Column('stats_conf_id', INTEGER, primary_key=True, autoincrement=False), - Column('incall_id', INTEGER, primary_key=True, autoincrement=False) - ) - - op.create_table( - 'stats_conf_user', - Column('stats_conf_id', INTEGER, primary_key=True, autoincrement=False), - Column('userfeatures_id', INTEGER, primary_key=True, autoincrement=False) - ) diff --git a/alembic/versions/1d4b487e4d1f_add_voicemail_foreign_key.py b/alembic/versions/1d4b487e4d1f_add_voicemail_foreign_key.py deleted file mode 100644 index 43b630bd..00000000 --- a/alembic/versions/1d4b487e4d1f_add_voicemail_foreign_key.py +++ /dev/null @@ -1,23 +0,0 @@ -"""add_voicemail_foreign_key - -Revision ID: 1d4b487e4d1f -Revises: 3a0ace87fc76 - -""" - -from alembic import op - -# revision identifiers, used by Alembic. -revision = '1d4b487e4d1f' -down_revision = '3a0ace87fc76' - - -def upgrade(): - op.execute("UPDATE userfeatures SET voicemailid = NULL WHERE voicemailid = 0") - op.create_foreign_key('userfeatures_voicemailid_fkey', - 'userfeatures', 'voicemail', - ['voicemailid'], ['uniqueid']) - - -def downgrade(): - op.drop_constraint('userfeatures_voicemailid_fkey', 'userfeatures') diff --git a/alembic/versions/1ddfb39a066f_drop_musiconhold_table.py b/alembic/versions/1ddfb39a066f_drop_musiconhold_table.py deleted file mode 100644 index 46d5c3aa..00000000 --- a/alembic/versions/1ddfb39a066f_drop_musiconhold_table.py +++ /dev/null @@ -1,57 +0,0 @@ -"""drop musiconhold table - -Revision ID: 1ddfb39a066f -Revises: 33fa1a10428f - -""" - -# revision identifiers, used by Alembic. -revision = '1ddfb39a066f' -down_revision = '33fa1a10428f' - -from alembic import op -from sqlalchemy import Column, PrimaryKeyConstraint, Integer, String, UniqueConstraint - - -def upgrade(): - op.execute(''' -INSERT INTO moh (uuid, name, mode, application, sort) -SELECT - uuid_generate_v4(), - category, - CASE (SELECT var_val FROM musiconhold WHERE category = m.category AND commented = 0 AND var_name = 'mode') - WHEN 'custom' THEN 'custom' - WHEN 'mp3' THEN 'mp3' - WHEN 'mp3nb' THEN 'mp3' - WHEN 'quietmp3' THEN 'mp3' - WHEN 'quietmp3nb' THEN 'mp3' - ELSE 'files' - END, - (SELECT var_val FROM musiconhold WHERE category = m.category AND commented = 0 AND var_name = 'application'), - CASE (SELECT var_val FROM musiconhold WHERE category = m.category AND commented = 0 AND var_name = 'sort') - WHEN 'alpha' THEN 'alphabetical' - WHEN 'random' THEN 'random' - WHEN 'randstart' THEN 'random_start' - END -FROM - musiconhold AS m -GROUP BY - category; -''') - op.drop_table('musiconhold') - - -def downgrade(): - op.create_table( - 'musiconhold', - Column('id', Integer), - Column('cat_metric', Integer, nullable=False, server_default='0'), - Column('var_metric', Integer, nullable=False, server_default='0'), - Column('commented', Integer, nullable=False, server_default='0'), - Column('filename', String(128), nullable=False), - Column('category', String(128), nullable=False), - Column('var_name', String(128), nullable=False), - Column('var_val', String(128)), - PrimaryKeyConstraint('id'), - UniqueConstraint('filename', 'category', 'var_name'), - ) diff --git a/alembic/versions/1f272484c083_remove_nullable_constraint_queueskill.py b/alembic/versions/1f272484c083_remove_nullable_constraint_queueskill.py deleted file mode 100644 index 3c5a9504..00000000 --- a/alembic/versions/1f272484c083_remove_nullable_constraint_queueskill.py +++ /dev/null @@ -1,20 +0,0 @@ -"""remove_nullable_constraint_queueskill - -Revision ID: 1f272484c083 -Revises: 8452bc3d5d67 - -""" - -from alembic import op - -# revision identifiers, used by Alembic. -revision = '1f272484c083' -down_revision = '8452bc3d5d67' - - -def upgrade(): - op.alter_column('queueskill', 'catid', nullable=True, server_default=None) - - -def downgrade(): - op.alter_column('queueskill', 'catid', nullable=False, server_default='1') diff --git a/alembic/versions/1f4cbd713979_add_missing_entity_id_column.py b/alembic/versions/1f4cbd713979_add_missing_entity_id_column.py deleted file mode 100644 index 500e17db..00000000 --- a/alembic/versions/1f4cbd713979_add_missing_entity_id_column.py +++ /dev/null @@ -1,39 +0,0 @@ -"""add_entity_to_callfilter - -Revision ID: 1f4cbd713979 -Revises: 3196befc4753 - -""" - -from sqlalchemy.sql.schema import Column, ForeignKey -from sqlalchemy.types import Integer -from sqlalchemy import text - -# revision identifiers, used by Alembic. -revision = '1f4cbd713979' -down_revision = '3196befc4753' - -from alembic import op - - -def upgrade(): - op.add_column('callfilter', - Column('entity_id', Integer, server_default=text('NULL'))) - op.create_foreign_key( - 'fk_entity_id', - 'callfilter', - 'entity', - ['entity_id'], - ['id'], - ) - - op.add_column('pickup', - Column('entity_id', Integer, ForeignKey('entity.id'), server_default=text('NULL'))) - op.add_column('schedule', - Column('entity_id', Integer, ForeignKey('entity.id'), server_default=text('NULL'))) - - -def downgrade(): - op.drop_column('callfilter', 'entity_id') - op.drop_column('pickup', 'entity_id') - op.drop_column('schedule', 'entity_id') diff --git a/alembic/versions/1f533d5f5f51_add_conference_dialaction.py b/alembic/versions/1f533d5f5f51_add_conference_dialaction.py deleted file mode 100644 index d478ae98..00000000 --- a/alembic/versions/1f533d5f5f51_add_conference_dialaction.py +++ /dev/null @@ -1,67 +0,0 @@ -"""add_conference_dialaction - -Revision ID: 1f533d5f5f51 -Revises: 462b92a4f5d8 - -""" - -# revision identifiers, used by Alembic. -revision = '1f533d5f5f51' -down_revision = '462b92a4f5d8' - -from alembic import op -from sqlalchemy import Enum - - -dialaction_action = Enum( - 'none', - 'endcall:busy', - 'endcall:congestion', - 'endcall:hangup', - 'user', - 'group', - 'queue', - 'meetme', - 'voicemail', - 'trunk', - 'schedule', - 'extension', - 'outcall', - 'application:callbackdisa', - 'application:disa', - 'application:directory', - 'application:faxtomail', - 'application:voicemailmain', - 'application:password', - 'sound', - 'custom', - 'ivr', - 'conference', - name='dialaction_action', -) - - -def upgrade(): - _modify_dialaction_action_type() - - -def _modify_dialaction_action_type(): - op.alter_column('schedule', 'fallback_action', server_default=None) - _modify_type(dialaction_action, - ('dialaction', 'action'), - ('schedule', 'fallback_action'), - ('schedule_time', 'action')) - op.alter_column('schedule', 'fallback_action', server_default='none') - - -def _modify_type(type_, *table_and_columns): - op.execute('ALTER TYPE {type_name} RENAME TO tmp_{type_name}'.format(type_name=type_.name)) - type_.create(op.get_bind()) - for table, column in table_and_columns: - op.execute('ALTER TABLE {table_name} ALTER COLUMN {column_name} TYPE {type_name} USING {column_name}::text::{type_name}'.format( - type_name=type_.name, table_name=table, column_name=column)) - op.execute('DROP TYPE tmp_{type_name}'.format(type_name=type_.name)) - - -def downgrade(): - pass diff --git a/alembic/versions/203129d6b213_remove_queue_info_table.py b/alembic/versions/203129d6b213_remove_queue_info_table.py deleted file mode 100644 index ccaf99c3..00000000 --- a/alembic/versions/203129d6b213_remove_queue_info_table.py +++ /dev/null @@ -1,37 +0,0 @@ -"""Remove queue_info table. - -Revision ID: 203129d6b213 -Revises: 5ffaec7e8db7 - -""" - -from alembic import op -from sqlalchemy import Column, Integer, String - - -# revision identifiers, used by Alembic. -revision = '203129d6b213' -down_revision = '5ffaec7e8db7' - - -def upgrade(): - op.drop_index('queue_info_call_time_t_index') - op.drop_index('queue_info_queue_name_index') - op.drop_table('queue_info') - - -def downgrade(): - op.create_table( - 'queue_info', - Column('id', Integer, primary_key=True), - Column('call_time_t', Integer), - Column('queue_name', String(128), nullable=False, server_default=''), - Column('caller', String(80), nullable=False, server_default=''), - Column('caller_uniqueid', String(32), nullable=False, server_default=''), - Column('call_picker', String(80)), - Column('hold_time', Integer), - Column('talk_time', Integer), - ) - - op.create_index('queue_info_call_time_t_index', 'queue_info', ['call_time_t']) - op.create_index('queue_info_queue_name_index', 'queue_info', ['queue_name']) diff --git a/alembic/versions/203f6f2cf0a0_remove_deprecated_incall_fields.py b/alembic/versions/203f6f2cf0a0_remove_deprecated_incall_fields.py deleted file mode 100644 index 0b9b5be6..00000000 --- a/alembic/versions/203f6f2cf0a0_remove_deprecated_incall_fields.py +++ /dev/null @@ -1,39 +0,0 @@ -"""remove-deprecated-incall-fields - -Revision ID: 203f6f2cf0a0 -Revises: 2bb55c201ee7 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '203f6f2cf0a0' -down_revision = '2bb55c201ee7' - - -def upgrade(): - op.drop_column('incall', 'exten') - op.drop_column('incall', 'context') - - -def downgrade(): - op.add_column('incall', sa.Column('exten', sa.String(40))) - op.add_column('incall', sa.Column('context', sa.String(39))) - op.create_unique_constraint( - 'incall_exten_context_key', - 'incall', - ['exten', 'context'], - ) - op.create_index( - index_name='incall__idx__context', - table_name='incall', - columns=['context'], - ) - op.create_index( - index_name='incall__idx__exten', - table_name='incall', - columns=['exten'], - ) diff --git a/alembic/versions/2072c1e66aa9_drop_dialaction_event.py b/alembic/versions/2072c1e66aa9_drop_dialaction_event.py deleted file mode 100644 index 893cefbe..00000000 --- a/alembic/versions/2072c1e66aa9_drop_dialaction_event.py +++ /dev/null @@ -1,26 +0,0 @@ -"""drop dialaction_event - -Revision ID: 2072c1e66aa9 -Revises: 2fbbd4231cca - -""" - -# revision identifiers, used by Alembic. -revision = '2072c1e66aa9' -down_revision = '2fbbd4231cca' - -from alembic import op -from sqlalchemy.types import String - - -def upgrade(): - _drop_dialaction_event() - - -def _drop_dialaction_event(): - op.alter_column('dialaction', 'event', type_=String(40)) - op.execute('DROP TYPE dialaction_event') - - -def downgrade(): - pass diff --git a/alembic/versions/2077c9fc2d49_replace_agent_action_by_extension_id.py b/alembic/versions/2077c9fc2d49_replace_agent_action_by_extension_id.py deleted file mode 100644 index 6d9af290..00000000 --- a/alembic/versions/2077c9fc2d49_replace_agent_action_by_extension_id.py +++ /dev/null @@ -1,87 +0,0 @@ -"""replace agent action by extension id - -Revision ID: 2077c9fc2d49 -Revises: 3ab7cf07eb66 - -""" - -# revision identifiers, used by Alembic. -revision = '2077c9fc2d49' -down_revision = '3ab7cf07eb66' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy import sql - -ACTIONS = { - 'login': 'agentstaticlogin', - 'logoff': 'agentstaticlogoff', - 'toggle': 'agentstaticlogtoggle' -} - -destination_agent = sql.table('func_key_dest_agent', - sql.column('func_key_id'), - sql.column('action'), - sql.column('extension_id')) - -extensions = sql.table('extensions', - sql.column('id'), - sql.column('type'), - sql.column('typeval')) - - -def upgrade(): - op.add_column('func_key_dest_agent', - sa.Column('extension_id', - sa.Integer(), - sa.ForeignKey('extensions.id')), - ) - - op.create_unique_constraint('func_key_dest_agent_agent_id_extension_id_key', - 'func_key_dest_agent', - ('agent_id', 'extension_id')) - - for action, wonky_action in ACTIONS.items(): - extension_query = (sql.select([extensions.c.id]) - .where(extensions.c.typeval == wonky_action)) - - extension_id = op.get_bind().execute(extension_query).scalar() - - query = (destination_agent - .update() - .values(extension_id=extension_id) - .where(destination_agent.c.action == action)) - - op.execute(query) - - op.alter_column('func_key_dest_agent', 'extension_id', nullable=False) - op.drop_column('func_key_dest_agent', 'action') - - -def downgrade(): - op.add_column('func_key_dest_agent', - sa.Column('action', - sa.Unicode(10))) - - op.create_unique_constraint('func_key_dest_agent_id_action_key', - 'func_key_dest_agent', - ('agent_id', 'action')) - - op.create_check_constraint('func_key_dest_agent_action_check', - 'func_key_dest_agent', - "action IN ('login', 'logoff', 'toggle')") - - for action, wonky_action in ACTIONS.items(): - extension_query = (sql.select([extensions.c.id]) - .where(extensions.c.typeval == wonky_action) - .alias()) - - query = (destination_agent - .update() - .values(action=action) - .where(destination_agent.c.extension_id == extension_query)) - - op.execute(query) - - op.alter_column('func_key_dest_agent', 'action', nullable=False) - op.drop_column('func_key_dest_agent', 'extension_id') diff --git a/alembic/versions/20d4630f2c8e_remove_constraints_from_linefeatures.py b/alembic/versions/20d4630f2c8e_remove_constraints_from_linefeatures.py deleted file mode 100644 index 57c83507..00000000 --- a/alembic/versions/20d4630f2c8e_remove_constraints_from_linefeatures.py +++ /dev/null @@ -1,26 +0,0 @@ -"""remove constraints from linefeatures - -Revision ID: 20d4630f2c8e -Revises: 46dbcd084872 - -""" - -from alembic import op - -# revision identifiers, used by Alembic. -revision = '20d4630f2c8e' -down_revision = '46dbcd084872' - - -def upgrade(): - op.alter_column('linefeatures', 'protocol', nullable=True) - op.alter_column('linefeatures', 'protocolid', nullable=True) - op.alter_column('linefeatures', 'name', nullable=True) - op.alter_column('linefeatures', 'num', server_default='1') - - -def downgrade(): - op.alter_column('linefeatures', 'protocol', nullable=False) - op.alter_column('linefeatures', 'protocolid', nullable=False) - op.alter_column('linefeatures', 'name', nullable=False) - op.alter_column('linefeatures', 'num', server_default='0') diff --git a/alembic/versions/20debb21dc01_move_column_merging_from_display_to_.py b/alembic/versions/20debb21dc01_move_column_merging_from_display_to_.py deleted file mode 100644 index 6ac43079..00000000 --- a/alembic/versions/20debb21dc01_move_column_merging_from_display_to_.py +++ /dev/null @@ -1,128 +0,0 @@ -"""move column merging from display to directories - -Revision ID: 20debb21dc01 -Revises: b2abcc84ad - -""" - -# revision identifiers, used by Alembic. -revision = '20debb21dc01' -down_revision = 'b2abcc84ad' - -import json -import re - -from alembic import op -from sqlalchemy import sql, and_ -from unidecode import unidecode - -cti_contexts = sql.table('cticontexts', - sql.column('id'), - sql.column('name'), - sql.column('directories'), - sql.column('display')) -cti_displays = sql.table('ctidisplays', - sql.column('id'), - sql.column('name'), - sql.column('data')) -cti_directories = sql.table('ctidirectories', - sql.column('id'), - sql.column('name')) -cti_directory_fields = sql.table('ctidirectoryfields', - sql.column('dir_id'), - sql.column('fieldname'), - sql.column('value')) - - -def _get_display_config(display): - return json.loads(display.data) if display.data else {} - - -def _find_formatted_fields(config): - formatted_fields = [] - for pos, (name, _, _, field) in config.items(): - if field and not field.isalpha(): - formatted_fields.append((name, pos, field)) - return formatted_fields - - -def _source_using_display(conn, display_name): - source_names = set() - rows = conn.execute(sql.select([cti_contexts]) - .where(and_(cti_contexts.c.display == display_name, - cti_contexts.c.directories != ''))) - for row in rows: - for name in row.directories.split(','): - source_names.add(name) - - return list(source_names) - - -def _update_sources(conn, column_info): - rows = conn.execute(sql.select([cti_directories.c.id]) - .where(cti_directories.c.name.in_(column_info['sources']))) - for row in rows: - already_there = conn.execute( - sql.select([cti_directory_fields.c.dir_id]) - .where(and_(cti_directory_fields.c.dir_id == row.id, - cti_directory_fields.c.fieldname == column_info['source_col']))).rowcount != 0 - if already_there: - continue - fields = conn.execute(sql.select([cti_directory_fields.c.fieldname, - cti_directory_fields.c.value]) - .where(cti_directory_fields.c.dir_id == row.id)) - - source_fields = column_info['source_fields'] - for field in fields: - old_field = '{%s}' % field.fieldname - new_field = field.value - source_fields = source_fields.replace(old_field, new_field) - - op.execute(cti_directory_fields.insert().values(dir_id=row.id, - fieldname=column_info['source_col'], - value=source_fields)) - - -def _update_display(conn, column_info): - new_data = column_info['display_data'] - pos = column_info['position'] - title, type_, default, _ = column_info['display_data'][pos] - new_data[pos] = title, type_, default, column_info['source_col'] - op.execute(cti_displays - .update() - .where(cti_displays.c.name == column_info['display']) - .values(data=json.dumps(new_data))) - - -def _get_column_to_migrate(conn): - r = re.compile(r'(\W*)(\w+)(\W*)') - rows = conn.execute(sql.select([cti_displays])) - to_migrate = [] - for row in rows: - config = _get_display_config(row) - to_move = _find_formatted_fields(config) - if not to_move: - continue - source_names = _source_using_display(conn, row.name) - for name, pos, field in to_move: - source_column = unidecode(name.lower().replace(' ', '_')) - source_format = r.sub(r'\1{\2}\3', field) - to_migrate.append({'display': row.name, - 'position': pos, - 'source_col': source_column, - 'source_fields': source_format, - 'sources': source_names, - 'display_data': config}) - return to_migrate - - -def upgrade(): - conn = op.get_bind() - to_migrate = _get_column_to_migrate(conn) - for column_info in to_migrate: - _update_sources(conn, column_info) - _update_display(conn, column_info) - - -def downgrade(): - pass diff --git a/alembic/versions/21b72c41eb6a_bump_version_22_05.py b/alembic/versions/21b72c41eb6a_bump_version_22_05.py deleted file mode 100644 index 63c36857..00000000 --- a/alembic/versions/21b72c41eb6a_bump_version_22_05.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_22_05 - -Revision ID: 21b72c41eb6a -Revises: 0ffacfab7041 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '21b72c41eb6a' -down_revision = '0ffacfab7041' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='22.05')) - - -def downgrade(): - pass diff --git a/alembic/versions/21d45c24210e_add_a_wizard_webservice_access.py b/alembic/versions/21d45c24210e_add_a_wizard_webservice_access.py deleted file mode 100644 index f90810b3..00000000 --- a/alembic/versions/21d45c24210e_add_a_wizard_webservice_access.py +++ /dev/null @@ -1,34 +0,0 @@ -"""add a wizard webservice access - -Revision ID: 21d45c24210e -Revises: 341f7e584088 - -""" - -# revision identifiers, used by Alembic. -revision = '21d45c24210e' -down_revision = '341f7e584088' - -from alembic import op -from sqlalchemy import sql, func - -webservice = sql.table('accesswebservice', - sql.column('name'), - sql.column('login'), - sql.column('passwd'), - sql.column('acl')) -ACL = '{dird.tenants.*.phonebooks.create}' - - -def upgrade(): - op.execute(webservice - .insert() - .values(name='xivo-wizard', - login='xivo-wizard', - passwd=func.substring(func.gen_salt('bf', 4), 8), - acl=ACL)) - - -def downgrade(): - op.execute(webservice.delete().where(webservice.c.name == 'xivo-wizard')) - diff --git a/alembic/versions/21f6963c1d35_call_filter_add_tenant_uuid.py b/alembic/versions/21f6963c1d35_call_filter_add_tenant_uuid.py deleted file mode 100644 index f1bfd7f3..00000000 --- a/alembic/versions/21f6963c1d35_call_filter_add_tenant_uuid.py +++ /dev/null @@ -1,56 +0,0 @@ -"""call_filter_add_tenant_uuid - -Revision ID: 21f6963c1d35 -Revises: 4f86216ba603 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '21f6963c1d35' -down_revision = '4f86216ba603' - -TABLE = 'callfilter' - - -def find_default_tenant_uuid(): - entity_table = sa.sql.table( - 'entity', - sa.sql.column('id'), - sa.sql.column('tenant_uuid'), - ) - query = sa.sql.select([entity_table.c.tenant_uuid]).order_by(entity_table.c.id) - for row in op.get_bind().execute(query): - return row.tenant_uuid - - -def associate_tenants(): - tbl = sa.sql.table('callfilter', sa.sql.column('id'), sa.sql.column('tenant_uuid')) - sql = "SELECT callfilter.id, entity.tenant_uuid FROM callfilter, entity WHERE entity.id=callfilter.entity_id" - callfilter_to_tenant = op.get_bind().execute(sa.sql.text(sql)) - - for callfilter_id, tenant_uuid in callfilter_to_tenant: - query = tbl.update().where(tbl.c.id == callfilter_id).values(tenant_uuid=tenant_uuid) - op.execute(query) - - -def upgrade(): - default_tenant = find_default_tenant_uuid() - op.add_column( - TABLE, - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=False, - server_default=default_tenant), - ) - associate_tenants() - op.alter_column(TABLE, 'tenant_uuid', server_default=None) - - -def downgrade(): - op.drop_column(TABLE, 'tenant_uuid') diff --git a/alembic/versions/2251b5ae9e6c_add_wazo_upgrade_acl.py b/alembic/versions/2251b5ae9e6c_add_wazo_upgrade_acl.py deleted file mode 100644 index 94ac18c5..00000000 --- a/alembic/versions/2251b5ae9e6c_add_wazo_upgrade_acl.py +++ /dev/null @@ -1,37 +0,0 @@ -"""add_wazo_upgrade_acl - -Revision ID: 2251b5ae9e6c -Revises: 41a523e18fdd - -""" - -from alembic import op -from sqlalchemy import sql, func - -# revision identifiers, used by Alembic. -revision = '2251b5ae9e6c' -down_revision = '41a523e18fdd' - -webservice = sql.table('accesswebservice', - sql.column('name'), - sql.column('login'), - sql.column('passwd'), - sql.column('acl'), - sql.column('description')) -ACL = '{plugind.#,confd.#,auth.#}' -DESCRIPTION = 'Automatically created during upgrade' -SERVICE = 'wazo-upgrade' - - -def upgrade(): - op.execute(webservice - .insert() - .values(name=SERVICE, - login=SERVICE, - passwd=func.substring(func.gen_salt('bf', 4), 8), - acl=ACL, - description=DESCRIPTION)) - - -def downgrade(): - op.execute(webservice.delete().where(webservice.c.name == SERVICE)) diff --git a/alembic/versions/2256e488e43c_change_email_body_new_lines.py b/alembic/versions/2256e488e43c_change_email_body_new_lines.py deleted file mode 100644 index 94ef538a..00000000 --- a/alembic/versions/2256e488e43c_change_email_body_new_lines.py +++ /dev/null @@ -1,29 +0,0 @@ -"""change email body new lines - -Revision ID: 2256e488e43c -Revises: 6545d103068c - -""" - -from alembic import op - -# revision identifiers, used by Alembic. -revision = '2256e488e43c' -down_revision = '6545d103068c' - - -def upgrade(): - _run(r"""UPDATE staticvoicemail -SET var_val = regexp_replace(staticvoicemail.var_val, E'\n', '\n', 'g') -WHERE var_name = 'emailbody'""") - - -def downgrade(): - _run(r"""UPDATE staticvoicemail -SET var_val = regexp_replace(staticvoicemail.var_val, '\\n', E'\n', 'g') -WHERE var_name = 'emailbody'""") - - -def _run(qry): - conn = op.get_bind() - conn.execute(qry) diff --git a/alembic/versions/232708be8a75_parking_lot_add_tenant_uuid.py b/alembic/versions/232708be8a75_parking_lot_add_tenant_uuid.py deleted file mode 100644 index 595e956b..00000000 --- a/alembic/versions/232708be8a75_parking_lot_add_tenant_uuid.py +++ /dev/null @@ -1,56 +0,0 @@ -"""parking_lot_add_tenant_uuid - -Revision ID: 232708be8a75 -Revises: 4f85f1de19b4 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '232708be8a75' -down_revision = '4f85f1de19b4' - -TABLE = 'parking_lot' - - -def find_default_tenant_uuid(): - entity_table = sa.sql.table( - 'entity', - sa.sql.column('id'), - sa.sql.column('tenant_uuid'), - ) - query = sa.sql.select([entity_table.c.tenant_uuid]).order_by(entity_table.c.id) - for row in op.get_bind().execute(query): - return row.tenant_uuid - - -def associate_tenants(): - tbl = sa.sql.table('parking_lot', sa.sql.column('id'), sa.sql.column('tenant_uuid')) - sql = "SELECT parking_lot.id, context.tenant_uuid FROM parking_lot, extensions, context WHERE extensions.type='parking' AND extensions.typeval=CAST(parking_lot.id AS text) AND extensions.context = context.name" - parking_lot_to_tenant = op.get_bind().execute(sa.sql.text(sql)) - - for parking_lot_id, tenant_uuid in parking_lot_to_tenant: - query = tbl.update().where(tbl.c.id == parking_lot_id).values(tenant_uuid=tenant_uuid) - op.execute(query) - - -def upgrade(): - default_tenant = find_default_tenant_uuid() - op.add_column( - TABLE, - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=False, - server_default=default_tenant), - ) - associate_tenants() - op.alter_column(TABLE, 'tenant_uuid', server_default=None) - - -def downgrade(): - op.drop_column(TABLE, 'tenant_uuid') diff --git a/alembic/versions/234745874c55_migrate_func_key_paging.py b/alembic/versions/234745874c55_migrate_func_key_paging.py deleted file mode 100644 index fe9da8fc..00000000 --- a/alembic/versions/234745874c55_migrate_func_key_paging.py +++ /dev/null @@ -1,349 +0,0 @@ -"""migrate func key paging - -Revision ID: 234745874c55 -Revises: 2d3d29858d6d - -""" - -# revision identifiers, used by Alembic. -revision = '234745874c55' -down_revision = '2d3d29858d6d' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy import sql - - -TYPE_SPEEDDIAL = 'speeddial' - -DESTINATION_PAGING_ID = 9 - -PAGING_TYPE = 'paging' - - -phonefunckey_table = sql.table('phonefunckey', - sql.column('iduserfeatures'), - sql.column('fknum'), - sql.column('exten'), - sql.column('typeextenumbers'), - sql.column('typevalextenumbers'), - sql.column('typeextenumbersright'), - sql.column('typevalextenumbersright'), - sql.column('label'), - sql.column('supervision'), - sql.column('progfunckey')) - -func_key_table = sql.table('func_key', - sql.column('id'), - sql.column('type_id'), - sql.column('destination_type_id')) - -func_key_type_table = sql.table('func_key_type', - sql.column('id'), - sql.column('name')) - -destination_type_table = sql.table('func_key_destination_type', - sql.column('id'), - sql.column('name')) - -func_key_mapping_table = sql.table('func_key_mapping', - sql.column('template_id'), - sql.column('func_key_id'), - sql.column('destination_type_id'), - sql.column('label'), - sql.column('position'), - sql.column('blf')) - -dest_paging_table = sql.table('func_key_dest_paging', - sql.column('func_key_id'), - sql.column('destination_type_id'), - sql.column('paging_id')) - -template_table = sql.table('func_key_template', sql.column('id')) - -user_table = sql.table('userfeatures', - sql.column('id'), - sql.column('func_key_private_template_id')) - -paging_table = sql.table('paging', - sql.column('id'), - sql.column('number')) - - -func_key_columns = ( - phonefunckey_table.c.iduserfeatures.label('user_id'), - phonefunckey_table.c.fknum.label('position'), - phonefunckey_table.c.label, - sql.cast(phonefunckey_table.c.supervision, sa.Boolean).label('blf'), - paging_table.c.id.label('paging_id') -) - -old_func_key_columns = ( - func_key_mapping_table.c.func_key_id, - func_key_mapping_table.c.template_id, - func_key_mapping_table.c.position, - func_key_mapping_table.c.blf, - func_key_mapping_table.c.label, - paging_table.c.number.label('number'), - user_table.c.id.label('user_id') -) - -func_keys_query = (sql.select(func_key_columns, - from_obj=[ - phonefunckey_table.join( - paging_table, - phonefunckey_table.c.typevalextenumbersright == paging_table.c.number) - ]) - .where(phonefunckey_table.c.typevalextenumbers == PAGING_TYPE)) - - -old_func_keys_query = (sql.select(old_func_key_columns, - from_obj=[ - func_key_mapping_table.join( - dest_paging_table, - func_key_mapping_table.c.func_key_id == dest_paging_table.c.func_key_id) - .join(paging_table, - dest_paging_table.c.paging_id == paging_table.c.id) - .join(template_table, - func_key_mapping_table.c.template_id == template_table.c.id) - .join(user_table, - template_table.c.id == user_table.c.func_key_private_template_id) - ])) - - -def upgrade(): - delete_duplicate_pagings() - delete_empty_pagings() - delete_invalid_pagings() - migrate_func_keys() - delete_old_func_keys() - - -def delete_duplicate_pagings(): - template = '[MIGRATE_FK] : Deleting func key for user "%s" (fk position %s with paging number %s)' - for row in get_duplicate_func_keys(): - message = template % (row.iduserfeatures, row.fknum, row.typevalextenumbersright) - delete_fk(row, message) - - -def get_duplicate_func_keys(): - columns = (phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.typevalextenumbersright, - sa.func.min(phonefunckey_table.c.fknum).label("first_position")) - - valid_fk_subq = (sql.select(columns) - .where( - phonefunckey_table.c.typevalextenumbers == PAGING_TYPE) - .group_by( - phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.typevalextenumbersright) - .having( - sa.func.count(phonefunckey_table.c.typevalextenumbersright) > 1) - .alias()) - - columns = (phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.typevalextenumbersright, - phonefunckey_table.c.fknum) - - join_condition = sql.and_( - phonefunckey_table.c.typevalextenumbersright == valid_fk_subq.c.typevalextenumbersright, - phonefunckey_table.c.fknum > valid_fk_subq.c.first_position, - phonefunckey_table.c.iduserfeatures == valid_fk_subq.c.iduserfeatures) - - duplicate_fk_query = (sql.select(columns, - from_obj=[ - phonefunckey_table.join( - valid_fk_subq, - join_condition - ) - ])) - - return op.get_bind().execute(duplicate_fk_query) - - -def delete_fk(row, message): - print(message) - - query = (phonefunckey_table - .delete() - .where( - sql.and_( - phonefunckey_table.c.iduserfeatures == row.iduserfeatures, - phonefunckey_table.c.fknum == row.fknum)) - ) - - op.get_bind().execute(query) - - -def delete_empty_pagings(): - template = '[MIGRATE_FK] : Deleting func key for user "%s" (fk position %s with empty paging)' - - columns = (phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.fknum) - - query = (sql.select(columns) - .where( - sql.and_( - phonefunckey_table.c.typevalextenumbers == PAGING_TYPE, - phonefunckey_table.c.typevalextenumbersright == None)) - ) - - for row in op.get_bind().execute(query): - message = template % (row.iduserfeatures, row.fknum) - delete_fk(row, message) - - -def delete_invalid_pagings(): - template = '[MIGRATE_FK] : Deleting func key for user "%s" (fk position %s with invalid paging)' - - rows = get_invalid_pagings() - - for row in rows: - message = template % (row.iduserfeatures, row.fknum) - delete_fk(row, message) - - -def get_invalid_pagings(): - paging_query = sql.select([paging_table.c.number]).alias() - - columns = (phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.fknum) - - query = (sql.select(columns) - .where( - sql.and_( - phonefunckey_table.c.typevalextenumbers == PAGING_TYPE, - phonefunckey_table.c.typevalextenumbersright.notin_( - paging_query))) - ) - - return op.get_bind().execute(query) - - -def migrate_func_keys(): - for row in op.get_bind().execute(func_keys_query): - func_key_id = find_or_create_paging(row.paging_id) - create_mapping(func_key_id, row) - - -def find_or_create_paging(paging_id): - query = (sql.select([dest_paging_table.c.func_key_id]) - .where(dest_paging_table.c.paging_id == paging_id) - ) - - func_key_id = op.get_bind().execute(query).scalar() - - if not func_key_id: - func_key_id = create_func_key() - create_paging_destination(func_key_id, paging_id) - - return func_key_id - - -def create_func_key(): - speeddial_id = get_speeddial_id() - insert_query = (func_key_table - .insert() - .returning(func_key_table.c.id) - .values(type_id=speeddial_id, - destination_type_id=DESTINATION_PAGING_ID)) - - return op.get_bind().execute(insert_query).scalar() - - -def get_speeddial_id(): - return op.get_bind().execute( - sql.select( - [func_key_type_table.c.id]) - .where( - func_key_type_table.c.name == TYPE_SPEEDDIAL) - ).scalar() - - -def create_paging_destination(func_key_id, paging_id): - destination_query = (dest_paging_table - .insert() - .returning(dest_paging_table.c.func_key_id) - .values(func_key_id=func_key_id, - paging_id=paging_id)) - - op.get_bind().execute(destination_query) - - -def create_mapping(func_key_id, func_key_row): - conn = op.get_bind() - - template_id = conn.execute(sql.select( - [user_table.c.func_key_private_template_id]) - .where( - user_table.c.id == func_key_row.user_id) - ).scalar() - - mapping_query = (func_key_mapping_table - .insert() - .returning(func_key_mapping_table.c.func_key_id) - .values(func_key_id=func_key_id, - template_id=template_id, - destination_type_id=DESTINATION_PAGING_ID, - label=func_key_row.label, - position=func_key_row.position, - blf=func_key_row.blf)) - - conn.execute(mapping_query) - - -def delete_old_func_keys(): - delete_query = (phonefunckey_table - .delete() - .where(phonefunckey_table.c.typevalextenumbers == PAGING_TYPE)) - - op.get_bind().execute(delete_query) - - -def downgrade(): - for row in op.get_bind().execute(old_func_keys_query): - create_old_func_keys(row) - delete_mapping(row.func_key_id, row.template_id) - delete_dest_paging(row.func_key_id) - delete_func_key(row.func_key_id) - - -def create_old_func_keys(row): - supervision = 1 if row.blf else 0 - - row = {'iduserfeatures': row.user_id, - 'fknum': row.position, - 'typeextenumbers': 'extenfeatures', - 'typevalextenumbers': 'paging', - 'typeextenumbersright': 'paging', - 'typevalextenumbersright': row.number, - 'label': row.label, - 'exten': None, - 'supervision': supervision} - - op.bulk_insert(phonefunckey_table, [row]) - - -def delete_mapping(func_key_id, template_id): - query = (func_key_mapping_table - .delete() - .where(sql.and_( - func_key_mapping_table.c.func_key_id == func_key_id, - func_key_mapping_table.c.template_id == template_id))) - - op.get_bind().execute(query) - - -def delete_dest_paging(func_key_id): - query = (dest_paging_table - .delete()) - - op.get_bind().execute(query) - - -def delete_func_key(func_key_id): - query = (func_key_table - .delete() - .where(func_key_table.c.destination_type_id == DESTINATION_PAGING_ID)) - - op.get_bind().execute(query) diff --git a/alembic/versions/235158681deb_calll_permission_add_tenant_uuid.py b/alembic/versions/235158681deb_calll_permission_add_tenant_uuid.py deleted file mode 100644 index d8c0eca2..00000000 --- a/alembic/versions/235158681deb_calll_permission_add_tenant_uuid.py +++ /dev/null @@ -1,45 +0,0 @@ -"""calll_permission_add_tenant_uuid - -Revision ID: 235158681deb -Revises: 21f6963c1d35 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '235158681deb' -down_revision = '21f6963c1d35' - -TABLE = 'rightcall' - - -def find_default_tenant_uuid(): - entity_table = sa.sql.table( - 'entity', - sa.sql.column('id'), - sa.sql.column('tenant_uuid'), - ) - query = sa.sql.select([entity_table.c.tenant_uuid]).order_by(entity_table.c.id) - for row in op.get_bind().execute(query): - return row.tenant_uuid - - -def upgrade(): - default_tenant = find_default_tenant_uuid() - op.add_column( - TABLE, - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=False, - server_default=default_tenant), - ) - op.alter_column(TABLE, 'tenant_uuid', server_default=None) - - -def downgrade(): - op.drop_column(TABLE, 'tenant_uuid') diff --git a/alembic/versions/2375157ea682_add_people_xlet.py b/alembic/versions/2375157ea682_add_people_xlet.py deleted file mode 100644 index 5ba1c127..00000000 --- a/alembic/versions/2375157ea682_add_people_xlet.py +++ /dev/null @@ -1,21 +0,0 @@ -"""add people xlet - -Revision ID: 2375157ea682 -Revises: 2077c9fc2d49 - -""" - -# revision identifiers, used by Alembic. -revision = '2375157ea682' -down_revision = '2077c9fc2d49' - -from alembic import op - - -def upgrade(): - op.execute("""DELETE FROM "cti_xlet" WHERE "plugin_name" = 'people'""") - op.execute("""INSERT INTO "cti_xlet" VALUES (DEFAULT, 'people')""") - - -def downgrade(): - op.execute("""DELETE FROM "cti_xlet" WHERE "plugin_name" = 'people'""") diff --git a/alembic/versions/241501a5f8ba_remove_queue_info_function.py b/alembic/versions/241501a5f8ba_remove_queue_info_function.py deleted file mode 100644 index bd768e93..00000000 --- a/alembic/versions/241501a5f8ba_remove_queue_info_function.py +++ /dev/null @@ -1,23 +0,0 @@ -"""remove queue_info function - -Revision ID: 241501a5f8ba -Revises: 203129d6b213 - -""" - -from alembic import op - - -# revision identifiers, used by Alembic. -revision = '241501a5f8ba' -down_revision = '203129d6b213' - - -def upgrade(): - op.get_bind().execute( - 'DROP FUNCTION IF EXISTS "get_queue_statistics" (text, int, int)' - ) - - -def downgrade(): - pass diff --git a/alembic/versions/241ba0a6d087_fix_broken_ctidirectories_fk.py b/alembic/versions/241ba0a6d087_fix_broken_ctidirectories_fk.py deleted file mode 100644 index 57a3e2a8..00000000 --- a/alembic/versions/241ba0a6d087_fix_broken_ctidirectories_fk.py +++ /dev/null @@ -1,60 +0,0 @@ -"""fix broken ctidirectories fk - -Revision ID: 241ba0a6d087 -Revises: 15b236bd8060 - -""" - -# revision identifiers, used by Alembic. -revision = '241ba0a6d087' -down_revision = '15b236bd8060' - -from alembic import op -import sqlalchemy as sa - -cti_directories_table = sa.sql.table('ctidirectories', - sa.Column('id'), - sa.Column('name'), - sa.Column('directory_id')) -directory_table = sa.sql.table('directories', - sa.Column('id'), - sa.Column('name')) - - -def get_directory_id_map(conn): - query = sa.sql.select([directory_table]) - return {d.name: d.id for d in conn.execute(query)} - - -def get_cti_directory_id_map(conn): - query = sa.sql.select([cti_directories_table]) - return {d.name: d.id for d in conn.execute(query)} - - -def associate_cti_directory_to_directory(cti_directory_id, directory_id): - if not cti_directory_id or not directory_id: - return - - op.execute( - cti_directories_table - .update() - .where(cti_directories_table.c.id == cti_directory_id) - .values(directory_id=directory_id) - ) - - -def upgrade(): - conn = op.get_bind() - - directory_id_map = get_directory_id_map(conn) - cti_directory_id_map = get_cti_directory_id_map(conn) - - associate_cti_directory_to_directory(cti_directory_id_map.get('xivodir'), - directory_id_map.get('phonebook')) - - associate_cti_directory_to_directory(cti_directory_id_map.get('internal'), - directory_id_map.get('xivo')) - - -def downgrade(): - pass diff --git a/alembic/versions/2485d7c1f8e9_fix_twilio_trunk_migration.py b/alembic/versions/2485d7c1f8e9_fix_twilio_trunk_migration.py deleted file mode 100644 index 6aadfd8d..00000000 --- a/alembic/versions/2485d7c1f8e9_fix_twilio_trunk_migration.py +++ /dev/null @@ -1,68 +0,0 @@ -"""fix-twilio-trunk-migration - -Revision ID: 2485d7c1f8e9 -Revises: 8e09c6fde62d - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '2485d7c1f8e9' -down_revision = '8e09c6fde62d' - - -tenant_tbl = sa.sql.table( - 'tenant', - sa.sql.column('uuid'), - sa.sql.column('twilio_trunk_sip_template_uuid'), - sa.sql.column('sip_templates_generated'), -) -trunk_tbl = sa.sql.table( - 'trunkfeatures', - sa.sql.column('endpoint_sip_uuid'), - sa.sql.column('twilio_incoming'), -) -endpoint_sip_template_tbl = sa.sql.table( - 'endpoint_sip_template', - sa.sql.column('child_uuid'), - sa.sql.column('parent_uuid'), -) - - -def find_twilio_template_uuid(): - query = sa.sql.select( - [tenant_tbl.c.twilio_trunk_sip_template_uuid] - ).where( - tenant_tbl.c.sip_templates_generated.is_(True), - ) - return [row.twilio_trunk_sip_template_uuid for row in op.get_bind().execute(query)] - - -def find_twilio_endpoints(): - query = sa.sql.select( - [trunk_tbl.c.endpoint_sip_uuid], - ).where( - trunk_tbl.c.twilio_incoming.is_(True) - ) - return [row.endpoint_sip_uuid for row in op.get_bind().execute(query)] - - -def dissociate_non_twilio_trunks(twilio_endpoint_uuids, twilio_templates): - query = endpoint_sip_template_tbl.delete().where(sa.and_( - endpoint_sip_template_tbl.c.parent_uuid.in_(twilio_templates), - ~endpoint_sip_template_tbl.c.child_uuid.in_(twilio_endpoint_uuids), - )) - op.execute(query) - - -def upgrade(): - twilio_template_uuids = find_twilio_template_uuid() - twilio_endpoint_uuids = find_twilio_endpoints() - dissociate_non_twilio_trunks(twilio_endpoint_uuids, twilio_template_uuids) - - -def downgrade(): - pass diff --git a/alembic/versions/24b41ddb07d7_migrate_agent_func_keys.py b/alembic/versions/24b41ddb07d7_migrate_agent_func_keys.py deleted file mode 100644 index b3ef223b..00000000 --- a/alembic/versions/24b41ddb07d7_migrate_agent_func_keys.py +++ /dev/null @@ -1,313 +0,0 @@ -"""migrate agent func keys - -Revision ID: 24b41ddb07d7 -Revises: 13917b00e63c - -""" - -# revision identifiers, used by Alembic. -revision = '24b41ddb07d7' -down_revision = '13917b00e63c' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy import sql - - -TYPE_ID = 1 -DESTINATION_TYPE_ID = 11 - -ACTIONS = {'agentstaticlogtoggle': 'toggle', - 'agentstaticlogin': 'login', - 'agentstaticlogoff': 'logoff'} - -AGENT_TYPES = ('agentstaticlogtoggle', 'agentstaticlogin', 'agentstaticlogoff') - -phonefunckey_table = sql.table('phonefunckey', - sql.column('iduserfeatures'), - sql.column('fknum'), - sql.column('exten'), - sql.column('typeextenumbers'), - sql.column('typevalextenumbers'), - sql.column('typeextenumbersright'), - sql.column('typevalextenumbersright'), - sql.column('label'), - sql.column('supervision'), - sql.column('progfunckey')) - -func_key_table = sql.table('func_key', - sql.column('id'), - sql.column('type_id'), - sql.column('destination_type_id')) - -dest_agent_table = sql.table('func_key_dest_agent', - sql.column('func_key_id'), - sql.column('destination_type_id'), - sql.column('agent_id'), - sql.column('action')) - -func_key_type_table = sql.table('func_key_type', - sql.column('id'), - sql.column('name')) - -func_key_mapping_table = sql.table('func_key_mapping', - sql.column('template_id'), - sql.column('func_key_id'), - sql.column('destination_type_id'), - sql.column('label'), - sql.column('position'), - sql.column('blf')) - -template_table = sql.table('func_key_template', sql.column('id')) - -user_table = sql.table('userfeatures', - sql.column('id'), - sql.column('func_key_private_template_id')) - -destination_type_table = sql.table('func_key_destination_type', - sql.column('id'), - sql.column('name')) - -agent_table = sql.table('agentfeatures', - sql.column('id')) - - -def upgrade(): - delete_missing_agents() - delete_duplicate_agents() - create_agent_func_keys() - migrate_func_keys() - delete_old_func_keys() - - -def create_agent_func_keys(): - agent_query = sql.select([agent_table.c.id]) - rows = op.get_bind().execute(agent_query) - - for row in rows: - for action in ACTIONS.values(): - create_agent_func_key(row.id, action) - - -def delete_duplicate_agents(): - template = '[MIGRATE_FK] : Deleting duplicate agent func key for user "%s" (fk position %s)' - for row in get_duplicate_agents(): - message = template % (row.iduserfeatures, row.fknum) - delete_fk(row.iduserfeatures, row.fknum, message) - - -def get_duplicate_agents(): - columns = (phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.typevalextenumbers, - sa.func.min(phonefunckey_table.c.fknum).label("first_position")) - - duplicate_query = (sql.select(columns) - .where( - phonefunckey_table.c.typevalextenumbers.in_(AGENT_TYPES)) - .group_by( - phonefunckey_table.c.typevalextenumbers, - phonefunckey_table.c.iduserfeatures) - .having( - sa.func.count(phonefunckey_table.c.typevalextenumbers) > 1) - .alias()) - - columns = (phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.fknum) - - join_condition = phonefunckey_table.join( - duplicate_query, - sql.and_( - phonefunckey_table.c.typevalextenumbers == duplicate_query.c.typevalextenumbers, - phonefunckey_table.c.fknum > duplicate_query.c.first_position, - phonefunckey_table.c.iduserfeatures == duplicate_query.c.iduserfeatures)) - - duplicate_fk_query = sql.select(columns, from_obj=[join_condition]) - - return op.get_bind().execute(duplicate_fk_query) - - -def delete_fk(iduserfeatures, fknum, message): - print(message) - - query = (phonefunckey_table - .delete() - .where(sql.and_( - phonefunckey_table.c.iduserfeatures == iduserfeatures, - phonefunckey_table.c.fknum == fknum))) - - op.get_bind().execute(query) - - -def delete_missing_agents(): - template = '[MIGRATE_FK] : Deleting missing agent func key for user "%s" (fk position %s)' - for row in get_missing_agents(): - message = template % (row.iduserfeatures, row.fknum) - delete_fk(row.iduserfeatures, row.fknum, message) - - -def get_missing_agents(): - agent_query = sql.select([agent_table.c.id]) - - columns = (phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.fknum) - - query = (sql.select(columns) - .where( - sql.and_( - phonefunckey_table.c.typevalextenumbers.in_(AGENT_TYPES), - sql.cast(phonefunckey_table.c.typevalextenumbersright, sa.Integer) - .notin_(agent_query))) - ) - - return op.get_bind().execute(query) - - -def migrate_func_keys(): - for row in get_func_keys(): - func_key_id = find_agent_func_key_id(row.agent_id, row.action) - create_mapping(func_key_id, row) - - -def get_func_keys(): - columns = ( - phonefunckey_table.c.iduserfeatures.label('user_id'), - phonefunckey_table.c.fknum.label('position'), - phonefunckey_table.c.label, - phonefunckey_table.c.typevalextenumbers.label('action'), - sql.cast(phonefunckey_table.c.typevalextenumbersright, sa.Integer).label('agent_id'), - sql.cast(phonefunckey_table.c.supervision, sa.Boolean).label('blf'), - ) - - query = (sql.select(columns) - .where( - phonefunckey_table.c.typevalextenumbers.in_(AGENT_TYPES)) - ) - - return op.get_bind().execute(query) - - -def find_agent_func_key_id(agent_id, action): - query = (sql.select([dest_agent_table.c.func_key_id]) - .where( - sql.and_( - dest_agent_table.c.agent_id == agent_id, - dest_agent_table.c.action == ACTIONS[action])) - ) - - return op.get_bind().execute(query).scalar() - - -def create_agent_func_key(agent_id, action): - func_key_query = (func_key_table - .insert() - .returning(func_key_table.c.id) - .values(type_id=TYPE_ID, - destination_type_id=DESTINATION_TYPE_ID) - ) - - func_key_id = op.get_bind().execute(func_key_query).scalar() - - agent_query = (dest_agent_table - .insert() - .returning(dest_agent_table.c.func_key_id) - .values(func_key_id=func_key_id, - destination_type_id=DESTINATION_TYPE_ID, - agent_id=agent_id, - action=action) - ) - - op.get_bind().execute(agent_query) - - return func_key_id - - -def create_mapping(func_key_id, func_key_row): - conn = op.get_bind() - - template_query = ( - sql.select( - [user_table.c.func_key_private_template_id]) - .where( - user_table.c.id == func_key_row.user_id)) - - template_id = conn.execute(template_query).scalar() - - mapping_query = (func_key_mapping_table - .insert() - .returning(func_key_mapping_table.c.func_key_id) - .values(func_key_id=func_key_id, - template_id=template_id, - destination_type_id=DESTINATION_TYPE_ID, - label=func_key_row.label, - position=func_key_row.position, - blf=func_key_row.blf)) - - conn.execute(mapping_query) - - -def delete_old_func_keys(): - delete_query = (phonefunckey_table - .delete() - .where( - phonefunckey_table.c.typevalextenumbers.in_(AGENT_TYPES)) - ) - - op.get_bind().execute(delete_query) - - -def downgrade(): - for row in get_old_func_keys(): - create_old_func_keys(row) - delete_mapping(row.func_key_id, row.template_id) - - -def get_old_func_keys(): - columns = ( - func_key_mapping_table.c.func_key_id, - func_key_mapping_table.c.template_id, - func_key_mapping_table.c.position, - func_key_mapping_table.c.blf, - func_key_mapping_table.c.label, - dest_agent_table.c.agent_id, - dest_agent_table.c.action, - user_table.c.id.label('user_id') - ) - - join_conditions = (func_key_mapping_table - .join(dest_agent_table, - func_key_mapping_table.c.func_key_id == dest_agent_table.c.func_key_id) - .join(template_table, - func_key_mapping_table.c.template_id == template_table.c.id) - .join(user_table, - template_table.c.id == user_table.c.func_key_private_template_id)) - - query = (sql.select(columns, from_obj=[join_conditions])) - - return op.get_bind().execute(query) - - -def create_old_func_keys(row): - supervision = 1 if row.blf else 0 - reversed_actions = {value: key for key, value in ACTIONS.items()} - - row = {'iduserfeatures': row.user_id, - 'fknum': row.position, - 'typeextenumbers': 'extenfeatures', - 'typevalextenumbers': reversed_actions[row.action], - 'typeextenumbersright': 'agent', - 'typevalextenumbersright': row.agent_id, - 'label': row.label, - 'exten': None, - 'supervision': supervision} - - op.bulk_insert(phonefunckey_table, [row]) - - -def delete_mapping(func_key_id, template_id): - query = (func_key_mapping_table - .delete() - .where(sql.and_( - func_key_mapping_table.c.func_key_id == func_key_id, - func_key_mapping_table.c.template_id == template_id))) - - op.get_bind().execute(query) diff --git a/alembic/versions/255de5d2adea_update_agid_forwards_acl.py b/alembic/versions/255de5d2adea_update_agid_forwards_acl.py deleted file mode 100644 index 0636f5f6..00000000 --- a/alembic/versions/255de5d2adea_update_agid_forwards_acl.py +++ /dev/null @@ -1,54 +0,0 @@ -"""update_agid_forwards_acl - -Revision ID: 255de5d2adea -Revises: 13f4485996fd - -""" - -from alembic import op -from sqlalchemy import sql -from sqlalchemy.dialects.postgresql import ARRAY, VARCHAR - -# revision identifiers, used by Alembic. -revision = '255de5d2adea' -down_revision = '13f4485996fd' - -accesswebservice = sql.table('accesswebservice', - sql.column('id'), - sql.column('name'), - sql.column('acl')) - -OLD_ACLS = ['confd.users.*.forwards.*.*'] -NEW_ACLS = ['confd.users.*.forwards.#'] - - -def upgrade(): - _remove_acls('xivo-agid', OLD_ACLS) - _add_acls('xivo-agid', NEW_ACLS) - - -def downgrade(): - _remove_acls('xivo-agid', NEW_ACLS) - _add_acls('xivo-agid', OLD_ACLS) - - -def _add_acls(name, acls): - acl = sql.cast(acls, ARRAY(VARCHAR)) - query = (accesswebservice - .update() - .values( - acl=sql.func.array_cat(accesswebservice.c.acl, acl)) - .where( - accesswebservice.c.name == name)) - op.execute(query) - - -def _remove_acls(name, acls): - for acl in acls: - query = (accesswebservice - .update() - .values( - acl=sql.func.array_remove(accesswebservice.c.acl, acl)) - .where( - accesswebservice.c.name == name)) - op.execute(query) diff --git a/alembic/versions/267d8bd31d11_add_xivo_auth_service_acl.py b/alembic/versions/267d8bd31d11_add_xivo_auth_service_acl.py deleted file mode 100644 index 88608833..00000000 --- a/alembic/versions/267d8bd31d11_add_xivo_auth_service_acl.py +++ /dev/null @@ -1,85 +0,0 @@ -"""add_xivo_auth_service_acl - -Revision ID: 267d8bd31d11 -Revises: 379ed6d9a62 - -""" - -# revision identifiers, used by Alembic. -revision = '267d8bd31d11' -down_revision = '379ed6d9a62' - -from alembic import op -from sqlalchemy import (Column, - String, - sql) -from sqlalchemy.sql import func -from sqlalchemy.dialects.postgresql import ARRAY - - -webservice = sql.table('accesswebservice', - sql.column('name'), - sql.column('login'), - sql.column('passwd'), - sql.column('acl'), - sql.column('description')) - - -def upgrade(): - op.add_column('accesswebservice', - Column('acl', - ARRAY(String), - nullable=False, - server_default='{}')) - - op.alter_column('accesswebservice', 'description', server_default='') - - _insert_web_service('xivo-agentd-cli', - 'xivo-agentd-cli', - '{agentd.#}', - 'Automatically created during upgrade') - - _insert_web_service('xivo-agid', - 'xivo-agid', - '{dird.directories.reverse.*.*}', - 'Automatically created during upgrade') - - _insert_web_service('xivo-ctid', - 'xivo-ctid', - '{dird.#, agentd.#}', - 'Automatically created during upgrade') - - _insert_web_service('xivo-ctid-ng', - 'xivo-ctid-ng', - '{confd.#}', - 'Automatically created during upgrade') - - _insert_web_service('xivo-dird-phoned', - 'xivo-dird-phoned', - '{dird.directories.menu.*.*, dird.directories.input.*.*, dird.directories.lookup.*.*}', - 'Automatically created during upgrade') - - -def _insert_web_service(name, login, acl, description): - op.execute(webservice - .insert() - .values(name=name, - login=login, - passwd=func.substring(func.gen_salt('bf', 4), 8), - acl=acl, - description=description)) - - -def downgrade(): - op.drop_column('accesswebservice', 'acl') - _delete_web_service('xivo-agentd-cli') - _delete_web_service('xivo-agid') - _delete_web_service('xivo-ctid') - _delete_web_service('xivo-ctid-ng') - _delete_web_service('xivo-dird-phoned') - - -def _delete_web_service(name): - op.execute(webservice - .delete() - .where(webservice.c.name == name)) diff --git a/alembic/versions/27040433c098_remove_invalid_user_email.py b/alembic/versions/27040433c098_remove_invalid_user_email.py deleted file mode 100644 index e960e639..00000000 --- a/alembic/versions/27040433c098_remove_invalid_user_email.py +++ /dev/null @@ -1,80 +0,0 @@ -"""remove_invalid_user_email - -Revision ID: 27040433c098 -Revises: 1747774cead4 - -""" - -import re - -from alembic import op -from sqlalchemy import sql - -# revision identifiers, used by Alembic. -revision = '27040433c098' -down_revision = '1747774cead4' - - -userfeatures = sql.table( - 'userfeatures', - sql.column('id'), - sql.column('email'), -) - -# the following code is copy/paste from python-marshmallow Email validator -USER_REGEX = re.compile( - r"(^[-!#$%&'*+/=?^`{}|~\w]+(\.[-!#$%&'*+/=?^`{}|~\w]+)*$" # dot-atom - # quoted-string - r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]' - r'|\\[\001-\011\013\014\016-\177])*"$)', re.IGNORECASE | re.UNICODE -) - -DOMAIN_REGEX = re.compile( - # domain - r'(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+' - r'(?:[A-Z]{2,6}|[A-Z0-9-]{2,})$' - # literal form, ipv4 address (SMTP 4.1.3) - r'|^\[(25[0-5]|2[0-4]\d|[0-1]?\d?\d)' - r'(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\]$', re.IGNORECASE | re.UNICODE -) - -DOMAIN_WHITELIST = ('localhost',) - - -def _list_users(): - query = sql.select([userfeatures.c.id, userfeatures.c.email]) - return op.get_bind().execute(query).fetchall() - - -def _remove_user_email(user_id): - query = userfeatures.update().where(userfeatures.c.id == user_id).values(email=None) - return op.execute(query) - - -def _is_valid_email(email): - if not email or '@' not in email: - return False - - user_part, domain_part = email.rsplit('@', 1) - - if not USER_REGEX.match(user_part): - return False - - if domain_part in DOMAIN_WHITELIST: - return True - - if not DOMAIN_REGEX.match(domain_part): - return False - - return True - - -def upgrade(): - users = _list_users() - for user in users: - if user.email and not _is_valid_email(user.email): - _remove_user_email(user.id) - - -def downgrade(): - pass diff --git a/alembic/versions/27801f8c2a80_add_direction_to_call_log.py b/alembic/versions/27801f8c2a80_add_direction_to_call_log.py deleted file mode 100644 index c42787c5..00000000 --- a/alembic/versions/27801f8c2a80_add_direction_to_call_log.py +++ /dev/null @@ -1,21 +0,0 @@ -"""add_direction_to_call_log - -Revision ID: 27801f8c2a80 -Revises: dba4e40979ae - -""" - -# revision identifiers, used by Alembic. -revision = '27801f8c2a80' -down_revision = 'dba4e40979ae' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - op.add_column('call_log', sa.Column('direction', sa.String(255))) - - -def downgrade(): - op.drop_column('call_log', 'direction') diff --git a/alembic/versions/2796b8c839c5_remove_ulaw_everywhere.py b/alembic/versions/2796b8c839c5_remove_ulaw_everywhere.py deleted file mode 100644 index b963ee71..00000000 --- a/alembic/versions/2796b8c839c5_remove_ulaw_everywhere.py +++ /dev/null @@ -1,103 +0,0 @@ -"""remove ulaw everywhere - -Revision ID: 2796b8c839c5 -Revises: 330b1c94980d - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '2796b8c839c5' -down_revision = '330b1c94980d' - -endpoint_sip_tbl = sa.sql.table( - 'endpoint_sip', - sa.sql.column('uuid'), - sa.sql.column('name'), -) -endpoint_sip_section_tbl = sa.sql.table( - 'endpoint_sip_section', - sa.sql.column('uuid'), - sa.sql.column('type'), - sa.sql.column('endpoint_sip_uuid'), -) -endpoint_sip_section_option_tbl = sa.sql.table( - 'endpoint_sip_section_option', - sa.sql.column('value'), - sa.sql.column('key'), - sa.sql.column('endpoint_sip_section_uuid'), -) - -user_sip_tbl = sa.sql.table( - 'usersip', - sa.sql.column('name'), - sa.sql.column('allow'), -) - -def list_endpoints_with_no_codecs(): - query = sa.sql.select([user_sip_tbl.c.name]).where(sa.sql.or_( - user_sip_tbl.c.allow == None, - user_sip_tbl.c.allow == '', - )) - return [row.name for row in op.get_bind().execute(query)] - - -def list_endpoints_with_ulaw(): - query = sa.sql.select( - [endpoint_sip_tbl.c.name] - ).select_from( - endpoint_sip_tbl.join( - endpoint_sip_section_tbl, - endpoint_sip_section_tbl.c.endpoint_sip_uuid == endpoint_sip_tbl.c.uuid, - ).join( - endpoint_sip_section_option_tbl, - endpoint_sip_section_option_tbl.c.endpoint_sip_section_uuid == endpoint_sip_section_tbl.c.uuid, - ) - ).where(endpoint_sip_section_option_tbl.c.value == '!all,ulaw') - - return [row.name for row in op.get_bind().execute(query)] - - -def remove_codecs(name): - query = sa.sql.select( - [endpoint_sip_section_tbl.c.uuid] - ).select_from( - endpoint_sip_tbl.join( - endpoint_sip_section_tbl, - endpoint_sip_section_tbl.c.endpoint_sip_uuid == endpoint_sip_tbl.c.uuid, - ).join( - endpoint_sip_section_option_tbl, - endpoint_sip_section_option_tbl.c.endpoint_sip_section_uuid == endpoint_sip_section_tbl.c.uuid, - ) - ).where( - endpoint_sip_section_tbl.c.type == 'endpoint', - ).where( - endpoint_sip_tbl.c.name == name, - ).group_by(endpoint_sip_section_tbl.c.uuid) - - for row in op.get_bind().execute(query): - query = endpoint_sip_section_option_tbl.delete().where( - endpoint_sip_section_option_tbl.c.endpoint_sip_section_uuid == row.uuid, - ).where( - endpoint_sip_section_option_tbl.c.key == 'allow', - ).where( - endpoint_sip_section_option_tbl.c.value == '!all,ulaw', - ) - op.execute(query) - - -def upgrade(): - endpoints_with_no_codecs = set(list_endpoints_with_no_codecs()) - endpoints_with_ulaw_only = set(list_endpoints_with_ulaw()) - - endpoints_to_fix = endpoints_with_ulaw_only.intersection(endpoints_with_no_codecs) - - for name in endpoints_to_fix: - remove_codecs(name) - - -def downgrade(): - pass diff --git a/alembic/versions/27d9ea4b21d0_fix_func_key_type_ids.py b/alembic/versions/27d9ea4b21d0_fix_func_key_type_ids.py deleted file mode 100644 index 5031655b..00000000 --- a/alembic/versions/27d9ea4b21d0_fix_func_key_type_ids.py +++ /dev/null @@ -1,75 +0,0 @@ -"""fix func key type ids - -Revision ID: 27d9ea4b21d0 -Revises: f485ac649eb - -""" - -# revision identifiers, used by Alembic. -revision = '27d9ea4b21d0' -down_revision = '18e40e519e1b' - -from alembic import op -from sqlalchemy import sql - - -func_key_table = sql.table('func_key', - sql.column('id'), - sql.column('type_id'), - sql.column('destination_type_id')) - -func_key_type_table = sql.table('func_key_type', - sql.column('id'), - sql.column('name')) - - -def upgrade(): - connection = op.get_bind() - func_key_ids = memorize_func_key_ids() - - op.drop_constraint('func_key_type_id_fkey', 'func_key') - fix_ids('speeddial', 1, func_key_ids['speeddial']) - fix_ids('transfer', 2, func_key_ids['transfer']) - connection.execute("SELECT setval('func_key_type_id_seq', (SELECT MAX(id) FROM func_key_type))") - op.create_foreign_key('func_key_type_id_fkey', 'func_key', 'func_key_type', ['type_id'], ['id']) - - -def memorize_func_key_ids(): - func_key_ids = {} - - columns = (func_key_type_table.c.name, - func_key_table.c.id) - - join_condition = (func_key_table - .join(func_key_type_table, - func_key_type_table.c.id == func_key_table.c.type_id) - ) - - query = sql.select(columns, from_obj=[join_condition]) - - for row in op.get_bind().execute(query): - func_key_ids.setdefault(row.name, []).append(row.id) - - return func_key_ids - - -def fix_ids(fk_type, type_id, func_key_ids): - query = (func_key_table - .update() - .values(type_id=type_id) - .where(func_key_table.c.id.in_(func_key_ids)) - ) - - op.get_bind().execute(query) - - query = (func_key_type_table - .update() - .values(id=type_id) - .where(func_key_type_table.c.name == fk_type) - ) - - op.get_bind().execute(query) - - -def downgrade(): - pass diff --git a/alembic/versions/27f83f39e031_add_user_contact_part_2.py b/alembic/versions/27f83f39e031_add_user_contact_part_2.py deleted file mode 100644 index 6f773f18..00000000 --- a/alembic/versions/27f83f39e031_add_user_contact_part_2.py +++ /dev/null @@ -1,39 +0,0 @@ -"""add user_contact part 2 - -Revision ID: 27f83f39e031 -Revises: 3c14d64c95a3 - -""" - -# revision identifiers, used by Alembic. -revision = '27f83f39e031' -down_revision = '3c14d64c95a3' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - op.execute(sa.text('DROP TABLE IF EXISTS "user_contact"')) - op.create_table( - 'user_contact', - sa.Column('user_id', sa.Integer), - sa.Column('phonebook_id', sa.Integer), - sa.PrimaryKeyConstraint('user_id', 'phonebook_id'), - sa.ForeignKeyConstraint( - ['phonebook_id'], - ['phonebook.id'], - name='user_contact_phonebook_id_fkey', - ondelete='CASCADE', - ), - sa.ForeignKeyConstraint( - ['user_id'], - ['userfeatures.id'], - name='user_contact_user_id_fkey', - ondelete='CASCADE', - ), - ) - - -def downgrade(): - pass diff --git a/alembic/versions/28195459f3d1_migrate_sip_general_to_pjsip_global.py b/alembic/versions/28195459f3d1_migrate_sip_general_to_pjsip_global.py deleted file mode 100644 index a94b09d2..00000000 --- a/alembic/versions/28195459f3d1_migrate_sip_general_to_pjsip_global.py +++ /dev/null @@ -1,145 +0,0 @@ -"""migrate_sip_general_to_pjsip_global - -Revision ID: 28195459f3d1 -Revises: 6ff776dde35e - -""" - -from alembic import op -from sqlalchemy import sql - - -# revision identifiers, used by Alembic. -revision = '28195459f3d1' -down_revision = '6ff776dde35e' - -FILENAME = 'pjsip.conf' -DEFAULTS = { - 'endpoint_identifier_order': 'auth_username,username,ip', - 'user_agent': 'Wazo PBX', -} - -# Fields that are actually "translated" by wazo-confgend -SIP_TO_PJSIP_MAPPING = { - 'legacy_useroption_parsing': 'ignore_uri_user_options', - 'sipdebug': 'debug', - 'useragent': 'user_agent', -} - -# zcat /usr/share/doc/asterisk-doc/json/pjsip.json.gz | jq .global[].name | sort -u -VERBATIM_PJSIP_GLOBAL_OPTIONS = [ - "contact_expiration_check_interval", - "debug", - "default_from_user", - "default_outbound_endpoint", - "default_realm", - "default_voicemail_extension", - "disable_multi_domain", - "endpoint_identifier_order", - "ignore_uri_user_options", - "keep_alive_interval", - "max_forwards", - "max_initial_qualify_time", - "mwi_disable_initial_unsolicited", - "mwi_tps_queue_high", - "mwi_tps_queue_low", - "norefersub", - "regcontext", - "send_contact_status_on_update_registration", - "taskprocessor_overload_trigger", - "unidentified_request_count", - "unidentified_request_period", - "unidentified_request_prune_interval", - "use_callerid_contact", - "user_agent", -] - -asterisk_file_table = sql.table( - 'asterisk_file', - sql.column('id'), - sql.column('name'), -) - -asterisk_file_section_table = sql.table( - 'asterisk_file_section', - sql.column('id'), - sql.column('name'), - sql.column('priority'), - sql.column('asterisk_file_id'), -) - -asterisk_file_variable_table = sql.table( - 'asterisk_file_variable', - sql.column('id'), - sql.column('key'), - sql.column('value'), - sql.column('asterisk_file_section_id'), -) - -staticsip_table = sql.table( - 'staticsip', - sql.column('var_name'), - sql.column('var_val'), -) - - -def upgrade(): - file_id = _insert_asterisk_file(FILENAME) - section_id = _insert_asterisk_file_section(file_id, 'global', priority=0) - current_sip_options = _get_current_sip_options() - - global_options = dict(DEFAULTS) - - for var, val in current_sip_options.items(): - # Add options mapped from sip.conf - if var in SIP_TO_PJSIP_MAPPING: - global_options[SIP_TO_PJSIP_MAPPING[var]] = val - - # If the admin used pjsip.conf keys - if var in VERBATIM_PJSIP_GLOBAL_OPTIONS: - global_options[var] = val - - for var, value in global_options.items(): - # We used to store null values in the db to match the form in the UI, not anymore. - if value is None: - continue - _insert_asterisk_file_variable(section_id, var, value) - - -def _get_current_sip_options(): - query = (sql.select([staticsip_table.c.var_name, staticsip_table.c.var_val])) - return {row[0]: row[1] for row in op.get_bind().execute(query)} - - -def _insert_asterisk_file(name): - query = (asterisk_file_table - .insert() - .returning(asterisk_file_table.c.id) - .values(name=name)) - - return op.get_bind().execute(query).scalar() - - -def _insert_asterisk_file_section(file_id, name, priority=None): - query = (asterisk_file_section_table - .insert() - .returning(asterisk_file_section_table.c.id) - .values(name=name, - priority=priority, - asterisk_file_id=file_id)) - - return op.get_bind().execute(query).scalar() - - -def _insert_asterisk_file_variable(section_id, key, value): - query = (asterisk_file_variable_table - .insert() - .values(key=key, - value=value, - asterisk_file_section_id=section_id)) - - op.execute(query) - - -def downgrade(): - op.execute(asterisk_file_table.delete().where(asterisk_file_table.c.name == FILENAME)) diff --git a/alembic/versions/28443bfc4fb1_update_nat_options_auto.py b/alembic/versions/28443bfc4fb1_update_nat_options_auto.py deleted file mode 100644 index 53fca9f0..00000000 --- a/alembic/versions/28443bfc4fb1_update_nat_options_auto.py +++ /dev/null @@ -1,72 +0,0 @@ -"""update nat options auto - -Revision ID: 28443bfc4fb1 -Revises: 2251b5ae9e6c - -""" - -from alembic import op -import sqlalchemy as sa -from sqlalchemy import sql - - -# revision identifiers, used by Alembic. -revision = '28443bfc4fb1' -down_revision = '2251b5ae9e6c' - -old_options = ( - 'no', - 'force_rport', - 'comedia', - 'force_rport,comedia', - 'auto_force_rport', - 'auto_comedia', -) -new_options = old_options + ('auto_force_rport,auto_comedia',) - -new_type = sa.Enum(*new_options, name='usersip_nat') -old_type = sa.Enum(*old_options, name='usersip_nat') - -staticsip_table = sql.table('staticsip', - sql.column('var_name'), - sql.column('var_val')) - -usersip_table = sa.sql.table('usersip', - sa.sql.column('id'), - sa.sql.column('nat')) - - -def upgrade(): - _update_staticsip_nat('auto_force_rport', 'auto_force_rport,auto_comedia') - _modify_type(new_type, ('usersip', 'nat')) - _update_usersip_nat('auto_force_rport', None) - - -def downgrade(): - _update_staticsip_nat('auto_force_rport,auto_comedia', 'auto_force_rport') - _modify_type(old_type, ('usersip', 'nat')) - - -def _update_staticsip_nat(val_from, val_to): - op.execute(staticsip_table.update(). - where(sql.and_( - staticsip_table.c.var_name == 'nat', - staticsip_table.c.var_val == val_from)). - values(var_val=val_to)) - - -def _update_usersip_nat(val_from, val_to): - op.execute(usersip_table.update(). - where(sql.and_( - usersip_table.c.nat == val_from)). - values(nat=val_to)) - - -def _modify_type(type_, *table_and_columns): - op.execute('ALTER TYPE {type_name} RENAME TO tmp_{type_name}'.format(type_name=type_.name)) - type_.create(op.get_bind()) - for table, column in table_and_columns: - op.execute( - 'ALTER TABLE {table_name} ALTER COLUMN {column_name} TYPE {type_name} USING {column_name}::text::{type_name}'.format( - type_name=type_.name, table_name=table, column_name=column)) - op.execute('DROP TYPE tmp_{type_name}'.format(type_name=type_.name)) diff --git a/alembic/versions/284a6962ac4e_fix_codec_migration.py b/alembic/versions/284a6962ac4e_fix_codec_migration.py deleted file mode 100644 index 4dcea1d5..00000000 --- a/alembic/versions/284a6962ac4e_fix_codec_migration.py +++ /dev/null @@ -1,140 +0,0 @@ -"""fix-codec-migration - -Revision ID: 284a6962ac4e -Revises: 6fc79e30e8bf - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '284a6962ac4e' -down_revision = '6fc79e30e8bf' - -endpoint_sip_tbl = sa.sql.table( - 'endpoint_sip', - sa.sql.column('uuid'), - sa.sql.column('name'), -) -endpoint_sip_section_tbl = sa.sql.table( - 'endpoint_sip_section', - sa.sql.column('uuid'), - sa.sql.column('endpoint_sip_uuid'), -) -endpoint_sip_section_option_tbl = sa.sql.table( - 'endpoint_sip_section_option', - sa.sql.column('uuid'), - sa.sql.column('key'), - sa.sql.column('value'), - sa.sql.column('endpoint_sip_section_uuid'), -) -user_sip_tbl = sa.sql.table( - 'usersip', - sa.sql.column('name'), - sa.sql.column('options'), -) - - -class NoSuchEndpoint(Exception): - pass - - -def find_broken_endpoints(): - query = sa.sql.select( - [endpoint_sip_tbl.c.name], - ).select_from( - endpoint_sip_tbl.join( - endpoint_sip_section_tbl, - endpoint_sip_section_tbl.c.endpoint_sip_uuid == endpoint_sip_tbl.c.uuid, - ).join( - endpoint_sip_section_option_tbl, - endpoint_sip_section_option_tbl.c.endpoint_sip_section_uuid == endpoint_sip_section_tbl.c.uuid, - ) - ).where( - endpoint_sip_section_option_tbl.c.key == 'allow', - ).where( - endpoint_sip_section_option_tbl.c.value == '!all,ulaw', - ) - return [endpoint.name for endpoint in op.get_bind().execute(query)] - - -def get_merged_codecs(endpoint_name): - query = sa.sql.select([ - user_sip_tbl.c.options, - ]).where( - user_sip_tbl.c.name == endpoint_name, - ) - - usersip = op.get_bind().execute(query).first() - if not usersip: - raise NoSuchEndpoint() - - codecs = [] - for key, value in usersip.options: - if key == 'allow': - for codec in value.split(','): - if not codec: - continue - - if codec == '!all': - codecs = ['!all'] - else: - codecs.append(codec) - elif key == 'disallow': - for codec in value.split(','): - if not codec: - continue - - if codec == 'all': - codecs.append('!all') - else: - while codec in codecs: - codecs.remove(codec) - - return codecs - - -def update_codecs(endpoint_name, original_codecs): - query = sa.sql.select( - [endpoint_sip_section_option_tbl.c.uuid], - ).select_from( - endpoint_sip_tbl.join( - endpoint_sip_section_tbl, - endpoint_sip_section_tbl.c.endpoint_sip_uuid == endpoint_sip_tbl.c.uuid, - ).join( - endpoint_sip_section_option_tbl, - endpoint_sip_section_option_tbl.c.endpoint_sip_section_uuid == endpoint_sip_section_tbl.c.uuid, - ) - ).where( - endpoint_sip_section_option_tbl.c.key == 'allow', - ).where( - endpoint_sip_tbl.c.name == endpoint_name, - ) - option_uuid = op.get_bind().execute(query).first().uuid - - filter_ = endpoint_sip_section_option_tbl.c.uuid == option_uuid - if original_codecs: - query = endpoint_sip_section_option_tbl.update().where(filter_).values(value=','.join(original_codecs)) - else: - query = endpoint_sip_section_option_tbl.delete().where(filter_) - op.execute(query) - - -def upgrade(): - potentially_broken_endpoint_names = find_broken_endpoints() - for endpoint_name in potentially_broken_endpoint_names: - try: - original_codecs = get_merged_codecs(endpoint_name) - except NoSuchEndpoint: - continue - - if original_codecs == '!all,ulaw': - continue - - update_codecs(endpoint_name, original_codecs) - - -def downgrade(): - pass diff --git a/alembic/versions/28721fe085d3_add_group_member_extensions.py b/alembic/versions/28721fe085d3_add_group_member_extensions.py deleted file mode 100644 index c97063ed..00000000 --- a/alembic/versions/28721fe085d3_add_group_member_extensions.py +++ /dev/null @@ -1,117 +0,0 @@ -"""add group member extensions - -Revision ID: 28721fe085d3 -Revises: 872b869e9675 - -""" - -from alembic import op -import sqlalchemy as sa -from sqlalchemy import sql - - -# revision identifiers, used by Alembic. -revision = '28721fe085d3' -down_revision = '872b869e9675' - -func_key_destination_type_table = sql.table('func_key_destination_type', - sql.column('id'), - sql.column('name')) -extensions_table = sql.table('extensions', - sql.column('context'), - sql.column('exten'), - sql.column('type'), - sql.column('typeval')) - -DESTINATION_ID = 13 -DESTINATION_NAME = 'groupmember' - - -def upgrade(): - insert_query = extensions_table.insert().values( - context='xivo-features', - exten='_*50.', - type='extenfeatures', - typeval='groupmembertoggle', - ) - op.get_bind().execute(insert_query) - insert_query = extensions_table.insert().values( - context='xivo-features', - exten='_*51.', - type='extenfeatures', - typeval='groupmemberjoin', - ) - op.get_bind().execute(insert_query) - insert_query = extensions_table.insert().values( - context='xivo-features', - exten='_*52.', - type='extenfeatures', - typeval='groupmemberleave', - ) - op.get_bind().execute(insert_query) - - insert_query = func_key_destination_type_table.insert().values( - id=DESTINATION_ID, - name=DESTINATION_NAME, - ) - op.get_bind().execute(insert_query) - - op.create_table( - 'func_key_dest_groupmember', - sa.Column('func_key_id', sa.Integer), - sa.Column('destination_type_id', - sa.Integer, - sa.CheckConstraint('destination_type_id = %d' % DESTINATION_ID), - server_default=str(DESTINATION_ID)), - sa.Column('group_id', - sa.Integer, - nullable=False), - sa.Column('extension_id', - sa.Integer, - sa.ForeignKey('extensions.id'), - nullable=False), - sa.PrimaryKeyConstraint('func_key_id', 'destination_type_id'), - sa.ForeignKeyConstraint(['func_key_id', 'destination_type_id'], - ['func_key.id', 'func_key.destination_type_id']), - sa.ForeignKeyConstraint(['group_id'], ['groupfeatures.id']), - sa.UniqueConstraint('group_id', 'extension_id'), - ) - - -def downgrade(): - query = (extensions_table - .delete() - .where( - sql.and_( - extensions_table.c.type == 'extenfeatures', - extensions_table.c.typeval == 'groupmembertoggle' - ) - )) - op.get_bind().execute(query) - query = (extensions_table - .delete() - .where( - sql.and_( - extensions_table.c.type == 'extenfeatures', - extensions_table.c.typeval == 'groupmemberjoin' - ) - )) - op.get_bind().execute(query) - query = (extensions_table - .delete() - .where( - sql.and_( - extensions_table.c.type == 'extenfeatures', - extensions_table.c.typeval == 'groupmemberleave' - ) - )) - op.get_bind().execute(query) - - query = (func_key_destination_type_table - .delete() - .where( - func_key_destination_type_table.c.id == DESTINATION_ID, - )) - op.get_bind().execute(query) - - op.drop_table('func_key_dest_groupmember') diff --git a/alembic/versions/29013d7926e6_dissociate_user_from_template.py b/alembic/versions/29013d7926e6_dissociate_user_from_template.py deleted file mode 100644 index 63741d5a..00000000 --- a/alembic/versions/29013d7926e6_dissociate_user_from_template.py +++ /dev/null @@ -1,31 +0,0 @@ -"""dissociate_user_from_template - -Revision ID: 29013d7926e6 -Revises: 5a4fe661486c - -""" - -from alembic import op - -# revision identifiers, used by Alembic. -revision = '29013d7926e6' -down_revision = '5a4fe661486c' - - -def upgrade(): - op.drop_constraint('userfeatures_func_key_template_id_fkey', 'userfeatures') - op.create_foreign_key('userfeatures_func_key_template_id_fkey', - 'userfeatures', - 'func_key_template', - ['func_key_template_id'], - ['id'], - ondelete="SET NULL") - - -def downgrade(): - op.drop_constraint('userfeatures_func_key_template_id_fkey', 'userfeatures') - op.create_foreign_key('userfeatures_func_key_template_id_fkey', - 'userfeatures', - 'func_key_template', - ['func_key_template_id'], - ['id']) diff --git a/alembic/versions/2903faf08938_add_read_postfix_to_service_acls.py b/alembic/versions/2903faf08938_add_read_postfix_to_service_acls.py deleted file mode 100644 index 2fb8fdf2..00000000 --- a/alembic/versions/2903faf08938_add_read_postfix_to_service_acls.py +++ /dev/null @@ -1,44 +0,0 @@ -"""add_read_postfix_to_service_acls - -Revision ID: 2903faf08938 -Revises: 503cf85083ba - -""" - -# revision identifiers, used by Alembic. -revision = '2903faf08938' -down_revision = '503cf85083ba' - -from alembic import op -from sqlalchemy import sql - -webservice = sql.table('accesswebservice', - sql.column('name'), - sql.column('login'), - sql.column('passwd'), - sql.column('acl'), - sql.column('description')) - - -def upgrade(): - _update_web_service_acl('xivo-dird-phoned', - '{dird.directories.menu.*.*.read, dird.directories.input.*.*.read, dird.directories.lookup.*.*.read}') - - _update_web_service_acl('xivo-agid', - '{dird.directories.reverse.*.*.read}') - - -def _update_web_service_acl(name, acl): - op.execute(webservice - .update() - .where( - webservice.c.name == name - ).values(acl=acl)) - - -def downgrade(): - _update_web_service_acl('xivo-dird-phoned', - '{dird.directories.menu.*.*.read, dird.directories.input.*.*.read, dird.directories.lookup.*.*}') - - _update_web_service_acl('xivo-agid', - '{dird.directories.reverse.*.*}') diff --git a/alembic/versions/291ed250b7a2_drop_useriax_realtime_columns.py b/alembic/versions/291ed250b7a2_drop_useriax_realtime_columns.py deleted file mode 100644 index 26a6b0e7..00000000 --- a/alembic/versions/291ed250b7a2_drop_useriax_realtime_columns.py +++ /dev/null @@ -1,23 +0,0 @@ -"""drop useriax realtime columns - -Revision ID: 291ed250b7a2 -Revises: 6e196b7526a - -""" - -# revision identifiers, used by Alembic. -revision = '291ed250b7a2' -down_revision = '6e196b7526a' - -from alembic import op -from sqlalchemy import Column, Integer, String - - -def upgrade(): - op.drop_column('useriax', 'ipaddr') - op.drop_column('useriax', 'regseconds') - - -def downgrade(): - op.add_column('useriax', Column('ipaddr', String(255), nullable=False, server_default='')) - op.add_column('useriax', Column('regseconds', Integer, nullable=False, server_default='0')) diff --git a/alembic/versions/29290c38946f_fix_queuemember_interfaces.py b/alembic/versions/29290c38946f_fix_queuemember_interfaces.py deleted file mode 100644 index 23eb8907..00000000 --- a/alembic/versions/29290c38946f_fix_queuemember_interfaces.py +++ /dev/null @@ -1,34 +0,0 @@ -"""fix queuemember interfaces - -Revision ID: 29290c38946f -Revises: 241501a5f8ba - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '29290c38946f' -down_revision = '241501a5f8ba' - - -queuemember_tbl = sa.sql.table( - 'queuemember', - sa.sql.column('interface'), - sa.sql.column('channel'), -) - - -def upgrade(): - op.execute( - queuemember_tbl - .update() - .where(queuemember_tbl.c.channel == 'SIP') - .values(interface='PJ' + queuemember_tbl.c.interface) - ) - - -def downgrade(): - pass diff --git a/alembic/versions/2956eaa19c7c_remove_dialer_xlet.py b/alembic/versions/2956eaa19c7c_remove_dialer_xlet.py deleted file mode 100644 index ac15a26a..00000000 --- a/alembic/versions/2956eaa19c7c_remove_dialer_xlet.py +++ /dev/null @@ -1,45 +0,0 @@ -"""remove dialer xlet - -Revision ID: 2956eaa19c7c -Revises: 534d6112e879 - -""" - -# revision identifiers, used by Alembic. -revision = '2956eaa19c7c' -down_revision = '534d6112e879' - -from alembic import op -import sqlalchemy as sa - - -DIAL_XLET = 'dial' - - -xlet_table = sa.sql.table('cti_xlet', - sa.sql.column('id'), - sa.sql.column('plugin_name')) -profile_xlet_table = sa.sql.table('cti_profile_xlet', - sa.sql.column('xlet_id')) - - -def remove_xlet(): - remove_xlet_query = (xlet_table - .delete() - .where(xlet_table.c.plugin_name == DIAL_XLET)) - op.execute(remove_xlet_query) - - -def create_xlet(): - create_xlet_query = (xlet_table - .insert() - .values(plugin_name=DIAL_XLET)) - op.execute(create_xlet_query) - - -def upgrade(): - remove_xlet() - - -def downgrade(): - create_xlet() diff --git a/alembic/versions/2984e5ede175_add_mongooseim_acl_to_ctid_ng.py b/alembic/versions/2984e5ede175_add_mongooseim_acl_to_ctid_ng.py deleted file mode 100644 index f63563c0..00000000 --- a/alembic/versions/2984e5ede175_add_mongooseim_acl_to_ctid_ng.py +++ /dev/null @@ -1,51 +0,0 @@ -"""add_mongooseim_acl_to_ctid_ng - -Revision ID: 2984e5ede175 -Revises: 52b66f888125 - -""" - -from alembic import op -from sqlalchemy import sql -from sqlalchemy.dialects.postgresql import ARRAY, VARCHAR - -# revision identifiers, used by Alembic. -revision = '2984e5ede175' -down_revision = '52b66f888125' - -accesswebservice = sql.table('accesswebservice', - sql.column('id'), - sql.column('name'), - sql.column('acl')) - -NEW_ACLS = ['websocketd', 'websocketd.#', 'mongooseim.admin'] - - -def upgrade(): - _add_acls('xivo-ctid-ng', NEW_ACLS) - - -def downgrade(): - _remove_acls('xivo-ctid-ng', NEW_ACLS) - - -def _add_acls(name, acls): - acl = sql.cast(acls, ARRAY(VARCHAR)) - query = (accesswebservice - .update() - .values( - acl=sql.func.array_cat(accesswebservice.c.acl, acl)) - .where( - accesswebservice.c.name == name)) - op.execute(query) - - -def _remove_acls(name, acls): - for acl in acls: - query = (accesswebservice - .update() - .values( - acl=sql.func.array_remove(accesswebservice.c.acl, acl)) - .where( - accesswebservice.c.name == name)) - op.execute(query) diff --git a/alembic/versions/2989b8b30fe7_create_line_extension_table.py b/alembic/versions/2989b8b30fe7_create_line_extension_table.py deleted file mode 100644 index 5abcb3b7..00000000 --- a/alembic/versions/2989b8b30fe7_create_line_extension_table.py +++ /dev/null @@ -1,133 +0,0 @@ -"""create_line_extension_table - -Revision ID: 2989b8b30fe7 -Revises: 4bb90c6c47bb - -""" - -from alembic import op -import sqlalchemy as sa - -# revision identifiers, used by Alembic. -revision = '2989b8b30fe7' -down_revision = '4bb90c6c47bb' - - -line_extension_table = sa.sql.table('line_extension', - sa.sql.column('line_id'), - sa.sql.column('extension_id'), - sa.sql.column('main_extension')) - -user_line_table = sa.sql.table('user_line', - sa.sql.column('line_id'), - sa.sql.column('extension_id'), - sa.sql.column('main_line'), - sa.sql.column('main_user'), - sa.sql.column('user_id')) - - -def upgrade(): - _create_line_extension_table() - _populate_line_extension_from_user_line() - _remove_unused_user_line_entries() - op.drop_column('user_line', 'extension_id') - op.drop_constraint('user_line_pkey', 'user_line') - op.drop_column('user_line', 'id') - op.execute("DROP SEQUENCE IF EXISTS user_line_id_seq") # downgrade create a persistent sequence - op.drop_constraint('user_line_user_id_line_id_key', 'user_line') - op.create_primary_key('user_line_pkey', 'user_line', ['user_id', 'line_id']) - op.alter_column('user_line', 'user_id', nullable=False) - - -def _create_line_extension_table(): - op.create_table( - 'line_extension', - sa.Column('line_id', - sa.Integer, - sa.ForeignKey('linefeatures.id'), - nullable=False), - sa.Column('extension_id', - sa.Integer, - sa.ForeignKey('extensions.id'), - nullable=False), - sa.Column('main_extension', - sa.Boolean, - nullable=False), - sa.PrimaryKeyConstraint('line_id', 'extension_id'), - ) - - -def _get_all_line_extension_from_user_line(): - query = ( - sa.sql.select( - [user_line_table.c.line_id, user_line_table.c.extension_id]) - .where( - user_line_table.c.extension_id != None) # noqa - .distinct()) - return op.get_bind().execute(query).fetchall() - - -def _populate_line_extension_from_user_line(): - for line_extension in _get_all_line_extension_from_user_line(): - query = (line_extension_table - .insert() - .values(line_id=line_extension.line_id, - extension_id=line_extension.extension_id, - main_extension=True)) - op.get_bind().execute(query) - - -def _remove_unused_user_line_entries(): - query = (user_line_table - .delete() - .where(user_line_table.c.user_id == None)) # noqa - op.get_bind().execute(query) - - -def downgrade(): - op.drop_constraint('user_line_pkey', 'user_line') - op.alter_column('user_line', 'user_id', nullable=True) - op.create_unique_constraint('user_line_user_id_line_id_key', 'user_line', ['user_id', 'line_id']) - op.execute(sa.schema.CreateSequence(sa.schema.Sequence('user_line_id_seq'))) - op.add_column('user_line', sa.Column('id', - sa.Integer, - nullable=False, - server_default=sa.text("nextval('user_line_id_seq'::regclass)"))) - op.create_primary_key('user_line_pkey', 'user_line', ['id', 'line_id']) - op.add_column('user_line', sa.Column('extension_id', sa.Integer, sa.ForeignKey('extensions.id'))) - _populate_user_line_from_line_extension() - op.drop_table('line_extension') - - -def _get_all_line_extension_from_line_extension(): - query = ( - sa.sql.select( - [line_extension_table.c.line_id, line_extension_table.c.extension_id])) - return op.get_bind().execute(query).fetchall() - - -def _user_line_exists(line_id): - query = ( - sa.sql.select( - [user_line_table.c.user_id, user_line_table.c.line_id]) - .where(user_line_table.c.line_id == line_id)) - return op.get_bind().execute(query).fetchall() - - -def _populate_user_line_from_line_extension(): - for line_extension in _get_all_line_extension_from_line_extension(): - if _user_line_exists(line_extension.line_id): - query = (user_line_table - .update() - .where(user_line_table.c.line_id == line_extension.line_id) - .values(extension_id=line_extension.extension_id)) - else: - query = (user_line_table - .insert() - .values(user_id=None, - line_id=line_extension.line_id, - extension_id=line_extension.extension_id, - main_line=True, - main_user=True)) - - op.get_bind().execute(query) diff --git a/alembic/versions/2991705be1ec_bump_version_18_02.py b/alembic/versions/2991705be1ec_bump_version_18_02.py deleted file mode 100644 index 82ccbc6f..00000000 --- a/alembic/versions/2991705be1ec_bump_version_18_02.py +++ /dev/null @@ -1,22 +0,0 @@ -"""bump_version_18_02 - -Revision ID: 2991705be1ec -Revises: 18840b2fdb03 - -""" - -# revision identifiers, used by Alembic. -revision = '2991705be1ec' -down_revision = '18840b2fdb03' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='18.02')) - - -def downgrade(): - pass diff --git a/alembic/versions/29a5eab6a19b_remove_duration_and_answered_from_call_.py b/alembic/versions/29a5eab6a19b_remove_duration_and_answered_from_call_.py deleted file mode 100644 index 9eff5479..00000000 --- a/alembic/versions/29a5eab6a19b_remove_duration_and_answered_from_call_.py +++ /dev/null @@ -1,37 +0,0 @@ -"""remove_duration_and_answered_from_call_log - -Revision ID: 29a5eab6a19b -Revises: 64c6bde0116c - -""" - -# revision identifiers, used by Alembic. -revision = '29a5eab6a19b' -down_revision = '64c6bde0116c' - -from alembic import op -import sqlalchemy as sa - - -call_log = sa.sql.table('call_log', - sa.sql.column('answered'), - sa.sql.column('date'), - sa.sql.column('date_answer'), - sa.sql.column('date_end'), - sa.sql.column('duration')) - - -def upgrade(): - op.execute(call_log.update() - .where(call_log.c.date_answer == None) - .where(call_log.c.answered == True) - .values(date_answer=call_log.c.date)) - op.execute(call_log.update() - .where(call_log.c.date_end == None) - .values(date_end=call_log.c.date+call_log.c.duration)) - op.drop_column('call_log', 'answered') - op.drop_column('call_log', 'duration') - - -def downgrade(): - pass diff --git a/alembic/versions/2a24c3d1d13e_call_log_add_requested_name.py b/alembic/versions/2a24c3d1d13e_call_log_add_requested_name.py deleted file mode 100644 index af0d737b..00000000 --- a/alembic/versions/2a24c3d1d13e_call_log_add_requested_name.py +++ /dev/null @@ -1,22 +0,0 @@ -"""call_log_add_requested_name - -Revision ID: 2a24c3d1d13e -Revises: 4d736bac41cb - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '2a24c3d1d13e' -down_revision = '4d736bac41cb' - - -def upgrade(): - op.add_column('call_log', sa.Column('requested_name', sa.Text)) - - -def downgrade(): - op.drop_column('call_log', 'requested_name') diff --git a/alembic/versions/2a27e01c8070_add_greeting_sound_to_incall.py b/alembic/versions/2a27e01c8070_add_greeting_sound_to_incall.py deleted file mode 100644 index 38a04ba6..00000000 --- a/alembic/versions/2a27e01c8070_add_greeting_sound_to_incall.py +++ /dev/null @@ -1,24 +0,0 @@ -"""add-greeting-sound-to-incall - -Revision ID: 2a27e01c8070 -Revises: 4c660492b365 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '2a27e01c8070' -down_revision = '4c660492b365' - -TABLE = 'incall' - - -def upgrade(): - op.add_column(TABLE, sa.Column('greeting_sound', sa.Text)) - - -def downgrade(): - op.drop_column(TABLE, 'greeting_sound') diff --git a/alembic/versions/2acff5c02871_change_datax_columns_to_type_text.py b/alembic/versions/2acff5c02871_change_datax_columns_to_type_text.py deleted file mode 100644 index 08d69933..00000000 --- a/alembic/versions/2acff5c02871_change_datax_columns_to_type_text.py +++ /dev/null @@ -1,30 +0,0 @@ -"""change dataX columns to type text - -Revision ID: 2acff5c02871 -Revises: 501dae22d6be - -""" - -# revision identifiers, used by Alembic. -revision = '2acff5c02871' -down_revision = '501dae22d6be' - -from alembic import op -from sqlalchemy.types import Text - - -def upgrade(): - op.alter_column('queue_log', 'data1', type_=Text) - op.alter_column('queue_log', 'data2', type_=Text) - op.alter_column('queue_log', 'data3', type_=Text) - op.alter_column('queue_log', 'data4', type_=Text) - op.alter_column('queue_log', 'data5', type_=Text) - op.alter_column('queue_log', 'data1', server_default='') - op.alter_column('queue_log', 'data2', server_default='') - op.alter_column('queue_log', 'data3', server_default='') - op.alter_column('queue_log', 'data4', server_default='') - op.alter_column('queue_log', 'data5', server_default='') - - -def downgrade(): - pass diff --git a/alembic/versions/2b0f5ee268c4_remove_orphan_lines.py b/alembic/versions/2b0f5ee268c4_remove_orphan_lines.py deleted file mode 100644 index d48d1290..00000000 --- a/alembic/versions/2b0f5ee268c4_remove_orphan_lines.py +++ /dev/null @@ -1,37 +0,0 @@ -"""remove orphan lines - -Revision ID: 2b0f5ee268c4 -Revises: 3133fb4958ef - -""" - -# revision identifiers, used by Alembic. -revision = '2b0f5ee268c4' -down_revision = '3133fb4958ef' - -from alembic import op -from sqlalchemy import sql - - -linefeatures_table = sql.table('linefeatures', - sql.column('id'), - sql.column('protocol'), - sql.column('protocolid'), - sql.column('device')) -user_line_table = sql.table('user_line', - sql.column('line_id')) - - -def upgrade(): - op.execute(linefeatures_table - .delete() - .where( - sql.and_( - linefeatures_table.c.protocol == None, - linefeatures_table.c.protocolid == None, - linefeatures_table.c.id.notin_(sql.select([user_line_table.c.line_id]))) - )) - - -def downgrade(): - pass diff --git a/alembic/versions/2b51ff81d388_add_the_meetingjoin_extenfeatures.py b/alembic/versions/2b51ff81d388_add_the_meetingjoin_extenfeatures.py deleted file mode 100644 index 88f59840..00000000 --- a/alembic/versions/2b51ff81d388_add_the_meetingjoin_extenfeatures.py +++ /dev/null @@ -1,46 +0,0 @@ -"""add the meetingjoin extenfeatures - -Revision ID: 2b51ff81d388 -Revises: 55cd08a0dae2 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '2b51ff81d388' -down_revision = '55cd08a0dae2' - -extensions_table = sa.sql.table( - 'extensions', - sa.sql.column('context'), - sa.sql.column('exten'), - sa.sql.column('type'), - sa.sql.column('typeval'), -) -FEATURE_NAME = 'meetingjoin' - - -def upgrade(): - insert_query = extensions_table.insert().values( - context='xivo-features', - exten='_*41.', - type='extenfeatures', - typeval=FEATURE_NAME, - ) - op.get_bind().execute(insert_query) - - -def downgrade(): - query = (extensions_table - .delete() - .where( - sa.sql.and_( - extensions_table.c.type == 'extenfeatures', - extensions_table.c.typeval == FEATURE_NAME, - ) - ) - ) - op.get_bind().execute(query) diff --git a/alembic/versions/2b5d68fa7ab8_bump_version_21_07.py b/alembic/versions/2b5d68fa7ab8_bump_version_21_07.py deleted file mode 100644 index 10583660..00000000 --- a/alembic/versions/2b5d68fa7ab8_bump_version_21_07.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_21_07 - -Revision ID: 2b5d68fa7ab8 -Revises: 060e2360612f - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '2b5d68fa7ab8' -down_revision = '060e2360612f' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='21.07')) - - -def downgrade(): - pass diff --git a/alembic/versions/2b65d248c2ad_meeting_require_authorization_not_null.py b/alembic/versions/2b65d248c2ad_meeting_require_authorization_not_null.py deleted file mode 100644 index 374a8e56..00000000 --- a/alembic/versions/2b65d248c2ad_meeting_require_authorization_not_null.py +++ /dev/null @@ -1,21 +0,0 @@ -"""meeting: require authorization not null - -Revision ID: 2b65d248c2ad -Revises: c9ed2541b284 - -""" - -from alembic import op - - -# revision identifiers, used by Alembic. -revision = '2b65d248c2ad' -down_revision = 'c9ed2541b284' - - -def upgrade(): - op.alter_column('meeting', 'require_authorization', nullable=False) - - -def downgrade(): - op.alter_column('meeting', 'require_authorization', nullable=True) diff --git a/alembic/versions/2ba2f1d009ca_add_autoprov_acl_to_xivo_agid.py b/alembic/versions/2ba2f1d009ca_add_autoprov_acl_to_xivo_agid.py deleted file mode 100644 index 67ad2e55..00000000 --- a/alembic/versions/2ba2f1d009ca_add_autoprov_acl_to_xivo_agid.py +++ /dev/null @@ -1,52 +0,0 @@ -"""add autoprov acl to xivo-agid - -Revision ID: 2ba2f1d009ca -Revises: 2b0f5ee268c4 - -""" - -# revision identifiers, used by Alembic. -revision = '2ba2f1d009ca' -down_revision = '2b0f5ee268c4' - -from alembic import op -from sqlalchemy import sql -from sqlalchemy.dialects.postgresql import ARRAY, VARCHAR - - -NEW_ACLS = ['confd.devices.*.autoprov.read'] - -accesswebservice = sql.table('accesswebservice', - sql.column('id'), - sql.column('name'), - sql.column('acl')) - - -def upgrade(): - _add_acls('xivo-agid', NEW_ACLS) - - -def downgrade(): - _remove_acls('xivo-agid', NEW_ACLS) - - -def _add_acls(name, acls): - acl = sql.cast(acls, ARRAY(VARCHAR)) - query = (accesswebservice - .update() - .values( - acl=sql.func.array_cat(accesswebservice.c.acl, acl)) - .where( - accesswebservice.c.name == name)) - op.execute(query) - - -def _remove_acls(name, acls): - for acl in acls: - query = (accesswebservice - .update() - .values( - acl=sql.func.array_remove(accesswebservice.c.acl, acl)) - .where( - accesswebservice.c.name == name)) - op.execute(query) diff --git a/alembic/versions/2bb55c201ee7_bump_version_21_01.py b/alembic/versions/2bb55c201ee7_bump_version_21_01.py deleted file mode 100644 index 47750518..00000000 --- a/alembic/versions/2bb55c201ee7_bump_version_21_01.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_21_01 - -Revision ID: 2bb55c201ee7 -Revises: b1dfaf771da8 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '2bb55c201ee7' -down_revision = 'b1dfaf771da8' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='21.01')) - - -def downgrade(): - pass diff --git a/alembic/versions/2bb6543883a6_make_directory_fields_format_strings.py b/alembic/versions/2bb6543883a6_make_directory_fields_format_strings.py deleted file mode 100644 index fe06c19c..00000000 --- a/alembic/versions/2bb6543883a6_make_directory_fields_format_strings.py +++ /dev/null @@ -1,48 +0,0 @@ -"""Make cti directory fields format strings - -Revision ID: 2bb6543883a6 -Revises: 444b39e9aa32 - -""" - -# revision identifiers, used by Alembic. -revision = '2bb6543883a6' -down_revision = '444b39e9aa32' - -from alembic import op -from sqlalchemy import sql, and_ - -fields_table = sql.table('ctidirectoryfields', - sql.column('dir_id'), - sql.column('fieldname'), - sql.column('value')) - - -def upgrade(): - conn = op.get_bind() - rows = conn.execute(sql.select([fields_table.c.dir_id, - fields_table.c.fieldname, - fields_table.c.value]).where(~fields_table.c.value.like('{%}'))) - to_upgrade = {(row.dir_id, row.fieldname): row.value for row in rows} - for (dir_id, fieldname), value in to_upgrade.items(): - new_value = '{%s}' % '} {'.join(value.split(' ')) - op.execute(fields_table - .update() - .where(and_(fields_table.c.dir_id == dir_id, - fields_table.c.fieldname == fieldname)) - .values(value=new_value)) - - -def downgrade(): - conn = op.get_bind() - rows = conn.execute(sql.select([fields_table.c.dir_id, - fields_table.c.fieldname, - fields_table.c.value])) - to_upgrade = {(row.dir_id, row.fieldname): row.value for row in rows} - for (dir_id, fieldname), value in to_upgrade.items(): - new_value = value.replace('{', '').replace('}', '') - op.execute(fields_table - .update() - .where(and_(fields_table.c.dir_id == dir_id, - fields_table.c.fieldname == fieldname)) - .values(value=new_value)) diff --git a/alembic/versions/2c004153ed7f_make_user_uuid_unique.py b/alembic/versions/2c004153ed7f_make_user_uuid_unique.py deleted file mode 100644 index f28c6d2a..00000000 --- a/alembic/versions/2c004153ed7f_make_user_uuid_unique.py +++ /dev/null @@ -1,20 +0,0 @@ -"""make user.uuid unique - -Revision ID: 2c004153ed7f -Revises: 1c3eb7380750 - -""" - -# revision identifiers, used by Alembic. -revision = '2c004153ed7f' -down_revision = '1c3eb7380750' - -from alembic import op - - -def upgrade(): - op.create_unique_constraint('userfeatures_uuid', 'userfeatures', ['uuid']) - - -def downgrade(): - op.drop_constraint('userfeatures_uuid', 'userfeatures') diff --git a/alembic/versions/2c6c9833d839_remove_unused_indexes_on_cel_and_qlog_.py b/alembic/versions/2c6c9833d839_remove_unused_indexes_on_cel_and_qlog_.py deleted file mode 100644 index dae5e252..00000000 --- a/alembic/versions/2c6c9833d839_remove_unused_indexes_on_cel_and_qlog_.py +++ /dev/null @@ -1,22 +0,0 @@ -"""remove unused indexes on cel and qlog tables - -Revision ID: 2c6c9833d839 -Revises: 30f88b362201 - -""" - -# revision identifiers, used by Alembic. -revision = '2c6c9833d839' -down_revision = '30f88b362201' - -from alembic import op - - -def upgrade(): - op.drop_index('cel__idx__uniqueid') - op.drop_index('queue_log__idx_queuename') - - -def downgrade(): - op.create_index('cel__idx__uniqueid', 'cel', ['uniqueid']) - op.create_index('queue_log__idx_queuename', 'queue_log', ['queuename']) diff --git a/alembic/versions/2c940e077157_add_xivo_configured.py b/alembic/versions/2c940e077157_add_xivo_configured.py deleted file mode 100644 index 40b6e402..00000000 --- a/alembic/versions/2c940e077157_add_xivo_configured.py +++ /dev/null @@ -1,33 +0,0 @@ -"""add_xivo_configured - -Revision ID: 2c940e077157 -Revises: 2ba2f1d009ca - -""" - -from alembic import op -from sqlalchemy import Column, sql -from sqlalchemy.types import Boolean - -# revision identifiers, used by Alembic. -revision = '2c940e077157' -down_revision = '2ba2f1d009ca' - -general = sql.table('general', - sql.column('configured')) - - -def upgrade(): - op.add_column('general', - Column('configured', - Boolean, - nullable=False, - server_default='False')) - - op.execute(general - .update() - .values(configured=True)) - - -def downgrade(): - op.drop_column('general', 'configured') diff --git a/alembic/versions/2cbd52dd69e1_bump_version_20_05.py b/alembic/versions/2cbd52dd69e1_bump_version_20_05.py deleted file mode 100644 index 54420b8f..00000000 --- a/alembic/versions/2cbd52dd69e1_bump_version_20_05.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_20_05 - -Revision ID: 2cbd52dd69e1 -Revises: 1c95890bb00d - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '2cbd52dd69e1' -down_revision = '1c95890bb00d' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='20.05')) - - -def downgrade(): - pass diff --git a/alembic/versions/2d0b0356eb76_add_cel_extra.py b/alembic/versions/2d0b0356eb76_add_cel_extra.py deleted file mode 100644 index 51c09f12..00000000 --- a/alembic/versions/2d0b0356eb76_add_cel_extra.py +++ /dev/null @@ -1,21 +0,0 @@ -"""add cel extra - -Revision ID: 2d0b0356eb76 -Revises: 3ecc983a901c - -""" - -# revision identifiers, used by Alembic. -revision = '2d0b0356eb76' -down_revision = '3ecc983a901c' - -from alembic import op -from sqlalchemy import Column, Text - - -def upgrade(): - op.add_column('cel', Column('extra', Text)) - - -def downgrade(): - op.drop_column('cel', 'extra') diff --git a/alembic/versions/2d3d29858d6d_create_func_key_paging.py b/alembic/versions/2d3d29858d6d_create_func_key_paging.py deleted file mode 100644 index 626cd489..00000000 --- a/alembic/versions/2d3d29858d6d_create_func_key_paging.py +++ /dev/null @@ -1,50 +0,0 @@ -"""create func key paging - - -Revision ID: 2d3d29858d6d -Revises: e0fd01d4c2a - -""" - -# revision identifiers, used by Alembic. -revision = '2d3d29858d6d' -down_revision = 'e0fd01d4c2a' - -from alembic import op -import sqlalchemy as sa - - -PAGING_TYPE_ID = 9 -PAGING_TYPE_NAME = 'paging' - -destination_type_table = sa.sql.table('func_key_destination_type', - sa.sql.column('id'), - sa.sql.column('name')) - - -def upgrade(): - parking_type_row = {'id': PAGING_TYPE_ID, 'name': PAGING_TYPE_NAME} - op.bulk_insert(destination_type_table, [parking_type_row]) - - op.create_table( - 'func_key_dest_paging', - sa.Column('func_key_id', sa.Integer), - sa.Column('destination_type_id', - sa.Integer, - sa.CheckConstraint('destination_type_id = %d' % PAGING_TYPE_ID), - server_default=str(PAGING_TYPE_ID)), - sa.Column('paging_id', sa.Integer), - sa.PrimaryKeyConstraint('func_key_id', 'destination_type_id', 'paging_id'), - sa.ForeignKeyConstraint(['func_key_id', 'destination_type_id'], - ['func_key.id', 'func_key.destination_type_id']), - sa.ForeignKeyConstraint(['paging_id'], ['paging.id']) - ) - - -def downgrade(): - op.drop_table('func_key_dest_paging') - - delete_query = (destination_type_table - .delete() - .where(destination_type_table.c.id == PAGING_TYPE_ID)) - op.execute(delete_query) diff --git a/alembic/versions/2ea8d6cb26f6_rename_enableautomon_to_enableonlinerec.py b/alembic/versions/2ea8d6cb26f6_rename_enableautomon_to_enableonlinerec.py deleted file mode 100644 index e97d1359..00000000 --- a/alembic/versions/2ea8d6cb26f6_rename_enableautomon_to_enableonlinerec.py +++ /dev/null @@ -1,20 +0,0 @@ -"""rename enableautomon to enableonlinerec - -Revision ID: 2ea8d6cb26f6 -Revises: 86511ef5d49 - -""" - -# revision identifiers, used by Alembic. -revision = '2ea8d6cb26f6' -down_revision = '86511ef5d49' - -from alembic import op - - -def upgrade(): - op.alter_column('userfeatures', 'enableautomon', new_column_name='enableonlinerec') - - -def downgrade(): - op.alter_column('userfeatures', 'enableonlinerec', new_column_name='enableautomon') diff --git a/alembic/versions/2f354a1653fc_add_deleted_col_to_stat_tables.py b/alembic/versions/2f354a1653fc_add_deleted_col_to_stat_tables.py deleted file mode 100644 index dea18986..00000000 --- a/alembic/versions/2f354a1653fc_add_deleted_col_to_stat_tables.py +++ /dev/null @@ -1,29 +0,0 @@ -"""add_deleted_col_to_stat_tables - -Revision ID: 2f354a1653fc -Revises: b1c4be6f46ff - -""" - -from alembic import op -import sqlalchemy as sa - -# revision identifiers, used by Alembic. -revision = '2f354a1653fc' -down_revision = 'b1c4be6f46ff' - - -def upgrade(): - op.add_column( - 'stat_queue', - sa.Column('deleted', sa.Boolean, nullable=False, server_default='false'), - ) - op.add_column( - 'stat_agent', - sa.Column('deleted', sa.Boolean, nullable=False, server_default='false'), - ) - - -def downgrade(): - op.drop_column('stat_agent', 'deleted') - op.drop_column('stat_queue', 'deleted') diff --git a/alembic/versions/2f69acadecbe_create_conference_table.py b/alembic/versions/2f69acadecbe_create_conference_table.py deleted file mode 100644 index 8c6f1b67..00000000 --- a/alembic/versions/2f69acadecbe_create_conference_table.py +++ /dev/null @@ -1,36 +0,0 @@ -"""create_conference_table - -Revision ID: 2f69acadecbe -Revises: 176660b8b2c3 - -""" - -# revision identifiers, used by Alembic. -revision = '2f69acadecbe' -down_revision = '176660b8b2c3' - -from alembic import op -from sqlalchemy import Column, Boolean, Integer, PrimaryKeyConstraint, String - - -def upgrade(): - op.create_table( - 'conference', - Column('id', Integer), - Column('name', String(128)), - Column('preprocess_subroutine', String(39)), - Column('max_users', Integer, nullable=False, server_default='50'), - Column('record', Boolean, nullable=False, server_default='False'), - Column('pin', String(80)), - Column('admin_pin', String(80)), - Column('quiet_join_leave', Boolean, nullable=False, server_default='False'), - Column('announce_join_leave', Boolean, nullable=False, server_default='False'), - Column('announce_user_count', Boolean, nullable=False, server_default='False'), - Column('announce_only_user', Boolean, nullable=False, server_default='True'), - Column('music_on_hold', String(128)), - PrimaryKeyConstraint('id'), - ) - - -def downgrade(): - op.drop_table('conference') diff --git a/alembic/versions/2f7e5c4119bc_add_xivo_directory_fields.py b/alembic/versions/2f7e5c4119bc_add_xivo_directory_fields.py deleted file mode 100644 index 417b81c2..00000000 --- a/alembic/versions/2f7e5c4119bc_add_xivo_directory_fields.py +++ /dev/null @@ -1,32 +0,0 @@ -"""add xivo directory fields - -Revision ID: 2f7e5c4119bc -Revises: 537774d3845a - -""" - -# revision identifiers, used by Alembic. -revision = '2f7e5c4119bc' -down_revision = '537774d3845a' - -from alembic import op -from sqlalchemy.schema import Column -from sqlalchemy.types import Boolean, Text - - -def upgrade(): - op.add_column('directories', - Column('xivo_username', Text)) - op.add_column('directories', - Column('xivo_password', Text)) - op.add_column('directories', - Column('xivo_verify_certificate', Boolean, nullable=False, server_default='False')) - op.add_column('directories', - Column('xivo_custom_ca_path', Text)) - - -def downgrade(): - op.drop_column('directories', 'xivo_username') - op.drop_column('directories', 'xivo_password') - op.drop_column('directories', 'xivo_verify_certificate') - op.drop_column('directories', 'xivo_custom_ca_path') diff --git a/alembic/versions/2fbbd4231cca_remove_phonebook_configuration.py b/alembic/versions/2fbbd4231cca_remove_phonebook_configuration.py deleted file mode 100644 index f2117159..00000000 --- a/alembic/versions/2fbbd4231cca_remove_phonebook_configuration.py +++ /dev/null @@ -1,80 +0,0 @@ -"""remove phonebook configuration - -Revision ID: 2fbbd4231cca -Revises: 56a9a83c26b3 - -""" - -# revision identifiers, used by Alembic. -revision = '2fbbd4231cca' -down_revision = '56a9a83c26b3' - -import json - -from alembic import op -from sqlalchemy import sql, and_ - - -directories = sql.table('directories', - sql.column('id'), - sql.column('dirtype')) -cti_directories = sql.table('ctidirectories', - sql.column('id'), - sql.column('name'), - sql.column('directory_id')) -cti_contexts = sql.table('cticontexts', - sql.column('id'), - sql.column('name'), - sql.column('directories')) -cti_reverse = sql.table('ctireversedirectories', - sql.column('id'), - sql.column('directories')) - - -def list_cti_directories(conn, type_): - query = sql.select( - [cti_directories] - ).where(and_(cti_directories.c.directory_id == directories.c.id, - directories.c.dirtype == type_)) - return [directory for directory in conn.execute(query)] - - -def remove_from_direct_directories(conn, name): - query = sql.select([cti_contexts]).where(cti_contexts.c.directories.ilike('%{}%'.format(name))) - for context in conn.execute(query): - directories = context.directories.split(',') - if name not in directories: - continue - directories.remove(name) - op.execute(cti_contexts - .update() - .where(cti_contexts.c.id == context.id) - .values({'directories': ','.join(directories)})) - - -def remove_from_reverse_directories(conn, name): - query = sql.select([cti_reverse]).where(cti_reverse.c.directories.ilike('%{}%'.format(name))) - for reverse in conn.execute(query): - directories = json.loads(reverse.directories) - if name not in directories: - continue - directories.remove(name) - op.execute(cti_reverse - .update() - .where(cti_reverse.c.id == reverse.id) - .values({'directories': json.dumps(directories)})) - - -def upgrade(): - conn = op.get_bind() - - names = [d.name for d in list_cti_directories(conn, 'phonebook')] - for name in names: - remove_from_direct_directories(conn, name) - remove_from_reverse_directories(conn, name) - - op.execute(directories.delete().where(directories.c.dirtype == 'phonebook')) - - -def downgrade(): - pass diff --git a/alembic/versions/2fe87e2b9580_add_user_specific_recording_options.py b/alembic/versions/2fe87e2b9580_add_user_specific_recording_options.py deleted file mode 100644 index 311a639f..00000000 --- a/alembic/versions/2fe87e2b9580_add_user_specific_recording_options.py +++ /dev/null @@ -1,60 +0,0 @@ -"""add-user-specific-recording-options - -Revision ID: 2fe87e2b9580 -Revises: 203f6f2cf0a0 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '2fe87e2b9580' -down_revision = '203f6f2cf0a0' - -user_tbl = sa.sql.table( - 'userfeatures', - sa.sql.column('callrecord'), - sa.sql.column('call_record_outgoing_external_enabled'), - sa.sql.column('call_record_outgoing_internal_enabled'), - sa.sql.column('call_record_incoming_external_enabled'), - sa.sql.column('call_record_incoming_internal_enabled'), -) - - -def upgrade(): - _add_user_bool_column('call_record_outgoing_external_enabled') - _add_user_bool_column('call_record_outgoing_internal_enabled') - _add_user_bool_column('call_record_incoming_external_enabled') - _add_user_bool_column('call_record_incoming_internal_enabled') - call_record = sa.sql.cast(user_tbl.c.callrecord, sa.Boolean) - query = ( - user_tbl.update() - .values( - call_record_outgoing_external_enabled=call_record, - call_record_outgoing_internal_enabled=call_record, - call_record_incoming_external_enabled=call_record, - call_record_incoming_internal_enabled=call_record, - ) - ) - op.execute(query) - op.drop_column('userfeatures', 'callrecord') - - -def _add_user_bool_column(name): - op.add_column( - 'userfeatures', - sa.Column(name, sa.Boolean, nullable=False, server_default='false') - ) - - -def downgrade(): - op.add_column( - 'userfeatures', - sa.Column('callrecord', sa.Integer, nullable=False, server_default='0') - ) - op.drop_column('userfeatures', 'call_record_outgoing_external_enabled') - op.drop_column('userfeatures', 'call_record_outgoing_internal_enabled') - op.drop_column('userfeatures', 'call_record_incoming_external_enabled') - op.drop_column('userfeatures', 'call_record_incoming_internal_enabled') diff --git a/alembic/versions/30271471ab8_remove_rightcallmember_incall_enum.py b/alembic/versions/30271471ab8_remove_rightcallmember_incall_enum.py deleted file mode 100644 index b097641d..00000000 --- a/alembic/versions/30271471ab8_remove_rightcallmember_incall_enum.py +++ /dev/null @@ -1,42 +0,0 @@ -"""remove_rightcallmember_incall_enum - -Revision ID: 30271471ab8 -Revises: e4f459f58795 - -""" - -from alembic import op -import sqlalchemy as sa - -# revision identifiers, used by Alembic. -revision = '30271471ab8' -down_revision = 'e4f459f58795' - -rightcallmember_type = sa.Enum('user', 'group', 'incall', 'outcall', name='rightcallmember_type') -rightcallmember = sa.sql.table('rightcallmember', sa.Column('type')) - - -def upgrade(): - op.execute( - rightcallmember - .delete() - .where(rightcallmember.c.type == 'incall') - ) - op.alter_column('rightcallmember', 'type', type_=sa.String(64)) - - op.create_check_constraint( - 'rightcallmember_type_check', - 'rightcallmember', - sa.sql.column('type').in_([ - 'group', - 'outcall', - 'user' - ]) - ) - rightcallmember_type.drop(op.get_bind(), checkfirst=False) - - -def downgrade(): - rightcallmember_type.create(op.get_bind()) - op.drop_constraint('rightcallmember_type_check', 'rightcallmember') - op.execute('ALTER TABLE rightcallmember ALTER COLUMN type TYPE rightcallmember_type USING type::text::rightcallmember_type') diff --git a/alembic/versions/30564ea14542_remove_voicemail_type.py b/alembic/versions/30564ea14542_remove_voicemail_type.py deleted file mode 100644 index e29fbd56..00000000 --- a/alembic/versions/30564ea14542_remove_voicemail_type.py +++ /dev/null @@ -1,32 +0,0 @@ -"""remove voicemail redundancy - -Revision ID: 30564ea14542 -Revises: 41f6ef3f00fe - -""" - -from alembic import op -import sqlalchemy as sa - -# revision identifiers, used by Alembic. -revision = '30564ea14542' -down_revision = '41f6ef3f00fe' - - -def upgrade(): - op.drop_column('userfeatures', 'voicemailtype') - op.drop_column('usersip', 'mailbox') - op.drop_column('sccpdevice', 'voicemail') - op.execute("DROP TYPE IF EXISTS userfeatures_voicemailtype") - - -def downgrade(): - op.add_column('userfeatures', - sa.Column('voicemailtype', - sa.Enum('asterisk', 'exchange', - name='userfeatures_voicemailtype'))) - - op.add_column('usersip', sa.Column('mailbox', sa.String(80))) - op.add_column('sccpdevice', - sa.Column('voicemail', - sa.String(80), nullable=False, server_default='')) diff --git a/alembic/versions/3096b11582cf_group_timeout_may_be_null.py b/alembic/versions/3096b11582cf_group_timeout_may_be_null.py deleted file mode 100644 index 87d2d462..00000000 --- a/alembic/versions/3096b11582cf_group_timeout_may_be_null.py +++ /dev/null @@ -1,28 +0,0 @@ -"""group timeout may be null - -Revision ID: 3096b11582cf -Revises: 4cf59c82b51e - -""" - -# revision identifiers, used by Alembic. -revision = '3096b11582cf' -down_revision = '4cf59c82b51e' - -from alembic import op -import sqlalchemy as sa - - -groupfeatures_table = sa.sql.table('groupfeatures', - sa.Column('timeout', sa.Integer)) - - -def upgrade(): - op.alter_column('groupfeatures', 'timeout', server_default=None, nullable=True) - - -def downgrade(): - op.execute(groupfeatures_table.update(). - where(groupfeatures_table.c.timeout == None). - values(timeout='0')) - op.alter_column('groupfeatures', 'timeout', server_default='0', nullable=False) diff --git a/alembic/versions/30d59d9b4b6e_remove_exchange_voicemail.py b/alembic/versions/30d59d9b4b6e_remove_exchange_voicemail.py deleted file mode 100644 index 632b9056..00000000 --- a/alembic/versions/30d59d9b4b6e_remove_exchange_voicemail.py +++ /dev/null @@ -1,25 +0,0 @@ -"""remove exchange voicemail - -Revision ID: 30d59d9b4b6e -Revises: 18cb96cb384 - -""" - -# revision identifiers, used by Alembic. -revision = '30d59d9b4b6e' -down_revision = '18cb96cb384' - -from alembic import op - -from sqlalchemy.types import Integer, String -from sqlalchemy.schema import Column - - -def upgrade(): - op.drop_column('general', 'exchange_trunkid') - op.drop_column('general', 'exchange_exten') - - -def downgrade(): - op.add_column('general', Column('exchange_trunkid', Integer)) - op.add_column('general', Column('exchange_exten', String(128))) diff --git a/alembic/versions/30d7dcbb9133_add_web_service_uuid.py b/alembic/versions/30d7dcbb9133_add_web_service_uuid.py deleted file mode 100644 index dcb82d0b..00000000 --- a/alembic/versions/30d7dcbb9133_add_web_service_uuid.py +++ /dev/null @@ -1,34 +0,0 @@ -"""add web service UUID - -Revision ID: 30d7dcbb9133 -Revises: 53fbfa53b47c - -""" - -# revision identifiers, used by Alembic. -revision = '30d7dcbb9133' -down_revision = '53fbfa53b47c' - -from alembic import op -import sqlalchemy as sa - - -table_name = 'accesswebservice' -column_name = 'uuid' -constraint_name = '{}_{}_key'.format(table_name, column_name) - - -def upgrade(): - op.add_column( - table_name, - sa.Column( - column_name, - sa.String(38), - nullable=False, - server_default=sa.text('uuid_generate_v4()'))) - op.create_unique_constraint(constraint_name, table_name, [column_name]) - - -def downgrade(): - op.drop_constraint(constraint_name, table_name) - op.drop_column(table_name, column_name) diff --git a/alembic/versions/30eebcef63ad_delete_sessions.py b/alembic/versions/30eebcef63ad_delete_sessions.py deleted file mode 100644 index 5b219837..00000000 --- a/alembic/versions/30eebcef63ad_delete_sessions.py +++ /dev/null @@ -1,23 +0,0 @@ -"""delete sessions - -Revision ID: 30eebcef63ad -Revises: ab2956a0168 - -""" - -# revision identifiers, used by Alembic. -revision = '30eebcef63ad' -down_revision = 'ab2956a0168' - -from alembic import op -from sqlalchemy import sql - -session = sql.table('session') - - -def upgrade(): - op.execute(session.delete()) - - -def downgrade(): - pass diff --git a/alembic/versions/30f88b362201_alter_queueskill_drop_printscreen.py b/alembic/versions/30f88b362201_alter_queueskill_drop_printscreen.py deleted file mode 100644 index c18a83e0..00000000 --- a/alembic/versions/30f88b362201_alter_queueskill_drop_printscreen.py +++ /dev/null @@ -1,22 +0,0 @@ -"""alter queueskill drop printscreen - -Revision ID: 30f88b362201 -Revises: 31eecc16c5c5 - -""" - -# revision identifiers, used by Alembic. -revision = '30f88b362201' -down_revision = '31eecc16c5c5' - -from alembic import op -from sqlalchemy.schema import Column -from sqlalchemy.types import String - - -def upgrade(): - op.drop_column('queueskill', 'printscreen') - - -def downgrade(): - op.add_column('queueskill', Column('printscreen', String(5))) diff --git a/alembic/versions/3133fb4958ef_add_acls_to_xivo_ctid_ng.py b/alembic/versions/3133fb4958ef_add_acls_to_xivo_ctid_ng.py deleted file mode 100644 index 77c648d4..00000000 --- a/alembic/versions/3133fb4958ef_add_acls_to_xivo_ctid_ng.py +++ /dev/null @@ -1,40 +0,0 @@ -"""add ACLs to xivo-ctid-ng - - -Revision ID: 3133fb4958ef -Revises: 1b6be5d5e4ac - -""" - -# revision identifiers, used by Alembic. -revision = '3133fb4958ef' -down_revision = '1b6be5d5e4ac' - -from alembic import op -from sqlalchemy import sql - - -webservice = sql.table('accesswebservice', - sql.column('name'), - sql.column('login'), - sql.column('passwd'), - sql.column('acl'), - sql.column('description')) - - -def upgrade(): - _update_web_service_acl('xivo-ctid-ng', - '{confd.#, amid.action.Redirect.create, amid.action.Setvar.create}') - - -def _update_web_service_acl(name, acl): - op.execute(webservice - .update() - .where( - webservice.c.name == name - ).values(acl=acl)) - - -def downgrade(): - _update_web_service_acl('xivo-ctid-ng', - '{confd.#}') diff --git a/alembic/versions/315f74edddb1_remove_nullable_constraint_.py b/alembic/versions/315f74edddb1_remove_nullable_constraint_.py deleted file mode 100644 index 6b5bd34e..00000000 --- a/alembic/versions/315f74edddb1_remove_nullable_constraint_.py +++ /dev/null @@ -1,20 +0,0 @@ -"""remove_nullable_constraint_queueskillrule - -Revision ID: 315f74edddb1 -Revises: 1f272484c083 - -""" - -from alembic import op - -# revision identifiers, used by Alembic. -revision = '315f74edddb1' -down_revision = '1f272484c083' - - -def upgrade(): - op.alter_column('queueskillrule', 'name', nullable=True, server_default=None) - - -def downgrade(): - op.alter_column('queueskillrule', 'name', nullable=False, server_default='') diff --git a/alembic/versions/3196befc4753_remove_custom_moh_directory.py b/alembic/versions/3196befc4753_remove_custom_moh_directory.py deleted file mode 100644 index 8ddb28c8..00000000 --- a/alembic/versions/3196befc4753_remove_custom_moh_directory.py +++ /dev/null @@ -1,62 +0,0 @@ -"""remove custom moh directory - -Revision ID: 3196befc4753 -Revises: 6bfd932df2c - -""" - -# revision identifiers, used by Alembic. -revision = '3196befc4753' -down_revision = '6bfd932df2c' - -from alembic import op -from sqlalchemy import sql - -musiconhold = sql.table('musiconhold', - sql.column('id'), - sql.column('category'), - sql.column('var_name'), - sql.column('var_val'), - sql.column('filename')) - - -def upgrade(): - custom_moh_query = sql.select( - [musiconhold.c.category] - ).where( - sql.and_( - musiconhold.c.var_name == 'mode', - musiconhold.c.var_val == 'custom' - )) - - query = (musiconhold.delete() - .where( - sql.and_( - musiconhold.c.var_name == 'directory', - musiconhold.c.category.in_(custom_moh_query)))) - - op.execute(query) - - -def downgrade(): - directory_query = sql.select( - [musiconhold.c.category.label('category'), - sql.literal_column("'directory'").label('var_name'), - sql.literal_column("'/var/lib/xivo/moh/' || category").label('var_val'), - sql.literal_column("'musiconhold.conf'").label('filename')] - ).where( - sql.and_( - musiconhold.c.var_name == 'mode', - musiconhold.c.var_val == 'custom')) - - query = (musiconhold - .insert() - .returning(musiconhold.c.id) - .from_select( - [musiconhold.c.category, - musiconhold.c.var_name, - musiconhold.c.var_val, - musiconhold.c.filename], - directory_query)) - - op.execute(query) diff --git a/alembic/versions/31eecc16c5c5_migrate_service_func_keys_without_.py b/alembic/versions/31eecc16c5c5_migrate_service_func_keys_without_.py deleted file mode 100644 index 7d5fff06..00000000 --- a/alembic/versions/31eecc16c5c5_migrate_service_func_keys_without_.py +++ /dev/null @@ -1,299 +0,0 @@ -"""migrate_service_func_keys_without_parameters - -Revision ID: 31eecc16c5c5 -Revises: 486c0749403c - -""" - -# revision identifiers, used by Alembic. -revision = '31eecc16c5c5' -down_revision = '486c0749403c' - -from alembic import op -import sqlalchemy as sa - - -TYPE_SPEEDDIAL = 'speeddial' - -DESTINATION_SERVICE_ID = 5 -DESTINATION_SERVICE_NAME = 'service' - -SERVICE_TYPES = ('phonestatus', - 'recsnd', - 'calllistening', - 'directoryaccess', - 'fwdundoall', - 'pickup', - 'callrecord', - 'incallfilter', - 'enablednd') - -phonefunckey_table = sa.sql.table('phonefunckey', - sa.sql.column('iduserfeatures'), - sa.sql.column('fknum'), - sa.sql.column('exten'), - sa.sql.column('typeextenumbers'), - sa.sql.column('typevalextenumbers'), - sa.sql.column('typeextenumbersright'), - sa.sql.column('typevalextenumbersright'), - sa.sql.column('label'), - sa.sql.column('supervision'), - sa.sql.column('progfunckey')) - -func_key_table = sa.sql.table('func_key', - sa.sql.column('id'), - sa.sql.column('type_id'), - sa.sql.column('destination_type_id')) - -destination_service_table = sa.sql.table('func_key_dest_service', - sa.sql.column('func_key_id'), - sa.sql.column('destination_type_id'), - sa.sql.column('extension_id')) - -func_key_type_table = sa.sql.table('func_key_type', - sa.sql.column('id'), - sa.sql.column('name')) - -func_key_mapping_table = sa.sql.table('func_key_mapping', - sa.sql.column('template_id'), - sa.sql.column('func_key_id'), - sa.sql.column('destination_type_id'), - sa.sql.column('label'), - sa.sql.column('position'), - sa.sql.column('blf')) - -template_table = sa.sql.table('func_key_template', - sa.sql.column('id')) - -extensions_table = sa.sql.table('extensions', - sa.sql.column('id'), - sa.sql.column('commented'), - sa.sql.column('context'), - sa.sql.column('exten'), - sa.sql.column('type'), - sa.sql.column('typeval')) - -user_table = sa.sql.table('userfeatures', - sa.sql.column('id'), - sa.sql.column('func_key_private_template_id')) - -destination_type_table = sa.sql.table('func_key_destination_type', - sa.sql.column('id'), - sa.sql.column('name')) - -blf_cast = sa.sql.cast(phonefunckey_table.c.supervision, sa.Boolean) - -service_func_keys_query = (sa.sql.select([phonefunckey_table.c.iduserfeatures.label('user_id'), - phonefunckey_table.c.fknum.label('position'), - phonefunckey_table.c.label, - phonefunckey_table.c.typevalextenumbers, - blf_cast.label('blf')]) - .where(phonefunckey_table.c.typevalextenumbers - .in_(SERVICE_TYPES))) - - -old_func_keys_query = (sa.sql.select([func_key_mapping_table.c.func_key_id, - func_key_mapping_table.c.template_id, - func_key_mapping_table.c.position, - func_key_mapping_table.c.blf, - func_key_mapping_table.c.label, - destination_service_table.c.extension_id, - extensions_table.c.typeval, - user_table.c.id.label('user_id')], - from_obj=[ - func_key_mapping_table.join( - destination_service_table, - func_key_mapping_table.c.func_key_id == destination_service_table.c.func_key_id) - .join(extensions_table, - destination_service_table.c.extension_id == extensions_table.c.id) - .join(template_table, - func_key_mapping_table.c.template_id == template_table.c.id) - .join(user_table, - template_table.c.id == user_table.c.func_key_private_template_id)]) - .where(extensions_table.c.typeval.in_(SERVICE_TYPES))) - - -def _delete_duplicate_fks(): - for row in _get_duplicate_func_keys(): - _delete_duplicate_fk(row.iduserfeatures, row.typevalextenumbers, row.fknum) - - -def _get_duplicate_func_keys(): - valid_fk_subq = sa.sql.select([phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.typevalextenumbers, - sa.func.min(phonefunckey_table.c.fknum).label("first_position")]).\ - where(phonefunckey_table.c.typevalextenumbers.in_(SERVICE_TYPES)).\ - group_by(phonefunckey_table.c.iduserfeatures, phonefunckey_table.c.typevalextenumbers).\ - having(sa.func.count(phonefunckey_table.c.typevalextenumbers) > 1).\ - alias() - - duplicate_fk_query = (sa.sql.select([phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.typevalextenumbers, - phonefunckey_table.c.fknum], - from_obj=[ - phonefunckey_table.join( - valid_fk_subq, - sa.sql.and_( - phonefunckey_table.c.typevalextenumbers == valid_fk_subq.c.typevalextenumbers, - phonefunckey_table.c.fknum > valid_fk_subq.c.first_position, - phonefunckey_table.c.iduserfeatures == valid_fk_subq.c.iduserfeatures) - ) - ] - )) - - return op.get_bind().execute(duplicate_fk_query) - - -def _delete_duplicate_fk(iduserfeatures, typevalextenumbers, fknum): - print('[MIGRATE_FK] : Deleting func key for user "%s" (fk position %s with action %s)' % - (iduserfeatures, fknum, typevalextenumbers)) - query = (phonefunckey_table - .delete() - .where(sa.sql.and_( - phonefunckey_table.c.iduserfeatures == iduserfeatures, - phonefunckey_table.c.typevalextenumbers == typevalextenumbers, - phonefunckey_table.c.fknum == fknum))) - - op.get_bind().execute(query) - - -def upgrade(): - _delete_duplicate_fks() - func_key_ids = _pregenerate_fk_destinations() - _migrate_func_keys(func_key_ids) - _delete_old_func_keys() - - -def _pregenerate_fk_destinations(): - func_key_ids = {} - for typeval in SERVICE_TYPES: - func_key_id = func_key_ids[typeval] = _create_func_key() - extension_id = _get_extension_id_from_type(typeval) - _create_service_destination(func_key_id, extension_id) - return func_key_ids - - -def _create_func_key(): - speeddial_id = _get_speeddial_id() - insert_query = (func_key_table - .insert() - .returning(func_key_table.c.id) - .values(type_id=speeddial_id, - destination_type_id=DESTINATION_SERVICE_ID)) - - return op.get_bind().execute(insert_query).scalar() - - -def _get_speeddial_id(): - return op.get_bind().execute( - sa.sql.select( - [func_key_type_table.c.id]) - .where( - func_key_type_table.c.name == TYPE_SPEEDDIAL) - ).scalar() - - -def _get_extension_id_from_type(extentype): - return op.get_bind().execute( - sa.sql.select( - [extensions_table.c.id]) - .where( - extensions_table.c.typeval == extentype) - ).scalar() - - -def _create_service_destination(func_key_id, extension_id): - destination_query = (destination_service_table - .insert() - .returning(destination_service_table.c.func_key_id) - .values(func_key_id=func_key_id, - destination_type_id=DESTINATION_SERVICE_ID, - extension_id=extension_id)) - - op.get_bind().execute(destination_query) - - -def _migrate_func_keys(func_key_ids): - for row in op.get_bind().execute(service_func_keys_query): - _create_mapping(func_key_ids[row.typevalextenumbers], row) - - -def _create_mapping(func_key_id, func_key_row): - conn = op.get_bind() - - template_id = conn.execute(sa.sql.select( - [user_table.c.func_key_private_template_id]) - .where( - user_table.c.id == func_key_row.user_id) - ).scalar() - - mapping_query = (func_key_mapping_table - .insert() - .returning(func_key_mapping_table.c.func_key_id) - .values(func_key_id=func_key_id, - template_id=template_id, - destination_type_id=DESTINATION_SERVICE_ID, - label=func_key_row.label, - position=func_key_row.position, - blf=func_key_row.blf)) - - conn.execute(mapping_query) - - -def _delete_old_func_keys(): - delete_query = (phonefunckey_table - .delete() - .where(phonefunckey_table.c.typevalextenumbers - .in_(SERVICE_TYPES))) - - op.get_bind().execute(delete_query) - - -def downgrade(): - for row in op.get_bind().execute(old_func_keys_query): - _create_old_func_keys(row) - _delete_mapping(row.func_key_id, row.template_id) - _delete_dest_service(row.func_key_id) - _delete_func_key(row.func_key_id) - - -def _create_old_func_keys(row): - supervision = 1 if row.blf else 0 - - row = {'iduserfeatures': row.user_id, - 'fknum': row.position, - 'typeextenumbers': 'extenfeatures', - 'typevalextenumbers': row.typeval, - 'typeextenumbersright': None, - 'typevalextenumbersright': None, - 'label': row.label, - 'supervision': supervision} - - op.bulk_insert(phonefunckey_table, [row]) - - -def _delete_mapping(func_key_id, template_id): - query = (func_key_mapping_table - .delete() - .where(sa.sql.and_( - func_key_mapping_table.c.func_key_id == func_key_id, - func_key_mapping_table.c.template_id == template_id))) - - op.get_bind().execute(query) - - -def _delete_dest_service(func_key_id): - query = (destination_service_table - .delete() - .where( - destination_service_table.c.func_key_id == func_key_id)) - - op.get_bind().execute(query) - - -def _delete_func_key(func_key_id): - query = (func_key_table - .delete() - .where(func_key_table.c.id == func_key_id)) - - op.get_bind().execute(query) diff --git a/alembic/versions/320d05ebad29_set_call_limit_default_to_10.py b/alembic/versions/320d05ebad29_set_call_limit_default_to_10.py deleted file mode 100644 index e5f61dc3..00000000 --- a/alembic/versions/320d05ebad29_set_call_limit_default_to_10.py +++ /dev/null @@ -1,20 +0,0 @@ -"""set call limit default to 10 - -Revision ID: 320d05ebad29 -Revises: 20d4630f2c8e - -""" - -from alembic import op - -# revision identifiers, used by Alembic. -revision = '320d05ebad29' -down_revision = '20d4630f2c8e' - - -def upgrade(): - op.alter_column("usersip", "call-limit", server_default="10") - - -def downgrade(): - op.alter_column("usersip", "call-limit", server_default="0") diff --git a/alembic/versions/324ad441b84c_add_wazo_plugind_cli_acl.py b/alembic/versions/324ad441b84c_add_wazo_plugind_cli_acl.py deleted file mode 100644 index c8be3019..00000000 --- a/alembic/versions/324ad441b84c_add_wazo_plugind_cli_acl.py +++ /dev/null @@ -1,38 +0,0 @@ -"""add wazo-plugind-cli acl - -Revision ID: 324ad441b84c -Revises: 13472f54a7 - -""" - -# revision identifiers, used by Alembic. -revision = '324ad441b84c' -down_revision = '13472f54a7' - -from alembic import op -from sqlalchemy import sql, func - - -webservice = sql.table('accesswebservice', - sql.column('name'), - sql.column('login'), - sql.column('passwd'), - sql.column('acl'), - sql.column('description')) -ACL = '{plugind.plugins.create, plugind.plugins.*.*.delete}' -DESCRIPTION = 'Automatically created during upgrade' -SERVICE = 'wazo-plugind-cli' - - -def upgrade(): - op.execute(webservice - .insert() - .values(name=SERVICE, - login=SERVICE, - passwd=func.substring(func.gen_salt('bf', 4), 8), - acl=ACL, - description=DESCRIPTION)) - - -def downgrade(): - op.execute(webservice.delete().where(webservice.c.name == SERVICE)) diff --git a/alembic/versions/3284584a535c_remove_nullable_constraint_pwd_vm.py b/alembic/versions/3284584a535c_remove_nullable_constraint_pwd_vm.py deleted file mode 100644 index d8aed4f4..00000000 --- a/alembic/versions/3284584a535c_remove_nullable_constraint_pwd_vm.py +++ /dev/null @@ -1,20 +0,0 @@ -"""remove_nullable_constraint_pwd_vm - -Revision ID: 3284584a535c -Revises: 58d561775bf3 - -""" - -# revision identifiers, used by Alembic. -revision = '3284584a535c' -down_revision = '58d561775bf3' - -from alembic import op - - -def upgrade(): - op.alter_column('voicemail', 'password', nullable=True, server_default=None) - - -def downgrade(): - op.alter_column('voicemail', 'password', nullable=False, server_default='') diff --git a/alembic/versions/330b1c94980d_remove_outbound_auth_key.py b/alembic/versions/330b1c94980d_remove_outbound_auth_key.py deleted file mode 100644 index 564ae892..00000000 --- a/alembic/versions/330b1c94980d_remove_outbound_auth_key.py +++ /dev/null @@ -1,30 +0,0 @@ -"""remove outbound-auth key - -Revision ID: 330b1c94980d -Revises: 284a6962ac4e - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '330b1c94980d' -down_revision = '284a6962ac4e' - -endpoint_sip_section_option_tbl = sa.sql.table( - 'endpoint_sip_section_option', - sa.sql.column('key'), -) - - -def upgrade(): - query = endpoint_sip_section_option_tbl.delete().where( - endpoint_sip_section_option_tbl.c.key == 'outbound_auth', - ) - op.execute(query) - - -def downgrade(): - pass diff --git a/alembic/versions/3314b25783a2_bump_version_22_02.py b/alembic/versions/3314b25783a2_bump_version_22_02.py deleted file mode 100644 index b791e8bb..00000000 --- a/alembic/versions/3314b25783a2_bump_version_22_02.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_22_02 - -Revision ID: 3314b25783a2 -Revises: 0dd3509ac1e2 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '3314b25783a2' -down_revision = '0dd3509ac1e2' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='22.02')) - - -def downgrade(): - pass diff --git a/alembic/versions/333cd1b1d31_add_dtmf_hangup_to_userfeatures.py b/alembic/versions/333cd1b1d31_add_dtmf_hangup_to_userfeatures.py deleted file mode 100644 index 68372df1..00000000 --- a/alembic/versions/333cd1b1d31_add_dtmf_hangup_to_userfeatures.py +++ /dev/null @@ -1,35 +0,0 @@ -"""add_dtmf_hangup_to_userfeatures - -Revision ID: 333cd1b1d31 -Revises: 56e683a865e0 - -""" - -# revision identifiers, used by Alembic. -revision = '333cd1b1d31' -down_revision = '56e683a865e0' - - -from sqlalchemy import Column, sql -from sqlalchemy.types import Integer -from alembic import op - -userfeatures = sql.table('userfeatures', sql.column('dtmf_hangup')) - - -def upgrade(): - op.add_column('userfeatures', Column('dtmf_hangup', Integer, nullable=False, server_default='0')) - _activate_dtmf_hangup() - - op.alter_column('userfeatures', 'enablexfer', server_default='0') - - -def _activate_dtmf_hangup(): - op.execute(userfeatures - .update() - .values(dtmf_hangup='1')) - - -def downgrade(): - op.drop_column('userfeatures', 'dtmf_hangup') - op.alter_column('userfeatures', 'enablexfer', server_default='1') diff --git a/alembic/versions/337f76c25478_update_internal_directory.py b/alembic/versions/337f76c25478_update_internal_directory.py deleted file mode 100644 index c63bfbdc..00000000 --- a/alembic/versions/337f76c25478_update_internal_directory.py +++ /dev/null @@ -1,63 +0,0 @@ -"""update internal directory - -Revision ID: 337f76c25478 -Revises: 20debb21dc01 - -""" - -# revision identifiers, used by Alembic. -revision = '337f76c25478' -down_revision = '20debb21dc01' - -from alembic import op -from sqlalchemy import sql, and_, or_ - -fields_table = sql.table('ctidirectoryfields', - sql.column('dir_id'), - sql.column('fieldname'), - sql.column('value')) -directories = sql.table('ctidirectories', - sql.column('id'), - sql.column('uri'), - sql.column('match_direct'), - sql.column('match_reverse')) - - -def _clean(field): - return field.replace('userfeatures.', '').replace('extensions.', '') - - -def _update_fields(conn): - rows = conn.execute(sql.select([fields_table.c.dir_id, - fields_table.c.fieldname, - fields_table.c.value]) - .where(or_(fields_table.c.value.like('{userfeatures.%}'), - fields_table.c.value.like('{extensions.%}')))) - for row in rows: - op.execute(fields_table - .update() - .where(and_(fields_table.c.dir_id == row.dir_id, - fields_table.c.fieldname == row.fieldname)) - .values(value=_clean(row.value))) - - -def _update_directories(conn): - rows = conn.execute(sql.select([directories]) - .where(directories.c.uri == 'http://localhost:9487')) - configs = {row.id: {'match_direct': row.match_direct, - 'match_reverse': row.match_reverse} for row in rows} - for id_, config in configs.items(): - op.execute(directories.update() - .where(directories.c.id == id_) - .values(match_direct=_clean(config['match_direct']), - match_reverse=_clean(config['match_reverse']))) - - -def upgrade(): - conn = op.get_bind() - _update_fields(conn) - _update_directories(conn) - - -def downgrade(): - pass diff --git a/alembic/versions/33e0cdb6971d_create_func_key_features.py b/alembic/versions/33e0cdb6971d_create_func_key_features.py deleted file mode 100644 index cbe3cb32..00000000 --- a/alembic/versions/33e0cdb6971d_create_func_key_features.py +++ /dev/null @@ -1,134 +0,0 @@ -"""create func key features - -Revision ID: 33e0cdb6971d -Revises: 4c13318f6975 - -""" - -# revision identifiers, used by Alembic. -revision = '33e0cdb6971d' -down_revision = '4c13318f6975' - -from alembic import op -import sqlalchemy as sa - - -PARKING_TYPE = 'parkext' - -TRANSFER_TYPE_NAME = 'transfer' - -FEATURES_DESTINATION_ID = 8 -FEATURES_DESTINATION_NAME = 'features' - - -func_key_table = sa.sql.table('func_key', - sa.sql.column('id'), - sa.sql.column('type_id'), - sa.sql.column('destination_type_id')) - -func_key_type_table = sa.sql.table('func_key_type', - sa.sql.column('id'), - sa.sql.column('name')) - -func_key_destination_type_table = sa.sql.table('func_key_destination_type', - sa.sql.column('id'), - sa.sql.column('name')) - -func_key_dest_features_table = sa.sql.table('func_key_dest_features', - sa.sql.column('func_key_id'), - sa.sql.column('destination_type_id'), - sa.sql.column('features_id')) - -features_table = sa.sql.table('features', - sa.sql.column('id'), - sa.sql.column('category'), - sa.sql.column('var_name')) - - -def upgrade(): - type_id = insert_transfer_type() - destination_type_id = insert_features_destination_type() - create_dest_features_table() - insert_parking_func_key(type_id, destination_type_id) - - -def insert_transfer_type(): - query = (func_key_type_table - .insert() - .returning(func_key_type_table.c.id) - .values(name=TRANSFER_TYPE_NAME)) - - return op.get_bind().execute(query).scalar() - - -def insert_features_destination_type(): - query = (func_key_destination_type_table - .insert() - .returning(func_key_destination_type_table.c.id) - .values(id=FEATURES_DESTINATION_ID, - name=FEATURES_DESTINATION_NAME)) - - return op.get_bind().execute(query).scalar() - - -def create_dest_features_table(): - op.create_table( - 'func_key_dest_features', - sa.Column('func_key_id', sa.Integer), - sa.Column('destination_type_id', - sa.Integer, - sa.CheckConstraint('destination_type_id = %d' % FEATURES_DESTINATION_ID), - server_default=str(FEATURES_DESTINATION_ID)), - sa.Column('features_id', sa.Integer), - sa.PrimaryKeyConstraint('func_key_id', 'destination_type_id', 'features_id'), - sa.ForeignKeyConstraint(['func_key_id', 'destination_type_id'], - ['func_key.id', 'func_key.destination_type_id']), - sa.ForeignKeyConstraint(['features_id'], ['features.id']) - ) - - -def insert_parking_func_key(type_id, destination_type_id): - func_key_query = (func_key_table - .insert() - .returning(func_key_table.c.id) - .values(type_id=type_id, - destination_type_id=destination_type_id)) - - func_key_id = op.get_bind().execute(func_key_query).scalar() - - features_query = ( - sa.sql.select( - [features_table.c.id]) - .where( - sa.sql.and_( - features_table.c.category == 'general', - features_table.c.var_name == PARKING_TYPE))) - - features_id = op.get_bind().execute(features_query).scalar() - - dest_query = (func_key_dest_features_table - .insert() - .returning(func_key_dest_features_table.c.func_key_id) - .values(func_key_id=func_key_id, - destination_type_id=destination_type_id, - features_id=features_id)) - - return op.get_bind().execute(dest_query).scalar() - - -def downgrade(): - op.execute(func_key_dest_features_table.delete()) - - op.execute(func_key_table - .delete() - .where(func_key_table.c.destination_type_id == FEATURES_DESTINATION_ID)) - - op.execute(func_key_destination_type_table - .delete() - .where(func_key_destination_type_table.c.id == FEATURES_DESTINATION_ID)) - - op.execute(func_key_type_table - .delete() - .where(func_key_type_table.c.name == TRANSFER_TYPE_NAME)) - - op.drop_table('func_key_dest_features') diff --git a/alembic/versions/33fa1a10428f_add_moh_table.py b/alembic/versions/33fa1a10428f_add_moh_table.py deleted file mode 100644 index 96b083d0..00000000 --- a/alembic/versions/33fa1a10428f_add_moh_table.py +++ /dev/null @@ -1,32 +0,0 @@ -"""add moh table - -Revision ID: 33fa1a10428f -Revises: 34122e276b2 - -""" - -# revision identifiers, used by Alembic. -revision = '33fa1a10428f' -down_revision = '34122e276b2' - -from alembic import op -from sqlalchemy import Column, PrimaryKeyConstraint, String, Text, UniqueConstraint - - -def upgrade(): - op.create_table( - 'moh', - Column('uuid', String(38), nullable=False), - Column('name', Text, nullable=False), - Column('label', Text), - Column('mode', Text, nullable=False), - Column('application', Text), - Column('sort', Text), - PrimaryKeyConstraint('uuid'), - UniqueConstraint('name'), - ) - - - -def downgrade(): - op.drop_table('moh') diff --git a/alembic/versions/34122e276b2_bump_version_17_03.py b/alembic/versions/34122e276b2_bump_version_17_03.py deleted file mode 100644 index cd4d6d35..00000000 --- a/alembic/versions/34122e276b2_bump_version_17_03.py +++ /dev/null @@ -1,22 +0,0 @@ -"""bump_version_17_03 - -Revision ID: 34122e276b2 -Revises: c3b40a0998c4 - -""" - -# revision identifiers, used by Alembic. -revision = '34122e276b2' -down_revision = 'c3b40a0998c4' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='17.03')) - - -def downgrade(): - pass diff --git a/alembic/versions/341f7e584088_remove_old_phonebook.py b/alembic/versions/341f7e584088_remove_old_phonebook.py deleted file mode 100644 index 4485c058..00000000 --- a/alembic/versions/341f7e584088_remove_old_phonebook.py +++ /dev/null @@ -1,41 +0,0 @@ -"""remove old phonebook - -Revision ID: 341f7e584088 -Revises: 43a39441ae83 - -""" - -# revision identifiers, used by Alembic. -revision = '341f7e584088' -down_revision = '43a39441ae83' - -from alembic import op -from sqlalchemy import sql - -cti_directory_fields = sql.table('ctidirectoryfields', sql.column('dir_id')) -cti_directories = sql.table('ctidirectories', sql.column('id')) -directories = sql.table('directories', sql.column('dirtype')) - - -def upgrade(): - conn = op.get_bind() - - remove_unused_fields(conn) - op.create_foreign_key('ctidirectoryfields_dir_id_fkey', - 'ctidirectoryfields', 'ctidirectories', - ['dir_id'], ['id'], - ondelete='CASCADE') - - op.execute(directories.delete() - .where(directories.c.dirtype == 'phonebook')) - - -def downgrade(): - pass - - -def remove_unused_fields(conn): - query = sql.select([cti_directories]) - ids = [d.id for d in conn.execute(query)] - op.execute(cti_directory_fields.delete() - .where(~cti_directory_fields.c.dir_id.in_(ids))) diff --git a/alembic/versions/3420040c5650_add_confd_acls_to_agid.py b/alembic/versions/3420040c5650_add_confd_acls_to_agid.py deleted file mode 100644 index f84be035..00000000 --- a/alembic/versions/3420040c5650_add_confd_acls_to_agid.py +++ /dev/null @@ -1,47 +0,0 @@ -"""add_confd_acls_to_agid - -Revision ID: 3420040c5650 -Revises: 7f1c1c00662 - -""" - -from alembic import op -from sqlalchemy import sql -from sqlalchemy.dialects.postgresql import ARRAY, VARCHAR - -# revision identifiers, used by Alembic. -revision = '3420040c5650' -down_revision = '7f1c1c00662' - - -accesswebservice = sql.table('accesswebservice', - sql.column('id'), - sql.column('name'), - sql.column('acl')) - -ACLS = ['confd.lines.read', - 'confd.devices.read', - 'confd.lines.*.devices.*.update', - 'confd.devices.*.synchronize.read'] - - -def upgrade(): - acls = sql.cast(ACLS, ARRAY(VARCHAR)) - query = (accesswebservice - .update() - .values( - acl=sql.func.array_cat(accesswebservice.c.acl, acls)) - .where( - accesswebservice.c.name == "xivo-agid")) - op.execute(query) - - -def downgrade(): - for acl in ACLS: - query = (accesswebservice - .update() - .values( - acl=sql.func.array_remove(accesswebservice.c.acl, acl)) - .where( - accesswebservice.c.name == "xivo-agid")) - op.execute(query) diff --git a/alembic/versions/3462497a56f8_add_tenants_acl_to_the_wizard.py b/alembic/versions/3462497a56f8_add_tenants_acl_to_the_wizard.py deleted file mode 100644 index 2967e4ab..00000000 --- a/alembic/versions/3462497a56f8_add_tenants_acl_to_the_wizard.py +++ /dev/null @@ -1,46 +0,0 @@ -"""add tenants acl to the wizard - -Revision ID: 3462497a56f8 -Revises: 01b4c79b3d47 - -""" - -from alembic import op -from sqlalchemy import sql - -# revision identifiers, used by Alembic. -revision = '3462497a56f8' -down_revision = '01b4c79b3d47' - -webservice = sql.table('accesswebservice', - sql.column('name'), - sql.column('acl')) - -SERVICE = 'xivo-wizard' -NEW_ACL = set(['auth.tenants.create']) - - -def _get_current_acl(name): - return set(op.get_bind().execute( - sql.select([webservice.c.acl]).where(webservice.c.name == name) - ).scalar()) - - -def _update_web_service_acl(name, acl): - op.execute(webservice - .update() - .where( - webservice.c.name == name - ).values(acl=list(acl))) - - -def upgrade(): - current_acls = _get_current_acl(SERVICE) - new_acls = current_acls | NEW_ACL - _update_web_service_acl(SERVICE, new_acls) - - -def downgrade(): - current_acls = _get_current_acl(SERVICE) - new_acls = current_acls - NEW_ACL - _update_web_service_acl(SERVICE, new_acls) diff --git a/alembic/versions/34748356e196_bump_version_18_07.py b/alembic/versions/34748356e196_bump_version_18_07.py deleted file mode 100644 index 1ab0f3e0..00000000 --- a/alembic/versions/34748356e196_bump_version_18_07.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_18_07 - -Revision ID: 34748356e196 -Revises: b5c40615bc21 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '34748356e196' -down_revision = 'b5c40615bc21' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='18.07')) - - -def downgrade(): - pass diff --git a/alembic/versions/34b2b6ca345e_bump_version_19_13.py b/alembic/versions/34b2b6ca345e_bump_version_19_13.py deleted file mode 100644 index 2dd62abc..00000000 --- a/alembic/versions/34b2b6ca345e_bump_version_19_13.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_19_13 - -Revision ID: 34b2b6ca345e -Revises: 43995f4ac823 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '34b2b6ca345e' -down_revision = '43995f4ac823' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='19.13')) - - -def downgrade(): - pass diff --git a/alembic/versions/354fe6b9e819_sccpline_add_tenant_uuid.py b/alembic/versions/354fe6b9e819_sccpline_add_tenant_uuid.py deleted file mode 100644 index 22d41d4b..00000000 --- a/alembic/versions/354fe6b9e819_sccpline_add_tenant_uuid.py +++ /dev/null @@ -1,64 +0,0 @@ -"""sccpline_add_tenant_uuid - -Revision ID: 354fe6b9e819 -Revises: 4a0281e1a826 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '354fe6b9e819' -down_revision = '4a0281e1a826' - -TABLE = 'sccpline' - - -def find_default_tenant_uuid(): - entity_table = sa.sql.table( - 'entity', - sa.sql.column('id'), - sa.sql.column('name'), - sa.sql.column('tenant_uuid'), - ) - query = sa.sql.select([entity_table.c.tenant_uuid]).order_by(entity_table.c.id) - for row in op.get_bind().execute(query): - return row.tenant_uuid - - -def associate_tenants(): - tbl = sa.sql.table('sccpline', sa.sql.column('id'), sa.sql.column('tenant_uuid')) - sql = "SELECT sccpline.id, context.tenant_uuid FROM sccpline JOIN linefeatures ON (linefeatures.protocol = 'sccp' AND linefeatures.protocolid = sccpline.id) JOIN context ON linefeatures.context = context.name" - sccpline_to_tenant = op.get_bind().execute(sa.sql.text(sql)) - - for sccpline_id, tenant_uuid in sccpline_to_tenant: - query = tbl.update().where(tbl.c.id == sccpline_id).values(tenant_uuid=tenant_uuid) - op.execute(query) - - sql = "SELECT sccpline.id, context.tenant_uuid FROM sccpline JOIN context ON sccpline.context = context.name LEFT JOIN linefeatures ON (linefeatures.protocol = 'sccp' AND linefeatures.protocolid = sccpline.id) WHERE linefeatures.protocolid IS NULL" - sccpline_to_tenant = op.get_bind().execute(sa.sql.text(sql)) - - for sccpline_id, tenant_uuid in sccpline_to_tenant: - query = tbl.update().where(tbl.c.id == sccpline_id).values(tenant_uuid=tenant_uuid) - op.execute(query) - - -def upgrade(): - default_tenant = find_default_tenant_uuid() - op.add_column( - TABLE, - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=False, - server_default=default_tenant), - ) - associate_tenants() - op.alter_column(TABLE, 'tenant_uuid', server_default=None) - - -def downgrade(): - op.drop_column(TABLE, 'tenant_uuid') diff --git a/alembic/versions/35a7f7e2dc33_create_automon_func_key.py b/alembic/versions/35a7f7e2dc33_create_automon_func_key.py deleted file mode 100644 index 8e6df323..00000000 --- a/alembic/versions/35a7f7e2dc33_create_automon_func_key.py +++ /dev/null @@ -1,174 +0,0 @@ -"""create_automon_func_key - -Revision ID: 35a7f7e2dc33 -Revises: 3ab28f25de30 - -""" - -# revision identifiers, used by Alembic. -revision = '35a7f7e2dc33' -down_revision = '3ab28f25de30' - -from alembic import op -from sqlalchemy import sql -import sqlalchemy as sa - - -FEATURES_DESTINATION_NAME = 'features' -AUTOMON_FUNC_KEY_TYPE = 'dtmf' -AUTOMON_TYPE = 'automon' - -features_table = sql.table('features', - sql.column('id'), - sql.column('category'), - sql.column('var_name')) - -func_key_table = sql.table('func_key', - sql.column('id'), - sql.column('type_id'), - sql.column('destination_type_id')) - -func_key_type_table = sql.table('func_key_type', - sql.column('id'), - sql.column('name')) - -func_key_destination_type_table = sql.table('func_key_destination_type', - sql.column('id'), - sql.column('name')) - -func_key_dest_features_table = sql.table('func_key_dest_features', - sql.column('func_key_id'), - sql.column('destination_type_id'), - sql.column('features_id')) - -func_key_mapping_table = sql.table('func_key_mapping', - sql.column('template_id'), - sql.column('func_key_id'), - sql.column('destination_type_id'), - sql.column('label'), - sql.column('position'), - sql.column('blf')) - -phonefunckey_table = sql.table('phonefunckey', - sql.column('iduserfeatures'), - sql.column('fknum'), - sql.column('exten'), - sql.column('typeextenumbers'), - sql.column('typevalextenumbers'), - sql.column('typeextenumbersright'), - sql.column('typevalextenumbersright'), - sql.column('label'), - sql.column('supervision'), - sql.column('progfunckey')) - -user_table = sql.table('userfeatures', - sql.column('id'), - sql.column('func_key_private_template_id')) - - -func_key_columns = ( - phonefunckey_table.c.iduserfeatures.label('user_id'), - phonefunckey_table.c.fknum.label('position'), - phonefunckey_table.c.label, - phonefunckey_table.c.exten.label('park_position'), - sql.cast(phonefunckey_table.c.supervision, sa.Boolean).label('blf'), -) - -func_keys_query = (sql.select(func_key_columns) - .where(phonefunckey_table.c.typevalextenumbers == AUTOMON_TYPE)) - - -def upgrade(): - type_id = find_func_key_type_id() - destination_type_id = find_destination_type_id() - func_key_id = insert_automon_dest_features(type_id, destination_type_id) - migrate_func_keys(func_key_id, destination_type_id) - delete_old_func_keys() - - -def downgrade(): - op.execute(func_key_dest_features_table - .delete() - .where(func_key_dest_features_table.c.features_id == find_features_id())) - - -def migrate_func_keys(func_key_id, destination_type_id): - for row in op.get_bind().execute(func_keys_query): - create_mapping(func_key_id, row, destination_type_id) - - -def create_mapping(func_key_id, func_key_row, destination_type_id): - conn = op.get_bind() - - template_query = ( - sql.select( - [user_table.c.func_key_private_template_id]) - .where( - user_table.c.id == func_key_row.user_id)) - - template_id = conn.execute(template_query).scalar() - - mapping_query = (func_key_mapping_table - .insert() - .returning(func_key_mapping_table.c.func_key_id) - .values(func_key_id=func_key_id, - template_id=template_id, - destination_type_id=destination_type_id, - label=func_key_row.label, - position=func_key_row.position, - blf=func_key_row.blf)) - - conn.execute(mapping_query) - - -def delete_old_func_keys(): - delete_query = (phonefunckey_table - .delete() - .where(phonefunckey_table.c.typevalextenumbers == AUTOMON_TYPE)) - - op.get_bind().execute(delete_query) - - -def find_func_key_type_id(): - query = (sql.select([func_key_type_table.c.id]) - .where(func_key_type_table.c.name == AUTOMON_FUNC_KEY_TYPE)) - - return op.get_bind().execute(query).scalar() - - -def find_destination_type_id(): - query = (sql.select([func_key_destination_type_table.c.id]) - .where(func_key_destination_type_table.c.name == FEATURES_DESTINATION_NAME)) - - return op.get_bind().execute(query).scalar() - - -def find_features_id(): - features_query = ( - sql.select( - [features_table.c.id]) - .where( - sql.and_( - features_table.c.category == 'featuremap', - features_table.c.var_name == 'automon'))) - - return op.get_bind().execute(features_query).scalar() - - -def insert_automon_dest_features(type_id, destination_type_id): - func_key_query = (func_key_table - .insert() - .returning(func_key_table.c.id) - .values(type_id=type_id, - destination_type_id=destination_type_id)) - - func_key_id = op.get_bind().execute(func_key_query).scalar() - - dest_query = (func_key_dest_features_table - .insert() - .returning(func_key_dest_features_table.c.func_key_id) - .values(func_key_id=func_key_id, - destination_type_id=destination_type_id, - features_id=find_features_id())) - - return op.get_bind().execute(dest_query).scalar() diff --git a/alembic/versions/3612e8058d92_bump_version_17_08.py b/alembic/versions/3612e8058d92_bump_version_17_08.py deleted file mode 100644 index 370768aa..00000000 --- a/alembic/versions/3612e8058d92_bump_version_17_08.py +++ /dev/null @@ -1,22 +0,0 @@ -"""bump_version_17_08 - -Revision ID: 3612e8058d92 -Revises: 3e6bc9ae6158 - -""" - -# revision identifiers, used by Alembic. -revision = '3612e8058d92' -down_revision = '3e6bc9ae6158' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='17.08')) - - -def downgrade(): - pass diff --git a/alembic/versions/36516503ae1b_add_call_log_requested_exten_context.py b/alembic/versions/36516503ae1b_add_call_log_requested_exten_context.py deleted file mode 100644 index 6e96a9e9..00000000 --- a/alembic/versions/36516503ae1b_add_call_log_requested_exten_context.py +++ /dev/null @@ -1,24 +0,0 @@ -"""add call-log requested exten - -Revision ID: 36516503ae1b -Revises: 5085447dd295 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '36516503ae1b' -down_revision = '5085447dd295' - - -def upgrade(): - op.add_column('call_log', sa.Column('requested_exten', sa.String(255))) - op.add_column('call_log', sa.Column('requested_context', sa.String(255))) - - -def downgrade(): - op.drop_column('call_log', 'requested_exten') - op.drop_column('call_log', 'requested_context') diff --git a/alembic/versions/36c3f75ac228_ast13_remove_adsipark.py b/alembic/versions/36c3f75ac228_ast13_remove_adsipark.py deleted file mode 100644 index 00947fa9..00000000 --- a/alembic/versions/36c3f75ac228_ast13_remove_adsipark.py +++ /dev/null @@ -1,29 +0,0 @@ -"""ast13: remove adsipark - -Revision ID: 36c3f75ac228 -Revises: f5f2dd21819 - -""" - -# revision identifiers, used by Alembic. -revision = '36c3f75ac228' -down_revision = 'f5f2dd21819' - -from alembic import op -from sqlalchemy import sql - - -features_table = sql.table('features', - sql.column('var_name')) - - -def upgrade(): - _delete_features_adsipark() - - -def _delete_features_adsipark(): - op.execute(features_table.delete().where(features_table.c.var_name == 'adsipark')) - - -def downgrade(): - pass diff --git a/alembic/versions/374507a67216_userfeatures_tenant_uuid_cascade.py b/alembic/versions/374507a67216_userfeatures_tenant_uuid_cascade.py deleted file mode 100644 index 6a9c4e76..00000000 --- a/alembic/versions/374507a67216_userfeatures_tenant_uuid_cascade.py +++ /dev/null @@ -1,34 +0,0 @@ -"""userfeatures_tenant_uuid_cascade - -Revision ID: 374507a67216 -Revises: 476a2700b4c2 - -""" - -from alembic import op - - -# revision identifiers, used by Alembic. -revision = '374507a67216' -down_revision = '476a2700b4c2' - -constraint_name = 'userfeatures_tenant_uuid_fkey' - - -def upgrade(): - op.drop_constraint(constraint_name, 'userfeatures') - op.create_foreign_key( - constraint_name, - 'userfeatures', 'tenant', - ['tenant_uuid'], ['uuid'], - ondelete='CASCADE', - ) - - -def downgrade(): - op.drop_constraint(constraint_name, 'userfeatures') - op.create_foreign_key( - constraint_name, - 'userfeatures', 'tenant', - ['tenant_uuid'], ['uuid'], - ) diff --git a/alembic/versions/3770e116222d_divide_queue_waitratio.py b/alembic/versions/3770e116222d_divide_queue_waitratio.py deleted file mode 100644 index e59d3640..00000000 --- a/alembic/versions/3770e116222d_divide_queue_waitratio.py +++ /dev/null @@ -1,34 +0,0 @@ -"""divide queue waitratio - -Revision ID: 3770e116222d -Revises: 2375157ea682 - -""" - -# revision identifiers, used by Alembic. -revision = '3770e116222d' -down_revision = '2375157ea682' - -from alembic import op -from sqlalchemy import sql - - -queuefeatures = sql.table('queuefeatures', - sql.column('waitratio'), -) - - -def upgrade(): - op.execute( - queuefeatures.update() - .where(queuefeatures.c.waitratio != None) - .values(waitratio=queuefeatures.c.waitratio / 100.0) - ) - - -def downgrade(): - op.execute( - queuefeatures.update() - .where(queuefeatures.c.waitratio != None) - .values(waitratio=queuefeatures.c.waitratio * 100.0) - ) diff --git a/alembic/versions/378c46e8c6fe_remove_pickupmember_invalid.py b/alembic/versions/378c46e8c6fe_remove_pickupmember_invalid.py deleted file mode 100644 index 801d7949..00000000 --- a/alembic/versions/378c46e8c6fe_remove_pickupmember_invalid.py +++ /dev/null @@ -1,75 +0,0 @@ -"""remove_pickupmember_invalid - -Revision ID: 378c46e8c6fe -Revises: 58fc78d9f67f - -""" - -from alembic import op -from sqlalchemy import sql - -# revision identifiers, used by Alembic. -revision = '378c46e8c6fe' -down_revision = '58fc78d9f67f' - -userfeatures = sql.table( - 'userfeatures', - sql.column('id'), -) - -groupfeatures = sql.table( - 'groupfeatures', - sql.column('id'), -) - -queuefeatures = sql.table( - 'queuefeatures', - sql.column('id'), -) - -pickupmember = sql.table( - 'pickupmember', - sql.column('membertype'), - sql.column('memberid'), -) - - -def upgrade(): - conn = op.get_bind() - group_ids = [r.id for r in conn.execute(sql.select([groupfeatures.c.id])).fetchall()] - queue_ids = [r.id for r in conn.execute(sql.select([queuefeatures.c.id])).fetchall()] - user_ids = [r.id for r in conn.execute(sql.select([userfeatures.c.id])).fetchall()] - - filters = [] - if group_ids: - filters.append( - sql.and_( - pickupmember.c.membertype == 'group', - sql.not_(pickupmember.c.memberid.in_(group_ids)), - ) - ) - if queue_ids: - filters.append( - sql.and_( - pickupmember.c.membertype == 'queue', - sql.not_(pickupmember.c.memberid.in_(queue_ids)), - ), - ) - if user_ids: - filters.append( - sql.and_( - pickupmember.c.membertype == 'user', - sql.not_(pickupmember.c.memberid.in_(user_ids)), - ), - ) - - if filters: - op.execute( - pickupmember - .delete() - .where(sql.or_(*filters)) - ) - - -def downgrade(): - pass diff --git a/alembic/versions/379d2e0c5e51_add_directmedia_outgoing_option.py b/alembic/versions/379d2e0c5e51_add_directmedia_outgoing_option.py deleted file mode 100644 index 83d24daa..00000000 --- a/alembic/versions/379d2e0c5e51_add_directmedia_outgoing_option.py +++ /dev/null @@ -1,62 +0,0 @@ -"""add directmedia outgoing option - -Revision ID: 379d2e0c5e51 -Revises: 1888ca44e08f - -""" - -from alembic import op -import sqlalchemy as sa -from sqlalchemy import sql - -revision = '379d2e0c5e51' -down_revision = '1888ca44e08f' - - -old_options = ('no', 'yes', 'nonat', 'update', 'update,nonat') - -old_type = sa.Enum(*old_options, name='usersip_directmedia') - -usersip_table = sa.sql.table('usersip', - sql.column('directmedia')) - -staticsip_table = sa.sql.table('staticsip', - sql.column('var_name'), - sql.column('var_val')) - - -def upgrade(): - op.alter_column('usersip', 'directmedia', type_=sa.String(20)) - - op.create_check_constraint( - "usersip_directmedia_check", - "usersip", - usersip_table.c.directmedia.in_( - ['no', 'yes', 'nonat', 'update', 'update,nonat', 'outgoing']) - ) - - old_type.drop(op.get_bind(), checkfirst=False) - - -def downgrade(): - op.execute(usersip_table.update(). - where(usersip_table.c.directmedia == 'outgoing'). - values(directmedia='no')) - - op.execute(staticsip_table.update(). - where(sa.sql.and_( - staticsip_table.c.var_name == 'directmedia', - staticsip_table.c.var_val == 'outgoing')). - values(var_val='no')) - - op.drop_constraint('usersip_directmedia_check', 'usersip') - - old_type.create(op.get_bind(), checkfirst=False) - - qry = """ - ALTER TABLE usersip - ALTER COLUMN directmedia - TYPE usersip_directmedia - USING (directmedia::usersip_directmedia); - """ - op.execute(qry) diff --git a/alembic/versions/379ed6d9a62_remove_acesswebservice_acl_obj.py b/alembic/versions/379ed6d9a62_remove_acesswebservice_acl_obj.py deleted file mode 100644 index 9ce42900..00000000 --- a/alembic/versions/379ed6d9a62_remove_acesswebservice_acl_obj.py +++ /dev/null @@ -1,20 +0,0 @@ -"""remove_acesswebservice_acl_obj - -Revision ID: 379ed6d9a62 -Revises: d6be50f692dc - -""" - -# revision identifiers, used by Alembic. -revision = '379ed6d9a62' -down_revision = 'd6be50f692dc' - -from alembic import op - - -def upgrade(): - op.drop_column('accesswebservice', 'obj') - - -def downgrade(): - pass diff --git a/alembic/versions/37b9ac945437_bump_version_17_04.py b/alembic/versions/37b9ac945437_bump_version_17_04.py deleted file mode 100644 index ef598204..00000000 --- a/alembic/versions/37b9ac945437_bump_version_17_04.py +++ /dev/null @@ -1,22 +0,0 @@ -"""bump_version_17_04 - -Revision ID: 37b9ac945437 -Revises: 415b08ed9959 - -""" - -# revision identifiers, used by Alembic. -revision = '37b9ac945437' -down_revision = '415b08ed9959' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='17.04')) - - -def downgrade(): - pass diff --git a/alembic/versions/37c0864e0b2b_convert_agent_status_login_to_pjsip.py b/alembic/versions/37c0864e0b2b_convert_agent_status_login_to_pjsip.py deleted file mode 100644 index 9c4482fb..00000000 --- a/alembic/versions/37c0864e0b2b_convert_agent_status_login_to_pjsip.py +++ /dev/null @@ -1,39 +0,0 @@ -"""convert agent_status_login to pjsip - -Revision ID: 37c0864e0b2b -Revises: 42db6d46c98a - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '37c0864e0b2b' -down_revision = '42db6d46c98a' - -agent_login_status_tbl = sa.sql.table( - 'agent_login_status', - sa.sql.column('state_interface'), - sa.sql.column('interface'), -) - - -def upgrade(): - op.execute( - agent_login_status_tbl - .update() - .where(agent_login_status_tbl.c.state_interface.startswith('SIP/')) - .values(state_interface='PJ' + agent_login_status_tbl.c.state_interface) - ) - op.execute( - agent_login_status_tbl - .update() - .where(agent_login_status_tbl.c.interface.startswith('SIP/')) - .values(interface='PJ' + agent_login_status_tbl.c.interface) - ) - - -def downgrade(): - pass diff --git a/alembic/versions/37c6976343d4_fix_partial_call_stats.py b/alembic/versions/37c6976343d4_fix_partial_call_stats.py deleted file mode 100644 index 52cafbb2..00000000 --- a/alembic/versions/37c6976343d4_fix_partial_call_stats.py +++ /dev/null @@ -1,55 +0,0 @@ -"""fix_partial_call_stats - -Revision ID: 37c6976343d4 -Revises: 5073b1fa473e - -""" - -# revision identifiers, used by Alembic. -revision = '37c6976343d4' -down_revision = 'dd011dfbb5' - -from alembic import op - -old_procedure = """ -CREATE OR REPLACE FUNCTION "fill_answered_calls"(period_start text, period_end text) - RETURNS void AS -$$ - INSERT INTO stat_call_on_queue (callid, "time", talktime, waittime, queue_id, agent_id, status) - SELECT - outer_queue_log.callid, - CAST ((SELECT "time" - FROM queue_log - WHERE callid=outer_queue_log.callid AND - queuename=outer_queue_log.queuename AND - event='ENTERQUEUE' ORDER BY "time" DESC LIMIT 1) AS TIMESTAMP) AS "time", - CASE WHEN event IN ('COMPLETEAGENT', 'COMPLETECALLER') THEN CAST (data2 AS INTEGER) - WHEN event = 'TRANSFER' THEN CAST (data4 AS INTEGER) END as talktime, - CASE WHEN event IN ('COMPLETEAGENT', 'COMPLETECALLER') THEN CAST (data1 AS INTEGER) - WHEN event = 'TRANSFER' THEN CAST (data3 AS INTEGER) END as waittime, - stat_queue.id AS queue_id, - stat_agent.id AS agent_id, - 'answered' AS status - FROM - queue_log as outer_queue_log - LEFT JOIN - stat_agent ON outer_queue_log.agent = stat_agent.name - LEFT JOIN - stat_queue ON outer_queue_log.queuename = stat_queue.name - WHERE - callid IN - (SELECT callid - FROM queue_log - WHERE event = 'ENTERQUEUE' AND "time" BETWEEN $1 AND $2) - AND event IN ('COMPLETEAGENT', 'COMPLETECALLER', 'TRANSFER'); -$$ -LANGUAGE SQL; -""" - - -def upgrade(): - op.execute('DROP FUNCTION IF EXISTS "fill_answered_calls"(text, text)') - - -def downgrade(): - op.execute(old_procedure) diff --git a/alembic/versions/381de5b6a1a5_create_meeting_authorization_table.py b/alembic/versions/381de5b6a1a5_create_meeting_authorization_table.py deleted file mode 100644 index 4b72c995..00000000 --- a/alembic/versions/381de5b6a1a5_create_meeting_authorization_table.py +++ /dev/null @@ -1,53 +0,0 @@ -"""create meeting authorization table - -Revision ID: 381de5b6a1a5 -Revises: 21b72c41eb6a - -""" - -import datetime -import sqlalchemy as sa - -from alembic import op -from sqlalchemy.types import DateTime - -from sqlalchemy.dialects.postgresql import UUID - -# revision identifiers, used by Alembic. -revision = '381de5b6a1a5' -down_revision = '21b72c41eb6a' - - -def upgrade(): - op.create_table( - 'meeting_authorization', - sa.Column( - 'uuid', - UUID, - server_default=sa.text('uuid_generate_v4()'), - primary_key=True - ), - sa.Column( - 'meeting_uuid', - UUID, - sa.ForeignKey('meeting.uuid', ondelete='CASCADE'), - nullable=False, - ), - sa.Column( - 'guest_uuid', - UUID, - nullable=False, - ), - sa.Column('guest_name', sa.Text), - sa.Column('status', sa.Text), - sa.Column( - 'created_at', - DateTime(timezone=True), - default=datetime.datetime.utcnow, - server_default=sa.text("(now() at time zone 'utc')") - ) - ) - - -def downgrade(): - op.drop_table('meeting_authorization') diff --git a/alembic/versions/382aaefc59ec_add_group_uuid.py b/alembic/versions/382aaefc59ec_add_group_uuid.py deleted file mode 100644 index 6a1ca480..00000000 --- a/alembic/versions/382aaefc59ec_add_group_uuid.py +++ /dev/null @@ -1,36 +0,0 @@ -"""add group uuid - -Revision ID: 382aaefc59ec -Revises: 9442da3b20b6 - -""" - -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects.postgresql import UUID - - -# revision identifiers, used by Alembic. -revision = '382aaefc59ec' -down_revision = '9442da3b20b6' - - -def upgrade(): - op.add_column( - 'groupfeatures', - sa.Column( - 'uuid', - UUID, - server_default=sa.text('uuid_generate_v4()'), - nullable=False, - ) - ) - op.create_index( - index_name='groupfeatures__idx__uuid', - table_name='groupfeatures', - columns=['uuid'], - ) - - -def downgrade(): - op.drop_column('groupfeatures', 'uuid') diff --git a/alembic/versions/387d650380bd_change_defaut_cti_colors.py b/alembic/versions/387d650380bd_change_defaut_cti_colors.py deleted file mode 100644 index 6cf8fa6d..00000000 --- a/alembic/versions/387d650380bd_change_defaut_cti_colors.py +++ /dev/null @@ -1,92 +0,0 @@ -"""change defaut CTI colors - -Revision ID: 387d650380bd -Revises: 5ace7dc40b5c - -""" - -# revision identifiers, used by Alembic. -revision = '387d650380bd' -down_revision = '5ace7dc40b5c' - -from alembic import op -import sqlalchemy as sa - - -ctistatus_table = sa.sql.table('ctistatus', - sa.sql.column('presence_id'), - sa.sql.column('color')) -ctiphonehints_table = sa.sql.table('ctiphonehints', - sa.sql.column('idgroup'), - sa.sql.column('number'), - sa.sql.column('color')) - -OLD_GREEN = ('#08FD20', '#0DFF25') -OLD_YELLOW = ('#FDE50A', '#F7FF05') -OLD_BLUE = ('#001AFF', '#1B0AFF') -OLD_RED = ('#FF032D', '#FF0526', '#FF0008') -OLD_ORANGE = ('#F2833A',) -OLD_BLACK = ('#202020', '#000000', '#030303') -OLD_WHITE = ('#FFFFFF',) - -NEW_GREEN = '#9BC920' -NEW_YELLOW = '#FFDD00' -NEW_BLUE = '#6CA6FF' -NEW_RED = '#D13224' -NEW_ORANGE = '#F2833A' -NEW_GREY = '#9E9E9E' - - -def upgrade(): - _upgrade_ctistatus(OLD_GREEN, NEW_GREEN) - _upgrade_ctistatus(OLD_YELLOW, NEW_YELLOW) - _upgrade_ctistatus(OLD_BLUE, NEW_BLUE) - _upgrade_ctistatus(OLD_RED, NEW_RED) - _upgrade_ctistatus(OLD_ORANGE, NEW_ORANGE) - _upgrade_ctistatus(OLD_BLACK, NEW_GREY) - - _upgrade_ctiphonehints(OLD_GREEN, NEW_GREEN) - _upgrade_ctiphonehints(OLD_YELLOW, NEW_YELLOW) - _upgrade_ctiphonehints(OLD_BLUE, NEW_BLUE) - _upgrade_ctiphonehints(OLD_RED, NEW_RED) - _upgrade_ctiphonehints(OLD_BLACK, NEW_GREY) - _upgrade_ctiphonehints(OLD_WHITE, NEW_GREY) - - -def downgrade(): - _upgrade_ctistatus([NEW_GREEN], OLD_GREEN[0]) - _upgrade_ctistatus([NEW_YELLOW], OLD_YELLOW[0]) - _upgrade_ctistatus([NEW_BLUE], OLD_BLUE[0]) - _upgrade_ctistatus([NEW_RED], OLD_RED[0]) - _upgrade_ctistatus([NEW_ORANGE], OLD_ORANGE[0]) - _upgrade_ctistatus([NEW_GREY], OLD_BLACK[0]) - - _upgrade_ctiphonehints([NEW_GREEN], OLD_GREEN[0]) - _upgrade_ctiphonehints([NEW_YELLOW], OLD_YELLOW[0]) - _upgrade_ctiphonehints([NEW_BLUE], OLD_BLUE[0]) - _upgrade_ctiphonehints([NEW_RED], OLD_RED[0]) - _upgrade_ctiphonehints([NEW_GREY], OLD_BLACK[0]) - query = (ctiphonehints_table - .update() - .values(color=OLD_WHITE[0]) - .where(sa.sql.and_(ctiphonehints_table.c.idgroup == 1, - ctiphonehints_table.c.number == '4'))) - op.execute(query) - - -def _upgrade_ctistatus(old_colors, new_color): - query = (ctistatus_table - .update() - .values(color=new_color) - .where(sa.sql.and_(ctistatus_table.c.presence_id == 1, - ctistatus_table.c.color.in_(old_colors)))) - op.execute(query) - - -def _upgrade_ctiphonehints(old_colors, new_color): - query = (ctiphonehints_table - .update() - .values(color=new_color) - .where(sa.sql.and_(ctiphonehints_table.c.idgroup == 1, - ctiphonehints_table.c.color.in_(old_colors)))) - op.execute(query) diff --git a/alembic/versions/394edc522e4a_add_ldapfitler_id_to_directories.py b/alembic/versions/394edc522e4a_add_ldapfitler_id_to_directories.py deleted file mode 100644 index f8bd1e34..00000000 --- a/alembic/versions/394edc522e4a_add_ldapfitler_id_to_directories.py +++ /dev/null @@ -1,25 +0,0 @@ -"""add ldapfitler_id to directories - -Revision ID: 394edc522e4a -Revises: 30eebcef63ad - -""" - -# revision identifiers, used by Alembic. -revision = '394edc522e4a' -down_revision = '30eebcef63ad' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - op.add_column('directories', - sa.Column('ldapfilter_id', - sa.Integer, - sa.ForeignKey('ldapfilter.id', ondelete='CASCADE'), - nullable=True)) - - -def downgrade(): - op.drop_column('directories', 'ldapfilter_id') diff --git a/alembic/versions/39f7b89af84e_randomize_uuid.py b/alembic/versions/39f7b89af84e_randomize_uuid.py deleted file mode 100644 index 8e0cf6cf..00000000 --- a/alembic/versions/39f7b89af84e_randomize_uuid.py +++ /dev/null @@ -1,28 +0,0 @@ -"""randomize uuid - -Revision ID: 39f7b89af84e -Revises: 3770e116222d - -""" - -# revision identifiers, used by Alembic. -revision = '39f7b89af84e' -down_revision = '3770e116222d' - -import os - -from alembic import op -import sqlalchemy as sa - - -infos_table = sa.sql.table('infos', sa.sql.column('uuid')) - - -def upgrade(): - new_uuid = os.environ['XIVO_UUID'] - infos_query = infos_table.update().values({'uuid': new_uuid}) - op.get_bind().execute(infos_query) - - -def downgrade(): - pass diff --git a/alembic/versions/3a091c2f91bc_call_log_add_internal_extensions.py b/alembic/versions/3a091c2f91bc_call_log_add_internal_extensions.py deleted file mode 100644 index dd7491d6..00000000 --- a/alembic/versions/3a091c2f91bc_call_log_add_internal_extensions.py +++ /dev/null @@ -1,32 +0,0 @@ -"""call_log: add internal extensions - -Revision ID: 3a091c2f91bc -Revises: b8f8ba046d25 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '3a091c2f91bc' -down_revision = 'b8f8ba046d25' - - -def upgrade(): - op.add_column('call_log', sa.Column('source_internal_exten', sa.Text)) - op.add_column('call_log', sa.Column('source_internal_context', sa.Text)) - op.add_column('call_log', sa.Column('destination_internal_exten', sa.Text)) - op.add_column('call_log', sa.Column('destination_internal_context', sa.Text)) - op.add_column('call_log', sa.Column('requested_internal_exten', sa.Text)) - op.add_column('call_log', sa.Column('requested_internal_context', sa.Text)) - - -def downgrade(): - op.drop_column('call_log', 'source_internal_exten') - op.drop_column('call_log', 'source_internal_context') - op.drop_column('call_log', 'destination_internal_exten') - op.drop_column('call_log', 'destination_internal_context') - op.drop_column('call_log', 'requested_internal_exten') - op.drop_column('call_log', 'requested_internal_context') diff --git a/alembic/versions/3a0ace87fc76_remove_contact_xlet.py b/alembic/versions/3a0ace87fc76_remove_contact_xlet.py deleted file mode 100644 index 9cfb20e7..00000000 --- a/alembic/versions/3a0ace87fc76_remove_contact_xlet.py +++ /dev/null @@ -1,78 +0,0 @@ -"""remove contact xlet - -Revision ID: 3a0ace87fc76 -Revises: 2f7e5c4119bc - -""" - -# revision identifiers, used by Alembic. -revision = '3a0ace87fc76' -down_revision = '2f7e5c4119bc' - -from alembic import op -import sqlalchemy as sa - - -CONTACT_XLET = 'search' -PEOPLE_XLET = 'people' - - -xlet_table = sa.sql.table('cti_xlet', - sa.sql.column('id'), - sa.sql.column('plugin_name')) -profile_xlet_table = sa.sql.table('cti_profile_xlet', - sa.sql.column('profile_id'), - sa.sql.column('xlet_id')) - - -def get_xlet_id(xlet_name): - return op.get_bind().execute( - sa.sql.select( - [xlet_table.c.id] - ).where( - xlet_table.c.plugin_name == xlet_name - )).scalar() - - -def find_profile_with_xlet(xlet_id): - rows = op.get_bind().execute( - sa.sql.select( - [profile_xlet_table.c.profile_id] - ).where( - profile_xlet_table.c.xlet_id == xlet_id - )) - - return list(set(row.profile_id for row in rows)) - - -def substitute_xlet(profile_ids, from_id, to_id): - if not profile_ids: - return - op.execute(profile_xlet_table.update() - .values(xlet_id=to_id) - .where(sa.and_(profile_xlet_table.c.xlet_id == from_id, - profile_xlet_table.c.profile_id.in_(profile_ids)))) - - -def remove_xlet(xlet_id): - op.execute(xlet_table.delete().where(xlet_table.c.id == xlet_id)) - - -def create_xlet_contact(): - op.execute(xlet_table.insert().values(plugin_name=CONTACT_XLET)) - - -def upgrade(): - contact_id = get_xlet_id(CONTACT_XLET) - people_id = get_xlet_id(PEOPLE_XLET) - - profile_ids_with_contact = find_profile_with_xlet(contact_id) - profile_ids_with_people = find_profile_with_xlet(people_id) - profile_ids_with_contact_only = list(set(profile_ids_with_contact) - set(profile_ids_with_people)) - - substitute_xlet(profile_ids_with_contact_only, contact_id, people_id) - remove_xlet(contact_id) - - -def downgrade(): - create_xlet_contact() diff --git a/alembic/versions/3ab28f25de30_reset_queue_exit_context.py b/alembic/versions/3ab28f25de30_reset_queue_exit_context.py deleted file mode 100644 index 7a6f7bf5..00000000 --- a/alembic/versions/3ab28f25de30_reset_queue_exit_context.py +++ /dev/null @@ -1,21 +0,0 @@ -"""reset queue exit context - -Revision ID: 3ab28f25de30 -Revises: 3770e116222d - -""" - -# revision identifiers, used by Alembic. -revision = '3ab28f25de30' -down_revision = '39f7b89af84e' - -from alembic import op - - -def upgrade(): - op.execute('''UPDATE queue SET context = null FROM queuefeatures WHERE queue.name = queuefeatures.name AND queue.context = queuefeatures.context''') - op.execute('''UPDATE queue SET context = null FROM groupfeatures WHERE queue.name = groupfeatures.name AND queue.context = groupfeatures.context''') - - -def downgrade(): - pass diff --git a/alembic/versions/3ab7cf07eb66_migrate_func_key_bsfilter.py b/alembic/versions/3ab7cf07eb66_migrate_func_key_bsfilter.py deleted file mode 100644 index 3b42468e..00000000 --- a/alembic/versions/3ab7cf07eb66_migrate_func_key_bsfilter.py +++ /dev/null @@ -1,516 +0,0 @@ -"""migrate func key bsfilter - -Revision ID: 3ab7cf07eb66 -Revises: 11b792bcc775 - -""" - -# revision identifiers, used by Alembic. -revision = '3ab7cf07eb66' -down_revision = '11b792bcc775' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy import sql - -BSFILTER_TYPE = 'bsfilter' -SECRETARY_TYPE = 'secretary' -BOSS_TYPE = 'boss' -TYPE_ID = 1 -DESTINATION_TYPE_ID = 12 - -phonefunckey_table = sql.table('phonefunckey', - sql.column('iduserfeatures'), - sql.column('fknum'), - sql.column('exten'), - sql.column('typeextenumbers'), - sql.column('typevalextenumbers'), - sql.column('typeextenumbersright'), - sql.column('typevalextenumbersright'), - sql.column('label'), - sql.column('supervision'), - sql.column('progfunckey')) - -func_key_table = sql.table('func_key', - sql.column('id'), - sql.column('type_id'), - sql.column('destination_type_id')) - -dest_bsfilter_table = sql.table('func_key_dest_bsfilter', - sql.column('func_key_id'), - sql.column('destination_type_id'), - sql.column('filtermember_id')) - -func_key_type_table = sql.table('func_key_type', - sql.column('id'), - sql.column('name')) - -func_key_mapping_table = sql.table('func_key_mapping', - sql.column('template_id'), - sql.column('func_key_id'), - sql.column('destination_type_id'), - sql.column('label'), - sql.column('position'), - sql.column('blf')) - -user_table = sql.table('userfeatures', - sql.column('id'), - sql.column('func_key_private_template_id'), - sql.column('bsfilter')) - -template_table = sql.table('func_key_template', sql.column('id')) - -destination_type_table = sql.table('func_key_destination_type', - sql.column('id'), - sql.column('name')) - -callfilter_table = sql.table('callfilter', - sql.column('id'), - sql.column('callfilterid'), - sql.column('type'), - sql.column('typeval'), - sql.column('bstype')) - -callfiltermember_table = sql.table('callfiltermember', - sql.column('id'), - sql.column('callfilterid'), - sql.column('type'), - sql.column('typeval'), - sql.column('bstype')) - - -def upgrade(): - delete_bsfilters_without_bosses() - delete_bsfilters_with_mutant_bosses() - delete_bsfilters_with_mutant_secretaries() - delete_missing_bsfilter_funckeys() - delete_duplicate_bsfilter_funckeys() - create_bsfilter_func_keys() - migrate_func_keys() - delete_old_func_keys() - - -def delete_bsfilters_without_bosses(): - for bsfilter_id in get_bsfilters_without_bosses(): - delete_bsfilter(bsfilter_id) - - -def get_bsfilters_without_bosses(): - bsfilter_ids = sql.select([callfilter_table.c.id]) - - bsfilter_with_bosses_ids = (sql.select([callfiltermember_table.c.callfilterid]) - .where(callfiltermember_table.c.bstype == BOSS_TYPE)) - - bsfilters_without_bosses = bsfilter_ids.except_(bsfilter_with_bosses_ids) - - return [row.id for row in op.get_bind().execute(bsfilters_without_bosses)] - - -def delete_bsfilter(bsfilter_id): - print('[MIGRATE_FK] : Deleting invalid bsfilter with id %s' % bsfilter_id) - query = (callfiltermember_table - .delete() - .where(callfiltermember_table.c.callfilterid == bsfilter_id)) - - op.get_bind().execute(query) - - query = (callfilter_table - .delete() - .where(callfilter_table.c.id == bsfilter_id)) - - op.get_bind().execute(query) - - -def delete_bsfilters_with_mutant_bosses(): - for bsfilter_id in get_bsfilters_with_mutant_bosses(): - delete_bsfilter(bsfilter_id) - - -def get_bsfilters_with_mutant_bosses(): - join = callfiltermember_table.join( - user_table, - sql.and_( - callfiltermember_table.c.bstype == BOSS_TYPE, - sql.cast(callfiltermember_table.c.typeval, sa.Integer) == user_table.c.id)) - - query = (sql.select([callfiltermember_table.c.callfilterid], - from_obj=join) - .where(user_table.c.bsfilter != BOSS_TYPE)) - - return [row.callfilterid for row in op.get_bind().execute(query)] - - -def delete_bsfilters_with_mutant_secretaries(): - for bsfilter_id in get_bsfilters_with_mutant_secretaries(): - delete_bsfilter(bsfilter_id) - - -def get_bsfilters_with_mutant_secretaries(): - join = callfiltermember_table.join( - user_table, - sql.and_( - callfiltermember_table.c.bstype == SECRETARY_TYPE, - sql.cast(callfiltermember_table.c.typeval, sa.Integer) == user_table.c.id)) - - query = (sql.select([callfiltermember_table.c.callfilterid], - from_obj=join) - .where(user_table.c.bsfilter != SECRETARY_TYPE)) - - return [row.callfilterid for row in op.get_bind().execute(query)] - - -def delete_missing_bsfilter_funckeys(): - template = '[MIGRATE_FK] : Deleting missing bsfilter func key for user "%s" (fk position %s)' - for row in get_missing_bsfilter_funckeys(): - message = template % (row.iduserfeatures, row.fknum) - delete_fk(row.iduserfeatures, row.fknum, message) - - -def delete_fk(iduserfeatures, fknum, message): - print(message) - - query = (phonefunckey_table - .delete() - .where(sql.and_( - phonefunckey_table.c.iduserfeatures == iduserfeatures, - phonefunckey_table.c.fknum == fknum))) - - op.get_bind().execute(query) - - -def get_missing_bsfilter_funckeys(): - secretary = callfiltermember_table.alias() - boss = callfiltermember_table.alias() - pfk = phonefunckey_table.alias() - - bs_columns = (boss.c.typeval.label('boss_id'), - secretary.c.typeval.label('secretary_id')) - - bs_join = boss.join(secretary, - sql.and_( - secretary.c.bstype == SECRETARY_TYPE, - secretary.c.callfilterid == boss.c.callfilterid)) - - boss_secretary = (sql.select(bs_columns, from_obj=[bs_join]) - .where(boss.c.bstype == BOSS_TYPE) - .alias()) - - pfk_columns = (pfk.c.iduserfeatures, - pfk.c.fknum) - - boss_join = pfk.join(boss_secretary, - sql.and_( - sql.cast(pfk.c.iduserfeatures, sa.Unicode) == boss_secretary.c.boss_id, - pfk.c.typevalextenumbersright == boss_secretary.c.secretary_id)) - - sec_join = pfk.join(boss_secretary, - sql.and_( - sql.cast(pfk.c.iduserfeatures, sa.Unicode) == boss_secretary.c.secretary_id, - pfk.c.typevalextenumbersright == boss_secretary.c.boss_id)) - - all_bsfilters = (sql.select(pfk_columns, from_obj=[boss_join]) - .union( - sql.select(pfk_columns, from_obj=[sec_join])) - ) - - query = (sql.select(pfk_columns) - .where(pfk.c.typevalextenumbers == BSFILTER_TYPE) - .except_(all_bsfilters) - ) - - return op.get_bind().execute(query) - - -def delete_duplicate_bsfilter_funckeys(): - template = '[MIGRATE_FK] : Deleting duplicate bsfilter func key for user "%s" (fk position %s)' - for row in get_duplicate_bsfilter_funckeys(): - message = template % (row.iduserfeatures, row.fknum) - delete_fk(row.iduserfeatures, row.fknum, message) - - -def get_duplicate_bsfilter_funckeys(): - duplicate_columns = (phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.typevalextenumbersright, - sa.func.min(phonefunckey_table.c.fknum).label("first_position")) - - duplicate_query = (sql.select(duplicate_columns) - .where( - phonefunckey_table.c.typevalextenumbers == BSFILTER_TYPE) - .group_by( - phonefunckey_table.c.typevalextenumbersright, - phonefunckey_table.c.iduserfeatures) - .having( - sa.func.count(phonefunckey_table.c.typevalextenumbersright) > 1) - .alias() - ) - - columns = (phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.fknum) - - join = phonefunckey_table.join( - duplicate_query, - sql.and_( - phonefunckey_table.c.typevalextenumbersright == duplicate_query.c.typevalextenumbersright, - phonefunckey_table.c.fknum > duplicate_query.c.first_position, - phonefunckey_table.c.iduserfeatures == duplicate_query.c.iduserfeatures)) - - query = sql.select(columns, from_obj=[join]) - - return op.get_bind().execute(query) - - -def create_bsfilter_func_keys(): - for row in get_filter_member_ids(): - create_bsfilter_func_key(row.id) - - -def get_filter_member_ids(): - bsfilter_query = (sql.select([callfiltermember_table.c.id]) - .where( - callfiltermember_table.c.bstype == SECRETARY_TYPE) - ) - - return op.get_bind().execute(bsfilter_query) - - -def create_bsfilter_func_key(filtermember_id): - func_key_query = (func_key_table - .insert() - .returning(func_key_table.c.id) - .values(type_id=TYPE_ID, - destination_type_id=DESTINATION_TYPE_ID) - ) - - func_key_id = op.get_bind().execute(func_key_query).scalar() - - bsfilter_query = (dest_bsfilter_table - .insert() - .returning(dest_bsfilter_table.c.func_key_id) - .values(func_key_id=func_key_id, - destination_type_id=DESTINATION_TYPE_ID, - filtermember_id=filtermember_id) - ) - - op.get_bind().execute(bsfilter_query) - - return func_key_id - - -def migrate_func_keys(): - for row in get_boss_func_keys(): - func_key_id = find_secretary_func_key(row.boss_id, row.secretary_id) - create_mapping(func_key_id, row) - - for row in get_secretary_func_keys(): - func_key_id = find_secretary_func_key(row.boss_id, row.secretary_id) - create_mapping(func_key_id, row) - - -def get_boss_func_keys(): - columns = (phonefunckey_table.c.iduserfeatures.label('boss_id'), - phonefunckey_table.c.iduserfeatures.label('user_id'), - sql.cast(phonefunckey_table.c.typevalextenumbersright, sa.Integer).label('secretary_id'), - phonefunckey_table.c.fknum.label('position'), - phonefunckey_table.c.label, - sql.cast(phonefunckey_table.c.supervision, sa.Boolean).label('blf')) - - join = user_table.join( - phonefunckey_table, - phonefunckey_table.c.iduserfeatures == user_table.c.id - ) - - query = sql.select(columns, from_obj=[join]).where(sql.and_(user_table.c.bsfilter == BOSS_TYPE, - phonefunckey_table.c.typevalextenumbers == BSFILTER_TYPE)) - - return op.get_bind().execute(query) - - -def get_secretary_func_keys(): - columns = (phonefunckey_table.c.iduserfeatures.label('secretary_id'), - phonefunckey_table.c.iduserfeatures.label('user_id'), - sql.cast(phonefunckey_table.c.typevalextenumbersright, sa.Integer).label('boss_id'), - phonefunckey_table.c.fknum.label('position'), - phonefunckey_table.c.label, - sql.cast(phonefunckey_table.c.supervision, sa.Boolean).label('blf')) - - join = user_table.join( - phonefunckey_table, - phonefunckey_table.c.iduserfeatures == user_table.c.id - ) - - query = sql.select(columns, from_obj=[join]).where(sql.and_(user_table.c.bsfilter == SECRETARY_TYPE, - phonefunckey_table.c.typevalextenumbers == BSFILTER_TYPE)) - - return op.get_bind().execute(query) - - -def find_secretary_func_key(boss_id, secretary_id): - filter_query = (sql.select([callfiltermember_table.c.callfilterid]) - .where( - sql.and_( - callfiltermember_table.c.bstype == BOSS_TYPE, - sql.cast(callfiltermember_table.c.typeval, sa.Integer) == boss_id)) - ) - - filter_id = op.get_bind().execute(filter_query).scalar() - - filter_member_query = (sql.select([callfiltermember_table.c.id]) - .where( - sql.and_( - callfiltermember_table.c.bstype == SECRETARY_TYPE, - sql.cast(callfiltermember_table.c.typeval, sa.Integer) == secretary_id, - callfiltermember_table.c.callfilterid == filter_id)) - ) - - filter_member_id = op.get_bind().execute(filter_member_query).scalar() - - func_key_query = (sql.select([dest_bsfilter_table.c.func_key_id]) - .where( - dest_bsfilter_table.c.filtermember_id == filter_member_id) - ) - - return op.get_bind().execute(func_key_query).scalar() - - -def create_mapping(func_key_id, func_key_row): - conn = op.get_bind() - - template_query = ( - sql.select( - [user_table.c.func_key_private_template_id]) - .where( - user_table.c.id == func_key_row.user_id)) - - template_id = conn.execute(template_query).scalar() - - mapping_query = (func_key_mapping_table - .insert() - .returning(func_key_mapping_table.c.func_key_id) - .values(func_key_id=func_key_id, - template_id=template_id, - destination_type_id=DESTINATION_TYPE_ID, - label=func_key_row.label, - position=func_key_row.position, - blf=func_key_row.blf)) - - conn.execute(mapping_query) - - -def delete_old_func_keys(): - delete_query = (phonefunckey_table - .delete() - .where( - phonefunckey_table.c.typevalextenumbers == BSFILTER_TYPE) - ) - - op.get_bind().execute(delete_query) - - -def downgrade(): - for row in get_old_boss_func_keys(): - create_old_func_key(row) - delete_mapping(row.func_key_id, row.template_id) - - for row in get_old_secretary_func_keys(): - create_old_func_key(row) - delete_mapping(row.func_key_id, row.template_id) - - delete_bsfilter_func_keys() - - -def get_old_boss_func_keys(): - columns = ( - func_key_mapping_table.c.func_key_id, - func_key_mapping_table.c.template_id, - func_key_mapping_table.c.position, - func_key_mapping_table.c.blf, - func_key_mapping_table.c.label, - callfiltermember_table.c.typeval.label('destination_id'), - user_table.c.id.label('user_id') - ) - - join = (func_key_mapping_table - .join(dest_bsfilter_table, - func_key_mapping_table.c.func_key_id == dest_bsfilter_table.c.func_key_id) - .join(template_table, - func_key_mapping_table.c.template_id == template_table.c.id) - .join(user_table, - template_table.c.id == user_table.c.func_key_private_template_id) - .join(callfiltermember_table, - callfiltermember_table.c.id == dest_bsfilter_table.c.filtermember_id)) - - query = (sql.select(columns, from_obj=[join])) - - return op.get_bind().execute(query) - - -def get_old_secretary_func_keys(): - boss_filtermember = callfiltermember_table.alias() - - columns = ( - func_key_mapping_table.c.func_key_id, - func_key_mapping_table.c.template_id, - func_key_mapping_table.c.position, - func_key_mapping_table.c.blf, - func_key_mapping_table.c.label, - boss_filtermember.c.typeval.label('destination_id'), - user_table.c.id.label('user_id') - ) - - join_conditions = (func_key_mapping_table - .join(dest_bsfilter_table, - func_key_mapping_table.c.func_key_id == dest_bsfilter_table.c.func_key_id) - .join(template_table, - func_key_mapping_table.c.template_id == template_table.c.id) - .join(user_table, - template_table.c.id == user_table.c.func_key_private_template_id) - .join(callfiltermember_table, - callfiltermember_table.c.id == dest_bsfilter_table.c.filtermember_id) - .join(boss_filtermember, - sql.and_( - boss_filtermember.c.bstype == BOSS_TYPE, - boss_filtermember.c.callfilterid == callfiltermember_table.c.callfilterid)) - ) - - query = sql.select(columns, from_obj=[join_conditions]) - - return op.get_bind().execute(query) - - -def create_old_func_key(row): - supervision = 1 if row.blf else 0 - - row = {'iduserfeatures': row.user_id, - 'fknum': row.position, - 'typeextenumbers': 'extenfeatures', - 'typevalextenumbers': 'bsfilter', - 'typeextenumbersright': 'user', - 'typevalextenumbersright': row.destination_id, - 'label': row.label, - 'exten': None, - 'supervision': supervision, - 'progfunckey': 0} - - op.bulk_insert(phonefunckey_table, [row]) - - -def delete_mapping(func_key_id, template_id): - query = (func_key_mapping_table - .delete() - .where(sql.and_( - func_key_mapping_table.c.func_key_id == func_key_id, - func_key_mapping_table.c.template_id == template_id))) - - op.get_bind().execute(query) - - -def delete_bsfilter_func_keys(): - query = dest_bsfilter_table.delete() - - op.get_bind().execute(query) - - query = (func_key_table - .delete() - .where(func_key_table.c.destination_type_id == DESTINATION_TYPE_ID)) - - op.get_bind().execute(query) diff --git a/alembic/versions/3b2e82f0bfbe_add_the_tenant_table.py b/alembic/versions/3b2e82f0bfbe_add_the_tenant_table.py deleted file mode 100644 index 308ff21c..00000000 --- a/alembic/versions/3b2e82f0bfbe_add_the_tenant_table.py +++ /dev/null @@ -1,25 +0,0 @@ -"""add the tenant table - -Revision ID: 3b2e82f0bfbe -Revises: 404300b7c16d - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '3b2e82f0bfbe' -down_revision = '404300b7c16d' - - -def upgrade(): - op.create_table( - 'tenant', - sa.Column('uuid', sa.String(36), server_default=sa.text('uuid_generate_v4()'), primary_key=True), - ) - - -def downgrade(): - op.drop_table('tenant') diff --git a/alembic/versions/3b7b334edb5c_add_services_forwards_acl_to_agid.py b/alembic/versions/3b7b334edb5c_add_services_forwards_acl_to_agid.py deleted file mode 100644 index 8db2ef6c..00000000 --- a/alembic/versions/3b7b334edb5c_add_services_forwards_acl_to_agid.py +++ /dev/null @@ -1,45 +0,0 @@ -"""add_services_forwards_acl_to_agid - -Revision ID: 3b7b334edb5c -Revises: 4a1c2a87321 - -""" - -from alembic import op -from sqlalchemy import sql -from sqlalchemy.dialects.postgresql import ARRAY, VARCHAR - - -# revision identifiers, used by Alembic. -revision = '3b7b334edb5c' -down_revision = '4a1c2a87321' - -accesswebservice = sql.table('accesswebservice', - sql.column('id'), - sql.column('name'), - sql.column('acl')) - -ACLS = ['confd.users.*.services.*.*', - 'confd.users.*.forwards.*.*'] - - -def upgrade(): - acls = sql.cast(ACLS, ARRAY(VARCHAR)) - query = (accesswebservice - .update() - .values( - acl=sql.func.array_cat(accesswebservice.c.acl, acls)) - .where( - accesswebservice.c.name == "xivo-agid")) - op.execute(query) - - -def downgrade(): - for acl in ACLS: - query = (accesswebservice - .update() - .values( - acl=sql.func.array_remove(accesswebservice.c.acl, acl)) - .where( - accesswebservice.c.name == "xivo-agid")) - op.execute(query) diff --git a/alembic/versions/3c14d64c95a3_add_index_on_callid_in_stat_call_on_.py b/alembic/versions/3c14d64c95a3_add_index_on_callid_in_stat_call_on_.py deleted file mode 100644 index 4f4e3693..00000000 --- a/alembic/versions/3c14d64c95a3_add_index_on_callid_in_stat_call_on_.py +++ /dev/null @@ -1,20 +0,0 @@ -"""add_index_on_callid_in_stat_call_on_queue - -Revision ID: 3c14d64c95a3 -Revises: 37c6976343d4 - -""" - -# revision identifiers, used by Alembic. -revision = '3c14d64c95a3' -down_revision = '37c6976343d4' - -from alembic import op - - -def upgrade(): - op.create_index('stat_call_on_queue__idx_callid', 'stat_call_on_queue', ['callid']) - - -def downgrade(): - op.drop_index('stat_call_on_queue__idx_callid') diff --git a/alembic/versions/3c72c43e39fa_remove_cel_fields_limits.py b/alembic/versions/3c72c43e39fa_remove_cel_fields_limits.py deleted file mode 100644 index 4796ec1d..00000000 --- a/alembic/versions/3c72c43e39fa_remove_cel_fields_limits.py +++ /dev/null @@ -1,55 +0,0 @@ -"""remove_cel_fields_limits - -Revision ID: 3c72c43e39fa -Revises: 4fe888586ba3 - -""" - -# revision identifiers, used by Alembic. -revision = '3c72c43e39fa' -down_revision = '4fe888586ba3' - -from alembic import op -from sqlalchemy.types import String, Text, UnicodeText - - -def upgrade(): - op.alter_column('cel', 'eventtype', type_=Text) - op.alter_column('cel', 'userdeftype', type_=Text) - op.alter_column('cel', 'cid_name', type_=UnicodeText) - op.alter_column('cel', 'cid_num', type_=UnicodeText) - op.alter_column('cel', 'cid_ani', type_=Text) - op.alter_column('cel', 'cid_rdnis', type_=Text) - op.alter_column('cel', 'cid_dnid', type_=Text) - op.alter_column('cel', 'exten', type_=UnicodeText) - op.alter_column('cel', 'context', type_=Text) - op.alter_column('cel', 'channame', type_=UnicodeText) - op.alter_column('cel', 'appname', type_=Text) - op.alter_column('cel', 'appdata', type_=Text) - op.alter_column('cel', 'accountcode', type_=Text) - op.alter_column('cel', 'peeraccount', type_=Text) - op.alter_column('cel', 'uniqueid', type_=Text) - op.alter_column('cel', 'linkedid', type_=Text) - op.alter_column('cel', 'userfield', type_=Text) - op.alter_column('cel', 'peer', type_=Text) - - -def downgrade(): - op.alter_column('cel', 'eventtype', type_=String(30)) - op.alter_column('cel', 'userdeftype', type_=String(255)) - op.alter_column('cel', 'cid_name', type_=String(80, convert_unicode=True)) - op.alter_column('cel', 'cid_num', type_=String(80, convert_unicode=True)) - op.alter_column('cel', 'cid_ani', type_=String(80)) - op.alter_column('cel', 'cid_rdnis', type_=String(80)) - op.alter_column('cel', 'cid_dnid', type_=String(80)) - op.alter_column('cel', 'exten', type_=String(80, convert_unicode=True)) - op.alter_column('cel', 'context', type_=String(80)) - op.alter_column('cel', 'channame', type_=String(80, convert_unicode=True)) - op.alter_column('cel', 'appname', type_=String(80)) - op.alter_column('cel', 'appdata', type_=String(512)) - op.alter_column('cel', 'accountcode', type_=String(20)) - op.alter_column('cel', 'peeraccount', type_=String(20)) - op.alter_column('cel', 'uniqueid', type_=String(150)) - op.alter_column('cel', 'linkedid', type_=String(150)) - op.alter_column('cel', 'userfield', type_=String(255)) - op.alter_column('cel', 'peer', type_=String(80)) diff --git a/alembic/versions/3c9280e9ed5c_adjust_agent_login_status_login_at.py b/alembic/versions/3c9280e9ed5c_adjust_agent_login_status_login_at.py deleted file mode 100644 index 708ee1f0..00000000 --- a/alembic/versions/3c9280e9ed5c_adjust_agent_login_status_login_at.py +++ /dev/null @@ -1,22 +0,0 @@ -"""adjust agent_login_status login_at - -Revision ID: 3c9280e9ed5c -Revises: 2c940e077157 - -""" - -# revision identifiers, used by Alembic. -revision = '3c9280e9ed5c' -down_revision = '2c940e077157' - -from alembic import op -from sqlalchemy import text - - -def upgrade(): - op.execute("UPDATE agent_login_status SET login_at = cast(login_at as timestamp with time zone) at time zone 'utc'") - op.alter_column('agent_login_status', 'login_at', server_default=text("(current_timestamp at time zone 'utc')")) - - -def downgrade(): - pass diff --git a/alembic/versions/3d22f40558d1_add_infos_table.py b/alembic/versions/3d22f40558d1_add_infos_table.py deleted file mode 100644 index 076cb8b7..00000000 --- a/alembic/versions/3d22f40558d1_add_infos_table.py +++ /dev/null @@ -1,32 +0,0 @@ -"""add infos table - -Revision ID: 3d22f40558d1 -Revises: 24b41ddb07d7 - -""" - -import os - -from alembic import op -import sqlalchemy as sa - -# revision identifiers, used by Alembic. -revision = '3d22f40558d1' -down_revision = '24b41ddb07d7' - - -def upgrade(): - op.create_table( - 'infos', - sa.Column('uuid', sa.String(38), nullable=False), - sa.PrimaryKeyConstraint('uuid') - ) - - xivo_uuid = os.environ['XIVO_UUID'] - infos_table = sa.sql.table('infos', sa.sql.column('uuid')) - infos_query = infos_table.insert().values(uuid=xivo_uuid) - op.get_bind().execute(infos_query) - - -def downgrade(): - op.drop_table('infos') diff --git a/alembic/versions/3df184c10386_create_transfer_function_keys.py b/alembic/versions/3df184c10386_create_transfer_function_keys.py deleted file mode 100644 index e3530d2a..00000000 --- a/alembic/versions/3df184c10386_create_transfer_function_keys.py +++ /dev/null @@ -1,132 +0,0 @@ -"""create transfer function keys - -Revision ID: 3df184c10386 -Revises: 18e40e519e1b - -""" - -# revision identifiers, used by Alembic. -revision = '3df184c10386' -down_revision = '27d9ea4b21d0' - -from alembic import op -import sqlalchemy as sa - - -DTMF_TYPE_NAME = 'dtmf' -DTMF_TYPE_ID = 3 - -FEATURES_TYPE_NAME = 'features' - -BLIND_TRANSFER_TYPE = 'blindxfer' -ATTENDED_TRANSFER_TYPE = 'atxfer' - -func_key_table = sa.sql.table('func_key', - sa.sql.column('id'), - sa.sql.column('type_id'), - sa.sql.column('destination_type_id')) - -func_key_type_table = sa.sql.table('func_key_type', - sa.sql.column('id'), - sa.sql.column('name')) - -func_key_destination_type_table = sa.sql.table('func_key_destination_type', - sa.sql.column('id'), - sa.sql.column('name')) - -func_key_dest_features_table = sa.sql.table('func_key_dest_features', - sa.sql.column('func_key_id'), - sa.sql.column('destination_type_id'), - sa.sql.column('features_id')) - -features_table = sa.sql.table('features', - sa.sql.column('id'), - sa.sql.column('category'), - sa.sql.column('var_name')) - - -def upgrade(): - type_id = insert_dtmf_type() - destination_type_id = find_features_type() - insert_transfer_func_key(type_id, destination_type_id, BLIND_TRANSFER_TYPE) - insert_transfer_func_key(type_id, destination_type_id, ATTENDED_TRANSFER_TYPE) - - -def insert_dtmf_type(): - query = (func_key_type_table - .insert() - .returning(func_key_type_table.c.id) - .values(id=DTMF_TYPE_ID, - name=DTMF_TYPE_NAME)) - - dtmf_id = op.get_bind().execute(query).scalar() - op.get_bind().execute("SELECT setval('func_key_type_id_seq', (SELECT MAX(id) FROM func_key_type))") - - return dtmf_id - - -def find_features_type(): - query = (sa.sql.select([func_key_destination_type_table.c.id]) - .where(func_key_destination_type_table.c.name == FEATURES_TYPE_NAME)) - - return op.get_bind().execute(query).scalar() - - -def insert_transfer_func_key(type_id, destination_type_id, transfer_type): - func_key_query = (func_key_table - .insert() - .returning(func_key_table.c.id) - .values(type_id=type_id, - destination_type_id=destination_type_id)) - - func_key_id = op.get_bind().execute(func_key_query).scalar() - - features_query = ( - sa.sql.select( - [features_table.c.id]) - .where( - sa.sql.and_( - features_table.c.category == 'featuremap', - features_table.c.var_name == transfer_type))) - - features_id = op.get_bind().execute(features_query).scalar() - - dest_query = (func_key_dest_features_table - .insert() - .returning(func_key_dest_features_table.c.func_key_id) - .values(func_key_id=func_key_id, - destination_type_id=destination_type_id, - features_id=features_id)) - - return op.get_bind().execute(dest_query).scalar() - - -def downgrade(): - features_query = (sa.sql.select([features_table.c.id]) - .where( - sa.sql.and_( - features_table.c.category == 'featuremap', - features_table.c.var_name.in_((BLIND_TRANSFER_TYPE, - ATTENDED_TRANSFER_TYPE)))) - .alias()) - - query = (sa.sql.select([func_key_dest_features_table.c.func_key_id]) - .where( - func_key_dest_features_table.c.features_id.in_(features_query)) - ) - - for row in op.get_bind().execute(query): - dest_query = (func_key_dest_features_table - .delete() - .where(func_key_dest_features_table.c.func_key_id == row.func_key_id)) - - func_key_query = (func_key_table - .delete() - .where(func_key_table.c.id == row.func_key_id)) - - op.get_bind().execute(dest_query) - op.get_bind().execute(func_key_query) - - op.execute(func_key_type_table - .delete() - .where(func_key_type_table.c.name == DTMF_TYPE_NAME)) diff --git a/alembic/versions/3e185fe069be_remove_constraints_agentfeatures.py b/alembic/versions/3e185fe069be_remove_constraints_agentfeatures.py deleted file mode 100644 index 250c1d9e..00000000 --- a/alembic/versions/3e185fe069be_remove_constraints_agentfeatures.py +++ /dev/null @@ -1,30 +0,0 @@ -"""remove_constraints_agentfeatures - -Revision ID: 3e185fe069be -Revises: 570d858c41d6 - -""" - -from alembic import op - -# revision identifiers, used by Alembic. -revision = '3e185fe069be' -down_revision = '570d858c41d6' - - -def upgrade(): - op.alter_column('agentfeatures', 'firstname', nullable=True, server_default=None) - op.alter_column('agentfeatures', 'lastname', nullable=True, server_default=None) - op.alter_column('agentfeatures', 'passwd', nullable=True) - op.alter_column('agentfeatures', 'language', nullable=True) - op.alter_column('agentfeatures', 'context', nullable=True) - op.alter_column('agentfeatures', 'description', nullable=True) - - -def downgrade(): - op.alter_column('agentfeatures', 'firstname', nullable=False, server_default='') - op.alter_column('agentfeatures', 'lastname', nullable=False, server_default='') - op.alter_column('agentfeatures', 'passwd', nullable=False) - op.alter_column('agentfeatures', 'language', nullable=False) - op.alter_column('agentfeatures', 'context', nullable=False) - op.alter_column('agentfeatures', 'description', nullable=False) diff --git a/alembic/versions/3e6bc9ae6158_add_xivo_call_logs_web_service.py b/alembic/versions/3e6bc9ae6158_add_xivo_call_logs_web_service.py deleted file mode 100644 index 5217046f..00000000 --- a/alembic/versions/3e6bc9ae6158_add_xivo_call_logs_web_service.py +++ /dev/null @@ -1,38 +0,0 @@ -"""add xivo-auth web service - -Revision ID: 3e6bc9ae6158 -Revises: d9e7aac4970 - -""" - -# revision identifiers, used by Alembic. -revision = '3e6bc9ae6158' -down_revision = 'd9e7aac4970' - -from alembic import op -from sqlalchemy import sql, func - - -webservice = sql.table('accesswebservice', - sql.column('name'), - sql.column('login'), - sql.column('passwd'), - sql.column('acl'), - sql.column('description')) -ACL = '{confd.lines.read}' -DESCRIPTION = 'Automatically created during upgrade' -SERVICE = 'xivo-call-logd' - - -def upgrade(): - op.execute(webservice - .insert() - .values(name=SERVICE, - login=SERVICE, - passwd=func.substring(func.gen_salt('bf', 4), 8), - acl=ACL, - description=DESCRIPTION)) - - -def downgrade(): - op.execute(webservice.delete().where(webservice.c.name == SERVICE)) diff --git a/alembic/versions/3e7dbde01837_bump_version_17_13.py b/alembic/versions/3e7dbde01837_bump_version_17_13.py deleted file mode 100644 index bf808b5b..00000000 --- a/alembic/versions/3e7dbde01837_bump_version_17_13.py +++ /dev/null @@ -1,22 +0,0 @@ -"""bump_version_17_13 - -Revision ID: 3e7dbde01837 -Revises: 508c5a0382dc - -""" - -# revision identifiers, used by Alembic. -revision = '3e7dbde01837' -down_revision = '508c5a0382dc' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='17.13')) - - -def downgrade(): - pass diff --git a/alembic/versions/3ecc983a901c_remove_usersip_registertrying.py b/alembic/versions/3ecc983a901c_remove_usersip_registertrying.py deleted file mode 100644 index 85c7ef91..00000000 --- a/alembic/versions/3ecc983a901c_remove_usersip_registertrying.py +++ /dev/null @@ -1,21 +0,0 @@ -"""remove usersip registertrying - -Revision ID: 3ecc983a901c -Revises: b8d0848e7b2 - -""" - -# revision identifiers, used by Alembic. -revision = '3ecc983a901c' -down_revision = 'b8d0848e7b2' - -from alembic import op -from sqlalchemy import Column, Integer - - -def upgrade(): - op.drop_column('usersip', 'registertrying') - - -def downgrade(): - op.add_column('usersip', Column('registertrying', Integer)) diff --git a/alembic/versions/3edd3b3aac7d_bump_version_21_13.py b/alembic/versions/3edd3b3aac7d_bump_version_21_13.py deleted file mode 100644 index b7391f0b..00000000 --- a/alembic/versions/3edd3b3aac7d_bump_version_21_13.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_21_13 - -Revision ID: 3edd3b3aac7d -Revises: d9eaed7a2f42 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '3edd3b3aac7d' -down_revision = 'd9eaed7a2f42' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='21.13')) - - -def downgrade(): - pass diff --git a/alembic/versions/3f132402532b_bump_version_19_04.py b/alembic/versions/3f132402532b_bump_version_19_04.py deleted file mode 100644 index d26faca4..00000000 --- a/alembic/versions/3f132402532b_bump_version_19_04.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_19_04 - -Revision ID: 3f132402532b -Revises: 1a13acc6cdb0 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '3f132402532b' -down_revision = '1a13acc6cdb0' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='19.04')) - - -def downgrade(): - pass diff --git a/alembic/versions/3f310bfa7f9a_remove_chan_sip_permaturemedia.py b/alembic/versions/3f310bfa7f9a_remove_chan_sip_permaturemedia.py deleted file mode 100644 index 04b05901..00000000 --- a/alembic/versions/3f310bfa7f9a_remove_chan_sip_permaturemedia.py +++ /dev/null @@ -1,25 +0,0 @@ -"""remove chan_sip permaturemedia - -Revision ID: 3f310bfa7f9a -Revises: 2989b8b30fe7 - -""" - -# revision identifiers, used by Alembic. -revision = '3f310bfa7f9a' -down_revision = '2989b8b30fe7' - -from alembic import op -from sqlalchemy import sql - - -staticsip = sql.table('staticsip', - sql.column('var_name')) - - -def upgrade(): - op.execute(staticsip.delete().where(staticsip.c.var_name == 'permaturemedia')) - - -def downgrade(): - pass diff --git a/alembic/versions/3fe6319ce27a_create_func_key_custom.py b/alembic/versions/3fe6319ce27a_create_func_key_custom.py deleted file mode 100644 index 86b1cdf3..00000000 --- a/alembic/versions/3fe6319ce27a_create_func_key_custom.py +++ /dev/null @@ -1,48 +0,0 @@ -"""create func key custom - -Revision ID: 3fe6319ce27a -Revises: 234745874c55 - -""" - -# revision identifiers, used by Alembic. -revision = '3fe6319ce27a' -down_revision = '234745874c55' - -from alembic import op -import sqlalchemy as sa - - -CUSTOM_TYPE_ID = 10 -CUSTOM_TYPE_NAME = 'custom' - -destination_type_table = sa.sql.table('func_key_destination_type', - sa.sql.column('id'), - sa.sql.column('name')) - - -def upgrade(): - service_type_row = {'id': CUSTOM_TYPE_ID, 'name': CUSTOM_TYPE_NAME} - op.bulk_insert(destination_type_table, [service_type_row]) - - op.create_table( - 'func_key_dest_custom', - sa.Column('func_key_id', sa.Integer), - sa.Column('destination_type_id', - sa.Integer, - sa.CheckConstraint('destination_type_id = %d' % CUSTOM_TYPE_ID), - server_default=str(CUSTOM_TYPE_ID)), - sa.Column('exten', sa.String(40), nullable=False), - sa.PrimaryKeyConstraint('func_key_id', 'destination_type_id'), - sa.ForeignKeyConstraint(['func_key_id', 'destination_type_id'], - ['func_key.id', 'func_key.destination_type_id']), - ) - - -def downgrade(): - op.drop_table('func_key_dest_custom') - - delete_query = (destination_type_table - .delete() - .where(destination_type_table.c.id == CUSTOM_TYPE_ID)) - op.execute(delete_query) diff --git a/alembic/versions/40359c5c2c92_bump_version_18_01.py b/alembic/versions/40359c5c2c92_bump_version_18_01.py deleted file mode 100644 index c35186fa..00000000 --- a/alembic/versions/40359c5c2c92_bump_version_18_01.py +++ /dev/null @@ -1,22 +0,0 @@ -"""bump_version_18_01 - -Revision ID: 40359c5c2c92 -Revises: 1815dcbc813f - -""" - -# revision identifiers, used by Alembic. -revision = '40359c5c2c92' -down_revision = '1815dcbc813f' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='18.01')) - - -def downgrade(): - pass diff --git a/alembic/versions/404300b7c16d_remove_loginclient_passwdclient_data_from_.py b/alembic/versions/404300b7c16d_remove_loginclient_passwdclient_data_from_.py deleted file mode 100644 index 59dc4eda..00000000 --- a/alembic/versions/404300b7c16d_remove_loginclient_passwdclient_data_from_.py +++ /dev/null @@ -1,27 +0,0 @@ -"""remove_loginclient_passwdclient_data_from_userfeatures - -Revision ID: 404300b7c16d -Revises: eee032b308b - -""" - -from alembic import op -from sqlalchemy import sql - -# revision identifiers, used by Alembic. -revision = '404300b7c16d' -down_revision = 'eee032b308b' - -userfeatures = sql.table( - 'userfeatures', - sql.column('loginclient'), - sql.column('passwdclient'), -) - - -def upgrade(): - op.execute(userfeatures.update().values(loginclient='', passwdclient='')) - - -def downgrade(): - pass diff --git a/alembic/versions/40ba1a488aa7_phonebook_file_to_csv.py b/alembic/versions/40ba1a488aa7_phonebook_file_to_csv.py deleted file mode 100644 index ad20bee0..00000000 --- a/alembic/versions/40ba1a488aa7_phonebook_file_to_csv.py +++ /dev/null @@ -1,32 +0,0 @@ -"""phonebook file to csv - -Revision ID: 40ba1a488aa7 -Revises: 1a730d10e4a7 - -""" - -# revision identifiers, used by Alembic. -revision = '40ba1a488aa7' -down_revision = '1a730d10e4a7' - -from alembic import op -from sqlalchemy import sql - -directories_table = sql.table('directories', - sql.column('dirtype')) - - -def upgrade(): - op.execute(directories_table - .update() - .where( - directories_table.c.dirtype == 'file' - ).values(dirtype='csv')) - - -def downgrade(): - op.execute(directories_table - .update() - .where( - directories_table.c.dirtype == 'csv' - ).values(dirtype='file')) diff --git a/alembic/versions/40e2f31cf146_remove_orphan_func_key.py b/alembic/versions/40e2f31cf146_remove_orphan_func_key.py deleted file mode 100644 index 0a8bd706..00000000 --- a/alembic/versions/40e2f31cf146_remove_orphan_func_key.py +++ /dev/null @@ -1,152 +0,0 @@ -"""remove_orphan_func_key - -Revision ID: 40e2f31cf146 -Revises: 014b218f97dd - -""" - -from alembic import op -from sqlalchemy import sql - - -# revision identifiers, used by Alembic. -revision = '40e2f31cf146' -down_revision = '014b218f97dd' - -func_key = sql.table( - 'func_key', - sql.column('id'), - sql.column('destination_type_id'), -) - -func_key_mapping = sql.table( - 'func_key_mapping', - sql.column('func_key_id'), -) - -func_key_dest_agent = sql.table( - 'func_key_dest_agent', - sql.column('func_key_id'), - sql.column('destination_type_id'), -) - -func_key_dest_bsfilter = sql.table( - 'func_key_dest_bsfilter', - sql.column('func_key_id'), - sql.column('destination_type_id'), -) - -func_key_dest_conference = sql.table( - 'func_key_dest_conference', - sql.column('func_key_id'), - sql.column('destination_type_id'), -) - -func_key_dest_custom = sql.table( - 'func_key_dest_custom', - sql.column('func_key_id'), - sql.column('destination_type_id'), -) - -func_key_dest_features = sql.table( - 'func_key_dest_features', - sql.column('func_key_id'), - sql.column('destination_type_id'), -) - -func_key_dest_forward = sql.table( - 'func_key_dest_forward', - sql.column('func_key_id'), - sql.column('destination_type_id'), -) - -func_key_dest_group = sql.table( - 'func_key_dest_group', - sql.column('func_key_id'), - sql.column('destination_type_id'), -) - -func_key_dest_paging = sql.table( - 'func_key_dest_paging', - sql.column('func_key_id'), - sql.column('destination_type_id'), -) - -func_key_dest_park_position = sql.table( - 'func_key_dest_park_position', - sql.column('func_key_id'), - sql.column('destination_type_id'), -) - -func_key_dest_queue = sql.table( - 'func_key_dest_queue', - sql.column('func_key_id'), - sql.column('destination_type_id'), -) - -func_key_dest_service = sql.table( - 'func_key_dest_service', - sql.column('func_key_id'), - sql.column('destination_type_id'), -) - -func_key_dest_user = sql.table( - 'func_key_dest_user', - sql.column('func_key_id'), - sql.column('destination_type_id'), -) - - -def upgrade(): - func_key_results = op.get_bind().execute( - sql.select([func_key.c.id]) - .select_from( - func_key - .outerjoin(func_key_dest_agent, func_key_dest_agent.c.func_key_id == func_key.c.id) - .outerjoin(func_key_dest_bsfilter, func_key_dest_bsfilter.c.func_key_id == func_key.c.id) - .outerjoin(func_key_dest_conference, func_key_dest_conference.c.func_key_id == func_key.c.id) - .outerjoin(func_key_dest_custom, func_key_dest_custom.c.func_key_id == func_key.c.id) - .outerjoin(func_key_dest_features, func_key_dest_features.c.func_key_id == func_key.c.id) - .outerjoin(func_key_dest_forward, func_key_dest_forward.c.func_key_id == func_key.c.id) - .outerjoin(func_key_dest_group, func_key_dest_group.c.func_key_id == func_key.c.id) - .outerjoin(func_key_dest_paging, func_key_dest_paging.c.func_key_id == func_key.c.id) - .outerjoin(func_key_dest_park_position, func_key_dest_park_position.c.func_key_id == func_key.c.id) - .outerjoin(func_key_dest_queue, func_key_dest_queue.c.func_key_id == func_key.c.id) - .outerjoin(func_key_dest_service, func_key_dest_service.c.func_key_id == func_key.c.id) - .outerjoin(func_key_dest_user, func_key_dest_user.c.func_key_id == func_key.c.id) - ) - .where(sql.and_( - func_key_dest_agent.c.func_key_id == None, - func_key_dest_bsfilter.c.func_key_id == None, - func_key_dest_conference.c.func_key_id == None, - func_key_dest_custom.c.func_key_id == None, - func_key_dest_features.c.func_key_id == None, - func_key_dest_forward.c.func_key_id == None, - func_key_dest_group.c.func_key_id == None, - func_key_dest_paging.c.func_key_id == None, - func_key_dest_park_position.c.func_key_id == None, - func_key_dest_queue.c.func_key_id == None, - func_key_dest_service.c.func_key_id == None, - func_key_dest_user.c.func_key_id == None, - )) - - ) - func_key_ids = [func_key_result.id for func_key_result in func_key_results] - - if not func_key_ids: - return - - op.execute( - func_key_mapping - .delete() - .where(func_key_mapping.c.func_key_id.in_(func_key_ids)) - ) - op.execute( - func_key - .delete() - .where(func_key.c.id.in_(func_key_ids)) - ) - - -def downgrade(): - pass diff --git a/alembic/versions/40e6d1e4c2c3_schedule_add_tenant_uuid.py b/alembic/versions/40e6d1e4c2c3_schedule_add_tenant_uuid.py deleted file mode 100644 index d2b28ab1..00000000 --- a/alembic/versions/40e6d1e4c2c3_schedule_add_tenant_uuid.py +++ /dev/null @@ -1,57 +0,0 @@ -"""schedule_add_tenant_uuid - -Revision ID: 40e6d1e4c2c3 -Revises: 58cd88054523 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '40e6d1e4c2c3' -down_revision = '58cd88054523' - - -TABLE = 'schedule' - - -def find_default_tenant_uuid(): - entity_table = sa.sql.table( - 'entity', - sa.sql.column('id'), - sa.sql.column('tenant_uuid'), - ) - query = sa.sql.select([entity_table.c.tenant_uuid]).order_by(entity_table.c.id) - for row in op.get_bind().execute(query): - return row.tenant_uuid - - -def associate_tenants(): - tbl = sa.sql.table('schedule', sa.sql.column('id'), sa.sql.column('tenant_uuid')) - sql = "SELECT schedule.id, entity.tenant_uuid FROM schedule, entity WHERE entity.id=schedule.entity_id" - schedule_to_tenant = op.get_bind().execute(sa.sql.text(sql)) - - for schedule_id, tenant_uuid in schedule_to_tenant: - query = tbl.update().where(tbl.c.id == schedule_id).values(tenant_uuid=tenant_uuid) - op.execute(query) - - -def upgrade(): - default_tenant = find_default_tenant_uuid() - op.add_column( - TABLE, - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=False, - server_default=default_tenant), - ) - associate_tenants() - op.alter_column(TABLE, 'tenant_uuid', server_default=None) - - -def downgrade(): - op.drop_column(TABLE, 'tenant_uuid') diff --git a/alembic/versions/4123465e114e_add_agentd_acl_to_agid.py b/alembic/versions/4123465e114e_add_agentd_acl_to_agid.py deleted file mode 100644 index e16fb2f0..00000000 --- a/alembic/versions/4123465e114e_add_agentd_acl_to_agid.py +++ /dev/null @@ -1,35 +0,0 @@ -"""add_agentd_acl_to_agid - -Revision ID: 4123465e114e -Revises: 2903faf08938 - -""" - -# revision identifiers, used by Alembic. -revision = '4123465e114e' -down_revision = '2903faf08938' - -from alembic import op -from sqlalchemy import sql - -webservice = sql.table('accesswebservice', - sql.column('name'), - sql.column('acl')) - - -def upgrade(): - _update_web_service_acl('xivo-agid', - '{dird.directories.reverse.*.*.read, agentd.#}') - - -def downgrade(): - _update_web_service_acl('xivo-agid', - '{dird.directories.reverse.*.*.read}') - - -def _update_web_service_acl(name, acl): - op.execute(webservice - .update() - .where( - webservice.c.name == name - ).values(acl=acl)) diff --git a/alembic/versions/412b6135f650_rename_xivo_auth_to_wazo_auth.py b/alembic/versions/412b6135f650_rename_xivo_auth_to_wazo_auth.py deleted file mode 100644 index d2c80613..00000000 --- a/alembic/versions/412b6135f650_rename_xivo_auth_to_wazo_auth.py +++ /dev/null @@ -1,40 +0,0 @@ -"""rename xivo-auth to wazo-auth - -Revision ID: 412b6135f650 -Revises: 5c8dc069cfd7 - -""" - -# revision identifiers, used by Alembic. -revision = '412b6135f650' -down_revision = '5c8dc069cfd7' - -from alembic import op -import sqlalchemy as sa - -webservice = sa.sql.table('accesswebservice', - sa.sql.column('name'), - sa.sql.column('login')) - -OLD_NAME = 'xivo-auth' -NEW_NAME = 'wazo-auth' - - -def rename_webservice_access(old_name, new_name): - op.execute( - webservice.update( - ).values( - name=new_name, - login=new_name, - ).where( - webservice.c.name == old_name, - ) - ) - - -def upgrade(): - rename_webservice_access(OLD_NAME, NEW_NAME) - - -def downgrade(): - rename_webservice_access(NEW_NAME, OLD_NAME) diff --git a/alembic/versions/415b08ed9959_add_xivo_auth_web_service.py b/alembic/versions/415b08ed9959_add_xivo_auth_web_service.py deleted file mode 100644 index b43347ca..00000000 --- a/alembic/versions/415b08ed9959_add_xivo_auth_web_service.py +++ /dev/null @@ -1,38 +0,0 @@ -"""add xivo-auth web service - -Revision ID: 415b08ed9959 -Revises: 1ddfb39a066f - -""" - -# revision identifiers, used by Alembic. -revision = '415b08ed9959' -down_revision = '1ddfb39a066f' - -from alembic import op -from sqlalchemy import sql, func - - -webservice = sql.table('accesswebservice', - sql.column('name'), - sql.column('login'), - sql.column('passwd'), - sql.column('acl'), - sql.column('description')) -ACL = '{confd.users.read}' -DESCRIPTION = 'Automatically created during upgrade' -SERVICE = 'xivo-auth' - - -def upgrade(): - op.execute(webservice - .insert() - .values(name=SERVICE, - login=SERVICE, - passwd=func.substring(func.gen_salt('bf', 4), 8), - acl=ACL, - description=DESCRIPTION)) - - -def downgrade(): - op.execute(webservice.delete().where(webservice.c.name == SERVICE)) diff --git a/alembic/versions/41a523e18fdd_bump_version_18_03.py b/alembic/versions/41a523e18fdd_bump_version_18_03.py deleted file mode 100644 index 3ec2f7f1..00000000 --- a/alembic/versions/41a523e18fdd_bump_version_18_03.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_18_03 - -Revision ID: 41a523e18fdd -Revises: 36516503ae1b - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '41a523e18fdd' -down_revision = '36516503ae1b' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='18.03')) - - -def downgrade(): - pass diff --git a/alembic/versions/41b6afe5b164_usercustom_add_tenant_uuid.py b/alembic/versions/41b6afe5b164_usercustom_add_tenant_uuid.py deleted file mode 100644 index 0a8874ff..00000000 --- a/alembic/versions/41b6afe5b164_usercustom_add_tenant_uuid.py +++ /dev/null @@ -1,71 +0,0 @@ -"""usercustom_add_tenant_uuid - -Revision ID: 41b6afe5b164 -Revises: 354fe6b9e819 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '41b6afe5b164' -down_revision = '354fe6b9e819' - -TABLE = 'usercustom' - - -def find_default_tenant_uuid(): - entity_table = sa.sql.table( - 'entity', - sa.sql.column('id'), - sa.sql.column('name'), - sa.sql.column('tenant_uuid'), - ) - query = sa.sql.select([entity_table.c.tenant_uuid]).order_by(entity_table.c.id) - for row in op.get_bind().execute(query): - return row.tenant_uuid - - -def associate_tenants(): - tbl = sa.sql.table('usercustom', sa.sql.column('id'), sa.sql.column('tenant_uuid')) - sql = "SELECT usercustom.id, context.tenant_uuid FROM usercustom JOIN linefeatures ON (linefeatures.protocol = 'custom' AND linefeatures.protocolid = usercustom.id) JOIN context ON linefeatures.context = context.name" - usercustom_to_tenant = op.get_bind().execute(sa.sql.text(sql)) - - for usercustom_id, tenant_uuid in usercustom_to_tenant: - query = tbl.update().where(tbl.c.id == usercustom_id).values(tenant_uuid=tenant_uuid) - op.execute(query) - - sql = "SELECT usercustom.id, trunkfeatures.tenant_uuid FROM usercustom, trunkfeatures WHERE trunkfeatures.protocol = 'custom' AND trunkfeatures.protocolid = usercustom.id" - usercustom_to_tenant = op.get_bind().execute(sa.sql.text(sql)) - - for usercustom_id, tenant_uuid in usercustom_to_tenant: - query = tbl.update().where(tbl.c.id == usercustom_id).values(tenant_uuid=tenant_uuid) - op.execute(query) - - sql = "SELECT usercustom.id, context.tenant_uuid FROM usercustom JOIN context ON usercustom.context = context.name LEFT JOIN linefeatures ON (linefeatures.protocol = 'custom' AND linefeatures.protocolid = usercustom.id) LEFT JOIN trunkfeatures ON (trunkfeatures.protocol = 'custom' AND trunkfeatures.protocolid = usercustom.id) WHERE linefeatures.protocolid IS NULL AND trunkfeatures.protocolid IS NULL;" - usercustom_to_tenant = op.get_bind().execute(sa.sql.text(sql)) - - for usercustom_id, tenant_uuid in usercustom_to_tenant: - query = tbl.update().where(tbl.c.id == usercustom_id).values(tenant_uuid=tenant_uuid) - op.execute(query) - - -def upgrade(): - default_tenant = find_default_tenant_uuid() - op.add_column( - TABLE, - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=False, - server_default=default_tenant), - ) - associate_tenants() - op.alter_column(TABLE, 'tenant_uuid', server_default=None) - - -def downgrade(): - op.drop_column(TABLE, 'tenant_uuid') diff --git a/alembic/versions/41d3e47edf4a_missing_func_key_dest_user_pointing_to_.py b/alembic/versions/41d3e47edf4a_missing_func_key_dest_user_pointing_to_.py deleted file mode 100644 index 4d7d66f9..00000000 --- a/alembic/versions/41d3e47edf4a_missing_func_key_dest_user_pointing_to_.py +++ /dev/null @@ -1,138 +0,0 @@ -"""Missing func_key_dest_user_pointing_to_users - -Revision ID: 41d3e47edf4a -Revises: 58e808b69aec - -""" - -# revision identifiers, used by Alembic. -revision = '41d3e47edf4a' -down_revision = '58e808b69aec' - -from alembic import op -import sqlalchemy as sa - - -TYPE_SPEEDDIAL = 'speeddial' - -DESTINATION_USER_ID = 1 -DESTINATION_USER_NAME = 'user' - - -userfeatures_table = sa.sql.table('userfeatures', - sa.sql.column('id'), - sa.sql.column('func_key_private_template_id')) - -func_key_table = sa.sql.table('func_key', - sa.sql.column('id'), - sa.sql.column('type_id'), - sa.sql.column('destination_type_id')) - -func_key_type_table = sa.sql.table('func_key_type', - sa.sql.column('id'), - sa.sql.column('name')) - -destination_type_table = sa.sql.table('func_key_destination_type', - sa.sql.column('id'), - sa.sql.column('name')) - -destination_user_table = sa.sql.table('func_key_dest_user', - sa.sql.column('func_key_id'), - sa.sql.column('destination_type_id'), - sa.sql.column('user_id')) - -userfeatures_table_query = (sa.sql.select( - [userfeatures_table.c.id, - userfeatures_table.c.func_key_private_template_id])) - -destination_user_table_query = (sa.sql.select([destination_user_table.c.func_key_id, - destination_user_table.c.destination_type_id, - destination_user_table.c.user_id])) - -func_key_table_query = (sa.sql.select([func_key_table.c.id, - func_key_table.c.type_id, - func_key_table.c.destination_type_id]) - .where(func_key_table.c.destination_type_id == DESTINATION_USER_ID)) - - -def upgrade(): - for user in _get_users(): - if _get_fk_id_dst_user_with_user_id(user.id) is None: - _create_func_key_for_user(user.id) - - _clean_orphan_func_key() - - -def _get_speeddial_id(): - return op.get_bind().execute( - sa.sql.select( - [func_key_type_table.c.id]) - .where( - func_key_type_table.c.name == TYPE_SPEEDDIAL) - ).scalar() - - -def _get_users(): - return op.get_bind().execute(userfeatures_table_query) - - -def _get_all_user_func_key(): - return op.get_bind().execute(func_key_table_query) - - -def _get_fk_id_dst_user_with_user_id(user_id): - return op.get_bind().execute( - sa.sql.select( - [destination_user_table.c.func_key_id]) - .where( - destination_user_table.c.user_id == user_id) - ).scalar() - - -def _get_user_id_with_func_key_id(fk_id): - return op.get_bind().execute( - sa.sql.select( - [destination_user_table.c.user_id]) - .where( - destination_user_table.c.func_key_id == fk_id) - ).scalar() - - -def _create_func_key(): - speeddial_id = _get_speeddial_id() - insert_query = (func_key_table - .insert() - .returning(func_key_table.c.id) - .values(type_id=speeddial_id, - destination_type_id=DESTINATION_USER_ID)) - - return op.get_bind().execute(insert_query).scalar() - - -def _create_func_key_for_user(user_id): - func_key_id = _create_func_key() - insert_query = (destination_user_table - .insert() - .values(func_key_id=func_key_id, - user_id=user_id, - destination_type_id=DESTINATION_USER_ID)) - - op.get_bind().execute(insert_query) - - -def _clean_orphan_func_key(): - for fk in _get_all_user_func_key(): - if _get_user_id_with_func_key_id(fk.id) is None: - _delete_func_key_with_id(fk.id) - - -def _delete_func_key_with_id(fk_id): - query = (func_key_table - .delete() - .where(func_key_table.c.id == fk_id)) - - op.get_bind().execute(query) - - -def downgrade(): - pass diff --git a/alembic/versions/41e07bde92da_directories_rename_internal_to_xivo.py b/alembic/versions/41e07bde92da_directories_rename_internal_to_xivo.py deleted file mode 100644 index bad5ce75..00000000 --- a/alembic/versions/41e07bde92da_directories_rename_internal_to_xivo.py +++ /dev/null @@ -1,48 +0,0 @@ -"""directories rename internal to xivo - -Revision ID: 41e07bde92da -Revises: 4a80d0e24028 - -""" - -# revision identifiers, used by Alembic. -revision = '41e07bde92da' -down_revision = '4a80d0e24028' - -from alembic import op -from sqlalchemy import sql - -directories_table = sql.table('directories', - sql.column('name'), - sql.column('uri'), - sql.column('id'), - sql.column('dirtype')) - -cti_directories_table = sql.table('ctidirectories', - sql.column('uri')) - - -def upgrade(): - op.execute(directories_table - .update() - .where( - directories_table.c.uri == 'internal' - ).values(uri='xivo', name='xivo', dirtype='xivo')) - op.execute(cti_directories_table - .update() - .where( - cti_directories_table.c.uri == 'internal' - ).values(uri='xivo')) - - -def downgrade(): - op.execute(directories_table - .update() - .where( - directories_table.c.uri == 'xivo' - ).values(uri='internal', name='internal', dirtype='internal')) - op.execute(cti_directories_table - .update() - .where( - cti_directories_table.c.uri == 'xivo' - ).values(uri='internal')) diff --git a/alembic/versions/41f6ef3f00fe_voicemail_extra_options.py b/alembic/versions/41f6ef3f00fe_voicemail_extra_options.py deleted file mode 100644 index 2ed43262..00000000 --- a/alembic/versions/41f6ef3f00fe_voicemail_extra_options.py +++ /dev/null @@ -1,188 +0,0 @@ -"""voicemail_extra_options - -Revision ID: 41f6ef3f00fe -Revises: 1632064e0441 - -""" - -from alembic import op -import sqlalchemy as sa -from sqlalchemy import sql, Column, String, Integer, Enum, Text, Float -from sqlalchemy.dialects.postgresql import ARRAY - -# revision identifiers, used by Alembic. -revision = '41f6ef3f00fe' -down_revision = '1632064e0441' - - -OPTIONS = ('dialout', - 'callback', - 'exitcontext', - 'saycid', - 'review', - 'operator', - 'envelope', - 'sayduration', - 'saydurationm', - 'sendvoicemail', - 'forcename', - 'forcegreetings', - 'hidefromdir', - 'emailsubject', - 'emailbody', - 'imapuser', - 'imappassword', - 'imapfolder', - 'imapvmsharedid', - 'attachfmt', - 'serveremail', - 'locale', - 'tempgreetwarn', - 'messagewrap', - 'moveheard', - 'minsecs', - 'maxsecs', - 'nextaftercmd', - 'backupdeleted', - 'volgain', - 'passwordlocation') - - -NUMERIC_OPTIONS = ('minsecs', - 'maxsecs', - 'backupdeleted', - 'volgain') - - -LEGACY_FLAGS = ('saycid', - 'review', - 'operator', - 'envelope', - 'sayduration', - 'saydurationm', - 'forcename', - 'forcegreetings', - 'tempgreetwarn', - 'messagewrap', - 'moveheard', - 'nextaftercmd', - 'backupdeleted') - - -def gen_columns(): - return (Column('dialout', String(39)), - Column('callback', String(39)), - Column('exitcontext', String(39)), - Column('saycid', Integer), - Column('review', Integer), - Column('operator', Integer), - Column('envelope', Integer), - Column('sayduration', Integer), - Column('saydurationm', Integer), - Column('sendvoicemail', Integer), - Column('forcename', Integer), - Column('forcegreetings', Integer), - Column('hidefromdir', - Enum('no', 'yes', name='voicemail_hidefromdir'), - nullable=False, - server_default='no'), - Column('emailsubject', String(1024)), - Column('emailbody', Text), - Column('imapuser', String(1024)), - Column('imappassword', String(1024)), - Column('imapfolder', String(1024)), - Column('imapvmsharedid', String(1024)), - Column('attachfmt', String(1024)), - Column('serveremail', String(1024)), - Column('locale', String(1024)), - Column('tempgreetwarn', Integer), - Column('messagewrap', Integer), - Column('moveheard', Integer), - Column('minsecs', Integer), - Column('maxsecs', Integer), - Column('nextaftercmd', Integer), - Column('backupdeleted', Integer), - Column('volgain', Float), - Column('passwordlocation', - Enum('spooldir', 'voicemail', name='voicemail_passwordlocation')), - ) - - -def upgrade(): - op.add_column('voicemail', sa.Column('options', - ARRAY(sa.String, dimensions=2), - nullable=False, server_default='{}')) - - voicemail = sql.table('voicemail', - sql.column('uniqueid'), - sql.column('options'), - *gen_columns()) - - query = sql.select([voicemail]) - - for row in op.get_bind().execute(query): - op.execute( - voicemail - .update() - .values(options=convert_options(row)) - .where(voicemail.c.uniqueid == row.uniqueid) - ) - - for name in OPTIONS: - op.drop_column('voicemail', name) - for enum in ('voicemail_hidefromdir', 'voicemail_passwordlocation'): - op.execute("DROP TYPE IF EXISTS {}".format(enum)) - - -def convert_options(row): - options = [] - for name in OPTIONS: - value = getattr(row, name) - if value: - options.append(convert_option(name, value)) - return options - - -def convert_option(name, value): - if isinstance(value, (int, float)): - if name in NUMERIC_OPTIONS: - value = str(value) - else: - value = "yes" if value == 1 else "no" - - return [name, value] - - -def downgrade(): - for column in gen_columns(): - op.add_column('voicemail', column) - - voicemail = sql.table('voicemail', - sql.column('uniqueid'), - sql.column('options'), - *gen_columns()) - - query = sql.select([voicemail.c.uniqueid, voicemail.c.options]) - - for row in op.get_bind().execute(query): - op.execute( - voicemail - .update() - .values(**convert_legacy(row)) - .where(voicemail.c.uniqueid == row.uniqueid) - ) - - op.drop_column('voicemail', 'options') - - -def convert_legacy(row): - values = {} - for name, value in row.options: - if name == 'volgain': - value = float(value) - elif name in NUMERIC_OPTIONS: - value = int(value) - elif name in LEGACY_FLAGS: - value = int(value == "yes") - values[name] = value - return values diff --git a/alembic/versions/425eebc346b1_bump_version_17_14.py b/alembic/versions/425eebc346b1_bump_version_17_14.py deleted file mode 100644 index 64e3340d..00000000 --- a/alembic/versions/425eebc346b1_bump_version_17_14.py +++ /dev/null @@ -1,22 +0,0 @@ -"""bump_version_17_14 - -Revision ID: 425eebc346b1 -Revises: 3e7dbde01837 - -""" - -# revision identifiers, used by Alembic. -revision = '425eebc346b1' -down_revision = '3e7dbde01837' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='17.14')) - - -def downgrade(): - pass diff --git a/alembic/versions/42db6d46c98a_add_an_external_meeting_sip_template.py b/alembic/versions/42db6d46c98a_add_an_external_meeting_sip_template.py deleted file mode 100644 index 1a4b635b..00000000 --- a/alembic/versions/42db6d46c98a_add_an_external_meeting_sip_template.py +++ /dev/null @@ -1,178 +0,0 @@ -"""add an external meeting sip template - -Revision ID: 42db6d46c98a -Revises: 706a7655606e - -""" - -import string -import random - -from alembic import op -import sqlalchemy as sa -from sqlalchemy import sql - -from sqlalchemy.dialects.postgresql import UUID - -# revision identifiers, used by Alembic. -revision = "42db6d46c98a" -down_revision = "706a7655606e" - -ALPHANUMERIC_POOL = string.ascii_lowercase + string.digits -MEETING_GUEST_COLUMN_NAME = "meeting_guest_sip_template_uuid" - -transport_option_tbl = sa.sql.table( - "pjsip_transport_option", - sa.sql.column("key"), - sa.sql.column("value"), -) -endpoint_sip_tbl = sa.sql.table( - "endpoint_sip", - sa.sql.column("uuid"), - sa.sql.column("label"), - sa.sql.column("name"), - sa.sql.column("tenant_uuid"), - sa.sql.column("template"), -) -endpoint_sip_section_tbl = sa.sql.table( - "endpoint_sip_section", - sa.sql.column("uuid"), - sa.sql.column("type"), - sa.sql.column("endpoint_sip_uuid"), -) -endpoint_sip_section_option_tbl = sa.sql.table( - "endpoint_sip_section_option", - sa.sql.column("uuid"), - sa.sql.column("key"), - sa.sql.column("value"), - sa.sql.column("endpoint_sip_section_uuid"), -) -endpoint_sip_template_tbl = sa.sql.table( - "endpoint_sip_template", - sa.sql.column("child_uuid"), - sa.sql.column("parent_uuid"), -) -tenant_tbl = sa.sql.table( - "tenant", - sa.sql.column("uuid"), - sa.sql.column("webrtc_video_sip_template_uuid"), - sa.sql.column(MEETING_GUEST_COLUMN_NAME), -) - - -def name_already_exists(name): - query = sa.sql.select([endpoint_sip_tbl.c.name]).where( - endpoint_sip_tbl.c.name == name - ) - return op.get_bind().execute(query).scalar() is not None - - -def generate_unused_name(): - while True: - data = "".join(random.choice(ALPHANUMERIC_POOL) for _ in range(8)) - if not name_already_exists(data): - return data - - -def insert_meeting_guest_endpoint(tenant_uuid, webrtc_video_sip_template_uuid): - query = ( - endpoint_sip_tbl.insert() - .returning(endpoint_sip_tbl.c.uuid) - .values( - label='meeting_guest', - name=generate_unused_name(), - tenant_uuid=tenant_uuid, - template=True, - ) - ) - endpoint_sip_uuid = op.get_bind().execute(query).scalar() - - query = ( - endpoint_sip_section_tbl.insert() - .returning(endpoint_sip_section_tbl.c.uuid) - .values( - endpoint_sip_uuid=endpoint_sip_uuid, - type='aor', - ) - ) - aor_section_uuid = op.get_bind().execute(query).scalar() - - options = [ - ("max_contacts", "50"), - ] - for key, value in options: - query = ( - endpoint_sip_section_option_tbl - .insert() - .values( - key=key, - value=value, - endpoint_sip_section_uuid=aor_section_uuid, - ) - ) - op.execute(query) - - if webrtc_video_sip_template_uuid: - query = ( - endpoint_sip_template_tbl - .insert() - .values( - child_uuid=endpoint_sip_uuid, - parent_uuid=webrtc_video_sip_template_uuid, - ) - ) - op.execute(query) - - return endpoint_sip_uuid - - -def configure_tenant(tenant_uuid, webrtc_video_sip_template_uuid): - guest_meeting_uuid = insert_meeting_guest_endpoint( - tenant_uuid, - webrtc_video_sip_template_uuid - ) - - op.execute( - tenant_tbl.update() - .values( - meeting_guest_sip_template_uuid=guest_meeting_uuid, - ) - .where(tenant_tbl.c.uuid == tenant_uuid) - ) - - -def upgrade(): - # 1. Add new column to tenant table - op.add_column( - "tenant", - sa.Column( - MEETING_GUEST_COLUMN_NAME, - UUID, - sa.ForeignKey( - "endpoint_sip.uuid", - ondelete="SET NULL", - name="tenant_meeting_guest_sip_template_uuid_fkey", - ), - ), - ) - - # 2. Assign template to tenants - query = sa.sql.select([tenant_tbl.c.uuid, tenant_tbl.c.webrtc_video_sip_template_uuid]) - tenants = op.get_bind().execute(query) - for tenant in tenants: - configure_tenant(tenant.uuid, tenant.webrtc_video_sip_template_uuid) - - -def downgrade(): - # 1. Drop templates meeting_guest - query = ( - endpoint_sip_tbl - .delete() - .where(endpoint_sip_tbl.c.uuid.in_( - sql.select([tenant_tbl.c.meeting_guest_sip_template_uuid]) - )) - ) - op.get_bind().execute(query) - - # 2. Drop table column - op.drop_column("tenant", MEETING_GUEST_COLUMN_NAME) diff --git a/alembic/versions/42e9771685b0_bump_version_17_07.py b/alembic/versions/42e9771685b0_bump_version_17_07.py deleted file mode 100644 index 7e0e8c1d..00000000 --- a/alembic/versions/42e9771685b0_bump_version_17_07.py +++ /dev/null @@ -1,22 +0,0 @@ -"""bump_version_17_07 - -Revision ID: 42e9771685b0 -Revises: 596b177ba681 - -""" - -# revision identifiers, used by Alembic. -revision = '42e9771685b0' -down_revision = '596b177ba681' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='17.07')) - - -def downgrade(): - pass diff --git a/alembic/versions/438cb372df48_remove_paging_callnotbusy_column.py b/alembic/versions/438cb372df48_remove_paging_callnotbusy_column.py deleted file mode 100644 index 2264e80e..00000000 --- a/alembic/versions/438cb372df48_remove_paging_callnotbusy_column.py +++ /dev/null @@ -1,26 +0,0 @@ -"""remove paging.callnotbusy column - -Revision ID: 438cb372df48 -Revises: 55f7b6c13454 - -""" - -# revision identifiers, used by Alembic. -revision = '438cb372df48' -down_revision = '55f7b6c13454' - -from alembic import op - - -def upgrade(): - connection = op.get_bind() - query = 'ALTER TABLE "paging" DROP COLUMN IF EXISTS "callnotbusy"' - connection.execute(query) - - -def downgrade(): - ''' - This migration fixes a desync between installed/migrated schema introduced - in 12.23. No downgrade supported. - ''' - pass diff --git a/alembic/versions/43995f4ac823_fix_invalid_context_name.py b/alembic/versions/43995f4ac823_fix_invalid_context_name.py deleted file mode 100644 index 1dec9b3e..00000000 --- a/alembic/versions/43995f4ac823_fix_invalid_context_name.py +++ /dev/null @@ -1,100 +0,0 @@ -"""fix-invalid-context-name - -Revision ID: 43995f4ac823 -Revises: 126c8c1fddb7 - -""" - -import re - -from alembic import op -from sqlalchemy import sql - - -# revision identifiers, used by Alembic. -revision = '43995f4ac823' -down_revision = '126c8c1fddb7' - -NOT_CONTEXT_REGEX = r"[^a-zA-Z0-9-_]" -INVALID_NAME = ( - 'authentication', - 'general', - 'global', - 'globals', - 'parkedcalls', - 'xivo-features', - 'zonemessages', -) - -context_tbl = sql.table( - 'context', - sql.column('name'), -) - -extensions_tbl = sql.table( - 'extensions', - sql.column('context'), -) - - -def find_next_available_name(name): - query = context_tbl.select().where(context_tbl.c.name == name) - context_exists = op.get_bind().execute(query).scalar() - if context_exists: - next_name = '{}_'.format(name) - return find_next_available_name(next_name) - return name - - -def upgrade(): - query = context_tbl.select() - for context in op.get_bind().execute(query): - clean_name = re.sub(NOT_CONTEXT_REGEX, '_', context.name) - if clean_name == context.name and context.name not in INVALID_NAME: - continue - old_name = context.name - new_name = find_next_available_name(clean_name) - op.execute( - context_tbl - .update() - .where(context_tbl.c.name == old_name) - .values(name=new_name) - ) - - # Fix associations - tables_name = [ - 'agent_login_status', - 'agentfeatures', - 'contextinclude', - 'contextmember', - 'contextnumbers', - 'extensions', - 'groupfeatures', - 'incall', - 'linefeatures', - 'meetmefeatures', - 'outcall', - 'queue', - 'queuefeatures', - 'sccpline', - 'trunkfeatures', - 'usercustom', - 'useriax', - 'usersip', - 'voicemail', - ] - for table_name in tables_name: - table = sql.table( - table_name, - sql.column('context'), - ) - op.execute( - table - .update() - .where(table.c.context == old_name) - .values(context=new_name) - ) - - -def downgrade(): - pass diff --git a/alembic/versions/43a39441ae83_update_directory_definition_joins.py b/alembic/versions/43a39441ae83_update_directory_definition_joins.py deleted file mode 100644 index b4f17cdd..00000000 --- a/alembic/versions/43a39441ae83_update_directory_definition_joins.py +++ /dev/null @@ -1,122 +0,0 @@ -"""update directory definition joins - -Revision ID: 43a39441ae83 -Revises: 5712e7a66baa - -""" - -# revision identifiers, used by Alembic. -revision = '43a39441ae83' -down_revision = '5712e7a66baa' - -import json - -from alembic import op -from sqlalchemy import sql - -directories = sql.table('directories', - sql.column('id'), - sql.column('dirtype')) -cti_contexts = sql.table('cticontexts', - sql.column('id'), - sql.column('name'), - sql.column('directories')) -context = sql.table('context', - sql.column('name'), - sql.column('entity')) -cti_directories = sql.table('ctidirectories', - sql.column('id'), - sql.column('name'), - sql.column('directory_id')) -cti_reverse = sql.table('ctireversedirectories', - sql.column('id'), - sql.column('directories')) - - -def upgrade(): - conn = op.get_bind() - - definitions = list_directory_definitions(conn) - cticontexts = list_cti_contexts(conn) - ctireverse = list_cti_reverse(conn) - context_to_entity = get_context_entity_map(conn) - - update_cti_context(cticontexts, definitions, context_to_entity) - update_cti_reverse(ctireverse, definitions) - - -def update_cti_reverse(ctireverse, definitions): - for r in ctireverse: - if r.directories == '[]': - continue - new_directories = [] - for name in json.loads(r.directories): - if is_phonebook(definitions, name): - for definition in definitions: - if definition.name.endswith('-{}'.format(name)): - new_directories.append(definition.name) - else: - new_directories.append(name) - op.execute(cti_reverse.update() - .where(cti_reverse.c.id == r.id) - .values({'directories': json.dumps(new_directories)})) - - -def update_cti_context(cticontexts, definitions, context_to_entity): - for c in cticontexts: - entity = context_to_entity.get(c.name) - if not entity: - continue - new_directories = [] - for name in c.directories.split(','): - if is_phonebook(definitions, name): - new_name = new_phonebook_name(definitions, entity, name) - if new_name: - new_directories.append(new_name) - else: - new_directories.append(name) - op.execute(cti_contexts.update() - .where(cti_contexts.c.id == c.id) - .values({'directories': ','.join(new_directories)})) - - -def downgrade(): - pass - - -def new_phonebook_name(definitions, entity, name): - expected_name = '{}-{}'.format(entity, name) - for definition in definitions: - if definition.name == expected_name: - return definition.name - - -def is_phonebook(definitions, name): - for definition in definitions: - if definition.name == name: - return definition.dirtype == 'phonebook' - - -def get_context_entity_map(conn): - query = sql.select([context]) - return {c.name: c.entity for c in conn.execute(query)} - - -def list_cti_contexts(conn): - query = sql.select([cti_contexts]) - return [c for c in conn.execute(query)] - - -def list_cti_reverse(conn): - query = sql.select([cti_reverse]) - return [r for r in conn.execute(query)] - - -def list_directory_definitions(conn): - query = sql.select([ - cti_directories.c.id, - cti_directories.c.name, - cti_directories.c.directory_id, - directories.c.dirtype - ]).where(cti_directories.c.directory_id == directories.c.id) - return [definition for definition in conn.execute(query)] diff --git a/alembic/versions/43c5188319dc_update_chan_sip_t1min.py b/alembic/versions/43c5188319dc_update_chan_sip_t1min.py deleted file mode 100644 index 34dedbbe..00000000 --- a/alembic/versions/43c5188319dc_update_chan_sip_t1min.py +++ /dev/null @@ -1,34 +0,0 @@ -"""update chan_sip t1min - -Revision ID: 43c5188319dc -Revises: 160e7b3161fa - -""" - -# revision identifiers, used by Alembic. -revision = '43c5188319dc' -down_revision = '160e7b3161fa' - -from alembic import op -from sqlalchemy import sql - - -staticsip_table = sql.table('staticsip', - sql.column('var_name'), - sql.column('var_val')) - - -def upgrade(): - _update_staticsip_t1min() - - -def _update_staticsip_t1min(): - op.execute(staticsip_table.update(). - where(sql.and_( - staticsip_table.c.var_name == 't1min', - staticsip_table.c.var_val == '100')). - values(var_val='500')) - - -def downgrade(): - pass diff --git a/alembic/versions/444b39e9aa32_rename_webservices_directory.py b/alembic/versions/444b39e9aa32_rename_webservices_directory.py deleted file mode 100644 index 6b41c3ae..00000000 --- a/alembic/versions/444b39e9aa32_rename_webservices_directory.py +++ /dev/null @@ -1,32 +0,0 @@ -"""rename webservices directory - -Revision ID: 444b39e9aa32 -Revises: 387d650380bd - -""" - -# revision identifiers, used by Alembic. -revision = '444b39e9aa32' -down_revision = '387d650380bd' - -from alembic import op -from sqlalchemy import sql - -directories_table = sql.table('directories', - sql.column('dirtype')) - - -def rename_dirtype(from_, to): - op.execute(directories_table - .update() - .where( - directories_table.c.dirtype == from_ - ).values(dirtype=to)) - - -def upgrade(): - rename_dirtype(from_='webservices', to='csv_ws') - - -def downgrade(): - rename_dirtype(from_='csv_ws', to='webservices') diff --git a/alembic/versions/447e4ab61975_fix_queue_table_without_context.py b/alembic/versions/447e4ab61975_fix_queue_table_without_context.py deleted file mode 100644 index e6850470..00000000 --- a/alembic/versions/447e4ab61975_fix_queue_table_without_context.py +++ /dev/null @@ -1,18 +0,0 @@ -"""fix_queue_table_without_context - -Revision ID: 447e4ab61975 -Revises: 146ddf6c4b36 - -""" - -# revision identifiers, used by Alembic. -revision = '447e4ab61975' -down_revision = '146ddf6c4b36' - - -def upgrade(): - pass - - -def downgrade(): - pass diff --git a/alembic/versions/449045080bf6_bump_version_19_16.py b/alembic/versions/449045080bf6_bump_version_19_16.py deleted file mode 100644 index 8abdaa09..00000000 --- a/alembic/versions/449045080bf6_bump_version_19_16.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_19_16 - -Revision ID: 449045080bf6 -Revises: 8691b32cf44e - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '449045080bf6' -down_revision = '8691b32cf44e' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='19.16')) - - -def downgrade(): - pass diff --git a/alembic/versions/44af2488e95_ast13_app_queue.py b/alembic/versions/44af2488e95_ast13_app_queue.py deleted file mode 100644 index f9822730..00000000 --- a/alembic/versions/44af2488e95_ast13_app_queue.py +++ /dev/null @@ -1,43 +0,0 @@ -"""ast13: remove app_queue eventmemberstatus and eventwhencalled - -Revision ID: 44af2488e95 -Revises: 1a25b8b93e70 - -""" - -# revision identifiers, used by Alembic. -revision = '44af2488e95' -down_revision = '1a25b8b93e70' - -from alembic import op -from sqlalchemy import sql -from sqlalchemy.types import Integer -from sqlalchemy.sql.schema import Column - - -queue_table_old = sql.table('queue', - sql.column('eventmemberstatus'), - sql.column('eventwhencalled')) - - -def upgrade(): - _drop_queue_columns() - - -def _drop_queue_columns(): - op.drop_column('queue', 'eventmemberstatus') - op.drop_column('queue', 'eventwhencalled') - - -def downgrade(): - _add_queue_columns() - - -def _add_queue_columns(): - op.add_column('queue', - Column('eventmemberstatus', Integer, nullable=False, server_default='0')) - op.add_column('queue', - Column('eventwhencalled', Integer, nullable=False, server_default='0')) - op.execute(queue_table_old - .update() - .values({'eventmemberstatus': 1, 'eventwhencalled': 1})) diff --git a/alembic/versions/44c6b8d8c196_activate_blf_by_default.py b/alembic/versions/44c6b8d8c196_activate_blf_by_default.py deleted file mode 100644 index c4546edd..00000000 --- a/alembic/versions/44c6b8d8c196_activate_blf_by_default.py +++ /dev/null @@ -1,20 +0,0 @@ -"""activate blf by default - -Revision ID: 44c6b8d8c196 -Revises: 40ba1a488aa7 - -""" - -from alembic import op - -# revision identifiers, used by Alembic. -revision = '44c6b8d8c196' -down_revision = '40ba1a488aa7' - - -def upgrade(): - op.alter_column('func_key_mapping', 'blf', server_default='True') - - -def downgrade(): - op.alter_column('func_key_mapping', 'blf', server_default='False') diff --git a/alembic/versions/454c3dfde5db_migrate_to_sip_webrtc_option.py b/alembic/versions/454c3dfde5db_migrate_to_sip_webrtc_option.py deleted file mode 100644 index 57f72c7b..00000000 --- a/alembic/versions/454c3dfde5db_migrate_to_sip_webrtc_option.py +++ /dev/null @@ -1,62 +0,0 @@ -"""migrate_to_sip_webrtc_option - -Revision ID: 454c3dfde5db -Revises: 7628599d48dc - -""" - -from alembic import op -from sqlalchemy import sql - -# revision identifiers, used by Alembic. -revision = '454c3dfde5db' -down_revision = '7628599d48dc' - -usersip_table = sql.table( - 'usersip', - sql.column('id'), - sql.column('encryption'), - sql.column('options'), -) - - -def upgrade(): - query = ( - sql.select([usersip_table.c.id, usersip_table.c.options]) - .where(usersip_table.c.encryption == 1) - ) - results = op.get_bind().execute(query).fetchall() - - for sip in results: - old_webrtc_options = ( - ['avpf', 'yes'] in sip.options - and ['dtlsenable', 'yes'] in sip.options - and ['dtlssetup', 'actpass'] in sip.options - and ['force_avp', 'yes'] in sip.options - and ['icesupport', 'yes'] in sip.options - and ['rtcp_mux', 'yes'] in sip.options - ) - if not old_webrtc_options: - continue - - sip.options.remove(['avpf', 'yes']) - sip.options.remove(['dtlsenable', 'yes']) - sip.options.remove(['dtlssetup', 'actpass']) - sip.options.remove(['force_avp', 'yes']) - sip.options.remove(['icesupport', 'yes']) - sip.options.remove(['rtcp_mux', 'yes']) - if ['webrtc', 'yes'] not in sip.options: - sip.options.append(['webrtc', 'yes']) - - op.execute( - usersip_table.update() - .where(usersip_table.c.id == sip.id) - .values( - encryption=None, - options=sip.options, - ) - ) - - -def downgrade(): - pass diff --git a/alembic/versions/45ceb32fae06_add_uuid_to_userfeatures.py b/alembic/versions/45ceb32fae06_add_uuid_to_userfeatures.py deleted file mode 100644 index 8e5cf3e9..00000000 --- a/alembic/versions/45ceb32fae06_add_uuid_to_userfeatures.py +++ /dev/null @@ -1,37 +0,0 @@ -"""add uuid to userfeatures - -Revision ID: 45ceb32fae06 -Revises: 2956eaa19c7c - -""" - -# revision identifiers, used by Alembic. -revision = '45ceb32fae06' -down_revision = '2956eaa19c7c' - -import uuid - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - # Create the column - op.add_column('userfeatures', sa.Column('uuid', sa.String(38))) - - # Insert some initial values - conn = op.get_bind() - user_table = sa.sql.table('userfeatures', sa.sql.column('id'), sa.sql.column('uuid')) - rows = conn.execute('SELECT "id" FROM "userfeatures"') - for row in rows.fetchall(): - user_id = row[0] - user_uuid = str(uuid.uuid4()) - op.execute(user_table.update().where(user_table.c.id == user_id).values({'uuid': user_uuid})) - - # Add the not null constraint - op.alter_column('userfeatures', 'uuid', nullable=False) - op.create_index('userfeatures__idx__uuid', 'userfeatures', ['uuid']) - - -def downgrade(): - op.drop_column('userfeatures', 'uuid') diff --git a/alembic/versions/45ec6bd040ac_remove_dangling_user_function_keys.py b/alembic/versions/45ec6bd040ac_remove_dangling_user_function_keys.py deleted file mode 100644 index 1a495e84..00000000 --- a/alembic/versions/45ec6bd040ac_remove_dangling_user_function_keys.py +++ /dev/null @@ -1,62 +0,0 @@ -"""remove-dangling-user-function-keys - -Revision ID: 45ec6bd040ac -Revises: bba3a031fd01 - -""" - -from alembic import op -from sqlalchemy import sql - - -# revision identifiers, used by Alembic. -revision = '45ec6bd040ac' -down_revision = 'bba3a031fd01' - -func_key = sql.table( - 'func_key', - sql.column('id'), - sql.column('destination_type_id'), -) - -func_key_mapping = sql.table( - 'func_key_mapping', - sql.column('func_key_id'), -) - -func_key_dest_user = sql.table( - 'func_key_dest_user', - sql.column('func_key_id'), -) - - -def upgrade(): - sub_query = sql.select([func_key_mapping.c.func_key_id]) - func_keys = op.get_bind().execute( - sql.select([func_key.c.id]) - .select_from( - func_key.join( - func_key_dest_user, func_key_dest_user.c.func_key_id == func_key.c.id - ) - ) - .where(func_key.c.id.notin_(sub_query)) - ) - func_key_ids = [func_key.id for func_key in func_keys] - - if not func_key_ids: - return - - op.execute( - func_key_dest_user - .delete() - .where(func_key_dest_user.c.func_key_id.in_(func_key_ids)) - ) - op.execute( - func_key - .delete() - .where(func_key.c.id.in_(func_key_ids)) - ) - - -def downgrade(): - pass diff --git a/alembic/versions/462b92a4f5d8_add_conference_exten_enum.py b/alembic/versions/462b92a4f5d8_add_conference_exten_enum.py deleted file mode 100644 index ef263491..00000000 --- a/alembic/versions/462b92a4f5d8_add_conference_exten_enum.py +++ /dev/null @@ -1,51 +0,0 @@ -"""add-conference-exten-enum - -Revision ID: 462b92a4f5d8 -Revises: 2f69acadecbe - -""" - -# revision identifiers, used by Alembic. -revision = '462b92a4f5d8' -down_revision = '2f69acadecbe' - -from alembic import op -from sqlalchemy import Enum - - -extenumbers_type = Enum( - 'extenfeatures', - 'featuremap', - 'generalfeatures', - 'group', - 'incall', - 'meetme', - 'outcall', - 'queue', - 'user', - 'voicemenu', - 'conference', - name='extenumbers_type' -) - - -def upgrade(): - _modify_extenumbers_type() - - -def _modify_extenumbers_type(): - _modify_type(extenumbers_type, - ('extensions', 'type')) - - -def _modify_type(type_, *table_and_columns): - op.execute('ALTER TYPE {type_name} RENAME TO tmp_{type_name}'.format(type_name=type_.name)) - type_.create(op.get_bind()) - for table, column in table_and_columns: - op.execute('ALTER TABLE {table_name} ALTER COLUMN {column_name} TYPE {type_name} USING {column_name}::text::{type_name}'.format( - type_name=type_.name, table_name=table, column_name=column)) - op.execute('DROP TYPE tmp_{type_name}'.format(type_name=type_.name)) - - -def downgrade(): - pass diff --git a/alembic/versions/46dbcd084872_remove_columns_from_ldapfilter.py b/alembic/versions/46dbcd084872_remove_columns_from_ldapfilter.py deleted file mode 100644 index b942a6c0..00000000 --- a/alembic/versions/46dbcd084872_remove_columns_from_ldapfilter.py +++ /dev/null @@ -1,24 +0,0 @@ -"""remove columns from ldapfilter - -Revision ID: 46dbcd084872 -Revises: 1493335e754b - -""" - -# revision identifiers, used by Alembic. -revision = '46dbcd084872' -down_revision = '1493335e754b' - -from alembic import op - - -def upgrade(): - op.drop_column('ldapfilter', 'attrdisplayname') - op.drop_column('ldapfilter', 'attrphonenumber') - op.drop_column('ldapfilter', 'additionaltype') - op.drop_column('ldapfilter', 'additionaltext') - op.execute('DROP TYPE ldapfilter_additionaltype') - - -def downgrade(): - pass diff --git a/alembic/versions/46dda7d0374e_bump_version_18_14.py b/alembic/versions/46dda7d0374e_bump_version_18_14.py deleted file mode 100644 index 65b9ed1a..00000000 --- a/alembic/versions/46dda7d0374e_bump_version_18_14.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_18_14 - -Revision ID: 46dda7d0374e -Revises: 99082b9c0b7b - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '46dda7d0374e' -down_revision = '99082b9c0b7b' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='18.14')) - - -def downgrade(): - pass diff --git a/alembic/versions/4722bbe519b1_remove_unused_values_dialaction_enum.py b/alembic/versions/4722bbe519b1_remove_unused_values_dialaction_enum.py deleted file mode 100644 index 482d738d..00000000 --- a/alembic/versions/4722bbe519b1_remove_unused_values_dialaction_enum.py +++ /dev/null @@ -1,138 +0,0 @@ -"""remove-unused-values-dialaction-enum - -Revision ID: 4722bbe519b1 -Revises: b536a68f5505 - -""" - -from alembic import op -from sqlalchemy import sql, Enum - -# revision identifiers, used by Alembic. -revision = '4722bbe519b1' -down_revision = 'b536a68f5505' - -dialaction_tbl = sql.table( - 'dialaction', - sql.column('action'), - sql.column('category'), -) - -dialaction_action = Enum( - 'none', - 'endcall:busy', - 'endcall:congestion', - 'endcall:hangup', - 'user', - 'group', - 'queue', - 'meetme', - 'voicemail', - 'extension', - 'outcall', - 'application:callbackdisa', - 'application:disa', - 'application:directory', - 'application:faxtomail', - 'application:voicemailmain', - 'application:password', - 'sound', - 'custom', - 'ivr', - 'conference', - 'switchboard', - 'application:custom', - name='dialaction_action', -) -dialaction_category = Enum( - 'callfilter', - 'group', - 'incall', - 'queue', - 'user', - 'ivr', - 'ivr_choice', - name='dialaction_category', -) -dialaction_action_old = Enum( - 'none', - 'endcall:busy', - 'endcall:congestion', - 'endcall:hangup', - 'user', - 'group', - 'queue', - 'meetme', - 'voicemail', - 'trunk', - 'schedule', - 'extension', - 'outcall', - 'application:callbackdisa', - 'application:disa', - 'application:directory', - 'application:faxtomail', - 'application:voicemailmain', - 'application:password', - 'sound', - 'custom', - 'ivr', - 'conference', - 'switchboard', - 'application:custom', - name='dialaction_action', -) -dialaction_category_old = Enum( - 'callfilter', - 'group', - 'incall', - 'queue', - 'schedule', - 'user', - 'outcall', - 'ivr', - 'ivr_choice', - name='dialaction_category', -) - - -def upgrade(): - query = dialaction_tbl.delete().where(dialaction_tbl.c.action == 'schedule') - op.get_bind().execute(query) - query = dialaction_tbl.delete().where(dialaction_tbl.c.action == 'trunk') - op.get_bind().execute(query) - query = dialaction_tbl.delete().where(dialaction_tbl.c.category == 'schedule') - op.get_bind().execute(query) - query = dialaction_tbl.delete().where(dialaction_tbl.c.category == 'outcall') - op.get_bind().execute(query) - - op.alter_column('schedule', 'fallback_action', server_default=None) - _modify_type( - dialaction_action, - ('dialaction', 'action'), - ('schedule', 'fallback_action'), - ('schedule_time', 'action') - ) - op.alter_column('schedule', 'fallback_action', server_default='none') - _modify_type(dialaction_category, ('dialaction', 'category')) - - -def _modify_type(type_, *table_and_columns): - op.execute('ALTER TYPE {type_name} RENAME TO tmp_{type_name}'.format(type_name=type_.name)) - type_.create(op.get_bind()) - for table, column in table_and_columns: - op.execute('ALTER TABLE {table_name} ALTER COLUMN {column_name} TYPE {type_name} USING {column_name}::text::{type_name}'.format( - type_name=type_.name, table_name=table, column_name=column)) - op.execute('DROP TYPE tmp_{type_name}'.format(type_name=type_.name)) - - -def downgrade(): - op.alter_column('schedule', 'fallback_action', server_default=None) - _modify_type( - dialaction_action_old, - ('dialaction', 'action'), - ('schedule', 'fallback_action'), - ('schedule_time', 'action') - ) - op.alter_column('schedule', 'fallback_action', server_default='none') - _modify_type(dialaction_category_old, ('dialaction', 'category')) diff --git a/alembic/versions/476a2700b4c2_moh_add_tenant_uuid.py b/alembic/versions/476a2700b4c2_moh_add_tenant_uuid.py deleted file mode 100644 index 3967131b..00000000 --- a/alembic/versions/476a2700b4c2_moh_add_tenant_uuid.py +++ /dev/null @@ -1,46 +0,0 @@ -"""moh_add_tenant_uuid - -Revision ID: 476a2700b4c2 -Revises: 5a285558e46e - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '476a2700b4c2' -down_revision = '5a285558e46e' - -TABLE = 'moh' - - -def find_default_tenant_uuid(): - entity_table = sa.sql.table( - 'entity', - sa.sql.column('id'), - sa.sql.column('name'), - sa.sql.column('tenant_uuid'), - ) - query = sa.sql.select([entity_table.c.tenant_uuid]).order_by(entity_table.c.id) - for row in op.get_bind().execute(query): - return row.tenant_uuid - - -def upgrade(): - default_tenant = find_default_tenant_uuid() - op.add_column( - TABLE, - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=False, - server_default=default_tenant), - ) - op.alter_column(TABLE, 'tenant_uuid', server_default=None) - - -def downgrade(): - op.drop_column(TABLE, 'tenant_uuid') diff --git a/alembic/versions/47920341f392_add_application_dialaction.py b/alembic/versions/47920341f392_add_application_dialaction.py deleted file mode 100644 index f76e1e86..00000000 --- a/alembic/versions/47920341f392_add_application_dialaction.py +++ /dev/null @@ -1,70 +0,0 @@ -"""add_application_dialaction - -Revision ID: 47920341f392 -Revises: 5013b66e26d2 - -""" - -from alembic import op -from sqlalchemy import sql, Enum - -# revision identifiers, used by Alembic. -revision = '47920341f392' -down_revision = '5013b66e26d2' - -dialaction = sql.table('dialaction', sql.column('action')) - -dialaction_action = Enum( - 'none', - 'endcall:busy', - 'endcall:congestion', - 'endcall:hangup', - 'user', - 'group', - 'queue', - 'meetme', - 'voicemail', - 'trunk', - 'schedule', - 'extension', - 'outcall', - 'application:callbackdisa', - 'application:disa', - 'application:directory', - 'application:faxtomail', - 'application:voicemailmain', - 'application:password', - 'sound', - 'custom', - 'ivr', - 'conference', - 'switchboard', - 'application:custom', - name='dialaction_action', -) - - -def upgrade(): - _modify_dialaction_action_type() - - -def _modify_dialaction_action_type(): - op.alter_column('schedule', 'fallback_action', server_default=None) - _modify_type(dialaction_action, - ('dialaction', 'action'), - ('schedule', 'fallback_action'), - ('schedule_time', 'action')) - op.alter_column('schedule', 'fallback_action', server_default='none') - - -def _modify_type(type_, *table_and_columns): - op.execute('ALTER TYPE {type_name} RENAME TO tmp_{type_name}'.format(type_name=type_.name)) - type_.create(op.get_bind()) - for table, column in table_and_columns: - op.execute('ALTER TABLE {table_name} ALTER COLUMN {column_name} TYPE {type_name} USING {column_name}::text::{type_name}'.format( - type_name=type_.name, table_name=table, column_name=column)) - op.execute('DROP TYPE tmp_{type_name}'.format(type_name=type_.name)) - - -def downgrade(): - pass diff --git a/alembic/versions/486c0749403c_migrate_voicemail_func_keys.py b/alembic/versions/486c0749403c_migrate_voicemail_func_keys.py deleted file mode 100644 index d042f60f..00000000 --- a/alembic/versions/486c0749403c_migrate_voicemail_func_keys.py +++ /dev/null @@ -1,292 +0,0 @@ -"""migrate_voicemail_func_keys - -Revision ID: 486c0749403c -Revises: 55f3c86885c5 - -""" - -# revision identifiers, used by Alembic. -revision = '486c0749403c' -down_revision = '55f3c86885c5' - -from alembic import op -import sqlalchemy as sa - - -TYPE_SPEEDDIAL = 'speeddial' - -DESTINATION_SERVICE_ID = 5 -DESTINATION_SERVICE_NAME = 'service' - -VOICEMAIL_TYPES = ('enablevm', 'vmusermsg', 'vmuserpurge') -DELETED_VOICEMAIL_TYPES = ('enablevm', 'vmusermsg', 'vmuserpurge', 'enablevmbox') - -phonefunckey_table = sa.sql.table('phonefunckey', - sa.sql.column('iduserfeatures'), - sa.sql.column('fknum'), - sa.sql.column('exten'), - sa.sql.column('typeextenumbers'), - sa.sql.column('typevalextenumbers'), - sa.sql.column('typeextenumbersright'), - sa.sql.column('typevalextenumbersright'), - sa.sql.column('label'), - sa.sql.column('supervision'), - sa.sql.column('progfunckey')) - -func_key_table = sa.sql.table('func_key', - sa.sql.column('id'), - sa.sql.column('type_id'), - sa.sql.column('destination_type_id')) - -destination_service_table = sa.sql.table('func_key_dest_service', - sa.sql.column('func_key_id'), - sa.sql.column('destination_type_id'), - sa.sql.column('extension_id')) - -func_key_type_table = sa.sql.table('func_key_type', - sa.sql.column('id'), - sa.sql.column('name')) - -func_key_mapping_table = sa.sql.table('func_key_mapping', - sa.sql.column('template_id'), - sa.sql.column('func_key_id'), - sa.sql.column('destination_type_id'), - sa.sql.column('label'), - sa.sql.column('position'), - sa.sql.column('blf')) - -template_table = sa.sql.table('func_key_template', - sa.sql.column('id')) - -extensions_table = sa.sql.table('extensions', - sa.sql.column('id'), - sa.sql.column('commented'), - sa.sql.column('context'), - sa.sql.column('exten'), - sa.sql.column('type'), - sa.sql.column('typeval')) - -user_table = sa.sql.table('userfeatures', - sa.sql.column('id'), - sa.sql.column('func_key_private_template_id')) - -destination_type_table = sa.sql.table('func_key_destination_type', - sa.sql.column('id'), - sa.sql.column('name')) - -blf_cast = sa.sql.cast(phonefunckey_table.c.supervision, sa.Boolean) - -voicemail_func_keys_query = (sa.sql.select([phonefunckey_table.c.iduserfeatures.label('user_id'), - phonefunckey_table.c.fknum.label('position'), - phonefunckey_table.c.label, - phonefunckey_table.c.typevalextenumbers, - blf_cast.label('blf')]) - .where(phonefunckey_table.c.typevalextenumbers - .in_(VOICEMAIL_TYPES))) - - -old_func_keys_query = (sa.sql.select([func_key_mapping_table.c.func_key_id, - func_key_mapping_table.c.template_id, - func_key_mapping_table.c.position, - func_key_mapping_table.c.blf, - func_key_mapping_table.c.label, - destination_service_table.c.extension_id, - extensions_table.c.typeval, - user_table.c.id.label('user_id')], - from_obj=[ - func_key_mapping_table.join( - destination_service_table, - func_key_mapping_table.c.func_key_id == destination_service_table.c.func_key_id) - .join(extensions_table, - destination_service_table.c.extension_id == extensions_table.c.id) - .join(template_table, - func_key_mapping_table.c.template_id == template_table.c.id) - .join(user_table, - template_table.c.id == user_table.c.func_key_private_template_id)]) - .where(extensions_table.c.typeval.in_(VOICEMAIL_TYPES))) - - -def upgrade(): - _delete_duplicate_fks() - func_key_ids = _pregenerate_fk_destinations() - _migrate_func_keys(func_key_ids) - _delete_old_func_keys() - - -def _pregenerate_fk_destinations(): - func_key_ids = {} - for typeval in VOICEMAIL_TYPES: - func_key_id = func_key_ids[typeval] = _create_func_key() - extension_id = _get_extension_id_from_type(typeval) - _create_service_destination(func_key_id, extension_id) - return func_key_ids - - -def _create_func_key(): - speeddial_id = _get_speeddial_id() - insert_query = (func_key_table - .insert() - .returning(func_key_table.c.id) - .values(type_id=speeddial_id, - destination_type_id=DESTINATION_SERVICE_ID)) - - return op.get_bind().execute(insert_query).scalar() - - -def _get_speeddial_id(): - return op.get_bind().execute( - sa.sql.select( - [func_key_type_table.c.id]) - .where( - func_key_type_table.c.name == TYPE_SPEEDDIAL) - ).scalar() - - -def _get_extension_id_from_type(vmtype): - return op.get_bind().execute( - sa.sql.select( - [extensions_table.c.id]) - .where( - extensions_table.c.typeval == vmtype) - ).scalar() - - -def _create_service_destination(func_key_id, extension_id): - destination_query = (destination_service_table - .insert() - .returning(destination_service_table.c.func_key_id) - .values(func_key_id=func_key_id, - destination_type_id=DESTINATION_SERVICE_ID, - extension_id=extension_id)) - - op.get_bind().execute(destination_query) - - -def _migrate_func_keys(func_key_ids): - for row in op.get_bind().execute(voicemail_func_keys_query): - _create_mapping(func_key_ids[row.typevalextenumbers], row) - - -def _create_mapping(func_key_id, func_key_row): - conn = op.get_bind() - - template_id = conn.execute(sa.sql.select( - [user_table.c.func_key_private_template_id]) - .where( - user_table.c.id == func_key_row.user_id) - ).scalar() - - mapping_query = (func_key_mapping_table - .insert() - .returning(func_key_mapping_table.c.func_key_id) - .values(func_key_id=func_key_id, - template_id=template_id, - destination_type_id=DESTINATION_SERVICE_ID, - label=func_key_row.label, - position=func_key_row.position, - blf=func_key_row.blf)) - - conn.execute(mapping_query) - - -def _delete_old_func_keys(): - delete_query = (phonefunckey_table - .delete() - .where(phonefunckey_table.c.typevalextenumbers - .in_(DELETED_VOICEMAIL_TYPES))) - - op.get_bind().execute(delete_query) - - -def _delete_duplicate_fks(): - for row in _get_duplicate_func_keys(): - _delete_duplicate_fk(row.iduserfeatures, row.typevalextenumbers, row.fknum) - - -def _get_duplicate_func_keys(): - valid_fk_subq = sa.sql.select([phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.typevalextenumbers, - sa.func.min(phonefunckey_table.c.fknum).label("first_position")]).\ - where(phonefunckey_table.c.typevalextenumbers.in_(VOICEMAIL_TYPES)).\ - group_by(phonefunckey_table.c.iduserfeatures, phonefunckey_table.c.typevalextenumbers).\ - having(sa.func.count(phonefunckey_table.c.typevalextenumbers) > 1).\ - alias() - - duplicate_fk_query = (sa.sql.select([phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.typevalextenumbers, - phonefunckey_table.c.fknum], - from_obj=[ - phonefunckey_table.join( - valid_fk_subq, - sa.sql.and_( - phonefunckey_table.c.typevalextenumbers == valid_fk_subq.c.typevalextenumbers, - phonefunckey_table.c.fknum > valid_fk_subq.c.first_position, - phonefunckey_table.c.iduserfeatures == valid_fk_subq.c.iduserfeatures) - ) - ] - )) - - return op.get_bind().execute(duplicate_fk_query) - - -def _delete_duplicate_fk(iduserfeatures, typevalextenumbers, fknum): - print('[MIGRATE_FK] : Deleting func key for user "%s" (fk position %s with action %s)' % - (iduserfeatures, fknum, typevalextenumbers)) - query = (phonefunckey_table - .delete() - .where(sa.sql.and_( - phonefunckey_table.c.iduserfeatures == iduserfeatures, - phonefunckey_table.c.typevalextenumbers == typevalextenumbers, - phonefunckey_table.c.fknum == fknum))) - - op.get_bind().execute(query) - - -def downgrade(): - for row in op.get_bind().execute(old_func_keys_query): - _create_old_func_keys(row) - _delete_mapping(row.func_key_id, row.template_id) - _delete_dest_service(row.func_key_id) - _delete_func_key(row.func_key_id) - - -def _create_old_func_keys(row): - supervision = 1 if row.blf else 0 - - row = {'iduserfeatures': row.user_id, - 'fknum': row.position, - 'typeextenumbers': 'extenfeatures', - 'typevalextenumbers': row.typeval, - 'typeextenumbersright': None, - 'typevalextenumbersright': None, - 'label': row.label, - 'supervision': supervision} - - op.bulk_insert(phonefunckey_table, [row]) - - -def _delete_mapping(func_key_id, template_id): - query = (func_key_mapping_table - .delete() - .where(sa.sql.and_( - func_key_mapping_table.c.func_key_id == func_key_id, - func_key_mapping_table.c.template_id == template_id))) - - op.get_bind().execute(query) - - -def _delete_dest_service(func_key_id): - query = (destination_service_table - .delete() - .where( - destination_service_table.c.func_key_id == func_key_id)) - - op.get_bind().execute(query) - - -def _delete_func_key(func_key_id): - query = (func_key_table - .delete() - .where(func_key_table.c.id == func_key_id)) - - op.get_bind().execute(query) diff --git a/alembic/versions/488e5a3d75_create_asterisk_file_tables.py b/alembic/versions/488e5a3d75_create_asterisk_file_tables.py deleted file mode 100644 index a7a0b763..00000000 --- a/alembic/versions/488e5a3d75_create_asterisk_file_tables.py +++ /dev/null @@ -1,53 +0,0 @@ -"""create_asterisk_file_tables - -Revision ID: 488e5a3d75 -Revises: 40359c5c2c92 - -""" - -# revision identifiers, used by Alembic. -revision = '488e5a3d75' -down_revision = '40359c5c2c92' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy.schema import Column - -constraint_name = 'asterisk_file_section_name_asterisk_file_id_key' - - -def upgrade(): - op.create_table( - 'asterisk_file', - Column('id', sa.Integer, primary_key=True), - Column('name', sa.String(255), unique=True, nullable=False), - ) - - op.create_table( - 'asterisk_file_section', - Column('id', sa.Integer, primary_key=True), - Column('name', sa.String(255), nullable=False), - Column('priority', sa.Integer), - Column('asterisk_file_id', sa.Integer, - sa.ForeignKey('asterisk_file.id', ondelete='CASCADE'), - nullable=False), - ) - op.create_table( - 'asterisk_file_variable', - Column('id', sa.Integer, primary_key=True), - Column('key', sa.String(255), nullable=False), - Column('value', sa.Text), - Column('priority', sa.Integer), - Column('asterisk_file_section_id', sa.Integer, - sa.ForeignKey('asterisk_file_section.id', ondelete='CASCADE'), - nullable=False), - ) - op.create_unique_constraint(constraint_name, 'asterisk_file_section', - ['name', 'asterisk_file_id']) - - -def downgrade(): - op.drop_constraint(constraint_name, 'asterisk_file_section') - op.drop_table('asterisk_file_variable') - op.drop_table('asterisk_file_section') - op.drop_table('asterisk_file') diff --git a/alembic/versions/49126e9fffe2_remove_autochangestate.py b/alembic/versions/49126e9fffe2_remove_autochangestate.py deleted file mode 100644 index f4373e91..00000000 --- a/alembic/versions/49126e9fffe2_remove_autochangestate.py +++ /dev/null @@ -1,25 +0,0 @@ -"""remove autochangestate - -Revision ID: 49126e9fffe2 -Revises: 564d634619bc - -""" - -# revision identifiers, used by Alembic. -revision = '49126e9fffe2' -down_revision = '564d634619bc' - -from alembic import op -import sqlalchemy as sa - -preference_table = sa.sql.table('cti_preference', - sa.sql.column('id'), - sa.sql.column('option')) - - -def upgrade(): - op.execute(preference_table.delete().where(preference_table.c.option == 'presence.autochangestate')) - - -def downgrade(): - op.execute(preference_table.insert().values(option='presence.autochangestate')) diff --git a/alembic/versions/495accfabe9f_bump_version_22_15.py b/alembic/versions/495accfabe9f_bump_version_22_15.py deleted file mode 100644 index a3c84a72..00000000 --- a/alembic/versions/495accfabe9f_bump_version_22_15.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_22_15 - -Revision ID: 495accfabe9f -Revises: 7d342adb6ae1 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '495accfabe9f' -down_revision = '7d342adb6ae1' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='22.15')) - - -def downgrade(): - pass diff --git a/alembic/versions/4977a626c01_add_xivo_ctid_ng_acl.py b/alembic/versions/4977a626c01_add_xivo_ctid_ng_acl.py deleted file mode 100644 index f240dec3..00000000 --- a/alembic/versions/4977a626c01_add_xivo_ctid_ng_acl.py +++ /dev/null @@ -1,47 +0,0 @@ -"""add xivo-ctid-ng acl - -Revision ID: 4977a626c01 -Revises: 525b0cc45d2 - -""" - -# revision identifiers, used by Alembic. -revision = '4977a626c01' -down_revision = '525b0cc45d2' - -from alembic import op -from sqlalchemy import sql - - -webservice = sql.table('accesswebservice', - sql.column('name'), - sql.column('acl')) - -SERVICE = 'xivo-ctid-ng' -NEW_ACL = set(['amid.action.Command.create']) - - -def _get_current_acl(name): - return set(op.get_bind().execute( - sql.select([webservice.c.acl]).where(webservice.c.name == name) - ).scalar()) - - -def _update_web_service_acl(name, acl): - op.execute(webservice - .update() - .where( - webservice.c.name == name - ).values(acl=list(acl))) - - -def upgrade(): - current_acls = _get_current_acl(SERVICE) - new_acls = current_acls | NEW_ACL - _update_web_service_acl(SERVICE, new_acls) - - -def downgrade(): - current_acls = _get_current_acl(SERVICE) - new_acls = current_acls - NEW_ACL - _update_web_service_acl(SERVICE, new_acls) diff --git a/alembic/versions/498f0570ffef_fix_default_display_personal.py b/alembic/versions/498f0570ffef_fix_default_display_personal.py deleted file mode 100644 index 6b81c274..00000000 --- a/alembic/versions/498f0570ffef_fix_default_display_personal.py +++ /dev/null @@ -1,56 +0,0 @@ -"""fix-default-display-personal - -Revision ID: 498f0570ffef -Revises: 320d05ebad29 - -""" - -# revision identifiers, used by Alembic. -revision = '498f0570ffef' -down_revision = '320d05ebad29' - -import json - -from alembic import op -from sqlalchemy import sql - -cti_displays = sql.table('ctidisplays', - sql.column('id'), - sql.column('name'), - sql.column('data')) - -DISPLAY_COLUMN_TYPE_INDEX = 1 - - -def upgrade(): - conn = op.get_bind() - _fix_personal_typos(conn) - - -def downgrade(): - pass - - -def _fix_personal_typos(conn): - display_rows = conn.execute(sql.select([cti_displays])) - for display_row in display_rows: - display_config = _get_display_config(display_row) - display_config = _fix_display_config(display_config) - op.execute(cti_displays - .update() - .where(cti_displays.c.id == display_row.id) - .values(data=json.dumps(display_config))) - - -def _fix_display_config(display_config): - display_config = dict(display_config) - for display_priority in display_config: - if len(display_config[display_priority]) < (DISPLAY_COLUMN_TYPE_INDEX + 1): - continue - if display_config[display_priority][DISPLAY_COLUMN_TYPE_INDEX] == 'personnal': - display_config[display_priority][DISPLAY_COLUMN_TYPE_INDEX] = 'personal' - return display_config - - -def _get_display_config(display): - return json.loads(display.data) if display.data else {} diff --git a/alembic/versions/4a0281e1a826_usersip_add_tenant_uuid.py b/alembic/versions/4a0281e1a826_usersip_add_tenant_uuid.py deleted file mode 100644 index 9b03216c..00000000 --- a/alembic/versions/4a0281e1a826_usersip_add_tenant_uuid.py +++ /dev/null @@ -1,72 +0,0 @@ -"""usersip_add_tenant_uuid - -Revision ID: 4a0281e1a826 -Revises: 374507a67216 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '4a0281e1a826' -down_revision = '374507a67216' - - -TABLE = 'usersip' - - -def find_default_tenant_uuid(): - entity_table = sa.sql.table( - 'entity', - sa.sql.column('id'), - sa.sql.column('name'), - sa.sql.column('tenant_uuid'), - ) - query = sa.sql.select([entity_table.c.tenant_uuid]).order_by(entity_table.c.id) - for row in op.get_bind().execute(query): - return row.tenant_uuid - - -def associate_tenants(): - tbl = sa.sql.table('usersip', sa.sql.column('id'), sa.sql.column('tenant_uuid')) - sql = "SELECT usersip.id, context.tenant_uuid FROM usersip JOIN linefeatures ON (linefeatures.protocol = 'sip' AND linefeatures.protocolid = usersip.id) JOIN context ON linefeatures.context = context.name" - usersip_to_tenant = op.get_bind().execute(sa.sql.text(sql)) - - for usersip_id, tenant_uuid in usersip_to_tenant: - query = tbl.update().where(tbl.c.id == usersip_id).values(tenant_uuid=tenant_uuid) - op.execute(query) - - sql = "SELECT usersip.id, trunkfeatures.tenant_uuid FROM usersip, trunkfeatures WHERE trunkfeatures.protocol = 'sip' AND trunkfeatures.protocolid = usersip.id" - usersip_to_tenant = op.get_bind().execute(sa.sql.text(sql)) - - for usersip_id, tenant_uuid in usersip_to_tenant: - query = tbl.update().where(tbl.c.id == usersip_id).values(tenant_uuid=tenant_uuid) - op.execute(query) - - sql = "SELECT usersip.id, context.tenant_uuid FROM usersip JOIN context ON usersip.context = context.name LEFT JOIN linefeatures ON (linefeatures.protocol = 'sip' AND linefeatures.protocolid = usersip.id) LEFT JOIN trunkfeatures ON (trunkfeatures.protocol = 'sip' AND trunkfeatures.protocolid = usersip.id) WHERE linefeatures.protocolid IS NULL AND trunkfeatures.protocolid IS NULL;" - usersip_to_tenant = op.get_bind().execute(sa.sql.text(sql)) - - for usersip_id, tenant_uuid in usersip_to_tenant: - query = tbl.update().where(tbl.c.id == usersip_id).values(tenant_uuid=tenant_uuid) - op.execute(query) - - -def upgrade(): - default_tenant = find_default_tenant_uuid() - op.add_column( - TABLE, - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=False, - server_default=default_tenant), - ) - associate_tenants() - op.alter_column(TABLE, 'tenant_uuid', server_default=None) - - -def downgrade(): - op.drop_column(TABLE, 'tenant_uuid') diff --git a/alembic/versions/4a1c2a87321_add_foreignkey_on_rightcallexten.py b/alembic/versions/4a1c2a87321_add_foreignkey_on_rightcallexten.py deleted file mode 100644 index 5eaed368..00000000 --- a/alembic/versions/4a1c2a87321_add_foreignkey_on_rightcallexten.py +++ /dev/null @@ -1,23 +0,0 @@ -"""add_foreignkey_on_rightcallexten - -Revision ID: 4a1c2a87321 -Revises: 198cf8fda9a4 - -""" - -# revision identifiers, used by Alembic. -revision = '4a1c2a87321' -down_revision = '198cf8fda9a4' - -from alembic import op - - -def upgrade(): - op.execute("DELETE FROM rightcallexten WHERE rightcallid = 0") - op.create_foreign_key('rightcallexten_rightcallid_fkey', - 'rightcallexten', 'rightcall', - ['rightcallid'], ['id']) - - -def downgrade(): - op.drop_constraint('rightcallexten_rightcallid_fkey', 'rightcallexten') diff --git a/alembic/versions/4a5a1c3eb52f_add_subscription_to_userfeatures.py b/alembic/versions/4a5a1c3eb52f_add_subscription_to_userfeatures.py deleted file mode 100644 index bb94067c..00000000 --- a/alembic/versions/4a5a1c3eb52f_add_subscription_to_userfeatures.py +++ /dev/null @@ -1,34 +0,0 @@ -"""add-subscription-to-userfeatures - -Revision ID: 4a5a1c3eb52f -Revises: 68507181de97 - -""" - -import datetime - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '4a5a1c3eb52f' -down_revision = '68507181de97' - - -def upgrade(): - op.add_column( - 'userfeatures', - sa.Column( - 'created_at', - sa.DateTime, - default=datetime.datetime.utcnow, - server_default=sa.text("(now() at time zone 'utc')") - ) - ) - op.add_column('userfeatures', sa.Column('subscription_type', sa.Integer, nullable=False, server_default='0')) - - -def downgrade(): - op.drop_column('userfeatures', 'subscription_type') - op.drop_column('userfeatures', 'created_at') diff --git a/alembic/versions/4a80d0e24028_directories_use_dirtype_column.py b/alembic/versions/4a80d0e24028_directories_use_dirtype_column.py deleted file mode 100644 index 1c5de02e..00000000 --- a/alembic/versions/4a80d0e24028_directories_use_dirtype_column.py +++ /dev/null @@ -1,71 +0,0 @@ -"""directories use dirtype column - -Revision ID: 4a80d0e24028 -Revises: 151d1315479b - -""" - -# revision identifiers, used by Alembic. -revision = '4a80d0e24028' -down_revision = '151d1315479b' - -from alembic import op -from sqlalchemy import sql - -directories_table = sql.table('directories', - sql.column('uri'), - sql.column('id'), - sql.column('dirtype')) - - -def update_dirtype(uri_pattern, dirtype): - op.execute(directories_table - .update() - .where( - directories_table.c.uri.like(uri_pattern) - ) - .values(dirtype=dirtype)) - - -def drop_all_dirtype(): - op.execute(directories_table.update().values(dirtype='')) - - -def update_phonebook(): - update_dirtype('phonebook', 'phonebook') - - -def update_internal(): - update_dirtype('internal', 'internal') - - -def update_file(): - update_dirtype('file://%', 'file') - - -def update_ws(): - op.execute(directories_table - .update() - .where(directories_table.c.dirtype == '') - .values(dirtype='webservices')) - - -def add_not_null_constraint(): - op.alter_column('directories', 'dirtype', nullable=False) - - -def remove_not_null_constraint(): - op.alter_column('directories', 'dirtype', nullable=True) - - -def upgrade(): - update_phonebook() - update_internal() - update_file() - update_ws() - add_not_null_constraint() - - -def downgrade(): - remove_not_null_constraint() - drop_all_dirtype() diff --git a/alembic/versions/4aa03039dd2e_bump_version_20_13.py b/alembic/versions/4aa03039dd2e_bump_version_20_13.py deleted file mode 100644 index 2536c979..00000000 --- a/alembic/versions/4aa03039dd2e_bump_version_20_13.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_20_13 - -Revision ID: 4aa03039dd2e -Revises: d56d7434e9f4 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '4aa03039dd2e' -down_revision = 'd56d7434e9f4' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='20.13')) - - -def downgrade(): - pass diff --git a/alembic/versions/4bb90c6c47bb_allow_email_as_username.py b/alembic/versions/4bb90c6c47bb_allow_email_as_username.py deleted file mode 100644 index 7d196c86..00000000 --- a/alembic/versions/4bb90c6c47bb_allow_email_as_username.py +++ /dev/null @@ -1,26 +0,0 @@ -"""allow email as username - -Revision ID: 4bb90c6c47bb -Revises: edb58b09b15 - -""" - -# revision identifiers, used by Alembic. -revision = '4bb90c6c47bb' -down_revision = 'edb58b09b15' - -from alembic import op -from sqlalchemy.types import String - -TABLE_NAME = 'userfeatures' -NEW_TYPE = String(254) - - -def upgrade(): - op.alter_column(TABLE_NAME, 'email', type_=NEW_TYPE) - op.alter_column(TABLE_NAME, 'loginclient', type_=NEW_TYPE) - - -def downgrade(): - op.alter_column(TABLE_NAME, 'email', type_=String(128)) - op.alter_column(TABLE_NAME, 'loginclient', type_=String(64)) diff --git a/alembic/versions/4c13318f6975_migrate_func_key_park_position.py b/alembic/versions/4c13318f6975_migrate_func_key_park_position.py deleted file mode 100644 index 77196dea..00000000 --- a/alembic/versions/4c13318f6975_migrate_func_key_park_position.py +++ /dev/null @@ -1,344 +0,0 @@ -"""migrate func key park position - -Revision ID: 4c13318f6975 -Revises: a3e7fd7b670 - -""" - -# revision identifiers, used by Alembic. -revision = '4c13318f6975' -down_revision = 'a3e7fd7b670' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy import sql - - -TYPE_SPEEDDIAL = 'speeddial' - -DESTINATION_PARKING_ID = 7 - -PARKING_CATEGORY = 'general' -PARKING_TYPE = 'parkpos' - - -phonefunckey_table = sql.table('phonefunckey', - sql.column('iduserfeatures'), - sql.column('fknum'), - sql.column('exten'), - sql.column('typeextenumbers'), - sql.column('typevalextenumbers'), - sql.column('typeextenumbersright'), - sql.column('typevalextenumbersright'), - sql.column('label'), - sql.column('supervision'), - sql.column('progfunckey')) - -func_key_table = sql.table('func_key', - sql.column('id'), - sql.column('type_id'), - sql.column('destination_type_id')) - -dest_park_position_table = sql.table('func_key_dest_park_position', - sql.column('func_key_id'), - sql.column('destination_type_id'), - sql.column('park_position')) - -func_key_type_table = sql.table('func_key_type', - sql.column('id'), - sql.column('name')) - -func_key_mapping_table = sql.table('func_key_mapping', - sql.column('template_id'), - sql.column('func_key_id'), - sql.column('destination_type_id'), - sql.column('label'), - sql.column('position'), - sql.column('blf')) - -template_table = sql.table('func_key_template', sql.column('id')) - -user_table = sql.table('userfeatures', - sql.column('id'), - sql.column('func_key_private_template_id')) - -destination_type_table = sql.table('func_key_destination_type', - sql.column('id'), - sql.column('name')) - -features_table = sql.table('features', - sql.column('category'), - sql.column('var_name'), - sql.column('var_val')) - -func_key_columns = ( - phonefunckey_table.c.iduserfeatures.label('user_id'), - phonefunckey_table.c.fknum.label('position'), - phonefunckey_table.c.label, - phonefunckey_table.c.exten.label('park_position'), - sql.cast(phonefunckey_table.c.supervision, sa.Boolean).label('blf'), -) - -old_func_key_columns = ( - func_key_mapping_table.c.func_key_id, - func_key_mapping_table.c.template_id, - func_key_mapping_table.c.position, - func_key_mapping_table.c.blf, - func_key_mapping_table.c.label, - dest_park_position_table.c.park_position, - user_table.c.id.label('user_id') -) - -func_keys_query = (sql.select(func_key_columns) - .where(phonefunckey_table.c.typevalextenumbers == PARKING_TYPE)) - - -old_func_keys_query = (sql.select(old_func_key_columns, - from_obj=[ - func_key_mapping_table.join( - dest_park_position_table, - func_key_mapping_table.c.func_key_id == dest_park_position_table.c.func_key_id) - .join(template_table, - func_key_mapping_table.c.template_id == template_table.c.id) - .join(user_table, - template_table.c.id == user_table.c.func_key_private_template_id) - ])) - - -def upgrade(): - delete_duplicate_fks() - delete_empty_park_positions() - delete_invalid_park_positions() - migrate_func_keys() - delete_old_func_keys() - - -def delete_duplicate_fks(): - template = '[MIGRATE_FK] : Deleting func key for user "%s" (fk position %s with park position %s)' - for row in get_duplicate_func_keys(): - message = template % (row.iduserfeatures, row.fknum, row.exten) - delete_fk(row, message) - - -def get_duplicate_func_keys(): - columns = (phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.exten, - sa.func.min(phonefunckey_table.c.fknum).label("first_position")) - - valid_fk_subq = (sql.select(columns) - .where( - phonefunckey_table.c.typevalextenumbers == PARKING_TYPE) - .group_by( - phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.exten) - .having( - sa.func.count(phonefunckey_table.c.exten) > 1) - .alias()) - - columns = (phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.exten, - phonefunckey_table.c.fknum) - - join_condition = sql.and_( - phonefunckey_table.c.exten == valid_fk_subq.c.exten, - phonefunckey_table.c.fknum > valid_fk_subq.c.first_position, - phonefunckey_table.c.iduserfeatures == valid_fk_subq.c.iduserfeatures) - - duplicate_fk_query = (sql.select(columns, - from_obj=[ - phonefunckey_table.join( - valid_fk_subq, - join_condition - ) - ])) - - return op.get_bind().execute(duplicate_fk_query) - - -def delete_fk(row, message): - print(message) - - query = (phonefunckey_table - .delete() - .where( - sql.and_( - phonefunckey_table.c.iduserfeatures == row.iduserfeatures, - phonefunckey_table.c.fknum == row.fknum)) - ) - - op.get_bind().execute(query) - - -def delete_empty_park_positions(): - template = '[MIGRATE_FK] : Deleting func key for user "%s" (fk position %s with empty park position)' - - columns = (phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.fknum) - - query = (sql.select(columns) - .where( - sql.and_( - phonefunckey_table.c.typevalextenumbers == PARKING_TYPE, - phonefunckey_table.c.exten == None)) - ) - - for row in op.get_bind().execute(query): - message = template % (row.iduserfeatures, row.fknum) - delete_fk(row, message) - - -def delete_invalid_park_positions(): - template = '[MIGRATE_FK] : Deleting func key for user "%s" (fk position %s with invalid park position)' - - rows = get_invalid_park_positions() - - for row in rows: - message = template % (row.iduserfeatures, row.fknum) - delete_fk(row, message) - - -def get_invalid_park_positions(): - range_query = (sql.select( - [features_table.c.var_val]) - .where( - sql.and_( - features_table.c.category == PARKING_CATEGORY, - features_table.c.var_name == PARKING_TYPE)) - ) - - park_range = op.get_bind().execute(range_query).scalar() - - min_park, max_park = park_range.split('-') - - columns = (phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.fknum) - - query = (sql.select(columns) - .where( - sql.and_( - phonefunckey_table.c.typevalextenumbers == PARKING_TYPE, - sql.not_( - sql.cast( - phonefunckey_table.c.exten, sa.Integer) - .between( - int(min_park), - int(max_park))))) - ) - - return op.get_bind().execute(query) - - -def migrate_func_keys(): - for row in op.get_bind().execute(func_keys_query): - func_key_id = create_func_key() - create_parking_destination(func_key_id, row.park_position) - create_mapping(func_key_id, row) - - -def create_func_key(): - speeddial_id = get_speeddial_id() - insert_query = (func_key_table - .insert() - .returning(func_key_table.c.id) - .values(type_id=speeddial_id, - destination_type_id=DESTINATION_PARKING_ID)) - - return op.get_bind().execute(insert_query).scalar() - - -def get_speeddial_id(): - return op.get_bind().execute( - sql.select( - [func_key_type_table.c.id]) - .where( - func_key_type_table.c.name == TYPE_SPEEDDIAL) - ).scalar() - - -def create_parking_destination(func_key_id, park_position): - destination_query = (dest_park_position_table - .insert() - .returning(dest_park_position_table.c.func_key_id) - .values(func_key_id=func_key_id, - park_position=park_position)) - - op.get_bind().execute(destination_query) - - -def create_mapping(func_key_id, func_key_row): - conn = op.get_bind() - - template_id = conn.execute(sql.select( - [user_table.c.func_key_private_template_id]) - .where( - user_table.c.id == func_key_row.user_id) - ).scalar() - - mapping_query = (func_key_mapping_table - .insert() - .returning(func_key_mapping_table.c.func_key_id) - .values(func_key_id=func_key_id, - template_id=template_id, - destination_type_id=DESTINATION_PARKING_ID, - label=func_key_row.label, - position=func_key_row.position, - blf=func_key_row.blf)) - - conn.execute(mapping_query) - - -def delete_old_func_keys(): - delete_query = (phonefunckey_table - .delete() - .where(phonefunckey_table.c.typevalextenumbers == PARKING_TYPE)) - - op.get_bind().execute(delete_query) - - -def downgrade(): - for row in op.get_bind().execute(old_func_keys_query): - create_old_func_keys(row) - delete_mapping(row.func_key_id, row.template_id) - delete_dest_park_position(row.func_key_id) - delete_func_key(row.func_key_id) - - -def create_old_func_keys(row): - supervision = 1 if row.blf else 0 - - row = {'iduserfeatures': row.user_id, - 'fknum': row.position, - 'typeextenumbers': 'generalfeatures', - 'typevalextenumbers': 'parkpos', - 'typeextenumbersright': None, - 'typevalextenumbersright': None, - 'label': row.label, - 'exten': row.park_position, - 'supervision': supervision} - - op.bulk_insert(phonefunckey_table, [row]) - - -def delete_mapping(func_key_id, template_id): - query = (func_key_mapping_table - .delete() - .where(sql.and_( - func_key_mapping_table.c.func_key_id == func_key_id, - func_key_mapping_table.c.template_id == template_id))) - - op.get_bind().execute(query) - - -def delete_dest_park_position(func_key_id): - query = (dest_park_position_table - .delete()) - - op.get_bind().execute(query) - - -def delete_func_key(func_key_id): - query = (func_key_table - .delete() - .where(func_key_table.c.destination_type_id == DESTINATION_PARKING_ID)) - - op.get_bind().execute(query) diff --git a/alembic/versions/4c1cbf778770_bump_version_19_08.py b/alembic/versions/4c1cbf778770_bump_version_19_08.py deleted file mode 100644 index 4553e825..00000000 --- a/alembic/versions/4c1cbf778770_bump_version_19_08.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_19_08 - -Revision ID: 4c1cbf778770 -Revises: 15ca57fa1b71 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '4c1cbf778770' -down_revision = '15ca57fa1b71' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='19.08')) - - -def downgrade(): - pass diff --git a/alembic/versions/4c4a8eaa31e7_bump_version_19_17.py b/alembic/versions/4c4a8eaa31e7_bump_version_19_17.py deleted file mode 100644 index 47ef5e6f..00000000 --- a/alembic/versions/4c4a8eaa31e7_bump_version_19_17.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_19_17 - -Revision ID: 4c4a8eaa31e7 -Revises: 449045080bf6 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '4c4a8eaa31e7' -down_revision = '449045080bf6' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='19.17')) - - -def downgrade(): - pass diff --git a/alembic/versions/4c660492b365_fix_register_transports.py b/alembic/versions/4c660492b365_fix_register_transports.py deleted file mode 100644 index ef464309..00000000 --- a/alembic/versions/4c660492b365_fix_register_transports.py +++ /dev/null @@ -1,95 +0,0 @@ -"""fix-register-transports - -Revision ID: 4c660492b365 -Revises: 86c17bf55b92 - -""" - -import re -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '4c660492b365' -down_revision = '86c17bf55b92' - -# Regex copied from wazo-confd -REGISTER_REGEX = re.compile( - r'''^ - (?:(?P.*)://)? - (?P[^:/]*) - (?::(?P[^:/]*))? - (?::(?P[^:/]*))? - @ - (?P[^:~/]*) - (?::(?P\d*))? - (?:/(?P[^~]*))? - (?:~(?P\d*))? - $''', - re.VERBOSE, -) - -static_sip_table = sa.sql.table( - 'staticsip', - sa.sql.column('id'), - sa.sql.column('filename'), - sa.sql.column('category'), - sa.sql.column('var_name'), - sa.sql.column('var_val'), -) - -transport_table = sa.sql.table( - 'pjsip_transport', - sa.sql.column('name'), -) - -def _get_existing_transport_names(): - query = sa.sql.select([transport_table.c.name]) - rows = op.get_bind().execute(query) - return [row[0] for row in rows] - - -def _get_registers(): - query = sa.sql.select( - [static_sip_table.c.id, static_sip_table.c.var_val] - ).where(sa.sql.and_( - static_sip_table.c.filename == 'sip.conf', - static_sip_table.c.category == 'general', - static_sip_table.c.var_name == 'register', - )) - rows = op.get_bind().execute(query) - return [(row[0], row[1]) for row in rows] - - -def upgrade(): - configured_transport_names = _get_existing_transport_names() - registers = _get_registers() - for id_, url in registers: - matches = REGISTER_REGEX.match(url) - result = matches.groupdict() - transport_name = result['transport'] - if not transport_name: - continue - - if transport_name in configured_transport_names: - continue - - new_name = 'transport-{}'.format(transport_name) - if new_name not in configured_transport_names: - raise Exception( - 'cannot migrate the SIP register {} no matching transport {}'.format( - url, configured_transport_names - ) - ) - - new_url = url.replace(transport_name, new_name, 1) - op.execute( - static_sip_table.update().where( - static_sip_table.c.id == id_ - ).values(var_val=new_url) - ) - - -def downgrade(): - pass diff --git a/alembic/versions/4c79fd76bccb_drop_useless_provisioning_columns.py b/alembic/versions/4c79fd76bccb_drop_useless_provisioning_columns.py deleted file mode 100644 index 07903b4c..00000000 --- a/alembic/versions/4c79fd76bccb_drop_useless_provisioning_columns.py +++ /dev/null @@ -1,32 +0,0 @@ -"""drop useless provisioning columns -Revision ID: 4c79fd76bccb -Revises: a3b4e1bf633b - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '4c79fd76bccb' -down_revision = 'a3b4e1bf633b' - -TABLE = 'provisioning' - - -def upgrade(): - op.drop_column(TABLE, 'username') - op.drop_column(TABLE, 'password') - op.drop_column(TABLE, 'secure') - op.drop_column(TABLE, 'private') - - -def downgrade(): - op.add_column(TABLE, sa.Column('username', sa.String(32), nullable=False, server_default='')) - op.add_column(TABLE, sa.Column('password', sa.String(32), nullable=False, server_default='')) - op.add_column(TABLE, sa.Column('secure', sa.Integer(), nullable=False, server_default='0')) - op.add_column(TABLE, sa.Column('private', sa.Integer(), nullable=False, server_default='0')) - - op.alter_column(TABLE, 'username', server_default=None) - op.alter_column(TABLE, 'password', server_default=None) diff --git a/alembic/versions/4ce50bcf2a0e_create_forward_func_keys.py b/alembic/versions/4ce50bcf2a0e_create_forward_func_keys.py deleted file mode 100644 index 2c39e678..00000000 --- a/alembic/versions/4ce50bcf2a0e_create_forward_func_keys.py +++ /dev/null @@ -1,50 +0,0 @@ -"""create forward func keys - -Revision ID: 4ce50bcf2a0e -Revises: 379d2e0c5e51 - -""" - -# revision identifiers, used by Alembic. -revision = '4ce50bcf2a0e' -down_revision = '379d2e0c5e51' - -from alembic import op -import sqlalchemy as sa - - -FORWARD_TYPE_ID = 6 -FORWARD_TYPE_NAME = 'forward' - -destination_type_table = sa.sql.table('func_key_destination_type', - sa.sql.column('id'), - sa.sql.column('name')) - - -def upgrade(): - service_type_row = {'id': FORWARD_TYPE_ID, 'name': FORWARD_TYPE_NAME} - op.bulk_insert(destination_type_table, [service_type_row]) - - op.create_table( - 'func_key_dest_forward', - sa.Column('func_key_id', sa.Integer), - sa.Column('destination_type_id', - sa.Integer, - sa.CheckConstraint('destination_type_id = %d' % FORWARD_TYPE_ID), - server_default=str(FORWARD_TYPE_ID)), - sa.Column('extension_id', sa.Integer), - sa.Column('number', sa.String(40)), - sa.PrimaryKeyConstraint('func_key_id', 'destination_type_id', 'extension_id'), - sa.ForeignKeyConstraint(['func_key_id', 'destination_type_id'], - ['func_key.id', 'func_key.destination_type_id']), - sa.ForeignKeyConstraint(['extension_id'], ['extensions.id']) - ) - - -def downgrade(): - op.drop_table('func_key_dest_forward') - - delete_query = (destination_type_table - .delete() - .where(destination_type_table.c.id == FORWARD_TYPE_ID)) - op.execute(delete_query) diff --git a/alembic/versions/4cf59c82b51e_queue_timeout_may_be_null.py b/alembic/versions/4cf59c82b51e_queue_timeout_may_be_null.py deleted file mode 100644 index 81781486..00000000 --- a/alembic/versions/4cf59c82b51e_queue_timeout_may_be_null.py +++ /dev/null @@ -1,27 +0,0 @@ -"""queue timeout may be null - -Revision ID: 4cf59c82b51e -Revises: f485ac649eb - -""" - -# revision identifiers, used by Alembic. -revision = '4cf59c82b51e' -down_revision = 'f485ac649eb' - -from alembic import op -import sqlalchemy as sa - -queuefeatures_table = sa.sql.table('queuefeatures', - sa.Column('timeout', sa.Integer)) - - -def upgrade(): - op.alter_column('queuefeatures', 'timeout', server_default=None, nullable=True) - - -def downgrade(): - op.execute(queuefeatures_table.update(). - where(queuefeatures_table.c.timeout == None). - values(timeout='0')) - op.alter_column('queuefeatures', 'timeout', server_default='0', nullable=False) diff --git a/alembic/versions/4cf687f2c0eb_add_dird_xivo_backend_auth.py b/alembic/versions/4cf687f2c0eb_add_dird_xivo_backend_auth.py deleted file mode 100644 index aa4afbdf..00000000 --- a/alembic/versions/4cf687f2c0eb_add_dird_xivo_backend_auth.py +++ /dev/null @@ -1,39 +0,0 @@ -"""add dird-xivo-backend auth - -Revision ID: 4cf687f2c0eb -Revises: 52acaaba550c - -""" - -# revision identifiers, used by Alembic. -revision = '4cf687f2c0eb' -down_revision = '52acaaba550c' - - -from alembic import op -from sqlalchemy import sql, func - - -webservice = sql.table('accesswebservice', - sql.column('name'), - sql.column('login'), - sql.column('passwd'), - sql.column('acl'), - sql.column('description')) -ACL = '{confd.users.read, confd.infos.read}' -DESCRIPTION = 'Automatically created during upgrade' -SERVICE = 'wazo-dird-xivo-backend' - - -def upgrade(): - op.execute(webservice - .insert() - .values(name=SERVICE, - login=SERVICE, - passwd=func.substring(func.gen_salt('bf', 4), 8), - acl=ACL, - description=DESCRIPTION)) - - -def downgrade(): - op.execute(webservice.delete().where(webservice.c.name == SERVICE)) diff --git a/alembic/versions/4d539700bb90_add_group_label.py b/alembic/versions/4d539700bb90_add_group_label.py deleted file mode 100644 index 21e9eed4..00000000 --- a/alembic/versions/4d539700bb90_add_group_label.py +++ /dev/null @@ -1,35 +0,0 @@ -"""add-group-label - -Revision ID: 4d539700bb90 -Revises: 757111d049b6 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '4d539700bb90' -down_revision = '757111d049b6' - -groupfeatures_tbl = sa.sql.table( - 'groupfeatures', - sa.sql.column('uuid'), - sa.sql.column('name'), - sa.sql.column('label'), -) - - -def upgrade(): - op.add_column( - 'groupfeatures', - sa.Column('label', sa.Text), - ) - query = groupfeatures_tbl.update().values(label=groupfeatures_tbl.c.name) - op.execute(query) - op.alter_column('groupfeatures', 'label', nullable=False) - - -def downgrade(): - op.drop_column('groupfeatures', 'label') diff --git a/alembic/versions/4d736bac41cb_bump_version_20_06.py b/alembic/versions/4d736bac41cb_bump_version_20_06.py deleted file mode 100644 index 192c1720..00000000 --- a/alembic/versions/4d736bac41cb_bump_version_20_06.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_20_06 - -Revision ID: 4d736bac41cb -Revises: fb663a210806 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '4d736bac41cb' -down_revision = 'fb663a210806' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='20.06')) - - -def downgrade(): - pass diff --git a/alembic/versions/4d80d8106d1e_bump_version_19_14.py b/alembic/versions/4d80d8106d1e_bump_version_19_14.py deleted file mode 100644 index 983dd404..00000000 --- a/alembic/versions/4d80d8106d1e_bump_version_19_14.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_19_14 - -Revision ID: 4d80d8106d1e -Revises: cbd383662cc0 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '4d80d8106d1e' -down_revision = 'cbd383662cc0' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='19.14')) - - -def downgrade(): - pass diff --git a/alembic/versions/4e07e476eb0b_add_paused_and_paused_reason_to_agent_.py b/alembic/versions/4e07e476eb0b_add_paused_and_paused_reason_to_agent_.py deleted file mode 100644 index ecb79741..00000000 --- a/alembic/versions/4e07e476eb0b_add_paused_and_paused_reason_to_agent_.py +++ /dev/null @@ -1,25 +0,0 @@ -"""add paused and paused reason to agent status - -Revision ID: 4e07e476eb0b -Revises: 19a869176d6c - -""" - -# revision identifiers, used by Alembic. -revision = '4e07e476eb0b' -down_revision = '19a869176d6c' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - op.add_column('agent_login_status', - sa.Column('paused', sa.Boolean, nullable=False, server_default='false')) - op.add_column('agent_login_status', - sa.Column('paused_reason', sa.String(80), nullable=True)) - - -def downgrade(): - op.drop_column('agent_login_status', 'paused') - op.drop_column('agent_login_status', 'paused_reason') diff --git a/alembic/versions/4e2fb3cbc2a2_add_unique_constraint_queueskillrule.py b/alembic/versions/4e2fb3cbc2a2_add_unique_constraint_queueskillrule.py deleted file mode 100644 index 68339b1c..00000000 --- a/alembic/versions/4e2fb3cbc2a2_add_unique_constraint_queueskillrule.py +++ /dev/null @@ -1,25 +0,0 @@ -"""add_unique_constraint_queueskillrule - -Revision ID: 4e2fb3cbc2a2 -Revises: 129646f8f81f - -""" - -from alembic import op - -# revision identifiers, used by Alembic. -revision = '4e2fb3cbc2a2' -down_revision = '129646f8f81f' - -table_name = 'queueskillrule' -constraint_name = '{}_name_key'.format(table_name) - - -def upgrade(): - op.alter_column(table_name, 'name', nullable=False) - op.create_unique_constraint(constraint_name, table_name, ['name']) - - -def downgrade(): - op.drop_constraint(constraint_name, table_name) - op.alter_column(table_name, 'name', nullable=True) diff --git a/alembic/versions/4ee55e5290be_directories_xivo_confd_uri.py b/alembic/versions/4ee55e5290be_directories_xivo_confd_uri.py deleted file mode 100644 index 284a4be8..00000000 --- a/alembic/versions/4ee55e5290be_directories_xivo_confd_uri.py +++ /dev/null @@ -1,46 +0,0 @@ -"""directories xivo confd uri - -Revision ID: 4ee55e5290be -Revises: 41e07bde92da - -""" - -# revision identifiers, used by Alembic. -revision = '4ee55e5290be' -down_revision = '41e07bde92da' - -from alembic import op -from sqlalchemy import sql - -confd_url = 'http://localhost:9487' -directories_table = sql.table('directories', - sql.column('uri'), - sql.column('dirtype')) -cti_directories_table = sql.table('ctidirectories', - sql.column('uri')) - - -def upgrade(): - op.execute(directories_table - .update() - .where( - directories_table.c.dirtype == 'xivo' - ).values(uri=confd_url)) - op.execute(cti_directories_table - .update() - .where( - cti_directories_table.c.uri == 'xivo' - ).values(uri=confd_url)) - - -def downgrade(): - op.execute(directories_table - .update() - .where( - directories_table.c.uri == confd_url - ).values(uri='xivo')) - op.execute(cti_directories_table - .update() - .where( - cti_directories_table.c.uri == confd_url - ).values(uri='xivo')) diff --git a/alembic/versions/4f85f1de19b4_useriax_add_tenant_uuid.py b/alembic/versions/4f85f1de19b4_useriax_add_tenant_uuid.py deleted file mode 100644 index bdd11675..00000000 --- a/alembic/versions/4f85f1de19b4_useriax_add_tenant_uuid.py +++ /dev/null @@ -1,64 +0,0 @@ -"""useriax_add_tenant_uuid - -Revision ID: 4f85f1de19b4 -Revises: 41b6afe5b164 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '4f85f1de19b4' -down_revision = '41b6afe5b164' - -TABLE = 'useriax' - - -def find_default_tenant_uuid(): - entity_table = sa.sql.table( - 'entity', - sa.sql.column('id'), - sa.sql.column('name'), - sa.sql.column('tenant_uuid'), - ) - query = sa.sql.select([entity_table.c.tenant_uuid]).order_by(entity_table.c.id) - for row in op.get_bind().execute(query): - return row.tenant_uuid - - -def associate_tenants(): - tbl = sa.sql.table('useriax', sa.sql.column('id'), sa.sql.column('tenant_uuid')) - sql = "SELECT useriax.id, trunkfeatures.tenant_uuid FROM useriax, trunkfeatures WHERE trunkfeatures.protocol = 'iax' AND trunkfeatures.protocolid = useriax.id" - useriax_to_tenant = op.get_bind().execute(sa.sql.text(sql)) - - for useriax_id, tenant_uuid in useriax_to_tenant: - query = tbl.update().where(tbl.c.id == useriax_id).values(tenant_uuid=tenant_uuid) - op.execute(query) - - sql = "SELECT useriax.id, context.tenant_uuid FROM useriax JOIN context ON useriax.context = context.name LEFT JOIN trunkfeatures ON (trunkfeatures.protocol = 'iax' AND trunkfeatures.protocolid = useriax.id) WHERE trunkfeatures.protocolid IS NULL;" - useriax_to_tenant = op.get_bind().execute(sa.sql.text(sql)) - - for useriax_id, tenant_uuid in useriax_to_tenant: - query = tbl.update().where(tbl.c.id == useriax_id).values(tenant_uuid=tenant_uuid) - op.execute(query) - - -def upgrade(): - default_tenant = find_default_tenant_uuid() - op.add_column( - TABLE, - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=False, - server_default=default_tenant), - ) - associate_tenants() - op.alter_column(TABLE, 'tenant_uuid', server_default=None) - - -def downgrade(): - op.drop_column(TABLE, 'tenant_uuid') diff --git a/alembic/versions/4f86216ba603_paging_add_tenant_uuid.py b/alembic/versions/4f86216ba603_paging_add_tenant_uuid.py deleted file mode 100644 index 59a19cde..00000000 --- a/alembic/versions/4f86216ba603_paging_add_tenant_uuid.py +++ /dev/null @@ -1,45 +0,0 @@ -"""paging_add_tenant_uuid - -Revision ID: 4f86216ba603 -Revises: 232708be8a75 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '4f86216ba603' -down_revision = '232708be8a75' - -TABLE = 'paging' - - -def find_default_tenant_uuid(): - entity_table = sa.sql.table( - 'entity', - sa.sql.column('id'), - sa.sql.column('tenant_uuid'), - ) - query = sa.sql.select([entity_table.c.tenant_uuid]).order_by(entity_table.c.id) - for row in op.get_bind().execute(query): - return row.tenant_uuid - - -def upgrade(): - default_tenant = find_default_tenant_uuid() - op.add_column( - TABLE, - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=False, - server_default=default_tenant), - ) - op.alter_column(TABLE, 'tenant_uuid', server_default=None) - - -def downgrade(): - op.drop_column(TABLE, 'tenant_uuid') diff --git a/alembic/versions/4fa0a41c0327_add_foreignkey_outcalltrunk.py b/alembic/versions/4fa0a41c0327_add_foreignkey_outcalltrunk.py deleted file mode 100644 index 741c69e3..00000000 --- a/alembic/versions/4fa0a41c0327_add_foreignkey_outcalltrunk.py +++ /dev/null @@ -1,60 +0,0 @@ -"""add_foreignkey_outcalltrunk - -Revision ID: 4fa0a41c0327 -Revises: 4fd0315a61fc - -""" - -# revision identifiers, used by Alembic. -revision = '4fa0a41c0327' -down_revision = '4fd0315a61fc' - -from alembic import op -from sqlalchemy import sql - -trunk_table = sql.table('trunkfeatures', - sql.column('id')) - -outcall_table = sql.table('outcall', - sql.column('id')) - -outcalltrunk_table = sql.table('outcalltrunk', - sql.column('trunkfeaturesid'), - sql.column('outcallid')) - - -def upgrade(): - _clean_outcalltrunk_table() - op.create_foreign_key('outcalltrunk_outcallid_fkey', - 'outcalltrunk', 'outcall', - ['outcallid'], ['id']) - op.create_foreign_key('outcalltrunk_trunkfeaturesid_fkey', - 'outcalltrunk', 'trunkfeatures', - ['trunkfeaturesid'], ['id']) - op.alter_column('outcalltrunk', 'outcallid', server_default=None) - op.alter_column('outcalltrunk', 'trunkfeaturesid', server_default=None) - - -def _clean_outcalltrunk_table(): - all_trunks = sql.select([trunk_table.c.id]).alias() - query = (outcalltrunk_table - .delete() - .where(outcalltrunk_table.c.trunkfeaturesid.notin_( - all_trunks))) - - op.execute(query) - - all_outcalls = sql.select([outcall_table.c.id]).alias() - query = (outcalltrunk_table - .delete() - .where(outcalltrunk_table.c.outcallid.notin_( - all_outcalls))) - - op.execute(query) - - -def downgrade(): - op.drop_constraint('outcalltrunk_outcallid_fkey', 'outcalltrunk') - op.drop_constraint('outcalltrunk_trunkfeaturesid_fkey', 'outcalltrunk') - op.alter_column('outcalltrunk', 'outcallid', server_default='0') - op.alter_column('outcalltrunk', 'trunkfeaturesid', server_default='0') diff --git a/alembic/versions/4fb644b564c8_bump_version_17_15.py b/alembic/versions/4fb644b564c8_bump_version_17_15.py deleted file mode 100644 index c2618d2c..00000000 --- a/alembic/versions/4fb644b564c8_bump_version_17_15.py +++ /dev/null @@ -1,22 +0,0 @@ -"""bump_version_17_15 - -Revision ID: 4fb644b564c8 -Revises: 412b6135f650 - -""" - -# revision identifiers, used by Alembic. -revision = '4fb644b564c8' -down_revision = '412b6135f650' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='17.15')) - - -def downgrade(): - pass diff --git a/alembic/versions/4fd0315a61fc_allow_context_none_in_outcall.py b/alembic/versions/4fd0315a61fc_allow_context_none_in_outcall.py deleted file mode 100644 index e07c3617..00000000 --- a/alembic/versions/4fd0315a61fc_allow_context_none_in_outcall.py +++ /dev/null @@ -1,20 +0,0 @@ -"""allow-context-none-in-outcall.py - -Revision ID: 4fd0315a61fc -Revises: 241ba0a6d087 - -""" - -# revision identifiers, used by Alembic. -revision = '4fd0315a61fc' -down_revision = '241ba0a6d087' - -from alembic import op - - -def upgrade(): - op.alter_column('outcall', 'context', nullable=True) - - -def downgrade(): - op.alter_column('outcall', 'context', nullable=False) diff --git a/alembic/versions/4fe20686380b_bump_version_19_10.py b/alembic/versions/4fe20686380b_bump_version_19_10.py deleted file mode 100644 index 3ed294d0..00000000 --- a/alembic/versions/4fe20686380b_bump_version_19_10.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_19_10 - -Revision ID: 4fe20686380b -Revises: 9b7e32eb0a77 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '4fe20686380b' -down_revision = '9b7e32eb0a77' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='19.10')) - - -def downgrade(): - pass diff --git a/alembic/versions/4fe888586ba3_add_unique_constraint_to_user_email.py b/alembic/versions/4fe888586ba3_add_unique_constraint_to_user_email.py deleted file mode 100644 index 8c90981a..00000000 --- a/alembic/versions/4fe888586ba3_add_unique_constraint_to_user_email.py +++ /dev/null @@ -1,48 +0,0 @@ -"""add_unique_constraint_to_user_email - -Revision ID: 4fe888586ba3 -Revises: 3420040c5650 - -""" - -# revision identifiers, used by Alembic. -revision = '4fe888586ba3' -down_revision = '3420040c5650' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy import sql - - -userfeatures_table = sql.table('userfeatures', - sql.column('id'), - sql.column('email')) - - -def upgrade(): - _delete_duplicate_emails() - op.create_unique_constraint('userfeatures_email', 'userfeatures', ['email']) - - -def _delete_duplicate_emails(): - for duplicate in _get_duplicate_emails(): - print('[MIGRATE_USER_EMAIL] : Deleting email "{}" for user id "{}"'.format( - duplicate.email, duplicate.array_id - )) - query = (userfeatures_table.update() - .values(email=None) - .where(userfeatures_table.c.email == duplicate.email)) - op.get_bind().execute(query) - - -def _get_duplicate_emails(): - query = (sql.select([userfeatures_table.c.email, - sa.func.array_agg(userfeatures_table.c.id).label('array_id')]) - .group_by(userfeatures_table.c.email) - .having(sa.func.count(userfeatures_table.c.email) > 1)) - - return op.get_bind().execute(query) - - -def downgrade(): - op.drop_constraint('userfeatures_email', 'userfeatures') diff --git a/alembic/versions/500ca962c3a8_use_automixmon_features_instead_of_.py b/alembic/versions/500ca962c3a8_use_automixmon_features_instead_of_.py deleted file mode 100644 index 5e7355ed..00000000 --- a/alembic/versions/500ca962c3a8_use_automixmon_features_instead_of_.py +++ /dev/null @@ -1,33 +0,0 @@ -"""use automixmon features instead of automixmon - -Revision ID: 500ca962c3a8 -Revises: 2ea8d6cb26f6 - -""" - -# revision identifiers, used by Alembic. -revision = '500ca962c3a8' -down_revision = '2ea8d6cb26f6' - -from alembic import op -from sqlalchemy import sql, and_ - -features_table = sql.table('features', - sql.column('category'), - sql.column('var_name')) - - -def upgrade(): - op.execute(features_table - .update() - .where(and_(features_table.c.category == 'featuremap', - features_table.c.var_name == 'automon')) - .values(var_name='automixmon')) - - -def downgrade(): - op.execute(features_table - .update() - .where(and_(features_table.c.category == 'featuremap', - features_table.c.var_name == 'automixmon')) - .values(var_name='automon')) diff --git a/alembic/versions/5013b66e26d2_add_auth_tenants_read_to_agid.py b/alembic/versions/5013b66e26d2_add_auth_tenants_read_to_agid.py deleted file mode 100644 index e320b6ab..00000000 --- a/alembic/versions/5013b66e26d2_add_auth_tenants_read_to_agid.py +++ /dev/null @@ -1,45 +0,0 @@ -"""add auth.tenants.read to agid - -Revision ID: 5013b66e26d2 -Revises: 0c84ec128899 - -""" - -from alembic import op -from sqlalchemy import sql -from sqlalchemy.dialects.postgresql import ARRAY, VARCHAR - - -# revision identifiers, used by Alembic. -revision = '5013b66e26d2' -down_revision = '0c84ec128899' - -accesswebservice = sql.table('accesswebservice', - sql.column('id'), - sql.column('name'), - sql.column('acl')) - -ACLS = ['auth.tenants.read'] -SERVICE = 'xivo-agid' - - -def upgrade(): - acls = sql.cast(ACLS, ARRAY(VARCHAR)) - query = (accesswebservice - .update() - .values( - acl=sql.func.array_cat(accesswebservice.c.acl, acls)) - .where( - accesswebservice.c.name == SERVICE)) - op.execute(query) - - -def downgrade(): - for acl in ACLS: - query = (accesswebservice - .update() - .values( - acl=sql.func.array_remove(accesswebservice.c.acl, acl)) - .where( - accesswebservice.c.name == SERVICE)) - op.execute(query) diff --git a/alembic/versions/501dae22d6be_ast13_update_findslot.py b/alembic/versions/501dae22d6be_ast13_update_findslot.py deleted file mode 100644 index c5b16797..00000000 --- a/alembic/versions/501dae22d6be_ast13_update_findslot.py +++ /dev/null @@ -1,34 +0,0 @@ -"""ast13: update findslot - -Revision ID: 501dae22d6be -Revises: 36c3f75ac228 - -""" - -# revision identifiers, used by Alembic. -revision = '501dae22d6be' -down_revision = '36c3f75ac228' - -from alembic import op -from sqlalchemy import sql - - -features_table = sql.table('features', - sql.column('var_name'), - sql.column('var_val')) - - -def upgrade(): - _update_features_findslot() - - -def _update_features_findslot(): - op.execute(features_table.update(). - where(sql.and_( - features_table.c.var_name == 'findslot', - features_table.c.var_val == 'no')). - values(var_val='first')) - - -def downgrade(): - pass diff --git a/alembic/versions/503cf85083ba_enable_starttls.py b/alembic/versions/503cf85083ba_enable_starttls.py deleted file mode 100644 index 410d6eaf..00000000 --- a/alembic/versions/503cf85083ba_enable_starttls.py +++ /dev/null @@ -1,23 +0,0 @@ -"""enable starttls - -Revision ID: 503cf85083ba -Revises: 57a7c7438b98 - -""" - -# revision identifiers, used by Alembic. -revision = '503cf85083ba' -down_revision = '57a7c7438b98' - -from alembic import op -from sqlalchemy import sql - -cti_main_table = sql.table('ctimain', sql.column('ctis_active')) - - -def upgrade(): - op.execute(cti_main_table.update().values(ctis_active=1)) - - -def downgrade(): - pass diff --git a/alembic/versions/5047425b0f5c_add_tenant_uuid_to_call_log.py b/alembic/versions/5047425b0f5c_add_tenant_uuid_to_call_log.py deleted file mode 100644 index 33d3a852..00000000 --- a/alembic/versions/5047425b0f5c_add_tenant_uuid_to_call_log.py +++ /dev/null @@ -1,31 +0,0 @@ -"""add_tenant_uuid_to_call_log_participant - -Revision ID: 5047425b0f5c -Revises: d0f74d74eb5f - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '5047425b0f5c' -down_revision = 'd0f74d74eb5f' - - -def upgrade(): - op.add_column( - 'call_log', - sa.Column( - 'tenant_uuid', - sa.String(36), - nullable=False, - server_default='00000000-0000-0000-0000-000000000000', - ) - ) - op.alter_column('call_log', 'tenant_uuid', server_default=None) - - -def downgrade(): - op.drop_column('call_log', 'tenant_uuid') diff --git a/alembic/versions/505c12d2ed73_add_iax_options.py b/alembic/versions/505c12d2ed73_add_iax_options.py deleted file mode 100644 index 587cc2d0..00000000 --- a/alembic/versions/505c12d2ed73_add_iax_options.py +++ /dev/null @@ -1,24 +0,0 @@ -"""add_iax_options - -Revision ID: 505c12d2ed73 -Revises: 672a6918b7f9 - -""" - -# revision identifiers, used by Alembic. -revision = '505c12d2ed73' -down_revision = '672a6918b7f9' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects.postgresql import ARRAY - - -def upgrade(): - op.add_column('useriax', sa.Column('options', - ARRAY(sa.String, dimensions=2), - nullable=False, server_default='{}')) - - -def downgrade(): - op.drop_column('useriax', 'options') diff --git a/alembic/versions/5073b1fa473e_force_user_to_entity_association.py b/alembic/versions/5073b1fa473e_force_user_to_entity_association.py deleted file mode 100644 index 05657903..00000000 --- a/alembic/versions/5073b1fa473e_force_user_to_entity_association.py +++ /dev/null @@ -1,71 +0,0 @@ -"""force user to entity association - -Revision ID: 5073b1fa473e -Revises: 1f4cbd713979 - -""" - -# revision identifiers, used by Alembic. -revision = '5073b1fa473e' -down_revision = '1f4cbd713979' - -from alembic import op -from sqlalchemy import sql - - -def upgrade(): - entity = sql.table( - 'entity', - sql.column('id'), - ) - user = sql.table( - 'userfeatures', - sql.column('entityid'), - ) - - entity_id = _default_entity_id(entity) - _sanitize_entity_ids(entity, user, entity_id) - _add_foreign_key() - - -def downgrade(): - _delete_foreign_key() - - -def _add_foreign_key(): - op.create_foreign_key( - name='userfeatures_entity_id_fkey', - source='userfeatures', - referent='entity', - local_cols=['entityid'], - remote_cols=['id'], - ondelete='RESTRICT', - ) - - -def _delete_foreign_key(): - op.drop_constraint( - name='userfeatures_entity_id_fkey', - table_name='userfeatures', - type_='foreignkey', - ) - - -def _default_entity_id(entity): - query = sql.select([entity.c.id], limit=1) - entity_id = op.get_bind().execute(query).scalar() - return entity_id - - -def _sanitize_entity_ids(entity, user, entity_id): - valid_entities = sql.select([entity.c.id]) - update_query = ( - user.update().values(entityid=entity_id) - .where( - sql.or_( - user.c.entityid == None, - sql.not_(user.c.entityid.in_(valid_entities)) - ) - ) - ) - op.get_bind().execute(update_query) diff --git a/alembic/versions/5085447dd295_allow_call_filter_description_none.py b/alembic/versions/5085447dd295_allow_call_filter_description_none.py deleted file mode 100644 index 120a9e53..00000000 --- a/alembic/versions/5085447dd295_allow_call_filter_description_none.py +++ /dev/null @@ -1,20 +0,0 @@ -"""allow-call-filter-description-none - -Revision ID: 5085447dd295 -Revises: 2991705be1ec - -""" - -from alembic import op - -# revision identifiers, used by Alembic. -revision = '5085447dd295' -down_revision = '2991705be1ec' - - -def upgrade(): - op.alter_column('callfilter', 'description', nullable=True) - - -def downgrade(): - op.alter_column('callfilter', 'description', nullable=False) diff --git a/alembic/versions/508c5a0382dc_bump_version_17_12.py b/alembic/versions/508c5a0382dc_bump_version_17_12.py deleted file mode 100644 index 041a518c..00000000 --- a/alembic/versions/508c5a0382dc_bump_version_17_12.py +++ /dev/null @@ -1,22 +0,0 @@ -"""bump_version_17_12 - -Revision ID: 508c5a0382dc -Revises: 60eb57605f3 - -""" - -# revision identifiers, used by Alembic. -revision = '508c5a0382dc' -down_revision = '60eb57605f3' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='17.12')) - - -def downgrade(): - pass diff --git a/alembic/versions/50cfb10bd01d_drop_empty_recording_tables.py b/alembic/versions/50cfb10bd01d_drop_empty_recording_tables.py deleted file mode 100644 index 58d3a1cd..00000000 --- a/alembic/versions/50cfb10bd01d_drop_empty_recording_tables.py +++ /dev/null @@ -1,66 +0,0 @@ -"""drop empty recording tables - -Revision ID: 50cfb10bd01d -Revises: 41d3e47edf4a - -""" - -# revision identifiers, used by Alembic. -revision = '50cfb10bd01d' -down_revision = '41d3e47edf4a' - -from alembic import op -from sqlalchemy import sql, text -from sqlalchemy.types import Integer - -recording_table = sql.table('recording', - sql.column('cid'), - sql.column('start_time'), - sql.column('end_time'), - sql.column('caller'), - sql.column('client_id'), - sql.column('callee'), - sql.column('filename'), - sql.column('campaign_id'), - sql.column('agent_id')) - -campaign_table = sql.table('record_campaign', - sql.column('id'), - sql.column('campaign_name'), - sql.column('activated'), - sql.column('base_filename'), - sql.column('queue_id'), - sql.column('start_date'), - sql.column('end_date')) - -tables = {'recording': recording_table, 'record_campaign': campaign_table} - - -def upgrade(): - _conditionnal_drop_table('recording') - _conditionnal_drop_table('record_campaign') - - -def downgrade(): - pass - - -def _conditionnal_drop_table(table_name): - if _table_exists_empty(table_name): - op.drop_table(table_name) - - -def _table_exists_empty(table_name): - if _table_does_not_exist(table_name): - return False - return 0 == op.get_bind().execute(sql.select([sql.func.count()]).select_from(tables[table_name])).scalar() - - -def _table_does_not_exist(table_name): - t = text("select count(*) from pg_class where relname=:table and relkind='r';").\ - bindparams(table=table_name).\ - columns(count=Integer) - - for record in op.get_bind().execute(t): - count = record[0] - return (count == 0) diff --git a/alembic/versions/51ebe7954da8_meeting_persistent_column.py b/alembic/versions/51ebe7954da8_meeting_persistent_column.py deleted file mode 100644 index 4e48d9a7..00000000 --- a/alembic/versions/51ebe7954da8_meeting_persistent_column.py +++ /dev/null @@ -1,26 +0,0 @@ -"""meeting persistent column - -Revision ID: 51ebe7954da8 -Revises: ce76c220eaab - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '51ebe7954da8' -down_revision = 'ce76c220eaab' - - -TABLE_NAME = 'meeting' -COLUMN_NAME = 'persistent' - - -def upgrade(): - op.add_column(TABLE_NAME, sa.Column(COLUMN_NAME, sa.Boolean, nullable=False, server_default='false')) - - -def downgrade(): - op.drop_column(TABLE_NAME, COLUMN_NAME) diff --git a/alembic/versions/525b0cc45d2_add_context_to_trunkfeatures.py b/alembic/versions/525b0cc45d2_add_context_to_trunkfeatures.py deleted file mode 100644 index 7a88c440..00000000 --- a/alembic/versions/525b0cc45d2_add_context_to_trunkfeatures.py +++ /dev/null @@ -1,73 +0,0 @@ -"""add_context_to_trunkfeatures - -Revision ID: 525b0cc45d2 -Revises: 3f310bfa7f9a - -""" - -# revision identifiers, used by Alembic. -revision = '525b0cc45d2' -down_revision = '3f310bfa7f9a' - -from alembic import op -import sqlalchemy as sa - - -trunk_table = sa.sql.table('trunkfeatures', - sa.sql.column('protocol'), - sa.sql.column('protocolid'), - sa.sql.column('context')) - -usersip_table = sa.sql.table('usersip', - sa.sql.column('id'), - sa.sql.column('context')) - -useriax_table = sa.sql.table('useriax', - sa.sql.column('id'), - sa.sql.column('context')) - -usercustom_table = sa.sql.table('usercustom', - sa.sql.column('id'), - sa.sql.column('context')) - - -def upgrade(): - op.alter_column('trunkfeatures', 'protocol', nullable=True) - op.alter_column('trunkfeatures', 'protocolid', nullable=True) - op.add_column('trunkfeatures', sa.Column('context', sa.String(39))) - _populate_context_from_usersip() - _populate_context_from_useriax() - _populate_context_from_usercustom() - - -def _populate_context_from_usersip(): - query = (trunk_table - .update() - .values(context=usersip_table.c.context) - .where(trunk_table.c.protocol == 'sip') - .where(trunk_table.c.protocolid == usersip_table.c.id)) - op.get_bind().execute(query) - - -def _populate_context_from_useriax(): - query = (trunk_table - .update() - .values(context=useriax_table.c.context) - .where(trunk_table.c.protocol == 'iax') - .where(trunk_table.c.protocolid == useriax_table.c.id)) - op.get_bind().execute(query) - - -def _populate_context_from_usercustom(): - query = (trunk_table - .update() - .values(context=usercustom_table.c.context) - .where(trunk_table.c.protocol == 'custom') - .where(trunk_table.c.protocolid == usercustom_table.c.id)) - op.get_bind().execute(query) - - -def downgrade(): - op.drop_column('trunkfeatures', 'context') - op.alter_column('trunkfeatures', 'protocolid', nullable=False) - op.alter_column('trunkfeatures', 'protocol', nullable=False) diff --git a/alembic/versions/5270d317f8fd_add_ldapfilter_directories.py b/alembic/versions/5270d317f8fd_add_ldapfilter_directories.py deleted file mode 100644 index afc70686..00000000 --- a/alembic/versions/5270d317f8fd_add_ldapfilter_directories.py +++ /dev/null @@ -1,40 +0,0 @@ -"""add ldapfilter directories - -Revision ID: 5270d317f8fd -Revises: 394edc522e4a - -""" - -# revision identifiers, used by Alembic. -revision = '5270d317f8fd' -down_revision = '394edc522e4a' - -from alembic import op -import sqlalchemy as sa - -ldapfilter_table = sa.sql.table('ldapfilter', - sa.Column('id'), - sa.Column('name')) -directory_table = sa.sql.table('directories', - sa.Column('name'), - sa.Column('dirtype'), - sa.Column('ldapfilter_id'), - sa.Column('description')) - -def list_ldap_filters(): - conn = op.get_bind() - query = sa.sql.select([ldapfilter_table]) - return [{'id': row.id, 'name': row.name} for row in conn.execute(query)] - - -def upgrade(): - ldapfilters = list_ldap_filters() - directories = [{'name': filter['name'], - 'dirtype': 'ldapfilter', - 'ldapfilter_id': filter['id'], - 'description': ''} for filter in ldapfilters] - op.bulk_insert(directory_table, directories) - - -def downgrade(): - op.execute(directory_table.delete().where(directory_table.c.dirtype=='ldapfilter')) diff --git a/alembic/versions/52acaaba550c_bump_version_18_05.py b/alembic/versions/52acaaba550c_bump_version_18_05.py deleted file mode 100644 index fab4f806..00000000 --- a/alembic/versions/52acaaba550c_bump_version_18_05.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_18_05 - -Revision ID: 52acaaba550c -Revises: 4a5a1c3eb52f - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '52acaaba550c' -down_revision = '4a5a1c3eb52f' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='18.05')) - - -def downgrade(): - pass diff --git a/alembic/versions/52b66f888125_bump_version_17_16.py b/alembic/versions/52b66f888125_bump_version_17_16.py deleted file mode 100644 index 969cd662..00000000 --- a/alembic/versions/52b66f888125_bump_version_17_16.py +++ /dev/null @@ -1,22 +0,0 @@ -"""bump_version_17_16 - -Revision ID: 52b66f888125 -Revises: 10bf9a42edee - -""" - -# revision identifiers, used by Alembic. -revision = '52b66f888125' -down_revision = '10bf9a42edee' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='17.16')) - - -def downgrade(): - pass diff --git a/alembic/versions/52bd5977c09d_initial_script.py b/alembic/versions/52bd5977c09d_initial_script.py deleted file mode 100644 index fb4e0c9a..00000000 --- a/alembic/versions/52bd5977c09d_initial_script.py +++ /dev/null @@ -1,21 +0,0 @@ -"""initial script - -Revision ID: 52bd5977c09d -Revises: None - -""" - -# revision identifiers, used by Alembic. -revision = '52bd5977c09d' -down_revision = None - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - pass - - -def downgrade(): - pass diff --git a/alembic/versions/534d6112e879_fix_sound_file_paths.py b/alembic/versions/534d6112e879_fix_sound_file_paths.py deleted file mode 100644 index ebce689c..00000000 --- a/alembic/versions/534d6112e879_fix_sound_file_paths.py +++ /dev/null @@ -1,166 +0,0 @@ -"""fix_sound_file_paths - -Revision ID: 534d6112e879 -Revises: 35a7f7e2dc33 - -""" - -# revision identifiers, used by Alembic. -from alembic import op -from sqlalchemy import sql - -revision = '534d6112e879' -down_revision = '35a7f7e2dc33' - - -schedule = sql.table('schedule', - sql.column('fallback_action'), - sql.column('fallback_actionid')) - -schedule_time = sql.table('schedule_time', - sql.column('action'), - sql.column('actionid')) - -dialaction = sql.table('dialaction', - sql.column('action'), - sql.column('actionarg1')) - - -def upgrade(): - fix_queues() - fix_schedules() - fix_dialactions() - - -def fix_queues(): - query = """ - UPDATE - queue - SET - "announce" = replace("announce", 'pf-xivo', 'xivo'), - "periodic-announce" = replace("periodic-announce", 'pf-xivo', 'xivo'), - "queue-youarenext" = replace("queue-youarenext", 'pf-xivo', 'xivo'), - "queue-thereare" = replace("queue-thereare", 'pf-xivo', 'xivo'), - "queue-callswaiting" = replace("queue-callswaiting", 'pf-xivo', 'xivo'), - "queue-holdtime" = replace("queue-holdtime", 'pf-xivo', 'xivo'), - "queue-minutes" = replace("queue-minutes", 'pf-xivo', 'xivo'), - "queue-seconds" = replace("queue-seconds", 'pf-xivo', 'xivo'), - "queue-thankyou" = replace("queue-thankyou", 'pf-xivo', 'xivo'), - "queue-reporthold" = replace("queue-reporthold", 'pf-xivo', 'xivo') - WHERE - announce LIKE '%pf-xivo%' - OR "periodic-announce" LIKE '%pf-xivo%' - OR "queue-youarenext" LIKE '%pf-xivo%' - OR "queue-thereare" LIKE '%pf-xivo%' - OR "queue-callswaiting" LIKE '%pf-xivo%' - OR "queue-holdtime" LIKE '%pf-xivo%' - OR "queue-minutes" LIKE '%pf-xivo%' - OR "queue-seconds" LIKE '%pf-xivo%' - OR "queue-thankyou" LIKE '%pf-xivo%' - OR "queue-reporthold" LIKE '%pf-xivo%' - """ - - op.execute(query) - - -def fix_schedules(): - schedule_query = (schedule.update() - .where( - sql.and_(schedule.c.fallback_action == 'sound', - schedule.c.fallback_actionid.like('%pf-xivo%'))) - .values(fallback_actionid=sql.func.replace(schedule.c.fallback_actionid, - 'pf-xivo', - 'xivo'))) - - schedule_time_query = (schedule_time.update() - .where( - sql.and_(schedule_time.c.action == 'sound', - schedule_time.c.actionid.like('%pf-xivo%'))) - .values(actionid=sql.func.replace(schedule_time.c.actionid, - 'pf-xivo', - 'xivo'))) - - op.execute(schedule_query) - op.execute(schedule_time_query) - - -def fix_dialactions(): - query = (dialaction.update() - .where( - sql.and_(dialaction.c.action == 'sound', - dialaction.c.actionarg1.like('%pf-xivo%'))) - .values(actionarg1=sql.func.replace(dialaction.c.actionarg1, - 'pf-xivo', - 'xivo'))) - - op.execute(query) - - -def downgrade(): - unfix_queues() - unfix_schedules() - unfix_dialactions() - - -def unfix_queues(): - query = """ - UPDATE - queue - SET - "announce" = replace("announce", '/xivo/', '/pf-xivo/'), - "periodic-announce" = replace("periodic-announce", '/xivo/', '/pf-xivo/'), - "queue-youarenext" = replace("queue-youarenext", '/xivo/', '/pf-xivo/'), - "queue-thereare" = replace("queue-thereare", '/xivo/', '/pf-xivo/'), - "queue-callswaiting" = replace("queue-callswaiting", '/xivo/', '/pf-xivo/'), - "queue-holdtime" = replace("queue-holdtime", '/xivo/', '/pf-xivo/'), - "queue-minutes" = replace("queue-minutes", '/xivo/', '/pf-xivo/'), - "queue-seconds" = replace("queue-seconds", '/xivo/', '/pf-xivo/'), - "queue-thankyou" = replace("queue-thankyou", '/xivo/', '/pf-xivo/'), - "queue-reporthold" = replace("queue-reporthold", '/xivo/', '/pf-xivo/') - WHERE - "announce" LIKE '%/xivo/%' - OR "periodic-announce" LIKE '%/xivo/%' - OR "queue-youarenext" LIKE '%/xivo/%' - OR "queue-thereare" LIKE '%/xivo/%' - OR "queue-callswaiting" LIKE '%/xivo/%' - OR "queue-holdtime" LIKE '%/xivo/%' - OR "queue-minutes" LIKE '%/xivo/%' - OR "queue-seconds" LIKE '%/xivo/%' - OR "queue-thankyou" LIKE '%/xivo/%' - OR "queue-reporthold" LIKE '%/xivo/%' - """ - - op.execute(query) - - -def unfix_schedules(): - schedule_query = (schedule.update() - .where( - sql.and_(schedule.c.fallback_action == 'sound', - schedule.c.fallback_actionid.like('%/xivo/%'))) - .values(fallback_actionid=sql.func.replace(schedule.c.fallback_actionid, - '/xivo/', - '/pf-xivo/'))) - - schedule_time_query = (schedule_time.update() - .where( - sql.and_(schedule_time.c.action == 'sound', - schedule_time.c.actionid.like('%/xivo/%'))) - .values(actionid=sql.func.replace(schedule_time.c.actionid, - '/xivo/', - '/pf-xivo/'))) - - op.execute(schedule_query) - op.execute(schedule_time_query) - - -def unfix_dialactions(): - query = (dialaction.update() - .where( - sql.and_(dialaction.c.action == 'sound', - dialaction.c.actionarg1.like('%/xivo/%'))) - .values(actionarg1=sql.func.replace(dialaction.c.actionarg1, - '/xivo/', - '/pf-xivo/'))) - - op.execute(query) diff --git a/alembic/versions/537774d3845a_add_email_field_in_phonebook.py b/alembic/versions/537774d3845a_add_email_field_in_phonebook.py deleted file mode 100644 index 2d4c6b7b..00000000 --- a/alembic/versions/537774d3845a_add_email_field_in_phonebook.py +++ /dev/null @@ -1,60 +0,0 @@ -"""add_email_field_in_phonebook - -Revision ID: 537774d3845a -Revises: 498f0570ffef - -""" - -# revision identifiers, used by Alembic. -revision = '537774d3845a' -down_revision = '498f0570ffef' - -from alembic import op -from sqlalchemy import sql, and_ - - -directories = sql.table('ctidirectories', - sql.column('id'), - sql.column('name')) -directory_fields = sql.table('ctidirectoryfields', - sql.column('dir_id'), - sql.column('fieldname'), - sql.column('value')) - - -def upgrade(): - _add_directory_field('xivodir', 'email', '{phonebook.email}') - - -def _add_directory_field(directory_name, field_name, value): - directory_id = _get_directory_id(directory_name) - if not directory_id: - return - - if not _have_directory_field(directory_id, field_name): - _insert_directory_field(directory_id, field_name, value) - - -def _get_directory_id(directory_name): - row = op.get_bind().execute(sql.select([directories.c.id]) - .where(directories.c.name == directory_name)).first() - return row.id if row else None - - -def _have_directory_field(directory_id, field_name): - row = op.get_bind().execute(sql.select([directory_fields.c.dir_id]) - .where(and_(directory_fields.c.dir_id == directory_id, - directory_fields.c.fieldname == field_name))).first() - return bool(row) - - -def _insert_directory_field(directory_id, field_name, value): - op.execute(directory_fields - .insert() - .values(dir_id=directory_id, - fieldname=field_name, - value=value)) - - -def downgrade(): - pass diff --git a/alembic/versions/5381b673cf2c_add_ignore_forward_columns.py b/alembic/versions/5381b673cf2c_add_ignore_forward_columns.py deleted file mode 100644 index 5bd03aa3..00000000 --- a/alembic/versions/5381b673cf2c_add_ignore_forward_columns.py +++ /dev/null @@ -1,30 +0,0 @@ -"""add ignore_forward columns - -Revision ID: 5381b673cf2c -Revises: 2d0b0356eb76 - -""" - -# revision identifiers, used by Alembic. -revision = '5381b673cf2c' -down_revision = '2d0b0356eb76' - -from alembic import op -from sqlalchemy import Column, Integer - -TABLE_NAMES = ['groupfeatures', 'queuefeatures'] -COLUMN_NAME = 'ignore_forward' - - -def upgrade(): - for table_name in TABLE_NAMES: - # on upgrade, existing queues and groups will have "ignore_forward" set to 0 (so the - # queue/group behaviour doesn't change on upgrade), but newly created queues will have by - # default "ignore_forward" set to 1 - op.add_column(table_name, Column(COLUMN_NAME, Integer, nullable=False, server_default='0')) - op.alter_column(table_name, COLUMN_NAME, server_default='1') - - -def downgrade(): - for table_name in TABLE_NAMES: - op.drop_column(table_name, COLUMN_NAME) diff --git a/alembic/versions/53ad771ac875_bump_version_21_02.py b/alembic/versions/53ad771ac875_bump_version_21_02.py deleted file mode 100644 index 2b16e3ca..00000000 --- a/alembic/versions/53ad771ac875_bump_version_21_02.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_21_02 - -Revision ID: 53ad771ac875 -Revises: a10db8de6372 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '53ad771ac875' -down_revision = 'a10db8de6372' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='21.02')) - - -def downgrade(): - pass diff --git a/alembic/versions/53ce4ff6ffe9_add_stat_switchboard_queue_table.py b/alembic/versions/53ce4ff6ffe9_add_stat_switchboard_queue_table.py deleted file mode 100644 index 6c87882c..00000000 --- a/alembic/versions/53ce4ff6ffe9_add_stat_switchboard_queue_table.py +++ /dev/null @@ -1,42 +0,0 @@ -"""add stat_switchboard_queue table - -Revision ID: 53ce4ff6ffe9 -Revises: 4123465e114e - -""" - -# revision identifiers, used by Alembic. -revision = '53ce4ff6ffe9' -down_revision = '4123465e114e' - -from alembic import op -import sqlalchemy as sa - - -stat_switchboard_endtype = sa.Enum( - 'abandoned', - 'completed', - 'forwarded', - 'transferred', - name='stat_switchboard_endtype', -) - - -def upgrade(): - op.create_table( - 'stat_switchboard_queue', - sa.Column('id', sa.Integer, nullable=False), - sa.Column('time', sa.DateTime, nullable=False), - sa.Column('end_type', stat_switchboard_endtype, nullable=False), - sa.Column('wait_time', sa.Float, nullable=False), - sa.Column('queue_id', sa.Integer, nullable=False), - sa.PrimaryKeyConstraint('id'), - sa.ForeignKeyConstraint(('queue_id',), ('queuefeatures.id',), ondelete='CASCADE'), - sa.Index('stat_switchboard_queue__idx__queue_id', 'queue_id'), - sa.Index('stat_switchboard_queue__idx__time', 'time'), - ) - - -def downgrade(): - op.drop_table('stat_switchboard_queue') - stat_switchboard_endtype.drop(op.get_bind()) diff --git a/alembic/versions/53e449192523_add_user_email.py b/alembic/versions/53e449192523_add_user_email.py deleted file mode 100644 index 29d91aa3..00000000 --- a/alembic/versions/53e449192523_add_user_email.py +++ /dev/null @@ -1,22 +0,0 @@ -"""add_user_email - -Revision ID: 53e449192523 -Revises: 267d8bd31d11 - -""" - -# revision identifiers, used by Alembic. -revision = '53e449192523' -down_revision = '267d8bd31d11' - -from alembic import op -from sqlalchemy import (Column, - String) - - -def upgrade(): - op.add_column('userfeatures', Column('email', String(128))) - - -def downgrade(): - op.drop_column('userfeatures', 'email') diff --git a/alembic/versions/53fbfa53b47c_add_user_uuid.py b/alembic/versions/53fbfa53b47c_add_user_uuid.py deleted file mode 100644 index 523584ea..00000000 --- a/alembic/versions/53fbfa53b47c_add_user_uuid.py +++ /dev/null @@ -1,33 +0,0 @@ -"""add user UUID - -Revision ID: 53fbfa53b47c -Revises: e66504d94e2e - -""" - -# revision identifiers, used by Alembic. -revision = '53fbfa53b47c' -down_revision = 'e66504d94e2e' - -from alembic import op -import sqlalchemy as sa - -table_name = 'user' -column_name = 'uuid' -constraint_name = '{}_{}_key'.format(table_name, column_name) - - -def upgrade(): - op.add_column( - table_name, - sa.Column( - column_name, - sa.String(38), - nullable=False, - server_default=sa.text('uuid_generate_v4()'))) - op.create_unique_constraint(constraint_name, table_name, [column_name]) - - -def downgrade(): - op.drop_constraint(constraint_name, table_name) - op.drop_column(table_name, column_name) diff --git a/alembic/versions/544f8b1e6905_remove_dialaction_n_plus_101_option.py b/alembic/versions/544f8b1e6905_remove_dialaction_n_plus_101_option.py deleted file mode 100644 index 2365c72e..00000000 --- a/alembic/versions/544f8b1e6905_remove_dialaction_n_plus_101_option.py +++ /dev/null @@ -1,59 +0,0 @@ -"""remove dialaction n plus 101 option - -Revision ID: 544f8b1e6905 -Revises: 4977a626c01 - -""" - -# revision identifiers, used by Alembic. -revision = '544f8b1e6905' -down_revision = '4977a626c01' - -from alembic import op -from sqlalchemy import sql - - -dialaction = sql.table('dialaction', - sql.column('action'), - sql.column('actionarg2')) - -schedule = sql.table('schedule', - sql.column('fallback_action'), - sql.column('fallback_actionargs')) - -schedule_time = sql.table('schedule_time', - sql.column('action'), - sql.column('actionargs')) - -ACTIONS = ['sound', 'voicemail'] - - -def upgrade(): - fix_dialactions() - fix_schedules() - - -def fix_dialactions(): - op.execute(dialaction.update() - .where( - sql.and_(dialaction.c.action.in_(ACTIONS), - dialaction.c.actionarg2 != None)) # noqa - .values(actionarg2=sql.func.nullif(sql.func.replace(dialaction.c.actionarg2, 'j', ''), ''))) - - -def fix_schedules(): - op.execute(schedule.update() - .where( - sql.and_(schedule.c.fallback_action.in_(ACTIONS), - schedule.c.fallback_actionargs != None)) # noqa - .values(fallback_actionargs=sql.func.replace(schedule.c.fallback_actionargs, 'j;', ''))) - - op.execute(schedule_time.update() - .where( - sql.and_(schedule_time.c.action.in_(ACTIONS), - schedule_time.c.actionargs != None)) # noqa - .values(actionargs=sql.func.nullif(sql.func.replace(schedule_time.c.actionargs, 'j;', ''), ''))) - - -def downgrade(): - pass diff --git a/alembic/versions/5450dd40916e_add_call_completion.py b/alembic/versions/5450dd40916e_add_call_completion.py deleted file mode 100644 index 4360c475..00000000 --- a/alembic/versions/5450dd40916e_add_call_completion.py +++ /dev/null @@ -1,56 +0,0 @@ -"""add call completion - -Revision ID: 5450dd40916e -Revises: dd0c465315d - -""" - -# revision identifiers, used by Alembic. -revision = '5450dd40916e' -down_revision = 'dd0c465315d' - -from alembic import op -import sqlalchemy as sa - - -extensions_table = sa.sql.table( - 'extensions', - sa.sql.column('commented'), - sa.sql.column('context'), - sa.sql.column('exten'), - sa.sql.column('type'), - sa.sql.column('typeval'), -) - - -def upgrade(): - _insert_cc_extension() - - -def _insert_cc_extension(): - connection = op.get_bind() - qry = 'SELECT exten, context FROM extensions WHERE context=\'xivo-features\' and exten=\'*40\'' - res = connection.execute(qry).fetchall() - if res: - exten = 'cctoggle' - else: - exten = '*40' - - op.bulk_insert(extensions_table, [{'commented': 1, - 'context': 'xivo-features', - 'exten': exten, - 'type': 'extenfeatures', - 'typeval': 'cctoggle'}]) - - -def downgrade(): - _delete_cc_extension() - - -def _delete_cc_extension(): - op.execute(extensions_table - .delete() - .where(sa.sql.and_( - extensions_table.c.type == 'extenfeatures', - extensions_table.c.typeval == 'cctoggle', - ))) diff --git a/alembic/versions/5497199c082f_add_queue_id_to_stat_queue.py b/alembic/versions/5497199c082f_add_queue_id_to_stat_queue.py deleted file mode 100644 index 6d7188b4..00000000 --- a/alembic/versions/5497199c082f_add_queue_id_to_stat_queue.py +++ /dev/null @@ -1,165 +0,0 @@ -"""add-queue-id-to-stat-queue - -Revision ID: 5497199c082f -Revises: de624f81421f - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '5497199c082f' -down_revision = 'de624f81421f' - - -stat_queue_table = sa.sql.table( - 'stat_queue', - sa.sql.column('id'), - sa.sql.column('name'), - sa.sql.column('queue_id'), -) -queuefeatures_table = sa.sql.table( - 'queuefeatures', - sa.sql.column('id'), - sa.sql.column('name'), -) - -stat_agent_table = sa.sql.table( - 'stat_agent', - sa.sql.column('id'), - sa.sql.column('name'), - sa.sql.column('agent_id'), -) -agentfeatures_table = sa.sql.table( - 'agentfeatures', - sa.sql.column('id'), - sa.sql.column('number'), -) - - -def _add_queue_id_to_queues(): - query = ( - stat_queue_table - .update() - .values(queue_id=queuefeatures_table.c.id) - .where(stat_queue_table.c.name == queuefeatures_table.c.name) - ) - op.execute(query) - - -def _add_agent_id_to_agents(): - query = ( - stat_agent_table - .update() - .values(agent_id=agentfeatures_table.c.id) - .where(stat_agent_table.c.name == sa.func.concat('Agent/', agentfeatures_table.c.number)) - ) - op.execute(query) - - -def rename_column_fk(table, old_name, new_name, ref_table): - old_fk_name = f'{table}_{old_name}_fkey' - new_fk_name = f'{table}_{new_name}_fkey' - op.alter_column(table, old_name, new_column_name=new_name) - op.drop_constraint( - constraint_name=old_fk_name, - table_name=table, - type_='foreignkey', - ) - op.create_foreign_key( - constraint_name=new_fk_name, - source_table=table, - referent_table=ref_table, - local_cols=[new_name], - remote_cols=['id'], - ) - - -def upgrade(): - op.add_column( - 'stat_queue', - sa.Column( - 'queue_id', - sa.Integer, - nullable=True), - ) - _add_queue_id_to_queues() - - op.add_column( - 'stat_agent', - sa.Column( - 'agent_id', - sa.Integer, - nullable=True), - ) - _add_agent_id_to_agents() - rename_column_fk('stat_queue_periodic', 'queue_id', 'stat_queue_id', 'stat_queue') - rename_column_fk('stat_call_on_queue', 'queue_id', 'stat_queue_id', 'stat_queue') - rename_column_fk('stat_agent_periodic', 'agent_id', 'stat_agent_id', 'stat_agent') - rename_column_fk('stat_call_on_queue', 'agent_id', 'stat_agent_id', 'stat_agent') - op.execute('DROP FUNCTION IF EXISTS "fill_simple_calls" (text, text);') - op.execute(""" -CREATE FUNCTION "fill_simple_calls"(period_start text, period_end text) - RETURNS void AS -$$ - INSERT INTO "stat_call_on_queue" (callid, "time", stat_queue_id, status) - SELECT - callid, - CAST ("time" AS TIMESTAMP) as "time", - (SELECT id FROM stat_queue WHERE name=queuename) as stat_queue_id, - CASE WHEN event = 'FULL' THEN 'full'::call_exit_type - WHEN event = 'DIVERT_CA_RATIO' THEN 'divert_ca_ratio' - WHEN event = 'DIVERT_HOLDTIME' THEN 'divert_waittime' - WHEN event = 'CLOSED' THEN 'closed' - WHEN event = 'JOINEMPTY' THEN 'joinempty' - END as status - FROM queue_log - WHERE event IN ('FULL', 'DIVERT_CA_RATIO', 'DIVERT_HOLDTIME', 'CLOSED', 'JOINEMPTY') AND - "time" BETWEEN $1 AND $2; -$$ -LANGUAGE SQL; - """) - op.execute('DROP FUNCTION IF EXISTS "fill_leaveempty_calls" (text, text);') - op.execute(""" -CREATE OR REPLACE FUNCTION "fill_leaveempty_calls" (period_start text, period_end text) - RETURNS void AS -$$ -INSERT INTO stat_call_on_queue (callid, time, waittime, stat_queue_id, status) -SELECT - callid, - enter_time as time, - EXTRACT(EPOCH FROM (leave_time - enter_time))::INTEGER as waittime, - stat_queue_id, - 'leaveempty' AS status -FROM (SELECT - CAST (time AS TIMESTAMP) AS enter_time, - (select CAST (time AS TIMESTAMP) from queue_log where callid=main.callid AND event='LEAVEEMPTY' LIMIT 1) AS leave_time, - callid, - (SELECT id FROM stat_queue WHERE name=queuename) AS stat_queue_id - FROM queue_log AS main - WHERE callid IN (SELECT callid FROM queue_log WHERE event = 'LEAVEEMPTY') - AND event = 'ENTERQUEUE' - AND time BETWEEN $1 AND $2) AS first; -$$ -LANGUAGE SQL; - """) - op.drop_index( - index_name='stat_agent_periodic__idx__agent_id', - table_name='stat_agent_periodic', - ) - op.create_index( - index_name='stat_agent_periodic__idx__stat_agent_id', - table_name='stat_agent_periodic', - columns=['stat_agent_id'], - ) - - -def downgrade(): - rename_column_fk('stat_queue_periodic', 'stat_queue_id', 'queue_id', 'stat_queue') - rename_column_fk('stat_call_on_queue', 'stat_queue_id', 'queue_id', 'stat_queue') - rename_column_fk('stat_agent_periodic', 'stat_agent_id', 'agent_id', 'stat_agent') - rename_column_fk('stat_call_on_queue', 'stat_agent_id', 'agent_id', 'stat_agent') - op.drop_column('stat_queue', 'queue_id') - op.drop_column('stat_agent', 'agent_id') diff --git a/alembic/versions/549c621ae619_update_musiconhold_random.py b/alembic/versions/549c621ae619_update_musiconhold_random.py deleted file mode 100644 index faf152a2..00000000 --- a/alembic/versions/549c621ae619_update_musiconhold_random.py +++ /dev/null @@ -1,33 +0,0 @@ -"""update musiconhold random - -Revision ID: 549c621ae619 -Revises: 544f8b1e6905 - -""" - -# revision identifiers, used by Alembic. -revision = '549c621ae619' -down_revision = '544f8b1e6905' - -from alembic import op -from sqlalchemy import sql - -musiconhold = sql.table('musiconhold', - sql.column('var_name'), - sql.column('var_val')) - - -def upgrade(): - op.execute(musiconhold.update() - .where(musiconhold.c.var_name == 'random') - .values( - var_name='sort', - var_val=sql.case([(musiconhold.c.var_val == 'yes', 'random')]))) - - -def downgrade(): - op.execute(musiconhold.update() - .where(musiconhold.c.var_name == 'sort') - .values( - var_name='random', - var_val=sql.case([(musiconhold.c.var_val == 'random', 'yes')], else_='no'))) diff --git a/alembic/versions/5524f5f02959_remove_ctis.py b/alembic/versions/5524f5f02959_remove_ctis.py deleted file mode 100644 index 56c5760a..00000000 --- a/alembic/versions/5524f5f02959_remove_ctis.py +++ /dev/null @@ -1,22 +0,0 @@ -"""remove ctis - -Revision ID: 5524f5f02959 -Revises: 1d4b487e4d1f - -""" - -# revision identifiers, used by Alembic. -revision = '5524f5f02959' -down_revision = '1d4b487e4d1f' - -from alembic import op - - -def upgrade(): - op.drop_column('ctimain', 'commandset') - op.drop_column('ctimain', 'ctis_port') - op.drop_column('ctimain', 'ctis_ip') - - -def downgrade(): - pass diff --git a/alembic/versions/55527c5cb4b1_bump_version_20_03.py b/alembic/versions/55527c5cb4b1_bump_version_20_03.py deleted file mode 100644 index 707345a7..00000000 --- a/alembic/versions/55527c5cb4b1_bump_version_20_03.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_20_03 - -Revision ID: 55527c5cb4b1 -Revises: 4722bbe519b1 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '55527c5cb4b1' -down_revision = '4722bbe519b1' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='20.03')) - - -def downgrade(): - pass diff --git a/alembic/versions/5576b5f933e6_queue_log_change_the_type_of_agent_to_.py b/alembic/versions/5576b5f933e6_queue_log_change_the_type_of_agent_to_.py deleted file mode 100644 index 65f573b0..00000000 --- a/alembic/versions/5576b5f933e6_queue_log_change_the_type_of_agent_to_.py +++ /dev/null @@ -1,22 +0,0 @@ -"""queue_log: change the type of agent to text - -Revision ID: 5576b5f933e6 -Revises: 28721fe085d3 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '5576b5f933e6' -down_revision = '28721fe085d3' - - -def upgrade(): - op.alter_column('queue_log', 'agent', nullable=False, server_default='', type_=sa.Text) - - -def downgrade(): - op.alter_column('queue_log', 'agent', nullable=False, server_default='', type_=sa.String(50)) diff --git a/alembic/versions/55cd08a0dae2_bump_version_to_22_01.py b/alembic/versions/55cd08a0dae2_bump_version_to_22_01.py deleted file mode 100644 index 0a9c0932..00000000 --- a/alembic/versions/55cd08a0dae2_bump_version_to_22_01.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump version to 22.01 - -Revision ID: 55cd08a0dae2 -Revises: c04ed3f6a685 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '55cd08a0dae2' -down_revision = 'c04ed3f6a685' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='22.01')) - - -def downgrade(): - pass diff --git a/alembic/versions/55f3c86885c5_create_func_key_destination_service.py b/alembic/versions/55f3c86885c5_create_func_key_destination_service.py deleted file mode 100644 index bc892015..00000000 --- a/alembic/versions/55f3c86885c5_create_func_key_destination_service.py +++ /dev/null @@ -1,49 +0,0 @@ -"""create_func_key_destination_service - -Revision ID: 55f3c86885c5 -Revises: b6bb28f27f2 - -""" - -# revision identifiers, used by Alembic. -revision = '55f3c86885c5' -down_revision = 'b6bb28f27f2' - -from alembic import op -import sqlalchemy as sa - - -SERVICE_TYPE_ID = 5 -SERVICE_TYPE_NAME = 'service' - -destination_type_table = sa.sql.table('func_key_destination_type', - sa.sql.column('id'), - sa.sql.column('name')) - - -def upgrade(): - service_type_row = {'id': SERVICE_TYPE_ID, 'name': SERVICE_TYPE_NAME} - op.bulk_insert(destination_type_table, [service_type_row]) - - op.create_table( - 'func_key_dest_service', - sa.Column('func_key_id', sa.Integer), - sa.Column('destination_type_id', - sa.Integer, - sa.CheckConstraint('destination_type_id = %d' % SERVICE_TYPE_ID), - server_default=str(SERVICE_TYPE_ID)), - sa.Column('extension_id', sa.Integer), - sa.PrimaryKeyConstraint('func_key_id', 'destination_type_id', 'extension_id'), - sa.ForeignKeyConstraint(['func_key_id', 'destination_type_id'], - ['func_key.id', 'func_key.destination_type_id']), - sa.ForeignKeyConstraint(['extension_id'], ['extensions.id']) - ) - - -def downgrade(): - op.drop_table('func_key_dest_service') - - delete_query = (destination_type_table - .delete() - .where(destination_type_table.c.id == SERVICE_TYPE_ID)) - op.execute(delete_query) diff --git a/alembic/versions/55f7b6c13454_populate_confbridge_configuration.py b/alembic/versions/55f7b6c13454_populate_confbridge_configuration.py deleted file mode 100644 index 968a8902..00000000 --- a/alembic/versions/55f7b6c13454_populate_confbridge_configuration.py +++ /dev/null @@ -1,73 +0,0 @@ -"""populate-confbridge-configuration - -Revision ID: 55f7b6c13454 -Revises: 488e5a3d75 - -""" - -# revision identifiers, used by Alembic. -revision = '55f7b6c13454' -down_revision = '488e5a3d75' - -from alembic import op -import sqlalchemy as sa - -asterisk_file_table = sa.sql.table('asterisk_file', - sa.sql.column('id'), - sa.sql.column('name')) - -asterisk_file_section_table = sa.sql.table('asterisk_file_section', - sa.sql.column('id'), - sa.sql.column('name'), - sa.sql.column('priority'), - sa.sql.column('asterisk_file_id')) - -asterisk_file_variable_table = sa.sql.table('asterisk_file_variable', - sa.sql.column('id'), - sa.sql.column('key'), - sa.sql.column('value'), - sa.sql.column('priority'), - sa.sql.column('asterisk_file_section_id')) - - -def upgrade(): - file_id = _insert_asterisk_file('confbridge.conf') - _insert_asterisk_file_section(file_id, 'general', priority=0) - _insert_asterisk_file_section(file_id, 'default_bridge') - - section_id = _insert_asterisk_file_section(file_id, 'default_user') - _insert_asterisk_file_variable(section_id, 'dsp_drop_silence', 'yes') - - -def _insert_asterisk_file(name): - query = (asterisk_file_table - .insert() - .returning(asterisk_file_table.c.id) - .values(name=name)) - - return op.get_bind().execute(query).scalar() - - -def _insert_asterisk_file_section(file_id, name, priority=None): - query = (asterisk_file_section_table - .insert() - .returning(asterisk_file_section_table.c.id) - .values(name=name, - priority=priority, - asterisk_file_id=file_id)) - - return op.get_bind().execute(query).scalar() - - -def _insert_asterisk_file_variable(section_id, key, value): - query = (asterisk_file_variable_table - .insert() - .values(key=key, - value=value, - asterisk_file_section_id=section_id)) - - op.get_bind().execute(query) - - -def downgrade(): - op.execute(asterisk_file_table.delete().where(asterisk_file_table.c.name == 'confbridge.conf')) diff --git a/alembic/versions/5600ad4c00b4_remove_unused_provisioning_columns.py b/alembic/versions/5600ad4c00b4_remove_unused_provisioning_columns.py deleted file mode 100644 index 7296fc7f..00000000 --- a/alembic/versions/5600ad4c00b4_remove_unused_provisioning_columns.py +++ /dev/null @@ -1,24 +0,0 @@ -"""remove-unused-provisioning-columns - -Revision ID: 5600ad4c00b4 -Revises: d47f295009dd - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '5600ad4c00b4' -down_revision = 'd47f295009dd' - - -def upgrade(): - op.drop_column('provisioning', 'net4_ip_rest') - op.drop_column('provisioning', 'rest_port') - - -def downgrade(): - op.add_column('provisoning', sa.Column('net4_ip_rest', sa.String(39))) - op.add_column('provisoning', sa.Column('rest_port', sa.Integer, nullable=False)) diff --git a/alembic/versions/560bfca6cf85_rename_dhcp_field_extra_iface.py b/alembic/versions/560bfca6cf85_rename_dhcp_field_extra_iface.py deleted file mode 100644 index 708b0fc3..00000000 --- a/alembic/versions/560bfca6cf85_rename_dhcp_field_extra_iface.py +++ /dev/null @@ -1,21 +0,0 @@ -"""rename dhcp field extra_iface - -Revision ID: 560bfca6cf85 -Revises: 62c5befaa8cf - -""" - -from alembic import op - - -# revision identifiers, used by Alembic. -revision = '560bfca6cf85' -down_revision = '62c5befaa8cf' - - -def upgrade(): - op.alter_column('dhcp', 'extra_ifaces', new_column_name='network_interfaces') - - -def downgrade(): - op.alter_column('dhcp', 'network_interfaces', new_column_name='extra_ifaces') diff --git a/alembic/versions/564d634619bc_add_dnd_acl_to_ctid.py b/alembic/versions/564d634619bc_add_dnd_acl_to_ctid.py deleted file mode 100644 index 375c0811..00000000 --- a/alembic/versions/564d634619bc_add_dnd_acl_to_ctid.py +++ /dev/null @@ -1,47 +0,0 @@ -"""add dnd acl to ctid - -Revision ID: 564d634619bc -Revises: 5381b673cf2c - -""" - -# revision identifiers, used by Alembic. -revision = '564d634619bc' -down_revision = '5381b673cf2c' - -from alembic import op -from sqlalchemy import sql - - -webservice = sql.table('accesswebservice', - sql.column('name'), - sql.column('acl')) - -SERVICE = 'xivo-ctid' -NEW_ACL = set(['confd.users.*.services.dnd.update']) - - -def _get_current_acl(name): - return set(op.get_bind().execute( - sql.select([webservice.c.acl]).where(webservice.c.name == name) - ).scalar()) - - -def _update_web_service_acl(name, acl): - op.execute(webservice - .update() - .where( - webservice.c.name == name - ).values(acl=list(acl))) - - -def upgrade(): - current_acls = _get_current_acl(SERVICE) - new_acls = current_acls | NEW_ACL - _update_web_service_acl(SERVICE, new_acls) - - -def downgrade(): - current_acls = _get_current_acl(SERVICE) - new_acls = current_acls - NEW_ACL - _update_web_service_acl(SERVICE, new_acls) diff --git a/alembic/versions/56a75d478edc_remove_staticsip_table.py b/alembic/versions/56a75d478edc_remove_staticsip_table.py deleted file mode 100644 index 76fe3e3d..00000000 --- a/alembic/versions/56a75d478edc_remove_staticsip_table.py +++ /dev/null @@ -1,35 +0,0 @@ -"""remove_staticsip_table - -Revision ID: 56a75d478edc -Revises: 06e9e3483fec - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '56a75d478edc' -down_revision = '06e9e3483fec' - - -def upgrade(): - op.drop_table('staticsip') - - -def downgrade(): - op.create_table( - 'staticsip', - sa.Column('id', sa.Integer, nullable=False, primary_key=True), - sa.Column('cat_metric', sa.Integer, - nullable=False, server_default='0'), - sa.Column('var_metric', sa.Integer, - nullable=False, server_default='0'), - sa.Column('commented', sa.Integer, nullable=False, server_default='0'), - sa.Column('filename', sa.String(128), nullable=False), - sa.Column('category', sa.String(128), nullable=False), - sa.Column('var_name', sa.String(128), nullable=False), - sa.Column('var_val', sa.String(255)) - ) - op.create_index('staticsip__idx__category', 'staticsip', ['category']) diff --git a/alembic/versions/56a9a83c26b3_remove_old_phonebook_tables.py b/alembic/versions/56a9a83c26b3_remove_old_phonebook_tables.py deleted file mode 100644 index e92790ef..00000000 --- a/alembic/versions/56a9a83c26b3_remove_old_phonebook_tables.py +++ /dev/null @@ -1,23 +0,0 @@ -"""remove old phonebook tables - -Revision ID: 56a9a83c26b3 -Revises: 21d45c24210e - -""" - -# revision identifiers, used by Alembic. -revision = '56a9a83c26b3' -down_revision = '21d45c24210e' - -from alembic import op - - -def upgrade(): - op.drop_table('user_contact') - op.drop_table('phonebooknumber') - op.drop_table('phonebookaddress') - op.drop_table('phonebook') - - -def downgrade(): - pass diff --git a/alembic/versions/56a9fce34ae9_link_default_template_to_tenant.py b/alembic/versions/56a9fce34ae9_link_default_template_to_tenant.py deleted file mode 100644 index 70e1e80e..00000000 --- a/alembic/versions/56a9fce34ae9_link_default_template_to_tenant.py +++ /dev/null @@ -1,79 +0,0 @@ -"""link_default_template_to_tenant - -Revision ID: 56a9fce34ae9 -Revises: a28974a2dc19 - -""" - -from alembic import op -import sqlalchemy as sa - -from sqlalchemy.dialects.postgresql import UUID - - -# revision identifiers, used by Alembic. -revision = '56a9fce34ae9' -down_revision = 'a28974a2dc19' - - -def upgrade(): - op.add_column( - 'tenant', - sa.Column('sip_templates_generated', sa.Boolean, nullable=False, server_default='false'), - ) - op.add_column( - 'tenant', - sa.Column( - 'global_sip_template_uuid', - UUID, - sa.ForeignKey( - 'endpoint_sip.uuid', - ondelete='SET NULL', - name='tenant_global_sip_template_uuid_fkey', - ), - ), - ) - op.add_column( - 'tenant', - sa.Column( - 'webrtc_sip_template_uuid', - UUID, - sa.ForeignKey( - 'endpoint_sip.uuid', - ondelete='SET NULL', - name='tenant_webrtc_sip_template_uuid_fkey', - ), - ), - ) - op.add_column( - 'tenant', - sa.Column( - 'global_trunk_sip_template_uuid', - UUID, - sa.ForeignKey( - 'endpoint_sip.uuid', - ondelete='SET NULL', - name='tenant_global_trunk_sip_template_uuid_fkey', - ), - ), - ) - op.add_column( - 'tenant', - sa.Column( - 'twilio_trunk_sip_template_uuid', - UUID, - sa.ForeignKey( - 'endpoint_sip.uuid', - ondelete='SET NULL', - name='tenant_twilio_trunk_sip_template_uuid_fkey', - ), - ), - ) - - -def downgrade(): - op.drop_column('tenant', 'sip_templates_generated') - op.drop_column('tenant', 'global_sip_template_uuid') - op.drop_column('tenant', 'webrtc_sip_template_uuid') - op.drop_column('tenant', 'global_trunk_sip_template_uuid') - op.drop_column('tenant', 'twilio_trunk_sip_template_uuid') diff --git a/alembic/versions/56e683a865e0_add_english_presence_statuses.py b/alembic/versions/56e683a865e0_add_english_presence_statuses.py deleted file mode 100644 index bf0c39bf..00000000 --- a/alembic/versions/56e683a865e0_add_english_presence_statuses.py +++ /dev/null @@ -1,136 +0,0 @@ -"""add english presence statuses - -Revision ID: 56e683a865e0 -Revises: da58e9e49eb - -""" - -# revision identifiers, used by Alembic. -revision = '56e683a865e0' -down_revision = 'da58e9e49eb' - -from alembic import op -from sqlalchemy import and_, sql - -ctipresences_table = sql.table('ctipresences', - sql.column('id'), - sql.column('name'), - sql.column('description'), - sql.column('deletable')) -ctistatus_table = sql.table('ctistatus', - sql.column('id'), - sql.column('presence_id'), - sql.column('name'), - sql.column('display_name'), - sql.column('actions'), - sql.column('color'), - sql.column('access_status'), - sql.column('deletable')) -old, new = 'xivo', 'francais' -english_params = ['english', 'Default english presence statuses'] - -available = ['available', 'Available', 'enablednd(false)', '#9BC920', 0] -away = ['away', 'Away', 'enablednd(false)', '#FFDD00', 1] -outtolunch = ['outtolunch', 'Out to lunch', 'enablednd(false)', '#6CA6FF', 1] -dnd = ['donotdisturb', 'Do not disturb', 'enablednd(true)', '#D13224', 1] -brb = ['berightback', 'Be right back', 'enablednd(false)', '#F2833A', 1] -disconnected = ['disconnected', 'Disconnected', 'agentlogoff()', '#9E9E9E', 0] -english_presences = [ - available, - away, - outtolunch, - dnd, - brb, - disconnected, -] -available_presence_map = { - 'available': ['available', 'away', 'outtolunch', 'donotdisturb', 'berightback'], - 'away': ['available', 'away', 'outtolunch', 'donotdisturb', 'berightback'], - 'outtolunch': ['available', 'away', 'outtolunch', 'donotdisturb', 'berightback'], - 'donotdisturb': ['available', 'away', 'outtolunch', 'donotdisturb', 'berightback'], - 'berightback': ['available', 'away', 'outtolunch', 'donotdisturb', 'berightback'], - 'disconnected': [], -} -fk_name = 'ctistatus_presence_id_fkey' - - -def rename_presences(old, new): - op.execute(ctipresences_table.update().where(ctipresences_table.c.name == old).values(name=new)) - - -def add_presence_group(name, description): - insert_query = (ctipresences_table - .insert() - .returning(ctipresences_table.c.id) - .values(name=name, - description=description, - deletable=0)) - return op.get_bind().execute(insert_query).scalar() - - -def remove_presences(name, description): - op.execute(ctipresences_table.delete().where(and_(ctipresences_table.c.name == name, - ctipresences_table.c.description == description, - ctipresences_table.c.deletable == 0))) - - -def insert_presence(group_id, name, display_name, actions, color, deletable): - insert_query = (ctistatus_table - .insert() - .returning(ctistatus_table.c.id) - .values(presence_id=group_id, - name=name, - display_name=display_name, - actions=actions, - color=color, - deletable=deletable)) - return op.get_bind().execute(insert_query).scalar(), name - - -def update_presence(presence_id, avail_ids): - op.execute(ctistatus_table - .update() - .where(ctistatus_table.c.id == presence_id) - .values(access_status=avail_ids)) - - -def insert_english_presences(group_id, presences): - presence_map = {} - for presence in presences: - id_, name = insert_presence(group_id, *presence) - presence_map[name] = id_ - - for name, availability in available_presence_map.items(): - presence_id = presence_map[name] - avail_ids = ','.join([str(presence_map[avail_name]) for avail_name in availability]) - update_presence(presence_id, avail_ids) - - -def delete_orphaned_statuses(): - presence_ids = set([row['id'] for row in op.get_bind().execute(ctipresences_table.select())]) - op.execute(ctistatus_table.delete().where(~ctistatus_table.c.presence_id.in_(presence_ids))) - - -def add_foreign_key(): - delete_orphaned_statuses() - op.create_foreign_key(fk_name, - 'ctistatus', 'ctipresences', - ['presence_id'], ['id'], - ondelete='CASCADE') - - -def remove_foreign_key(): - op.drop_constraint(fk_name, 'ctistatus') - - -def upgrade(): - add_foreign_key() - rename_presences(old, new) - group_id = add_presence_group(*english_params) - insert_english_presences(group_id, english_presences) - - -def downgrade(): - remove_presences(*english_params) - rename_presences(new, old) - remove_foreign_key() diff --git a/alembic/versions/570d858c41d6_remove_nullable_constraint_queuefeatures.py b/alembic/versions/570d858c41d6_remove_nullable_constraint_queuefeatures.py deleted file mode 100644 index 10941af8..00000000 --- a/alembic/versions/570d858c41d6_remove_nullable_constraint_queuefeatures.py +++ /dev/null @@ -1,20 +0,0 @@ -"""remove_nullable_constraint_queuefeatures - -Revision ID: 570d858c41d6 -Revises: 6a08e32fadba - -""" - -from alembic import op - -# revision identifiers, used by Alembic. -revision = '570d858c41d6' -down_revision = '6a08e32fadba' - - -def upgrade(): - op.alter_column('queuefeatures', 'number', nullable=True, server_default=None) - - -def downgrade(): - op.alter_column('queuefeatures', 'number', nullable=False, server_default='') diff --git a/alembic/versions/5712e7a66baa_create_new_dird_phonebooks_cti_directories.py b/alembic/versions/5712e7a66baa_create_new_dird_phonebooks_cti_directories.py deleted file mode 100644 index c0193b37..00000000 --- a/alembic/versions/5712e7a66baa_create_new_dird_phonebooks_cti_directories.py +++ /dev/null @@ -1,160 +0,0 @@ -"""create new dird phonebooks cti directories - -Revision ID: 5712e7a66baa -Revises: f721d0482a3 - -""" - -# revision identifiers, used by Alembic. -revision = '5712e7a66baa' -down_revision = 'f721d0482a3' - -from alembic import op -from sqlalchemy import and_, sql - - -directories = sql.table('directories', - sql.column('id'), - sql.column('name'), - sql.column('uri'), - sql.column('dirtype'), - sql.column('description')) -entity = sql.table('entity', - sql.column('name'), - sql.column('disable')) -cti_directories = sql.table('ctidirectories', - sql.column('id'), - sql.column('name'), - sql.column('match_direct'), - sql.column('match_reverse'), - sql.column('deletable'), - sql.column('directory_id'), - sql.column('description')) -directory_fields = sql.table('ctidirectoryfields', - sql.column('dir_id'), - sql.column('fieldname'), - sql.column('value')) - - -class DefinitionGenerator(object): - - def __init__(self, entities, current_definitions, directories): - self.entities = entities - self.definitions = current_definitions - self.directories = directories - - def generate(self): - new = [] - for entity in self.entities: - for definition in self.definitions: - new_directory_id = self._find_directory_id(entity, definition.directory_id) - if not new_directory_id: - continue - new.append({'name': '{}-{}'.format(entity, definition.name), - 'match_direct': format_fieldname(definition.match_direct), - 'match_reverse': format_fieldname(definition.match_reverse), - 'deletable': definition.deletable, - 'directory_id': new_directory_id, - 'description': definition.description}) - return new - - def _find_directory_id(self, entity, directory_id): - for directory in self.directories: - if directory.id == directory_id: - expected_name = '{}-{}'.format(entity, directory.name) - for directory in self.directories: - if directory.name == expected_name: - return directory.id - - -class FieldGenerator(object): - - def __init__(self, entities, phonebook_definitions, dird_definitions, directories, fields): - self.entities = entities - self.phonebook_definitions = phonebook_definitions - self.dird_definitions = dird_definitions - self.directories = directories - self.fields = fields - - def generate(self): - new = [] - for phonebook in self.phonebook_definitions: - for dird in self.dird_definitions: - if not dird.name.endswith('-{}'.format(phonebook.name)): - continue - for field in self.fields: - if field.dir_id != phonebook.id: - continue - new.append({'dir_id': dird.id, - 'fieldname': field.fieldname, - 'value': format_fieldname(field.value)}) - return new - - -def format_fieldname(fieldname): - # the fullname field used to be generated by the webi - fieldname = fieldname.replace('{phonebook.fullname}', '{displayname}') - - # {phonebook.firstname} => {firstname} - fieldname = fieldname.replace('phonebook.', '') - - # {phonebooknumber.office.number} => {number_office} - fieldname = fieldname.replace('phonebooknumber.', 'number_') - fieldname = fieldname.replace('.number', '') - - # {phonebookaddress.office.*} => {address_office_*} - fieldname = fieldname.replace('phonebookaddress.', 'address_') - for type_ in ['office', 'home', 'other']: - fieldname = fieldname.replace('address_{}.'.format(type_), - 'address_{}_'.format(type_)) - - return fieldname - - -def upgrade(): - conn = op.get_bind() - - entities = list_entities(conn) - cti_phonebook_directories = list_cti_directories(conn, 'phonebook') - directories = get_directories(conn) - - generator = DefinitionGenerator(entities, cti_phonebook_directories, directories) - op.bulk_insert(cti_directories, generator.generate()) - - cti_dird_phonebook_directories = list_cti_directories(conn, 'dird_phonebook') - fields = list_fields(conn) - - generator = FieldGenerator(entities, - cti_phonebook_directories, - cti_dird_phonebook_directories, - directories, - fields) - - op.bulk_insert(directory_fields, generator.generate()) - - -def downgrade(): - pass - - -def get_directories(conn): - query = sql.select([directories]) - return [d for d in conn.execute(query)] - - -def list_cti_directories(conn, type_): - query = sql.select( - [cti_directories] - ).where(and_(cti_directories.c.directory_id == directories.c.id, - directories.c.dirtype == type_)) - return [directory for directory in conn.execute(query)] - - -def list_entities(conn): - query = sql.select([entity]) - return [e.name for e in conn.execute(query)] - - -def list_fields(conn): - query = sql.select([directory_fields]) - return [f for f in conn.execute(query)] diff --git a/alembic/versions/57461905b7e6_bump_version_17_17.py b/alembic/versions/57461905b7e6_bump_version_17_17.py deleted file mode 100644 index 7804ce08..00000000 --- a/alembic/versions/57461905b7e6_bump_version_17_17.py +++ /dev/null @@ -1,22 +0,0 @@ -"""bump_version_17_17 - -Revision ID: 57461905b7e6 -Revises: 5b427e206bdf - -""" - -# revision identifiers, used by Alembic. -revision = '57461905b7e6' -down_revision = '5b427e206bdf' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='17.17')) - - -def downgrade(): - pass diff --git a/alembic/versions/57a7c7438b98_add_email_field_in_internal.py b/alembic/versions/57a7c7438b98_add_email_field_in_internal.py deleted file mode 100644 index cf374450..00000000 --- a/alembic/versions/57a7c7438b98_add_email_field_in_internal.py +++ /dev/null @@ -1,60 +0,0 @@ -"""add_email_field_in_internal - -Revision ID: 57a7c7438b98 -Revises: 53e449192523 - -""" - -# revision identifiers, used by Alembic. -revision = '57a7c7438b98' -down_revision = '53e449192523' - -from alembic import op -from sqlalchemy import sql, and_ - - -directories = sql.table('ctidirectories', - sql.column('id'), - sql.column('name')) -directory_fields = sql.table('ctidirectoryfields', - sql.column('dir_id'), - sql.column('fieldname'), - sql.column('value')) - - -def upgrade(): - _add_directory_field('internal', 'email', '{email}') - - -def _add_directory_field(directory_name, field_name, value): - directory_id = _get_directory_id(directory_name) - if not directory_id: - return - - if not _have_directory_field(directory_id, field_name): - _insert_directory_field(directory_id, field_name, value) - - -def _get_directory_id(directory_name): - row = op.get_bind().execute(sql.select([directories.c.id]) - .where(directories.c.name == directory_name)).first() - return row.id if row else None - - -def _have_directory_field(directory_id, field_name): - row = op.get_bind().execute(sql.select([directory_fields.c.dir_id]) - .where(and_(directory_fields.c.dir_id == directory_id, - directory_fields.c.fieldname == field_name))).first() - return bool(row) - - -def _insert_directory_field(directory_id, field_name, value): - op.execute(directory_fields - .insert() - .values(dir_id=directory_id, - fieldname=field_name, - value=value)) - - -def downgrade(): - pass diff --git a/alembic/versions/57ab432bb1c3_bump_version_18_10.py b/alembic/versions/57ab432bb1c3_bump_version_18_10.py deleted file mode 100644 index 558ff677..00000000 --- a/alembic/versions/57ab432bb1c3_bump_version_18_10.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_18_10 - -Revision ID: 57ab432bb1c3 -Revises: 235158681deb - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '57ab432bb1c3' -down_revision = '235158681deb' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='18.10')) - - -def downgrade(): - pass diff --git a/alembic/versions/5863384621a1_bump_version_22_03.py b/alembic/versions/5863384621a1_bump_version_22_03.py deleted file mode 100644 index 9496dd4f..00000000 --- a/alembic/versions/5863384621a1_bump_version_22_03.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_22_03 - -Revision ID: 5863384621a1 -Revises: 3314b25783a2 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '5863384621a1' -down_revision = '3314b25783a2' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='22.03')) - - -def downgrade(): - pass diff --git a/alembic/versions/58cd88054523_bump_version_19_02.py b/alembic/versions/58cd88054523_bump_version_19_02.py deleted file mode 100644 index 0751fde4..00000000 --- a/alembic/versions/58cd88054523_bump_version_19_02.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_19_02 - -Revision ID: 58cd88054523 -Revises: b6a0f4cc7e49 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '58cd88054523' -down_revision = 'b6a0f4cc7e49' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='19.02')) - - -def downgrade(): - pass diff --git a/alembic/versions/58d561775bf3_remove_nullable_constraint_groupfeatures.py b/alembic/versions/58d561775bf3_remove_nullable_constraint_groupfeatures.py deleted file mode 100644 index 0a35acf2..00000000 --- a/alembic/versions/58d561775bf3_remove_nullable_constraint_groupfeatures.py +++ /dev/null @@ -1,22 +0,0 @@ -"""remove_nullable_constraint_groupfeatures - -Revision ID: 58d561775bf3 -Revises: 18b419c519f4 - -""" - -# revision identifiers, used by Alembic. -revision = '58d561775bf3' -down_revision = '18b419c519f4' - -from alembic import op - - -def upgrade(): - op.alter_column('groupfeatures', 'number', nullable=True, server_default=None) - op.alter_column('groupfeatures', 'context', nullable=True) - - -def downgrade(): - op.alter_column('groupfeatures', 'number', nullable=False, server_default='') - op.alter_column('groupfeatures', 'context', nullable=False) diff --git a/alembic/versions/58e808b69aec_queue_autopause_option.py b/alembic/versions/58e808b69aec_queue_autopause_option.py deleted file mode 100644 index eae79155..00000000 --- a/alembic/versions/58e808b69aec_queue_autopause_option.py +++ /dev/null @@ -1,38 +0,0 @@ -"""queue_autopause_option - -Revision ID: 58e808b69aec -Revises: 2c6c9833d839 - -""" - -# revision identifiers, used by Alembic. -revision = '58e808b69aec' -down_revision = '2c6c9833d839' - -from alembic import op - - -def upgrade(): - qry = """ALTER TABLE queue ALTER COLUMN autopause TYPE varchar(3);""" - op.execute(qry) - qry = """ALTER TABLE queue ALTER COLUMN autopause SET DEFAULT 'no';""" - op.execute(qry) - qry = """UPDATE queue SET autopause='yes' WHERE autopause='1';""" - op.execute(qry) - qry = """UPDATE queue SET autopause='no' WHERE autopause='0';""" - op.execute(qry) - qry = """ALTER TABLE queue ADD CONSTRAINT queue_autopause CHECK (autopause IN ('no','yes','all'));""" - op.execute(qry) - - -def downgrade(): - qry = """ALTER TABLE queue DROP CONSTRAINT queue_autopause;""" - op.execute(qry) - qry = """UPDATE queue SET autopause='1' WHERE autopause in ('yes','all');""" - op.execute(qry) - qry = """UPDATE queue SET autopause='0' WHERE autopause='no';""" - op.execute(qry) - qry = """ALTER TABLE queue ALTER COLUMN autopause SET DEFAULT 1;""" - op.execute(qry) - qry = """ALTER TABLE queue ALTER COLUMN autopause TYPE integer USING (autopause::integer);""" - op.execute(qry) diff --git a/alembic/versions/58fc78d9f67f_bump_version_18_06.py b/alembic/versions/58fc78d9f67f_bump_version_18_06.py deleted file mode 100644 index c9291f9a..00000000 --- a/alembic/versions/58fc78d9f67f_bump_version_18_06.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_18_06 - -Revision ID: 58fc78d9f67f -Revises: 3a091c2f91bc - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '58fc78d9f67f' -down_revision = '3a091c2f91bc' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='18.06')) - - -def downgrade(): - pass diff --git a/alembic/versions/592e449b34ec_cti_displays_clean_fields.py b/alembic/versions/592e449b34ec_cti_displays_clean_fields.py deleted file mode 100644 index 6bb711cb..00000000 --- a/alembic/versions/592e449b34ec_cti_displays_clean_fields.py +++ /dev/null @@ -1,45 +0,0 @@ -"""cti_displays clean fields - -Revision ID: 592e449b34ec -Revises: 2bb6543883a6 - -""" - -# revision identifiers, used by Alembic. -revision = '592e449b34ec' -down_revision = '2bb6543883a6' - -import re - -from alembic import op -from sqlalchemy import sql -from functools import partial - -t = sql.table('ctidisplays', - sql.column('id'), - sql.column('data')) - - -def sub_all(pattern, repl, string): - r = re.compile(pattern) - while True: - string, n = r.subn(repl, string) - if not n: - return string - - -def upgrade(): - conn = op.get_bind() - rows = conn.execute(sql.select([t])) - - f = partial(sub_all, r'(.*)\{\w+-(\w+)\}(.*)', r'\1\2\3') - to_upgrade = {row.id: f(row.data) for row in rows} - - for id_, value in to_upgrade.items(): - op.execute(t.update() - .where(t.c.id == id_) - .values(data=value)) - - -def downgrade(): - pass diff --git a/alembic/versions/596b177ba681_bump_version_17_06.py b/alembic/versions/596b177ba681_bump_version_17_06.py deleted file mode 100644 index f11df4bd..00000000 --- a/alembic/versions/596b177ba681_bump_version_17_06.py +++ /dev/null @@ -1,22 +0,0 @@ -"""bump_version_17_06 - -Revision ID: 596b177ba681 -Revises: 4e07e476eb0b - -""" - -# revision identifiers, used by Alembic. -revision = '596b177ba681' -down_revision = '4e07e476eb0b' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='17.06')) - - -def downgrade(): - pass diff --git a/alembic/versions/59feecbe8d13_webi_to_dird_ldap_migration.py b/alembic/versions/59feecbe8d13_webi_to_dird_ldap_migration.py deleted file mode 100644 index 65f883b4..00000000 --- a/alembic/versions/59feecbe8d13_webi_to_dird_ldap_migration.py +++ /dev/null @@ -1,300 +0,0 @@ -"""webi to dird ldap migration - -Revision ID: 59feecbe8d13 -Revises: 500ca962c3a8 - -""" - -# revision identifiers, used by Alembic. -revision = '59feecbe8d13' -down_revision = '500ca962c3a8' - -import json -import string - -from alembic import op -from collections import namedtuple -from itertools import count -from sqlalchemy import sql, and_ - - -cticontexts = sql.table('cticontexts', - sql.column('id'), - sql.column('directories')) -ctidirectories = sql.table('ctidirectories', - sql.column('id'), - sql.column('name'), - sql.column('uri'), - sql.column('delimiter'), - sql.column('match_direct'), - sql.column('match_reverse'), - sql.column('description'), - sql.column('deletable')) -ctidirectoryfields = sql.table('ctidirectoryfields', - sql.column('dir_id'), - sql.column('fieldname'), - sql.column('value')) -ldapfilter = sql.table('ldapfilter', - sql.column('id'), - sql.column('name'), - sql.column('attrdisplayname'), - sql.column('attrphonenumber'), - sql.column('additionaltype'), - sql.column('additionaltext'), - sql.column('commented')) -serverfeatures = sql.table('serverfeatures', - sql.column('serverid'), - sql.column('type'), - sql.column('feature')) - -alphanum = string.ascii_letters + string.digits - - -def upgrade(): - ldap_filters = get_active_ldap_filters() - directories = get_ldap_directories() - profiles = get_profiles() - - directory_name_to_add_to_profiles = set() - for ldap_filter in ldap_filters: - if ldap_filter.additional_type == 'fax': - continue - directory = find_directory_by_ldap_filter_name(directories, ldap_filter.name) - if not directory: - directory = ldap_filter.build_directory(directories) - directory.insert_db() - directories.append(directory) - directory_name_to_add_to_profiles.add(directory.name) - else: - ldap_filter.update_directory(directory) - directory.update_db() - directory_name_to_add_to_profiles.add(directory.name) - - for profile in profiles: - profile.add_directories(directory_name_to_add_to_profiles) - profile.update_db() - - -DirectoryField = namedtuple('DirectoryField', ['name', 'value']) - - -class LDAPFilter(object): - - def __init__(self): - self.id = None - self.name = '' - self.display_names = [] - self.phone_numbers = [] - self.additional_type = '' - self.additional_text = '' - - def build_directory(self, directories): - # generate unique name - directory_names = [directory.name for directory in directories] - base_name = ''.join(c for c in self.name if c in alphanum) - name = base_name - for i in count(1): - if name not in directory_names: - break - name = '{}{}'.format(base_name, i) - - directory = LDAPDirectory() - directory.name = name - directory.ldap_filter_name = self.name - directory.match_direct = self._build_directory_match_direct() - directory.fields = self._build_directory_fields() - directory.description = 'Automatically created during upgrade' - return directory - - def update_directory(self, directory): - directory.add_match_direct(self._build_directory_match_direct()) - directory.add_fields(self._build_directory_fields()) - - def _build_directory_match_direct(self): - return self.display_names + self.phone_numbers - - def _build_directory_fields(self): - fields = [] - for i, display_name in enumerate(self.display_names): - field_name = 'display_name{}'.format(i if i else '') - field_value = '{{{}}}'.format(display_name) - fields.append(DirectoryField(field_name, field_value)) - - if self.additional_type == 'custom': - print('warning: LDAP filter {}: ignoring custom phone number type "{}"'.format( - self.name, self.additional_text - )) - phone_suffix = '' - else: - phone_suffix = '_{}'.format(self.additional_type) - - for i, phone_number in enumerate(self.phone_numbers): - field_name = 'phone{}{}'.format(phone_suffix, i if i else '') - field_value = '{{{}}}'.format(phone_number) - fields.append(DirectoryField(field_name, field_value)) - return fields - - @classmethod - def new_from_db(cls, row): - ldap_filter = cls() - ldap_filter.id = row.id - ldap_filter.name = row.name - if row.attrdisplayname: - ldap_filter.display_names = row.attrdisplayname.split(',') - if row.attrphonenumber: - ldap_filter.phone_numbers = row.attrphonenumber.split(',') - ldap_filter.additional_type = row.additionaltype - ldap_filter.additional_text = row.additionaltext - return ldap_filter - - -def get_active_ldap_filters(): - query = (sql.select([ldapfilter]) - .where(and_(ldapfilter.c.commented == 0, - ldapfilter.c.id == serverfeatures.c.serverid, - serverfeatures.c.type == 'ldap', - serverfeatures.c.feature == 'phonebook'))) - rows = op.get_bind().execute(query).fetchall() - return [LDAPFilter.new_from_db(row) for row in rows] - - -class LDAPDirectory(object): - - def __init__(self): - self.id = None - self.name = '' - self.ldap_filter_name = '' - self.match_direct = [] - self.description = '' - self.fields = [] - - def add_match_direct(self, new_match_direct): - for item in new_match_direct: - if item not in self.match_direct: - self.match_direct.append(item) - - def add_fields(self, new_fields): - for new_field in new_fields: - for existing_field in self.fields: - if new_field.name == existing_field.name: - if new_field.value != existing_field.value: - print('warning: directory {}: can\'t set field "{}" to "{}"; already defined as "{}"'.format( - self.name, new_field.name, new_field.value, existing_field.value - )) - break - else: - self.fields.append(new_field) - - def insert_db(self): - uri = 'ldapfilter://{}'.format(self.ldap_filter_name) - match_direct = self._convert_obj_match_direct(self.match_direct) - query = (ctidirectories - .insert() - .returning(ctidirectories.c.id) - .values(name=self.name, - uri=uri, - delimiter='', - match_direct=match_direct, - match_reverse='', - description=self.description, - deletable=1)) - self.id = op.get_bind().execute(query).scalar() - - rows = [{'dir_id': self.id, 'fieldname': field.name, 'value': field.value} for field in self.fields] - op.bulk_insert(ctidirectoryfields, rows) - - def update_db(self): - match_direct = self._convert_obj_match_direct(self.match_direct) - query = (ctidirectories - .update() - .where(ctidirectories.c.id == self.id) - .values(match_direct=match_direct)) - op.execute(query) - - query = (ctidirectoryfields - .delete() - .where(ctidirectoryfields.c.dir_id == self.id)) - op.execute(query) - - rows = [{'dir_id': self.id, 'fieldname': field.name, 'value': field.value} for field in self.fields] - op.bulk_insert(ctidirectoryfields, rows) - - @classmethod - def new_from_db(cls, ctidirectories_row, ctidirectoryfields_rows): - directory = cls() - directory.id = ctidirectories_row.id - directory.name = ctidirectories_row.name - directory.ldap_filter_name = ctidirectories_row.uri[len('ldapfilter://'):] - directory.match_direct = cls._convert_db_match_direct(ctidirectories_row.match_direct) - directory.fields = [DirectoryField(row.fieldname, row.value) for row in ctidirectoryfields_rows] - return directory - - @classmethod - def _convert_db_match_direct(cls, db_match_direct): - if not db_match_direct: - return [] - return json.loads(db_match_direct) - - @classmethod - def _convert_obj_match_direct(cls, obj_match_direct): - if not obj_match_direct: - return '' - return json.dumps(obj_match_direct) - - -def get_ldap_directories(): - query = (sql.select([ctidirectories]) - .where(ctidirectories.c.uri.like('ldapfilter://%'))) - ctidirectories_rows = op.get_bind().execute(query).fetchall() - - results = [] - for ctidirectories_row in ctidirectories_rows: - query = (sql.select([ctidirectoryfields]) - .where(ctidirectoryfields.c.dir_id == ctidirectories_row.id)) - ctidirectoryfields_rows = op.get_bind().execute(query).fetchall() - results.append(LDAPDirectory.new_from_db(ctidirectories_row, ctidirectoryfields_rows)) - return results - - -class Profile(object): - - def __init__(self): - self.id = None - self.directories = [] - - def add_directories(self, directories): - for directory in directories: - if directory not in self.directories: - self.directories.append(directory) - - def update_db(self): - directories = ','.join(self.directories) - op.execute(cticontexts - .update() - .where(cticontexts.c.id == self.id) - .values(directories=directories)) - - @classmethod - def new_from_db(cls, row): - profile = cls() - profile.id = row.id - if row.directories: - profile.directories = row.directories.split(',') - return profile - - -def get_profiles(): - query = (sql.select([cticontexts])) - rows = op.get_bind().execute(query).fetchall() - return [Profile.new_from_db(row) for row in rows] - - -def find_directory_by_ldap_filter_name(directories, filter_name): - for directory in directories: - if directory.ldap_filter_name == filter_name: - return directory - return None - - -def downgrade(): - pass diff --git a/alembic/versions/5a02fde67132_migrate_func_key_parking.py b/alembic/versions/5a02fde67132_migrate_func_key_parking.py deleted file mode 100644 index 76ead7c0..00000000 --- a/alembic/versions/5a02fde67132_migrate_func_key_parking.py +++ /dev/null @@ -1,275 +0,0 @@ -"""migrate func key parking - -Revision ID: 5a02fde67132 -Revises: 33e0cdb6971d - -""" - -# revision identifiers, used by Alembic. -revision = '5a02fde67132' -down_revision = '33e0cdb6971d' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy import sql - - -TYPE_FORWARD = 'forward' - -DESTINATION_FEATURES_ID = 8 - -PARKING_TYPE = 'parkext' - - -phonefunckey_table = sql.table('phonefunckey', - sql.column('iduserfeatures'), - sql.column('fknum'), - sql.column('exten'), - sql.column('typeextenumbers'), - sql.column('typevalextenumbers'), - sql.column('typeextenumbersright'), - sql.column('typevalextenumbersright'), - sql.column('label'), - sql.column('supervision'), - sql.column('progfunckey')) - -func_key_table = sql.table('func_key', - sql.column('id'), - sql.column('type_id'), - sql.column('destination_type_id')) - -dest_features_table = sql.table('func_key_dest_features', - sql.column('func_key_id'), - sql.column('destination_type_id'), - sql.column('features_id')) - -func_key_type_table = sql.table('func_key_type', - sql.column('id'), - sql.column('name')) - -func_key_mapping_table = sql.table('func_key_mapping', - sql.column('template_id'), - sql.column('func_key_id'), - sql.column('destination_type_id'), - sql.column('label'), - sql.column('position'), - sql.column('blf')) - -template_table = sql.table('func_key_template', sql.column('id')) - -user_table = sql.table('userfeatures', - sql.column('id'), - sql.column('func_key_private_template_id')) - -destination_type_table = sql.table('func_key_destination_type', - sql.column('id'), - sql.column('name')) - -features_table = sql.table('features', - sql.column('id'), - sql.column('category'), - sql.column('var_name')) - - -func_key_columns = ( - phonefunckey_table.c.iduserfeatures.label('user_id'), - phonefunckey_table.c.fknum.label('position'), - phonefunckey_table.c.label, - phonefunckey_table.c.exten.label('park_position'), - sql.cast(phonefunckey_table.c.supervision, sa.Boolean).label('blf'), -) - -old_func_key_columns = ( - func_key_mapping_table.c.func_key_id, - func_key_mapping_table.c.template_id, - func_key_mapping_table.c.position, - func_key_mapping_table.c.blf, - func_key_mapping_table.c.label, - user_table.c.id.label('user_id') -) - -func_keys_query = (sql.select(func_key_columns) - .where(phonefunckey_table.c.typevalextenumbers == PARKING_TYPE)) - - -old_func_keys_query = (sql.select(old_func_key_columns, - from_obj=[ - func_key_mapping_table.join( - dest_features_table, - func_key_mapping_table.c.func_key_id == dest_features_table.c.func_key_id) - .join(template_table, - func_key_mapping_table.c.template_id == template_table.c.id) - .join(user_table, - template_table.c.id == user_table.c.func_key_private_template_id) - ])) - - -def upgrade(): - delete_duplicate_fks() - migrate_func_keys() - delete_old_func_keys() - - -def delete_duplicate_fks(): - for row in get_duplicate_func_keys(): - delete_duplicate_fk(row.iduserfeatures, row.fknum) - - -def get_duplicate_func_keys(): - columns = (phonefunckey_table.c.iduserfeatures, - sa.func.min(phonefunckey_table.c.fknum).label("first_position")) - - valid_fk_subq = (sql.select(columns) - .where( - phonefunckey_table.c.typevalextenumbers == PARKING_TYPE) - .group_by( - phonefunckey_table.c.iduserfeatures) - .having( - sa.func.count(phonefunckey_table.c.typevalextenumbers) > 1) - .alias()) - - columns = (phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.fknum) - - join_condition = sql.and_( - phonefunckey_table.c.typevalextenumbers == PARKING_TYPE, - phonefunckey_table.c.fknum > valid_fk_subq.c.first_position, - phonefunckey_table.c.iduserfeatures == valid_fk_subq.c.iduserfeatures) - - duplicate_fk_query = (sql.select(columns, - from_obj=[ - phonefunckey_table.join( - valid_fk_subq, - join_condition - ) - ])) - - return op.get_bind().execute(duplicate_fk_query) - - -def delete_duplicate_fk(iduserfeatures, fknum): - print('[MIGRATE_FK] : Deleting parking func key for user "%s" (fk position %s)' % - (iduserfeatures, fknum)) - - query = (phonefunckey_table - .delete() - .where(sql.and_( - phonefunckey_table.c.iduserfeatures == iduserfeatures, - phonefunckey_table.c.fknum == fknum))) - - op.get_bind().execute(query) - - -def migrate_func_keys(): - func_key_id = get_parking_func_key() - for row in op.get_bind().execute(func_keys_query): - create_mapping(func_key_id, row) - - -def get_parking_func_key(): - park_subquery = ( - sql.select( - [features_table.c.id]) - .where( - sql.and_( - features_table.c.category == 'general', - features_table.c.var_name == PARKING_TYPE)) - .alias()) - - query = ( - sql.select( - [dest_features_table.c.func_key_id]) - .where( - dest_features_table.c.features_id == park_subquery)) - - return op.get_bind().execute(query).scalar() - - -def get_speeddial_id(): - return op.get_bind().execute( - sql.select( - [func_key_type_table.c.id]) - .where( - func_key_type_table.c.name == TYPE_FORWARD) - ).scalar() - - -def create_mapping(func_key_id, func_key_row): - conn = op.get_bind() - - template_query = ( - sql.select( - [user_table.c.func_key_private_template_id]) - .where( - user_table.c.id == func_key_row.user_id)) - - template_id = conn.execute(template_query).scalar() - - mapping_query = (func_key_mapping_table - .insert() - .returning(func_key_mapping_table.c.func_key_id) - .values(func_key_id=func_key_id, - template_id=template_id, - destination_type_id=DESTINATION_FEATURES_ID, - label=func_key_row.label, - position=func_key_row.position, - blf=func_key_row.blf)) - - conn.execute(mapping_query) - - -def delete_old_func_keys(): - delete_query = (phonefunckey_table - .delete() - .where(phonefunckey_table.c.typevalextenumbers == PARKING_TYPE)) - - op.get_bind().execute(delete_query) - - -def downgrade(): - for row in op.get_bind().execute(old_func_keys_query): - create_old_func_keys(row) - delete_mapping(row.func_key_id, row.template_id) - delete_dest_features(row.func_key_id) - delete_func_key(row.func_key_id) - - -def create_old_func_keys(row): - supervision = 1 if row.blf else 0 - - row = {'iduserfeatures': row.user_id, - 'fknum': row.position, - 'typeextenumbers': 'generalfeatures', - 'typevalextenumbers': 'parkext', - 'typeextenumbersright': None, - 'typevalextenumbersright': None, - 'label': row.label, - 'exten': None, - 'supervision': supervision} - - op.bulk_insert(phonefunckey_table, [row]) - - -def delete_mapping(func_key_id, template_id): - query = (func_key_mapping_table - .delete() - .where(sql.and_( - func_key_mapping_table.c.func_key_id == func_key_id, - func_key_mapping_table.c.template_id == template_id))) - - op.get_bind().execute(query) - - -def delete_dest_features(func_key_id): - query = (dest_features_table - .delete()) - - op.get_bind().execute(query) - - -def delete_func_key(func_key_id): - query = (func_key_table - .delete() - .where(func_key_table.c.destination_type_id == DESTINATION_FEATURES_ID)) - - op.get_bind().execute(query) diff --git a/alembic/versions/5a285558e46e_trunk_add_tenant_uuid.py b/alembic/versions/5a285558e46e_trunk_add_tenant_uuid.py deleted file mode 100644 index 93cc256c..00000000 --- a/alembic/versions/5a285558e46e_trunk_add_tenant_uuid.py +++ /dev/null @@ -1,64 +0,0 @@ -"""trunk_add_tenant_uuid - -Revision ID: 5a285558e46e -Revises: ee27cd6ccd9 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '5a285558e46e' -down_revision = 'ee27cd6ccd9' - -TABLE = 'trunkfeatures' - - -def find_default_tenant_uuid(): - entity_table = sa.sql.table( - 'entity', - sa.sql.column('id'), - sa.sql.column('name'), - sa.sql.column('tenant_uuid'), - ) - query = sa.sql.select([entity_table.c.tenant_uuid]).order_by(entity_table.c.id) - for row in op.get_bind().execute(query): - return row.tenant_uuid - - -def get_context_tenant_map(): - tbl = sa.sql.table('context', sa.sql.column('name'), sa.sql.column('tenant_uuid')) - query = sa.sql.select([tbl.c.name, tbl.c.tenant_uuid]) - rows = op.get_bind().execute(query) - return {row.name: row.tenant_uuid for row in rows} - - -def associate_tenants(): - tbl = sa.sql.table('trunkfeatures', sa.sql.column('id'), sa.sql.column('tenant_uuid')) - sql = "SELECT trunkfeatures.id, context.tenant_uuid FROM trunkfeatures, context WHERE trunkfeatures.context = context.name" - trunkfeatures_to_tenant = op.get_bind().execute(sa.sql.text(sql)) - - for trunkfeatures_id, tenant_uuid in trunkfeatures_to_tenant: - query = tbl.update().where(tbl.c.id == trunkfeatures_id).values(tenant_uuid=tenant_uuid) - op.execute(query) - - -def upgrade(): - default_tenant = find_default_tenant_uuid() - op.add_column( - TABLE, - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=False, - server_default=default_tenant), - ) - associate_tenants() - op.alter_column(TABLE, 'tenant_uuid', server_default=None) - - -def downgrade(): - op.drop_column(TABLE, 'tenant_uuid') diff --git a/alembic/versions/5a4fe661486c_fix_func_key_label_empty.py b/alembic/versions/5a4fe661486c_fix_func_key_label_empty.py deleted file mode 100644 index 3de1e517..00000000 --- a/alembic/versions/5a4fe661486c_fix_func_key_label_empty.py +++ /dev/null @@ -1,37 +0,0 @@ -"""fix_func_key_label_empty - -Revision ID: 5a4fe661486c -Revises: 43c5188319dc - -""" - -from alembic import op -from sqlalchemy import sql - -# revision identifiers, used by Alembic. -revision = '5a4fe661486c' -down_revision = '43c5188319dc' - - -func_key_mapping = sql.table('func_key_mapping', - sql.column('label')) - - -def upgrade(): - query = (func_key_mapping - .update() - .values(label=None) - .where(sql.func.trim(func_key_mapping.c.label) == '') - ) - - op.execute(query) - - -def downgrade(): - query = (func_key_mapping - .update() - .values(label='') - .where(func_key_mapping.c.label == None) - ) - - op.execute(query) diff --git a/alembic/versions/5ace7dc40b5c_create_missing_paging_func_keys.py b/alembic/versions/5ace7dc40b5c_create_missing_paging_func_keys.py deleted file mode 100644 index a1cdfb9b..00000000 --- a/alembic/versions/5ace7dc40b5c_create_missing_paging_func_keys.py +++ /dev/null @@ -1,70 +0,0 @@ -"""create_missing_paging_func_keys - -Revision ID: 5ace7dc40b5c -Revises: 13692a692d44 - -""" - -from alembic import op -from sqlalchemy import sql - -# revision identifiers, used by Alembic. -revision = '5ace7dc40b5c' -down_revision = '13692a692d44' - -paging = sql.table('paging', - sql.column('id')) - -dest_paging = sql.table('func_key_dest_paging', - sql.column('func_key_id'), - sql.column('paging_id')) - -funckey = sql.table('func_key', - sql.column('id'), - sql.column('type_id'), - sql.column('destination_type_id')) - -destination_type = sql.table('func_key_destination_type', - sql.column('id'), - sql.column('name')) - -funckey_type = sql.table('func_key_type', - sql.column('id'), - sql.column('name')) - - -def upgrade(): - speeddial = (sql.select([funckey_type.c.id]) - .where(funckey_type.c.name == 'speeddial') - ).as_scalar() - - paging_type = (sql.select([destination_type.c.id]) - .where(destination_type.c.name == 'paging') - ).as_scalar() - - create_funckey = (funckey - .insert() - .values(type_id=speeddial, - destination_type_id=paging_type) - .returning(funckey.c.id) - ) - - missing_pagings = (sql.select([paging.c.id]) - .select_from( - paging.outerjoin(dest_paging, - dest_paging.c.paging_id == paging.c.id)) - .where( - dest_paging.c.paging_id == None)) - - for row in op.get_bind().execute(missing_pagings): - func_key_id = op.get_bind().execute(create_funckey).scalar() - create_paging = (dest_paging - .insert() - .values(paging_id=row.id, - func_key_id=func_key_id) - ) - op.get_bind().execute(create_paging) - - -def downgrade(): - pass diff --git a/alembic/versions/5b427e206bdf_update_wazo_plugind_cli_acl.py b/alembic/versions/5b427e206bdf_update_wazo_plugind_cli_acl.py deleted file mode 100644 index 704cdd88..00000000 --- a/alembic/versions/5b427e206bdf_update_wazo_plugind_cli_acl.py +++ /dev/null @@ -1,55 +0,0 @@ -"""update wazo-plugind-cli ACL - -Revision ID: 5b427e206bdf -Revises: 6aead6a54bbb - -""" - -# revision identifiers, used by Alembic. -revision = '5b427e206bdf' -down_revision = '6aead6a54bbb' - -from alembic import op -from sqlalchemy import sql -from sqlalchemy.dialects.postgresql import ARRAY, VARCHAR - -webservice = sql.table('accesswebservice', - sql.column('id'), - sql.column('name'), - sql.column('acl')) - -SERVICE = 'wazo-plugind-cli' -OLD_ACLS = ['plugind.plugins.create', 'plugind.plugins.*.*.delete', 'plugind.plugins.read'] -NEW_ACLS = ['plugind.#'] - - -def upgrade(): - _remove_acls(SERVICE, OLD_ACLS) - _add_acls(SERVICE, NEW_ACLS) - - -def downgrade(): - _remove_acls(SERVICE, NEW_ACLS) - _add_acls(SERVICE, OLD_ACLS) - - -def _add_acls(name, acls): - acl = sql.cast(acls, ARRAY(VARCHAR)) - query = (webservice - .update() - .values( - acl=sql.func.array_cat(webservice.c.acl, acl)) - .where( - webservice.c.name == name)) - op.execute(query) - - -def _remove_acls(name, acls): - for acl in acls: - query = (webservice - .update() - .values( - acl=sql.func.array_remove(webservice.c.acl, acl)) - .where( - webservice.c.name == name)) - op.execute(query) diff --git a/alembic/versions/5c8dc069cfd7_fix_jitter_buffer_implementation_choice.py b/alembic/versions/5c8dc069cfd7_fix_jitter_buffer_implementation_choice.py deleted file mode 100644 index 3eafc2bb..00000000 --- a/alembic/versions/5c8dc069cfd7_fix_jitter_buffer_implementation_choice.py +++ /dev/null @@ -1,32 +0,0 @@ -"""fix_jitter_buffer_implementation_choice - -Revision ID: 5c8dc069cfd7 -Revises: 425eebc346b1 - -""" - -# revision identifiers, used by Alembic. -revision = '5c8dc069cfd7' -down_revision = '425eebc346b1' - -from alembic import op -from sqlalchemy import sql - - -staticsip = sql.table('staticsip', - sql.column('var_name'), - sql.column('var_val')) - - -def upgrade(): - query = (staticsip - .update() - .values(var_val='adaptive') - .where(sql.and_( - staticsip.c.var_name == "jbimpl", - staticsip.c.var_val == "adaptative"))) - op.execute(query) - - -def downgrade(): - pass diff --git a/alembic/versions/5c9f286599b6_bump_version_20_11.py b/alembic/versions/5c9f286599b6_bump_version_20_11.py deleted file mode 100644 index d21aa30c..00000000 --- a/alembic/versions/5c9f286599b6_bump_version_20_11.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_20_11 - -Revision ID: 5c9f286599b6 -Revises: f055e37e6196 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '5c9f286599b6' -down_revision = 'f055e37e6196' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='20.11')) - - -def downgrade(): - pass diff --git a/alembic/versions/5dd4a73c91c2_bump_version_19_03.py b/alembic/versions/5dd4a73c91c2_bump_version_19_03.py deleted file mode 100644 index 87f5fa68..00000000 --- a/alembic/versions/5dd4a73c91c2_bump_version_19_03.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_19_03 - -Revision ID: 5dd4a73c91c2 -Revises: d81a903b6d1e - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '5dd4a73c91c2' -down_revision = 'd81a903b6d1e' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='19.03')) - - -def downgrade(): - pass diff --git a/alembic/versions/5f8c8a323cbe_incall_add_tenant_uuid.py b/alembic/versions/5f8c8a323cbe_incall_add_tenant_uuid.py deleted file mode 100644 index 4ffc295f..00000000 --- a/alembic/versions/5f8c8a323cbe_incall_add_tenant_uuid.py +++ /dev/null @@ -1,60 +0,0 @@ -"""incall add tenant-uuid - - -Revision ID: 5f8c8a323cbe -Revises: c7de783d8c8c - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '5f8c8a323cbe' -down_revision = 'c7de783d8c8c' - -TBL = 'incall' - - -def find_default_tenant_uuid(): - entity_table = sa.sql.table( - 'entity', - sa.sql.column('id'), - sa.sql.column('name'), - sa.sql.column('tenant_uuid'), - ) - query = sa.sql.select([entity_table.c.tenant_uuid]).order_by(entity_table.c.id) - for row in op.get_bind().execute(query): - return row.tenant_uuid - - -def associate_tenants(): - ctx_tbl = sa.sql.table('context', sa.sql.column('name'), sa.sql.column('tenant_uuid')) - incall_tbl = sa.sql.table('incall', sa.sql.column('context'), sa.sql.column('tenant_uuid')) - query = sa.sql.select([ctx_tbl.c.name, ctx_tbl.c.tenant_uuid]) - context_to_tenant = {row.name: row.tenant_uuid for row in op.get_bind().execute(query)} - - for name, tenant_uuid in context_to_tenant.items(): - query = incall_tbl.update().where(incall_tbl.c.context == name).values(tenant_uuid=tenant_uuid) - op.execute(query) - - -def upgrade(): - default_tenant_uuid = find_default_tenant_uuid() - op.add_column( - TBL, - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=False, - server_default=default_tenant_uuid, - ) - ) - associate_tenants() - op.alter_column(TBL, 'tenant_uuid', server_default=None) - - -def downgrade(): - op.drop_column(TBL, 'tenant_uuid') diff --git a/alembic/versions/5faf5386dca8_remove_cti_directories_tables.py b/alembic/versions/5faf5386dca8_remove_cti_directories_tables.py deleted file mode 100644 index 3d02c659..00000000 --- a/alembic/versions/5faf5386dca8_remove_cti_directories_tables.py +++ /dev/null @@ -1,117 +0,0 @@ -"""remove cti directories tables - -Revision ID: 5faf5386dca8 -Revises: 4d80d8106d1e - -""" - -# revision identifiers, used by Alembic. -revision = '5faf5386dca8' -down_revision = '4d80d8106d1e' - - -from alembic import op -import sqlalchemy as sa - -ldapserver_securitylayer = sa.Enum('tls', 'ssl', name='ldapserver_securitylayer') -ldapserver_protocolversion = sa.Enum('2', '3', name='ldapserver_protocolversion') - - -def upgrade(): - op.drop_table('ctidisplays') - op.drop_table('cticontexts') - op.drop_table('ctidirectoryfields') - op.drop_table('ctidirectories') - op.drop_table('ctireversedirectories') - op.drop_table('directories') - op.drop_table('ldapfilter') - op.drop_table('ldapserver') - ldapserver_securitylayer.drop(op.get_bind()) - ldapserver_protocolversion.drop(op.get_bind()) - - -def downgrade(): - op.create_table( - 'ldapserver', - sa.Column('id', sa.Integer, primary_key=True), - sa.Column('name', sa.String(64)), - sa.Column('host', sa.String(255), nullable=False), - sa.Column('port', sa.Integer, nullable=False), - sa.Column('securitylayer', ldapserver_securitylayer), - sa.Column('protocolversion', ldapserver_protocolversion, nullable=False, default=3), - sa.Column('disable', sa.Integer, nullable=False, default=0), - sa.Column('dcreate', sa.Integer, nullable=False, default=0), - sa.Column('description', sa.Text), - ) - op.create_table( - 'ldapfilter', - sa.Column('id', sa.Integer, primary_key=True), - sa.Column('ldapserverid', sa.Integer, nullable=False), - sa.Column('name', sa.String(128)), - sa.Column('user', sa.String(255)), - sa.Column('passwd', sa.String(255)), - sa.Column('basedn', sa.String(255), nullable=False), - sa.Column('filter', sa.String(255), nullable=False), - sa.Column('commented', sa.Integer, nullable=False, default=0), - sa.Column('description', sa.Text), - ) - op.create_table( - 'directories', - sa.Column('id', sa.Integer, primary_key=True), - sa.Column('uri', sa.String(255)), - sa.Column('dirtype', sa.String(20), nullable=False), - sa.Column('name', sa.String(255)), - sa.Column('description', sa.Text), - sa.Column('xivo_username', sa.Text), - sa.Column('xivo_password', sa.Text), - sa.Column('xivo_verify_certificate', sa.Boolean, nullable=False, default=False), - sa.Column('xivo_custom_ca_path', sa.Text), - sa.Column('dird_tenant', sa.Text), - sa.Column('dird_phonebook', sa.Text), - sa.Column('auth_host', sa.Text), - sa.Column('auth_port', sa.Integer), - sa.Column('auth_backend', sa.Text), - sa.Column('auth_verify_certificate', sa.Boolean, nullable=False, default=False), - sa.Column('auth_custom_ca_path', sa.Text), - sa.Column('ldapfilter_id', sa.Integer, sa.ForeignKey('ldapfilter.id', ondelete='CASCADE')), - sa.Column('auth_key_file', sa.Text), - ) - op.create_table( - 'ctidirectoryfields', - sa.Column('dir_id', sa.Integer, nullable=False), - sa.Column('fieldname', sa.String(255), nullable=False), - sa.Column('value', sa.String(255)), - ) - op.create_table( - 'ctidirectories', - sa.Column('id', sa.Integer, primary_key=True), - sa.Column('name', sa.String(255)), - sa.Column('delimiter', sa.String(20)), - sa.Column('match_direct', sa.Text, nullable=False), - sa.Column('match_reverse', sa.Text, nullable=False), - sa.Column('description', sa.String(255)), - sa.Column('deletable', sa.Integer), - sa.Column('directory_id', sa.Integer, sa.ForeignKey('directories.id', ondelete='CASCADE')), - ) - op.create_table( - 'ctireversedirectories', - sa.Column('id', sa.Integer, primary_key=True), - sa.Column('directories', sa.Text), - ) - op.create_table( - 'cticontexts', - sa.Column('id', sa.Integer, primary_key=True), - sa.Column('name', sa.String(50)), - sa.Column('directories', sa.Text, nullable=False), - sa.Column('display', sa.Text, nullable=False), - sa.Column('deletable', sa.Integer), - sa.Column('description', sa.Text), - ) - op.create_table( - 'ctidisplays', - sa.Column('id', sa.Integer, primary_key=True), - sa.Column('name', sa.String(50)), - sa.Column('data', sa.Text, nullable=False), - sa.Column('deletable', sa.Integer), - sa.Column('description', sa.Text), - ) diff --git a/alembic/versions/5ffaec7e8db7_add_endpoint_sip_materialized_view.py b/alembic/versions/5ffaec7e8db7_add_endpoint_sip_materialized_view.py deleted file mode 100644 index 0bd54221..00000000 --- a/alembic/versions/5ffaec7e8db7_add_endpoint_sip_materialized_view.py +++ /dev/null @@ -1,145 +0,0 @@ -"""add endpoint_sip materialized view - -Revision ID: 5ffaec7e8db7 -Revises: 51ebe7954da8 - -""" - -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects.postgresql import JSONB, aggregate_order_by -from sqlalchemy.ext import compiler -from sqlalchemy.schema import DDLElement -from sqlalchemy.sql.functions import array_agg, func - - -# revision identifiers, used by Alembic. -revision = '5ffaec7e8db7' -down_revision = '51ebe7954da8' - - -class CreateMaterializedView(DDLElement): - def __init__(self, name, selectable): - self.name = name - self.selectable = selectable - - -@compiler.compiles(CreateMaterializedView) -def _compile_create_view(element, compiler, **kw): - name = compiler.dialect.identifier_preparer.quote(element.name) - selectable = compiler.sql_compiler.process(element.selectable, literal_binds=True) - return 'CREATE MATERIALIZED VIEW {} AS {}'.format(name, selectable) - - -# TODO: Replace by SQLAlchemy-Utils when possible -class DropMaterializedView(DDLElement): - def __init__(self, name, cascade=True): - self.name = name - self.cascade = cascade - - -@compiler.compiles(DropMaterializedView) -def _compile_drop_view(element, compiler, **kw): - name = compiler.dialect.identifier_preparer.quote(element.name) - cascade = 'CASCADE ' if element.cascade else '' - return 'DROP MATERIALIZED VIEW IF EXISTS {} {}'.format(name, cascade) - - -def generate_view_selectable(): - cte = ( - sa.select( - [ - sa.literal_column('endpoint_sip.uuid').label('uuid'), - sa.literal(0).label('level'), - sa.literal('0', sa.String).label('path'), - sa.literal_column('endpoint_sip.uuid').label('root'), - ] - ) - .select_from(sa.table('endpoint_sip')) - .cte(recursive=True) - ) - - endpoints = cte.union_all( - sa.select( - [ - sa.literal_column('endpoint_sip_template.parent_uuid').label('uuid'), - (cte.c.level + 1).label('level'), - ( - cte.c.path - + sa.cast( - func.row_number().over( - partition_by='level', - order_by=sa.literal_column( - 'endpoint_sip_template.priority' - ), - ), - sa.String, - ) - ).label('path'), - (cte.c.root), - ] - ).select_from( - sa.join( - cte, - sa.table('endpoint_sip_template'), - cte.c.uuid == sa.literal_column('endpoint_sip_template.child_uuid'), - ) - ) - ) - - return ( - sa.select( - [ - endpoints.c.root, - sa.cast( - sa.func.jsonb_object( - array_agg( - aggregate_order_by( - sa.literal_column('endpoint_sip_section_option.key'), - endpoints.c.path.desc(), - ) - ), - array_agg( - aggregate_order_by( - sa.literal_column('endpoint_sip_section_option.value'), - endpoints.c.path.desc(), - ) - ), - ), - JSONB, - ).label('options'), - ] - ) - .select_from( - sa.join( - endpoints, - sa.table('endpoint_sip_section'), - sa.literal_column('endpoint_sip_section.endpoint_sip_uuid') - == endpoints.c.uuid, - ).join( - sa.table('endpoint_sip_section_option'), - sa.literal_column( - 'endpoint_sip_section_option.endpoint_sip_section_uuid' - ) - == sa.literal_column('endpoint_sip_section.uuid'), - ) - ) - .group_by(endpoints.c.root) - ) - - -def upgrade(): - op.execute( - CreateMaterializedView('endpoint_sip_options_view', generate_view_selectable()) - ) - op.create_index( - 'endpoint_sip_options_view__idx_root', - 'endpoint_sip_options_view', - ['root'], - unique=True, - ) - - -def downgrade(): - op.drop_index('endpoint_sip_options_view__idx_root', 'endpoint_sip_mv') - op.execute(DropMaterializedView('endpoint_sip_options_view')) diff --git a/alembic/versions/60eb57605f3_bump_version_17_11.py b/alembic/versions/60eb57605f3_bump_version_17_11.py deleted file mode 100644 index 6c008b78..00000000 --- a/alembic/versions/60eb57605f3_bump_version_17_11.py +++ /dev/null @@ -1,22 +0,0 @@ -"""bump_version_17_11 - -Revision ID: 60eb57605f3 -Revises: bc9e62985a0 - -""" - -# revision identifiers, used by Alembic. -revision = '60eb57605f3' -down_revision = 'bc9e62985a0' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='17.11')) - - -def downgrade(): - pass diff --git a/alembic/versions/61e3d7c65755_set_all_moh_labels.py b/alembic/versions/61e3d7c65755_set_all_moh_labels.py deleted file mode 100644 index a1e92e22..00000000 --- a/alembic/versions/61e3d7c65755_set_all_moh_labels.py +++ /dev/null @@ -1,30 +0,0 @@ -"""set all moh labels - -Revision ID: 61e3d7c65755 -Revises: da06cfd76289 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '61e3d7c65755' -down_revision = 'da06cfd76289' - - -def upgrade(): - moh = sa.sql.table( - 'moh', - sa.sql.column('name'), - sa.sql.column('label'), - ) - op.execute( - moh.update().values(label=moh.c.name).where(moh.c.label.is_(None)) - ) - op.alter_column('moh', 'label', nullable=False) - - -def downgrade(): - op.alter_column('moh', 'label', nullable=True) diff --git a/alembic/versions/62c5befaa8cf_hep_general_section.py b/alembic/versions/62c5befaa8cf_hep_general_section.py deleted file mode 100644 index 2c00e107..00000000 --- a/alembic/versions/62c5befaa8cf_hep_general_section.py +++ /dev/null @@ -1,78 +0,0 @@ -"""hep general section - -Revision ID: 62c5befaa8cf -Revises: 87b36150b613 - -""" - -from alembic import op -from sqlalchemy import sql - - -# revision identifiers, used by Alembic. -revision = '62c5befaa8cf' -down_revision = '87b36150b613' - - -asterisk_file_table = sql.table( - 'asterisk_file', - sql.column('id'), - sql.column('name'), -) - -asterisk_file_section_table = sql.table( - 'asterisk_file_section', - sql.column('id'), - sql.column('name'), - sql.column('priority'), - sql.column('asterisk_file_id'), -) - -asterisk_file_variable_table = sql.table( - 'asterisk_file_variable', - sql.column('id'), - sql.column('key'), - sql.column('value'), - sql.column('asterisk_file_section_id'), -) - - -def upgrade(): - file_id = _insert_asterisk_file('hep.conf') - - section_id = _insert_asterisk_file_section(file_id, 'general', priority=0) - _insert_asterisk_file_variable(section_id, 'enabled', '0') - - -def _insert_asterisk_file(name): - query = (asterisk_file_table - .insert() - .returning(asterisk_file_table.c.id) - .values(name=name)) - - return op.get_bind().execute(query).scalar() - - -def _insert_asterisk_file_section(file_id, name, priority=None): - query = (asterisk_file_section_table - .insert() - .returning(asterisk_file_section_table.c.id) - .values(name=name, - priority=priority, - asterisk_file_id=file_id)) - - return op.get_bind().execute(query).scalar() - - -def _insert_asterisk_file_variable(section_id, key, value): - query = (asterisk_file_variable_table - .insert() - .values(key=key, - value=value, - asterisk_file_section_id=section_id)) - - op.get_bind().execute(query) - - -def downgrade(): - op.execute(asterisk_file_table.delete().where(asterisk_file_table.c.name == 'hep.conf')) diff --git a/alembic/versions/64c6bde0116c_add_date_end_to_call_log.py b/alembic/versions/64c6bde0116c_add_date_end_to_call_log.py deleted file mode 100644 index c883606d..00000000 --- a/alembic/versions/64c6bde0116c_add_date_end_to_call_log.py +++ /dev/null @@ -1,21 +0,0 @@ -"""add_date_end_to_call_log - -Revision ID: 64c6bde0116c -Revises: b5f230e1e0fe - -""" - -# revision identifiers, used by Alembic. -revision = '64c6bde0116c' -down_revision = 'b5f230e1e0fe' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - op.add_column('call_log', sa.Column('date_end', sa.DateTime)) - - -def downgrade(): - op.drop_column('call_log', 'date_end') diff --git a/alembic/versions/6545d103068c_add_the_asterisk_service_user.py b/alembic/versions/6545d103068c_add_the_asterisk_service_user.py deleted file mode 100644 index 25202b7a..00000000 --- a/alembic/versions/6545d103068c_add_the_asterisk_service_user.py +++ /dev/null @@ -1,38 +0,0 @@ -"""add the asterisk service user - -Revision ID: 6545d103068c -Revises: 74a76197acaa - -""" - -from alembic import op -from sqlalchemy import sql, func - - -# revision identifiers, used by Alembic. -revision = '6545d103068c' -down_revision = '74a76197acaa' - -webservice = sql.table('accesswebservice', - sql.column('name'), - sql.column('login'), - sql.column('passwd'), - sql.column('acl'), - sql.column('description')) -ACL = '{auth.tenants.read, confd.voicemails.read, confd.voicemails.*.update}' -DESCRIPTION = 'Automatically created during upgrade' -SERVICE = 'asterisk' - - -def upgrade(): - op.execute(webservice - .insert() - .values(name=SERVICE, - login=SERVICE, - passwd=func.substring(func.gen_salt('bf', 4), 8), - acl=ACL, - description=DESCRIPTION)) - - -def downgrade(): - op.execute(webservice.delete().where(webservice.c.name == SERVICE)) diff --git a/alembic/versions/66453e75a1fd_set_a_username_on_usersip.py b/alembic/versions/66453e75a1fd_set_a_username_on_usersip.py deleted file mode 100644 index 68388cdf..00000000 --- a/alembic/versions/66453e75a1fd_set_a_username_on_usersip.py +++ /dev/null @@ -1,32 +0,0 @@ -"""set a username on usersip - -Revision ID: 66453e75a1fd -Revises: c3ecaf2f9e78 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '66453e75a1fd' -down_revision = 'c3ecaf2f9e78' - -usersip_table = sa.sql.table( - 'usersip', - sa.sql.column('name'), - sa.sql.column('username'), -) - - -def upgrade(): - op.execute( - usersip_table.update().values( - username=usersip_table.c.name - ).where(usersip_table.c.username == None) - ) - - -def downgrade(): - pass diff --git a/alembic/versions/672a6918b7f9_fix_the_reverse_directory.py b/alembic/versions/672a6918b7f9_fix_the_reverse_directory.py deleted file mode 100644 index 68484f66..00000000 --- a/alembic/versions/672a6918b7f9_fix_the_reverse_directory.py +++ /dev/null @@ -1,38 +0,0 @@ -"""fix the reverse directory - -Revision ID: 672a6918b7f9 -Revises: 438cb372df48 - -""" - -# revision identifiers, used by Alembic. -revision = '672a6918b7f9' -down_revision = '438cb372df48' - -from sqlalchemy import sql -from alembic import op - -cti_reverse = sql.table( - 'ctireversedirectories', - sql.column('id'), - sql.column('directories'), -) - -BROKEN = '[wazophonebook]' -FIXED = '["wazophonebook"]' - - -def upgrade(): - _update_directories(BROKEN, FIXED) - - -def downgrade(): - _update_directories(FIXED, BROKEN) - - -def _update_directories(old, new): - op.execute( - cti_reverse - .update() - .where(cti_reverse.c.directories == old) - .values({'directories': new})) diff --git a/alembic/versions/67cdc9dfc2d0_remove_unused_tables.py b/alembic/versions/67cdc9dfc2d0_remove_unused_tables.py deleted file mode 100644 index 9c912df6..00000000 --- a/alembic/versions/67cdc9dfc2d0_remove_unused_tables.py +++ /dev/null @@ -1,78 +0,0 @@ -"""remove-unused-tables - -Revision ID: 67cdc9dfc2d0 -Revises: eddc1df1d57c - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '67cdc9dfc2d0' -down_revision = 'eddc1df1d57c' - - -def upgrade(): - op.drop_table('attachment') - op.drop_table('ctisheetactions') - op.drop_table('ctisheetevents') - op.drop_column('agentfeatures', 'numgroup') - op.drop_table('agentgroup') - - -def downgrade(): - op.create_table( - 'attachment', - sa.Column('id', sa.Integer, nullable=False, primary_key=True), - sa.Column('name', sa.String(64), nullable=False), - sa.Column('object_type', sa.String(16), nullable=False), - sa.Column('object_id', sa.Integer, nullable=False), - sa.Column('file', sa.Binary), - sa.Column('size', sa.Integer, nullable=False), - sa.Column('mime', sa.String(64), nullable=False), - ) - op.create_unique_constraint( - 'attachment_object_type_object_id_key', - 'attachment', - ['object_type', 'object_id'] - ) - - op.create_table( - 'ctisheetactions', - sa.Column('id', sa.Integer, primary_key=True), - sa.Column('name', sa.String(50)), - sa.Column('description', sa.Text, nullable=False), - sa.Column('whom', sa.String(50)), - sa.Column('sheet_info', sa.Text), - sa.Column('systray_info', sa.Text), - sa.Column('sheet_qtui', sa.Text), - sa.Column('action_info', sa.Text), - sa.Column('focus', sa.Integer), - sa.Column('deletable', sa.Integer), - sa.Column('disable', sa.Integer), - ) - - op.create_table( - 'ctisheetevents', - sa.Column('id', sa.Integer, primary_key=True), - sa.Column('incomingdid', sa.String(50)), - sa.Column('hangup', sa.String(50)), - sa.Column('dial', sa.String(50)), - sa.Column('link', sa.String(50)), - sa.Column('unlink', sa.String(50)), - ) - - op.create_table( - 'agentgroup', - sa.Column('id', sa.Integer, primary_key=True), - sa.Column('groupid', sa.Integer, nullable=False), - sa.Column('name', sa.String(128), nullable=False, server_default=''), - sa.Column('groups', sa.String(255), nullable=False, server_default=''), - sa.Column('commented', sa.Integer, nullable=False, server_default='0'), - sa.Column('deleted', sa.Integer, nullable=False, server_default='0'), - sa.Column('description', sa.Text), - ) - - op.add_column('agentfeatures', sa.Column('numgroup', sa.Integer, nullable=True)) diff --git a/alembic/versions/68507181de97_add_tenant_uuid_to_userfeatures.py b/alembic/versions/68507181de97_add_tenant_uuid_to_userfeatures.py deleted file mode 100644 index 1e8a99ae..00000000 --- a/alembic/versions/68507181de97_add_tenant_uuid_to_userfeatures.py +++ /dev/null @@ -1,55 +0,0 @@ -"""add tenant_uuid to userfeatures - -Revision ID: 68507181de97 -Revises: 3462497a56f8 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '68507181de97' -down_revision = '3462497a56f8' - - -def find_default_tenant_uuid(): - entity_table = sa.sql.table( - 'entity', - sa.sql.column('id'), - sa.sql.column('tenant_uuid'), - ) - query = sa.sql.select([entity_table.c.tenant_uuid]).order_by(entity_table.c.id) - for row in op.get_bind().execute(query): - return row.tenant_uuid - - -def associate_tenants(): - tbl = sa.sql.table('userfeatures', sa.sql.column('id'), sa.sql.column('tenant_uuid')) - sql = "SELECT userfeatures.id, entity.tenant_uuid FROM userfeatures, entity WHERE entity.id=userfeatures.entityid" - userfeatures_to_tenant = op.get_bind().execute(sa.sql.text(sql)) - - for userfeatures_id, tenant_uuid in userfeatures_to_tenant: - query = tbl.update().where(tbl.c.id == userfeatures_id).values(tenant_uuid=tenant_uuid) - op.execute(query) - - -def upgrade(): - default_tenant = find_default_tenant_uuid() - op.add_column( - 'userfeatures', - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid'), - nullable=False, - server_default=default_tenant, - ), - ) - associate_tenants() - op.alter_column('userfeatures', 'tenant_uuid', server_default=None) - - -def downgrade(): - op.drop_column('userfeatures', 'tenant_uuid') diff --git a/alembic/versions/69c55f395eb7_fix_global_trunk_template.py b/alembic/versions/69c55f395eb7_fix_global_trunk_template.py deleted file mode 100644 index eb0d190e..00000000 --- a/alembic/versions/69c55f395eb7_fix_global_trunk_template.py +++ /dev/null @@ -1,182 +0,0 @@ -"""fix-global-trunk-template - -Revision ID: 69c55f395eb7 -Revises: da53b63d9433 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '69c55f395eb7' -down_revision = 'da53b63d9433' - -tenant_tbl = sa.sql.table( - 'tenant', - sa.sql.column('uuid'), - sa.sql.column('global_trunk_sip_template_uuid'), - sa.sql.column('global_sip_template_uuid'), - sa.sql.column('sip_templates_generated'), -) -endpoint_sip_tbl = sa.sql.table( - 'endpoint_sip', - sa.sql.column('uuid'), - sa.sql.column('label'), - sa.sql.column('template'), - sa.sql.column('tenant_uuid'), -) -endpoint_sip_section_tbl = sa.sql.table( - 'endpoint_sip_section', - sa.sql.column('uuid'), - sa.sql.column('type'), - sa.sql.column('endpoint_sip_uuid'), -) -endpoint_sip_section_option_tbl = sa.sql.table( - 'endpoint_sip_section_option', - sa.sql.column('uuid'), - sa.sql.column('key'), - sa.sql.column('value'), - sa.sql.column('endpoint_sip_section_uuid'), -) -endpoint_sip_template_tbl = sa.sql.table( - 'endpoint_sip_template', - sa.sql.column('child_uuid'), - sa.sql.column('parent_uuid'), -) - - -def find_global_trunk_template_uuid(): - query = sa.sql.select( - [tenant_tbl.c.global_trunk_sip_template_uuid] - ).where(tenant_tbl.c.sip_templates_generated.is_(True)) - - return [ - row.global_trunk_sip_template_uuid - for row in op.get_bind().execute(query) - ] - - -def find_all_global_template_and_tenants(): - query = sa.sql.select( - [tenant_tbl.c.uuid, tenant_tbl.c.global_sip_template_uuid] - ).where(tenant_tbl.c.sip_templates_generated.is_(True)) - rows = op.get_bind().execute(query) - return {row.uuid: row.global_sip_template_uuid for row in rows} - - -def find_trunk_tenants(trunks): - query = sa.sql.select( - [endpoint_sip_tbl.c.uuid, endpoint_sip_tbl.c.tenant_uuid], - ).where(endpoint_sip_tbl.c.uuid.in_(trunks)) - rows = op.get_bind().execute(query) - return {row.uuid: row.tenant_uuid for row in rows} - - -def rename_templates(template_uuids): - query = endpoint_sip_tbl.update().values( - label='registration_trunk', - ).where( - endpoint_sip_tbl.c.uuid.in_(template_uuids), - ) - op.execute(query) - - -def rename_tenant_fk(old_name, new_name): - old_fk_name = 'tenant_{}_fkey'.format(old_name) - new_fk_name = 'tenant_{}_fkey'.format(new_name) - table = 'tenant' - op.alter_column(table, old_name, new_column_name=new_name) - op.drop_constraint( - constraint_name=old_fk_name, - table_name=table, - type_='foreignkey', - ) - op.create_foreign_key( - constraint_name=new_fk_name, - source_table=table, - referent_table='endpoint_sip', - local_cols=[new_name], - remote_cols=['uuid'], - ondelete='SET NULL', - ) - - -def dissociate_endpoints_with_no_sections(to_dissociate, templates): - query = endpoint_sip_template_tbl.delete().where(sa.and_( - endpoint_sip_template_tbl.c.parent_uuid.in_(templates), - endpoint_sip_template_tbl.c.child_uuid.in_(to_dissociate), - )) - op.execute(query) - - -def find_trunks_to_dissociate(endpoints_with_registrations, template_uuids): - query = sa.sql.select( - [endpoint_sip_template_tbl.c.child_uuid] - ).where(sa.and_( - endpoint_sip_template_tbl.c.parent_uuid.in_(template_uuids), - ~endpoint_sip_template_tbl.c.child_uuid.in_(endpoints_with_registrations), - )).distinct() - rows = op.get_bind().execute(query) - return [row.child_uuid for row in rows] - - -def remove_template_from_endpoint_without_registrations(template_uuids): - query = ( - sa.sql.select([endpoint_sip_tbl.c.uuid]) - .select_from( - endpoint_sip_tbl - .join( - endpoint_sip_section_tbl, - endpoint_sip_section_tbl.c.endpoint_sip_uuid == endpoint_sip_tbl.c.uuid, - ) - .join( - endpoint_sip_section_option_tbl, - endpoint_sip_section_option_tbl.c.endpoint_sip_section_uuid == endpoint_sip_section_tbl.c.uuid, - ) - ) - .where(endpoint_sip_tbl.c.template.is_(False)) - .where(endpoint_sip_section_tbl.c.type == 'registration') - .group_by(endpoint_sip_tbl.c.uuid) - ) - endpoints_with_registration = op.get_bind().execute(query) - endpoint_uuids = [endpoint.uuid for endpoint in endpoints_with_registration] - - trunks_to_dissociate = find_trunks_to_dissociate(endpoint_uuids, template_uuids) - dissociate_endpoints_with_no_sections(trunks_to_dissociate, template_uuids) - return trunks_to_dissociate - - -def associate_trunks_to_global_template(trunks): - trunks_to_tenant = find_trunk_tenants(trunks) - tenant_to_template = find_all_global_template_and_tenants() - for trunk in trunks: - tenant = trunks_to_tenant.get(trunk) - template = tenant_to_template.get(tenant) - if not template: - continue - - query = endpoint_sip_template_tbl.insert().values( - child_uuid=trunk, - parent_uuid=template, - ) - op.execute(query) - - -def upgrade(): - template_uuids = find_global_trunk_template_uuid() - rename_templates(template_uuids) - rename_tenant_fk( - old_name='global_trunk_sip_template_uuid', - new_name='registration_trunk_sip_template_uuid', - ) - unassociated_trunks = remove_template_from_endpoint_without_registrations(template_uuids) - associate_trunks_to_global_template(unassociated_trunks) - - -def downgrade(): - rename_tenant_fk( - old_name='registration_trunk_sip_template_uuid', - new_name='global_trunk_sip_template_uuid', - ) diff --git a/alembic/versions/6a08e32fadba_add_default_sccp_provisioning_values.py b/alembic/versions/6a08e32fadba_add_default_sccp_provisioning_values.py deleted file mode 100644 index e6bbc8c1..00000000 --- a/alembic/versions/6a08e32fadba_add_default_sccp_provisioning_values.py +++ /dev/null @@ -1,37 +0,0 @@ -"""add default sccp provisioning values - -Revision ID: 6a08e32fadba -Revises: 34748356e196 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '6a08e32fadba' -down_revision = '34748356e196' - -TABLE_NAME = 'sccpgeneralsettings' -SCCP_GENERAL_SETTINGS_TABLE = sa.sql.table( - TABLE_NAME, - sa.sql.column('option_name'), - sa.sql.column('option_value'), -) -DEFAULT_CONFIG = { - 'guest': 'no', - 'max_guests': '100', -} - - -def upgrade(): - values = [{'option_name': name, 'option_value': value} for name, value in DEFAULT_CONFIG.items()] - op.bulk_insert(SCCP_GENERAL_SETTINGS_TABLE, values) - - -def downgrade(): - query = SCCP_GENERAL_SETTINGS_TABLE.delete().where( - SCCP_GENERAL_SETTINGS_TABLE.c.option_name.in_(list(DEFAULT_CONFIG.keys())) - ) - op.execute(query) diff --git a/alembic/versions/6aead6a54bbb_update_uniqueconstraint_queuemember.py b/alembic/versions/6aead6a54bbb_update_uniqueconstraint_queuemember.py deleted file mode 100644 index 24504152..00000000 --- a/alembic/versions/6aead6a54bbb_update_uniqueconstraint_queuemember.py +++ /dev/null @@ -1,29 +0,0 @@ -"""update_uniqueconstraint_queuemember - -Revision ID: 6aead6a54bbb -Revises: 2984e5ede175 - -""" - -# revision identifiers, used by Alembic. -revision = '6aead6a54bbb' -down_revision = '2984e5ede175' - -from alembic import op - - -table_name = 'queuemember' -old_columns_name = ['queue_name', 'channel', 'usertype', 'userid', 'category'] -new_columns_name = ['queue_name', 'channel', 'interface', 'usertype', 'userid', 'category', 'position'] -old_constraint_name = '{}_{}_key'.format(table_name, '_'.join(old_columns_name)) -new_constraint_name = '{}_queue_name_channel_interface_usertype_userid_ca_key'.format(table_name) - - -def upgrade(): - op.drop_constraint(old_constraint_name, table_name) - op.create_unique_constraint(new_constraint_name, table_name, new_columns_name) - - -def downgrade(): - op.drop_constraint(new_constraint_name, table_name) - op.create_unique_constraint(old_constraint_name, table_name, old_columns_name) diff --git a/alembic/versions/6afcf16a334d_add_auth_tenants_read_to_auth.py b/alembic/versions/6afcf16a334d_add_auth_tenants_read_to_auth.py deleted file mode 100644 index acc0ec12..00000000 --- a/alembic/versions/6afcf16a334d_add_auth_tenants_read_to_auth.py +++ /dev/null @@ -1,44 +0,0 @@ -"""add_auth_tenants_read_to_auth - -Revision ID: 6afcf16a334d -Revises: e3f5e62ef9dd - -""" - -from alembic import op -from sqlalchemy import sql -from sqlalchemy.dialects.postgresql import ARRAY, VARCHAR - -# revision identifiers, used by Alembic. -revision = '6afcf16a334d' -down_revision = 'e3f5e62ef9dd' - -accesswebservice = sql.table( - 'accesswebservice', - sql.column('id'), - sql.column('name'), - sql.column('acl'), -) - -NEW_ACLS = ['auth.tenants.read', 'confd.users.*.read'] -OLD_ACLS = ['confd.users.read'] -SERVICE = 'wazo-auth' - - -def upgrade(): - _replace_acl(SERVICE, NEW_ACLS) - - -def downgrade(): - _replace_acl(SERVICE, OLD_ACLS) - - -def _replace_acl(service, new_acls): - acls = sql.cast(new_acls, ARRAY(VARCHAR)) - query = ( - accesswebservice - .update() - .values(acl=acls) - .where(accesswebservice.c.name == service) - ) - op.execute(query) diff --git a/alembic/versions/6bfd932df2c_add_user_contact_table.py b/alembic/versions/6bfd932df2c_add_user_contact_table.py deleted file mode 100644 index 65c0ce95..00000000 --- a/alembic/versions/6bfd932df2c_add_user_contact_table.py +++ /dev/null @@ -1,65 +0,0 @@ -"""add user_contact table - -Revision ID: 6bfd932df2c -Revises: 148a96399123 - -""" - -# revision identifiers, used by Alembic. -revision = '6bfd932df2c' -down_revision = '148a96399123' - -from alembic import op -import sqlalchemy as sa - - -phonebook_table = sa.sql.table( - 'phonebook', - sa.sql.column('id'), -) - - -def upgrade(): - op.create_table( - 'user_contact', - sa.Column('user_id', sa.Integer), - sa.Column('phonebook_id', sa.Integer), - sa.PrimaryKeyConstraint('user_id', 'phonebook_id'), - sa.ForeignKeyConstraint( - ['phonebook_id'], - ['phonebook.id'], - name='fk_phonebook_id', - ondelete='CASCADE', - ), - sa.ForeignKeyConstraint( - ['user_id'], - ['userfeatures.id'], - name='fk_user_id', - ondelete='CASCADE', - ), - ) - - -def downgrade(): - _remove_private_contacts() - op.drop_table('user_contact') - - -def _remove_private_contacts(): - user_contact_table = sa.sql.table( - 'user_contact', - sa.sql.column('user_id'), - sa.sql.column('phonebook_id'), - ) - - personal_contact_query = ( - sa.sql.select( - [user_contact_table.c.phonebook_id] - ) - ) - - delete_query = ( - phonebook_table.delete().where(phonebook_table.c.id.in_(personal_contact_query)) - ) - - op.get_bind().execute(delete_query) diff --git a/alembic/versions/6e196b7526a_drop_usersip_realtime_columns.py b/alembic/versions/6e196b7526a_drop_usersip_realtime_columns.py deleted file mode 100644 index beeb7b32..00000000 --- a/alembic/versions/6e196b7526a_drop_usersip_realtime_columns.py +++ /dev/null @@ -1,29 +0,0 @@ -"""drop usersip realtime columns - -Revision ID: 6e196b7526a -Revises: 3284584a535c - -""" - -# revision identifiers, used by Alembic. -revision = '6e196b7526a' -down_revision = '3284584a535c' - -from alembic import op -from sqlalchemy import Column, Integer, String - - -def upgrade(): - op.drop_column('usersip', 'fullcontact') - op.drop_column('usersip', 'ipaddr') - op.drop_column('usersip', 'regseconds') - op.drop_column('usersip', 'regserver') - op.drop_column('usersip', 'lastms') - - -def downgrade(): - op.add_column('usersip', Column('fullcontact', String(255))) - op.add_column('usersip', Column('ipaddr', String(255), nullable=False, server_default='')) - op.add_column('usersip', Column('regseconds', Integer, nullable=False, server_default='0')) - op.add_column('usersip', Column('regserver', String(20))) - op.add_column('usersip', Column('lastms', String(15), nullable=False, server_default='')) diff --git a/alembic/versions/6fc79e30e8bf_add_user_external_app_table.py b/alembic/versions/6fc79e30e8bf_add_user_external_app_table.py deleted file mode 100644 index 82fcacd4..00000000 --- a/alembic/versions/6fc79e30e8bf_add_user_external_app_table.py +++ /dev/null @@ -1,33 +0,0 @@ -"""add_user_external_app_table - -Revision ID: 6fc79e30e8bf -Revises: c1d845eb61b4 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '6fc79e30e8bf' -down_revision = 'c1d845eb61b4' - - -def upgrade(): - op.create_table( - 'user_external_app', - sa.Column('name', sa.Text, primary_key=True), - sa.Column( - 'user_uuid', - sa.String(38), - sa.ForeignKey('userfeatures.uuid', ondelete='CASCADE'), - primary_key=True - ), - sa.Column('label', sa.Text), - sa.Column('configuration', sa.JSON), - ) - - -def downgrade(): - op.drop_table('user_external_app') diff --git a/alembic/versions/6ff776dde35e_add_mark_answered_elsewhere_column_.py b/alembic/versions/6ff776dde35e_add_mark_answered_elsewhere_column_.py deleted file mode 100644 index 624f2460..00000000 --- a/alembic/versions/6ff776dde35e_add_mark_answered_elsewhere_column_.py +++ /dev/null @@ -1,30 +0,0 @@ -"""add mark_answered_elsewhere column groupfeatures queuefeatures - -Revision ID: 6ff776dde35e -Revises: 108f435e1af2 - -""" - -from alembic import op -from sqlalchemy import Column, Integer - - -# revision identifiers, used by Alembic. -revision = '6ff776dde35e' -down_revision = '108f435e1af2' - -COLUMN_NAME = 'mark_answered_elsewhere' - - -def upgrade(): - # on upgrade, existing queues and groups will have "mark_answered_elsewhere" set to 0 (so - # the queue/group behaviour doesn't change on upgrade), but newly created queues will have - # by default "mark_answered_elsewhere" set to 1 - op.add_column('groupfeatures', Column(COLUMN_NAME, Integer, nullable=False, server_default='0')) - op.add_column('queuefeatures', Column(COLUMN_NAME, Integer, nullable=False, server_default='0')) - op.alter_column('queuefeatures', COLUMN_NAME, server_default='1') - - -def downgrade(): - op.drop_column('groupfeatures', COLUMN_NAME) - op.drop_column('queuefeatures', COLUMN_NAME) diff --git a/alembic/versions/700711f75ee6_alter_provisioning_remove_not_null_.py b/alembic/versions/700711f75ee6_alter_provisioning_remove_not_null_.py deleted file mode 100644 index c89fbddf..00000000 --- a/alembic/versions/700711f75ee6_alter_provisioning_remove_not_null_.py +++ /dev/null @@ -1,26 +0,0 @@ -"""alter provisioning remove not null constraint - -Revision ID: 700711f75ee6 -Revises: 4c79fd76bccb - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '700711f75ee6' -down_revision = '4c79fd76bccb' - -TABLE = 'provisioning' - - -def upgrade(): - op.alter_column(TABLE, 'net4_ip', nullable=True) - op.alter_column(TABLE, 'net4_ip_rest', nullable=True) - - -def downgrade(): - op.alter_column(TABLE, 'net4_ip', nullable=False) - op.alter_column(TABLE, 'net4_ip_rest', nullable=False) diff --git a/alembic/versions/706a7655606e_add_the_meeting_table.py b/alembic/versions/706a7655606e_add_the_meeting_table.py deleted file mode 100644 index 1976252f..00000000 --- a/alembic/versions/706a7655606e_add_the_meeting_table.py +++ /dev/null @@ -1,57 +0,0 @@ -"""add the meeting table - -Revision ID: 706a7655606e -Revises: 3edd3b3aac7d - -""" - -from sqlalchemy.sql.schema import ForeignKey -from alembic import op -import sqlalchemy as sa - -from sqlalchemy.dialects.postgresql import UUID - - -# revision identifiers, used by Alembic. -revision = '706a7655606e' -down_revision = '3edd3b3aac7d' - - -def upgrade(): - op.create_table( - 'meeting', - sa.Column('uuid', UUID, server_default=sa.text('uuid_generate_v4()'), primary_key=True), - sa.Column('name', sa.Text), - sa.Column( - 'guest_endpoint_sip_uuid', - UUID, - sa.ForeignKey('endpoint_sip.uuid', ondelete='SET NULL'), - ), - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=False, - ) - ) - - op.create_table( - 'meeting_owner', - sa.Column( - 'meeting_uuid', - UUID, - sa.ForeignKey('meeting.uuid', ondelete='CASCADE'), - primary_key=True, - ), - sa.Column( - 'user_uuid', - sa.String(38), # 38 is the length of the userfeatures.uuid field - sa.ForeignKey('userfeatures.uuid', ondelete='CASCADE'), - primary_key=True, - ), - ) - - -def downgrade(): - op.drop_table('meeting_owner') - op.drop_table('meeting') diff --git a/alembic/versions/71c41130380e_drop_accesswebservice_table.py b/alembic/versions/71c41130380e_drop_accesswebservice_table.py deleted file mode 100644 index 0700b233..00000000 --- a/alembic/versions/71c41130380e_drop_accesswebservice_table.py +++ /dev/null @@ -1,20 +0,0 @@ -"""drop_accesswebservice_table - -Revision ID: 71c41130380e -Revises: 117b51a2d937 - -""" - -from alembic import op - -# revision identifiers, used by Alembic. -revision = '71c41130380e' -down_revision = '117b51a2d937' - - -def upgrade(): - op.drop_table('accesswebservice') - - -def downgrade(): - pass diff --git a/alembic/versions/73166af50deb_fix_trunk_with_host_migration.py b/alembic/versions/73166af50deb_fix_trunk_with_host_migration.py deleted file mode 100644 index 23730fc6..00000000 --- a/alembic/versions/73166af50deb_fix_trunk_with_host_migration.py +++ /dev/null @@ -1,133 +0,0 @@ -"""fix trunk with host migration - -Revision ID: 73166af50deb -Revises: 45ec6bd040ac - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '73166af50deb' -down_revision = '45ec6bd040ac' - -user_sip_tbl = sa.sql.table( - 'usersip', - sa.sql.column('name'), - sa.sql.column('category'), - sa.sql.column('host'), - sa.sql.column('username'), - sa.sql.column('port'), -) -endpoint_sip_tbl = sa.sql.table( - 'endpoint_sip', - sa.sql.column('uuid'), - sa.sql.column('name'), -) -endpoint_sip_section_tbl = sa.sql.table( - 'endpoint_sip_section', - sa.sql.column('uuid'), - sa.sql.column('type'), - sa.sql.column('endpoint_sip_uuid'), -) -endpoint_sip_section_option_tbl = sa.sql.table( - 'endpoint_sip_section_option', - sa.sql.column('uuid'), - sa.sql.column('key'), - sa.sql.column('value'), - sa.sql.column('endpoint_sip_section_uuid'), -) - - -def get_trunk_with_host(): - query = sa.sql.select([ - user_sip_tbl.c.name, - user_sip_tbl.c.host, - user_sip_tbl.c.username, - user_sip_tbl.c.port, - ]).where( - sa.and_( - user_sip_tbl.c.category == 'trunk', - user_sip_tbl.c.host != 'dynamic', - ) - ) - rows = op.get_bind().execute(query) - return [{ - 'name': row.name, - 'host': row.host, - 'username': row.username, - 'port': row.port, - } for row in rows] - - -def convert_host_to_contact(trunk): - result = 'sip:' - - username = trunk.get('username') - if username: - result += username + '@' - - result += trunk['host'] - port = trunk.get('port') or '5060' - result += ':' + str(port) - return result - - -def find_endpoint_sip(trunk): - query = sa.sql.select([ - endpoint_sip_tbl.c.uuid - ]).where(endpoint_sip_tbl.c.name == trunk['name']) - for row in op.get_bind().execute(query): - return row.uuid - - -def find_aor_section(endpoint_uuid): - query = sa.sql.select([ - endpoint_sip_section_tbl.c.uuid - ]).where(sa.and_( - endpoint_sip_section_tbl.c.type == 'aor', - endpoint_sip_section_tbl.c.endpoint_sip_uuid == endpoint_uuid, - )) - for row in op.get_bind().execute(query): - return row.uuid - - -def create_aor_section(endpoint_uuid): - query = endpoint_sip_section_tbl.insert().returning( - endpoint_sip_section_tbl.c.uuid, - ).values( - endpoint_sip_uuid=endpoint_uuid, - type='aor', - ) - return op.get_bind().execute(query).scalar() - - -def add_section_option(section_uuid, key, value): - query = endpoint_sip_section_option_tbl.insert().values( - key=key, value=value, endpoint_sip_section_uuid=section_uuid, - ) - op.execute(query) - - -def add_contact_to_endpoint(endpoint_uuid, contact): - aor_section_uuid = find_aor_section(endpoint_uuid) - if not aor_section_uuid: - aor_section_uuid = create_aor_section(endpoint_uuid) - - add_section_option(aor_section_uuid, 'contact', contact) - - -def upgrade(): - trunks_with_host = get_trunk_with_host() - for trunk in trunks_with_host: - matching_endpoint_uuid = find_endpoint_sip(trunk) - if not matching_endpoint_uuid: - continue - contact = convert_host_to_contact(trunk) - add_contact_to_endpoint(matching_endpoint_uuid, contact) - - -def downgrade(): - pass diff --git a/alembic/versions/732a9b6500da_bump_version_19_15.py b/alembic/versions/732a9b6500da_bump_version_19_15.py deleted file mode 100644 index 0f6c8511..00000000 --- a/alembic/versions/732a9b6500da_bump_version_19_15.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_19_15 - -Revision ID: 732a9b6500da -Revises: 5faf5386dca8 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '732a9b6500da' -down_revision = '5faf5386dca8' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='19.15')) - - -def downgrade(): - pass diff --git a/alembic/versions/73889d1db031_queueskillrule_add_tenant_uuid.py b/alembic/versions/73889d1db031_queueskillrule_add_tenant_uuid.py deleted file mode 100644 index e6effbea..00000000 --- a/alembic/versions/73889d1db031_queueskillrule_add_tenant_uuid.py +++ /dev/null @@ -1,53 +0,0 @@ -"""queueskillrule add tenant_uuid - -Revision ID: 73889d1db031 -Revises: eaffdf929dd1 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '73889d1db031' -down_revision = 'eaffdf929dd1' - -queueskillrule_tbl = sa.sql.table('queueskillrule', sa.sql.column('tenant_uuid')) -queuefeatures_tbl = sa.sql.table('queuefeatures', sa.sql.column('tenant_uuid')) - - -def associate_tenants(): - query = sa.sql.select([queuefeatures_tbl.c.tenant_uuid]) - result = op.get_bind().execute(query).first() - - if result: - tenant_uuid = result[0] - query = ( - queueskillrule_tbl.update() - .values(tenant_uuid=tenant_uuid) - ) - op.execute(query) - else: - query = queueskillrule_tbl.delete() - op.execute(query) - - -def upgrade(): - op.add_column( - 'queueskillrule', - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=True - ) - ) - - associate_tenants() - - op.alter_column('queueskillrule', 'tenant_uuid', nullable=False) - - -def downgrade(): - op.drop_column('queueskillrule', 'tenant_uuid') diff --git a/alembic/versions/74a76197acaa_bump_version_18_12.py b/alembic/versions/74a76197acaa_bump_version_18_12.py deleted file mode 100644 index b35e1b32..00000000 --- a/alembic/versions/74a76197acaa_bump_version_18_12.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_18_12 - -Revision ID: 74a76197acaa -Revises: ce624f5d7fe2 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '74a76197acaa' -down_revision = 'ce624f5d7fe2' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='18.12')) - - -def downgrade(): - pass diff --git a/alembic/versions/7541da6ac48f_bump_version_22_09.py b/alembic/versions/7541da6ac48f_bump_version_22_09.py deleted file mode 100644 index f48f4788..00000000 --- a/alembic/versions/7541da6ac48f_bump_version_22_09.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_22_09 - -Revision ID: 7541da6ac48f -Revises: ae5bee40e9d2 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '7541da6ac48f' -down_revision = 'ae5bee40e9d2' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='22.09')) - - -def downgrade(): - pass diff --git a/alembic/versions/757111d049b6_add_the_tenant_slug.py b/alembic/versions/757111d049b6_add_the_tenant_slug.py deleted file mode 100644 index f3920b3d..00000000 --- a/alembic/versions/757111d049b6_add_the_tenant_slug.py +++ /dev/null @@ -1,22 +0,0 @@ -"""add the tenant slug - -Revision ID: 757111d049b6 -Revises: 382aaefc59ec - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '757111d049b6' -down_revision = '382aaefc59ec' - - -def upgrade(): - op.add_column('tenant', sa.Column('slug', sa.String(10))) - - -def downgrade(): - op.drop_column('tenant', 'slug') diff --git a/alembic/versions/7628599d48dc_pickup_add_tenant_uuid.py b/alembic/versions/7628599d48dc_pickup_add_tenant_uuid.py deleted file mode 100644 index 6a3be968..00000000 --- a/alembic/versions/7628599d48dc_pickup_add_tenant_uuid.py +++ /dev/null @@ -1,55 +0,0 @@ -"""pickup_add_tenant_uuid - -Revision ID: 7628599d48dc -Revises: 3f132402532b - -""" - -from alembic import op -import sqlalchemy as sa - -# revision identifiers, used by Alembic. -revision = '7628599d48dc' -down_revision = '3f132402532b' - -TABLE = 'pickup' - - -def find_default_tenant_uuid(): - entity_table = sa.sql.table( - 'entity', - sa.sql.column('id'), - sa.sql.column('tenant_uuid'), - ) - query = sa.sql.select([entity_table.c.tenant_uuid]).order_by(entity_table.c.id) - for row in op.get_bind().execute(query): - return row.tenant_uuid - - -def associate_tenants(): - tbl = sa.sql.table('pickup', sa.sql.column('id'), sa.sql.column('tenant_uuid')) - sql = "SELECT pickup.id, entity.tenant_uuid FROM pickup, entity WHERE entity.id=pickup.entity_id" - pickup_to_tenant = op.get_bind().execute(sa.sql.text(sql)) - - for pickup_id, tenant_uuid in pickup_to_tenant: - query = tbl.update().where(tbl.c.id == pickup_id).values(tenant_uuid=tenant_uuid) - op.execute(query) - - -def upgrade(): - default_tenant = find_default_tenant_uuid() - op.add_column( - TABLE, - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=False, - server_default=default_tenant), - ) - associate_tenants() - op.alter_column(TABLE, 'tenant_uuid', server_default=None) - - -def downgrade(): - op.drop_column(TABLE, 'tenant_uuid') diff --git a/alembic/versions/778dc763148f_add_auth_tenants_read_to_dird.py b/alembic/versions/778dc763148f_add_auth_tenants_read_to_dird.py deleted file mode 100644 index 255e2ce7..00000000 --- a/alembic/versions/778dc763148f_add_auth_tenants_read_to_dird.py +++ /dev/null @@ -1,50 +0,0 @@ -"""add_auth_tenants_read_to_dird - -Revision ID: 778dc763148f -Revises: 6afcf16a334d - -""" - -from alembic import op -from sqlalchemy import sql -from sqlalchemy.dialects.postgresql import ARRAY, VARCHAR - -# revision identifiers, used by Alembic. -revision = '778dc763148f' -down_revision = '6afcf16a334d' - -accesswebservice = sql.table( - 'accesswebservice', - sql.column('id'), - sql.column('name'), - sql.column('acl'), -) - -ACLS = ['auth.tenants.read'] -SERVICE = 'wazo-dird-xivo-backend' - - -def upgrade(): - acls = sql.cast(ACLS, ARRAY(VARCHAR)) - query = ( - accesswebservice - .update() - .values( - acl=sql.func.array_cat(accesswebservice.c.acl, acls)) - .where( - accesswebservice.c.name == SERVICE) - ) - op.execute(query) - - -def downgrade(): - for acl in ACLS: - query = ( - accesswebservice - .update() - .values( - acl=sql.func.array_remove(accesswebservice.c.acl, acl)) - .where( - accesswebservice.c.name == SERVICE) - ) - op.execute(query) diff --git a/alembic/versions/785b8cb74daa_revert_version_upgrade.py b/alembic/versions/785b8cb74daa_revert_version_upgrade.py deleted file mode 100644 index c176e69b..00000000 --- a/alembic/versions/785b8cb74daa_revert_version_upgrade.py +++ /dev/null @@ -1,23 +0,0 @@ -"""revert version upgrade - -Revision ID: 785b8cb74daa -Revises: 93ea61395eef - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '785b8cb74daa' -down_revision = '93ea61395eef' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='21.16')) - - -def downgrade(): - pass diff --git a/alembic/versions/7b3b0ff90f0c_add_name_column_to_paging.py b/alembic/versions/7b3b0ff90f0c_add_name_column_to_paging.py deleted file mode 100644 index 2ea8e2c2..00000000 --- a/alembic/versions/7b3b0ff90f0c_add_name_column_to_paging.py +++ /dev/null @@ -1,23 +0,0 @@ -"""add_name_column_to_paging - -Revision ID: 7b3b0ff90f0c -Revises: 8a551a46dd5d - -""" - -# revision identifiers, used by Alembic. -revision = '7b3b0ff90f0c' -down_revision = '8a551a46dd5d' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - op.add_column('paging', sa.Column('name', sa.String(128))) - op.alter_column('paging', 'timeout', server_default='30') - - -def downgrade(): - op.alter_column('paging', 'timeout', server_default=None) - op.drop_column('paging', 'name') diff --git a/alembic/versions/7d342adb6ae1_bump_version_22_14.py b/alembic/versions/7d342adb6ae1_bump_version_22_14.py deleted file mode 100644 index 5ebe7691..00000000 --- a/alembic/versions/7d342adb6ae1_bump_version_22_14.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_22_14 - -Revision ID: 7d342adb6ae1 -Revises: f9ea1046c8e5 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '7d342adb6ae1' -down_revision = 'f9ea1046c8e5' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='22.14')) - - -def downgrade(): - pass diff --git a/alembic/versions/7d47aaef973a_bump_version_19_07.py b/alembic/versions/7d47aaef973a_bump_version_19_07.py deleted file mode 100644 index 0ee19094..00000000 --- a/alembic/versions/7d47aaef973a_bump_version_19_07.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_19_07 - -Revision ID: 7d47aaef973a -Revises: 9b0892a818e6 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '7d47aaef973a' -down_revision = '9b0892a818e6' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='19.07')) - - -def downgrade(): - pass diff --git a/alembic/versions/7d91d22133a9_bump_version_20_08.py b/alembic/versions/7d91d22133a9_bump_version_20_08.py deleted file mode 100644 index 7f8531d8..00000000 --- a/alembic/versions/7d91d22133a9_bump_version_20_08.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_20_08 - -Revision ID: 7d91d22133a9 -Revises: 2a27e01c8070 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '7d91d22133a9' -down_revision = '2a27e01c8070' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='20.08')) - - -def downgrade(): - pass diff --git a/alembic/versions/7f1c1c00662_remove_invalid_chars_from_label.py b/alembic/versions/7f1c1c00662_remove_invalid_chars_from_label.py deleted file mode 100644 index 7c191502..00000000 --- a/alembic/versions/7f1c1c00662_remove_invalid_chars_from_label.py +++ /dev/null @@ -1,62 +0,0 @@ -"""remove_invalid_chars_from_label - -Revision ID: 7f1c1c00662 -Revises: 53ce4ff6ffe9 - -""" - -from alembic import op -from sqlalchemy import sql - -# revision identifiers, used by Alembic. -revision = '7f1c1c00662' -down_revision = '53ce4ff6ffe9' - -fk_mapping = sql.table('func_key_mapping', - sql.column('label')) - -dest_custom = sql.table('func_key_dest_custom', - sql.column('exten')) - -dest_forward = sql.table('func_key_dest_forward', - sql.column('number')) - - -INVALID_CHARS = "\n\r\t;" - - -def upgrade(): - query = (fk_mapping - .update() - .values( - label=sql.func.translate(fk_mapping.c.label, - INVALID_CHARS, - '')) - .where( - fk_mapping.c.label != None) # noqa - ) - op.execute(query) - - query = (dest_custom - .update() - .values( - exten=sql.func.translate(dest_custom.c.exten, - INVALID_CHARS, - '')) - ) - op.execute(query) - - query = (dest_forward - .update() - .values( - number=sql.func.translate(dest_forward.c.number, - INVALID_CHARS, - '')) - .where( - dest_forward.c.number != None) # noqa - ) - op.execute(query) - - -def downgrade(): - pass diff --git a/alembic/versions/7f337d6ca187_unset_context_queue_from_groupfeatures.py b/alembic/versions/7f337d6ca187_unset_context_queue_from_groupfeatures.py deleted file mode 100644 index 1efac83c..00000000 --- a/alembic/versions/7f337d6ca187_unset_context_queue_from_groupfeatures.py +++ /dev/null @@ -1,31 +0,0 @@ -"""unset_context_queue_from_groupfeatures - -Revision ID: 7f337d6ca187 -Revises: c8abcc5497ef - -""" - -from alembic import op -from sqlalchemy import sql - -# revision identifiers, used by Alembic. -revision = '7f337d6ca187' -down_revision = 'c8abcc5497ef' - -queue_tbl = sql.table( - 'queue', - sql.column('category'), - sql.column('context'), -) - - -def upgrade(): - op.execute( - queue_tbl.update() - .where(queue_tbl.c.category == 'group') - .values(context=None) - ) - - -def downgrade(): - pass diff --git a/alembic/versions/8452bc3d5d67_conferences_add_tenant_uuid.py b/alembic/versions/8452bc3d5d67_conferences_add_tenant_uuid.py deleted file mode 100644 index 088fae9b..00000000 --- a/alembic/versions/8452bc3d5d67_conferences_add_tenant_uuid.py +++ /dev/null @@ -1,64 +0,0 @@ -"""conferences add tenant_uuid - -Revision ID: 8452bc3d5d67 -Revises: 08a23688eaf7 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '8452bc3d5d67' -down_revision = '08a23688eaf7' - -TABLE = 'conference' - - -def find_default_tenant_uuid(): - entity_table = sa.sql.table( - 'entity', - sa.sql.column('id'), - sa.sql.column('name'), - sa.sql.column('tenant_uuid'), - ) - query = sa.sql.select([entity_table.c.tenant_uuid]).order_by(entity_table.c.id) - for row in op.get_bind().execute(query): - return row.tenant_uuid - - -def get_context_tenant_map(): - tbl = sa.sql.table('context', sa.sql.column('name'), sa.sql.column('tenant_uuid')) - query = sa.sql.select([tbl.c.name, tbl.c.tenant_uuid]) - rows = op.get_bind().execute(query) - return {row.name: row.tenant_uuid for row in rows} - - -def associate_tenants(): - tbl = sa.sql.table('conference', sa.sql.column('id'), sa.sql.column('tenant_uuid')) - sql = "SELECT conference.id, context.tenant_uuid FROM conference, extensions, context WHERE extensions.type='conference' AND extensions.typeval=CAST(conference.id AS text) AND extensions.context = context.name" - conference_to_tenant = op.get_bind().execute(sa.sql.text(sql)) - - for conference_id, tenant_uuid in conference_to_tenant: - query = tbl.update().where(tbl.c.id == conference_id).values(tenant_uuid=tenant_uuid) - op.execute(query) - - -def upgrade(): - default_tenant = find_default_tenant_uuid() - op.add_column( - TABLE, - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=False, - server_default=default_tenant), - ) - associate_tenants() - op.alter_column(TABLE, 'tenant_uuid', server_default=None) - - -def downgrade(): - op.drop_column(TABLE, 'tenant_uuid') diff --git a/alembic/versions/84d91026c293_add_switchboard_moh.py b/alembic/versions/84d91026c293_add_switchboard_moh.py deleted file mode 100644 index 3e416bac..00000000 --- a/alembic/versions/84d91026c293_add_switchboard_moh.py +++ /dev/null @@ -1,37 +0,0 @@ -"""add switchboard moh - -Revision ID: 84d91026c293 -Revises: 9eeb96b396a7 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '84d91026c293' -down_revision = '9eeb96b396a7' - -COLUMN_NAMES = [ - 'hold_moh_uuid', - 'queue_moh_uuid', -] - - -def upgrade(): - for column_name in COLUMN_NAMES: - op.add_column( - 'switchboard', - sa.Column( - column_name, - sa.String(38), - sa.ForeignKey('moh.uuid', ondelete='SET NULL'), - nullable=True, - ) - ) - - -def downgrade(): - for column_name in COLUMN_NAMES: - op.drop_column('switchboard', column_name) diff --git a/alembic/versions/86511ef5d49_add_displayname_field_in_source_.py b/alembic/versions/86511ef5d49_add_displayname_field_in_source_.py deleted file mode 100644 index b98a1983..00000000 --- a/alembic/versions/86511ef5d49_add_displayname_field_in_source_.py +++ /dev/null @@ -1,66 +0,0 @@ -"""add displayname and phone fields in source definition - -Revision ID: 86511ef5d49 -Revises: 2c004153ed7f - -""" - -# revision identifiers, used by Alembic. -revision = '86511ef5d49' -down_revision = '2c004153ed7f' - -from alembic import op -from sqlalchemy import sql, and_ - - -directories = sql.table('ctidirectories', - sql.column('id'), - sql.column('name')) -directory_fields = sql.table('ctidirectoryfields', - sql.column('dir_id'), - sql.column('fieldname'), - sql.column('value')) - - -def upgrade(): - _add_directory_field('xivodir', 'display_name', '{phonebook.displayname}') - _add_directory_field('xivodir', 'phone', '{phonebooknumber.office.number}') - _add_directory_field('xivodir', 'phone_mobile', '{phonebooknumber.mobile.number}') - _add_directory_field('xivodir', 'phone_home', '{phonebooknumber.home.number}') - _add_directory_field('xivodir', 'phone_other', '{phonebooknumber.other.number}') - _add_directory_field('internal', 'display_name', '{firstname} {lastname}') - _add_directory_field('internal', 'phone', '{exten}') - - -def _add_directory_field(directory_name, field_name, value): - directory_id = _get_directory_id(directory_name) - if not directory_id: - return - - if not _have_directory_field(directory_id, field_name): - _insert_directory_field(directory_id, field_name, value) - - -def _get_directory_id(directory_name): - row = op.get_bind().execute(sql.select([directories.c.id]) - .where(directories.c.name == directory_name)).first() - return row.id if row else None - - -def _have_directory_field(directory_id, field_name): - row = op.get_bind().execute(sql.select([directory_fields.c.dir_id]) - .where(and_(directory_fields.c.dir_id == directory_id, - directory_fields.c.fieldname == field_name))).first() - return bool(row) - - -def _insert_directory_field(directory_id, field_name, value): - op.execute(directory_fields - .insert() - .values(dir_id=directory_id, - fieldname=field_name, - value=value)) - - -def downgrade(): - pass diff --git a/alembic/versions/867bd9268824_bump_version_21_03.py b/alembic/versions/867bd9268824_bump_version_21_03.py deleted file mode 100644 index dc8872fb..00000000 --- a/alembic/versions/867bd9268824_bump_version_21_03.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_21_03 - -Revision ID: 867bd9268824 -Revises: e5281e98b300 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '867bd9268824' -down_revision = 'e5281e98b300' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='21.03')) - - -def downgrade(): - pass diff --git a/alembic/versions/8691b32cf44e_remove_phonebook_enums.py b/alembic/versions/8691b32cf44e_remove_phonebook_enums.py deleted file mode 100644 index 8c558595..00000000 --- a/alembic/versions/8691b32cf44e_remove_phonebook_enums.py +++ /dev/null @@ -1,29 +0,0 @@ -"""remove phonebook enums - -Revision ID: 8691b32cf44e -Revises: 66453e75a1fd - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '8691b32cf44e' -down_revision = '66453e75a1fd' - -phonebook_title = sa.Enum('mr', 'mrs', 'ms', name='phonebook_title') -phonebookaddress_type = sa.Enum('home', 'office', 'other', name='phonebookaddress_type') -phonebooknumber_type = sa.Enum('home', 'office', 'mobile', 'fax', 'other', name='phonebooknumber_type') - - -def upgrade(): - phonebook_title.drop(op.get_bind(), checkfirst=True) - phonebookaddress_type.drop(op.get_bind(), checkfirst=True) - phonebooknumber_type.drop(op.get_bind(), checkfirst=True) - - -def downgrade(): - # No downgrade, since the tables using the enums do not exist anymore - pass diff --git a/alembic/versions/86c17bf55b92_bump_version_20_07.py b/alembic/versions/86c17bf55b92_bump_version_20_07.py deleted file mode 100644 index 90180cac..00000000 --- a/alembic/versions/86c17bf55b92_bump_version_20_07.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_20_07 - -Revision ID: 86c17bf55b92 -Revises: 2a24c3d1d13e - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '86c17bf55b92' -down_revision = '2a24c3d1d13e' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='20.07')) - - -def downgrade(): - pass diff --git a/alembic/versions/872b869e9675_remove_entity.py b/alembic/versions/872b869e9675_remove_entity.py deleted file mode 100644 index e043fa22..00000000 --- a/alembic/versions/872b869e9675_remove_entity.py +++ /dev/null @@ -1,26 +0,0 @@ -"""remove entity - -Revision ID: 872b869e9675 -Revises: 90f771359c71 - -""" - -from alembic import op - - -# revision identifiers, used by Alembic. -revision = '872b869e9675' -down_revision = '90f771359c71' - - -def upgrade(): - op.drop_column('schedule', 'entity_id') - op.drop_column('pickup', 'entity_id') - op.drop_column('callfilter', 'entity_id') - op.drop_column('userfeatures', 'entityid') - op.drop_column('context', 'entity') - op.drop_table('entity') - - -def downgrade(): - pass diff --git a/alembic/versions/87b36150b613_bump_version_19_06.py b/alembic/versions/87b36150b613_bump_version_19_06.py deleted file mode 100644 index e03fb5cd..00000000 --- a/alembic/versions/87b36150b613_bump_version_19_06.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_19_06 - -Revision ID: 87b36150b613 -Revises: 1192e6bfd226 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '87b36150b613' -down_revision = '1192e6bfd226' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='19.06')) - - -def downgrade(): - pass diff --git a/alembic/versions/8a551a46dd5d_add_wazo_version_column.py b/alembic/versions/8a551a46dd5d_add_wazo_version_column.py deleted file mode 100644 index c8517053..00000000 --- a/alembic/versions/8a551a46dd5d_add_wazo_version_column.py +++ /dev/null @@ -1,23 +0,0 @@ -"""add_wazo_version_column - -Revision ID: 8a551a46dd5d -Revises: 198c5bc02abf - -""" - -# revision identifiers, used by Alembic. -revision = '8a551a46dd5d' -down_revision = '198c5bc02abf' - -from alembic import op -from sqlalchemy.schema import Column -from sqlalchemy.types import String - - -def upgrade(): - op.add_column('infos', Column('wazo_version', String(64), nullable=False, server_default='17.01')) - op.alter_column('infos', 'wazo_version', server_default=None) - - -def downgrade(): - op.drop_column('infos', 'wazo_version') diff --git a/alembic/versions/8bbb46a9f362_bump_version_23_05.py b/alembic/versions/8bbb46a9f362_bump_version_23_05.py deleted file mode 100644 index 7f718e78..00000000 --- a/alembic/versions/8bbb46a9f362_bump_version_23_05.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_23_05 - -Revision ID: 8bbb46a9f362 -Revises: f33878e11ef4 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '8bbb46a9f362' -down_revision = 'f33878e11ef4' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='23.05')) - - -def downgrade(): - pass diff --git a/alembic/versions/8c21acf4e9e_bump_version_17_02.py b/alembic/versions/8c21acf4e9e_bump_version_17_02.py deleted file mode 100644 index f2877cb6..00000000 --- a/alembic/versions/8c21acf4e9e_bump_version_17_02.py +++ /dev/null @@ -1,22 +0,0 @@ -"""bump_version_17_02 - -Revision ID: 8c21acf4e9e -Revises: 196dea1085af - -""" - -# revision identifiers, used by Alembic. -revision = '8c21acf4e9e' -down_revision = '196dea1085af' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='17.02')) - - -def downgrade(): - pass diff --git a/alembic/versions/8e09c6fde62d_remove_auth_from_insecure_trunks.py b/alembic/versions/8e09c6fde62d_remove_auth_from_insecure_trunks.py deleted file mode 100644 index b93ad7ff..00000000 --- a/alembic/versions/8e09c6fde62d_remove_auth_from_insecure_trunks.py +++ /dev/null @@ -1,73 +0,0 @@ -"""remove-auth-from-insecure-trunks - -Revision ID: 8e09c6fde62d -Revises: 69c55f395eb7 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '8e09c6fde62d' -down_revision = '69c55f395eb7' - -user_sip_tbl = sa.sql.table( - 'usersip', - sa.sql.column('name'), - sa.sql.column('category'), - sa.sql.column('insecure'), -) -endpoint_sip_tbl = sa.sql.table( - 'endpoint_sip', - sa.sql.column('uuid'), - sa.sql.column('name'), -) -endpoint_sip_section_tbl = sa.sql.table( - 'endpoint_sip_section', - sa.sql.column('uuid'), - sa.sql.column('type'), - sa.sql.column('endpoint_sip_uuid'), -) - - -def find_insecure_trunks(): - query = ( - sa.sql.select([user_sip_tbl.c.name]) - .where( - sa.and_( - user_sip_tbl.c.category == 'trunk', - ~user_sip_tbl.c.insecure.is_(None) - ) - ) - ) - rows = op.get_bind().execute(query) - return [row.name for row in rows] - - -def delete_auth_sections(endpoint_names): - query = ( - endpoint_sip_section_tbl - .delete() - .where(endpoint_sip_section_tbl.c.type == 'auth') - .where( - endpoint_sip_section_tbl.c.endpoint_sip_uuid.in_( - sa.sql.select([endpoint_sip_tbl.c.uuid]) - .where(endpoint_sip_tbl.c.name.in_(endpoint_names)) - ) - ) - ) - op.execute(query) - - -def upgrade(): - endpoint_names = find_insecure_trunks() - if not endpoint_names: - return - - delete_auth_sections(endpoint_names) - - -def downgrade(): - pass diff --git a/alembic/versions/90518bf34218_back_to_19_12.py b/alembic/versions/90518bf34218_back_to_19_12.py deleted file mode 100644 index d21a9886..00000000 --- a/alembic/versions/90518bf34218_back_to_19_12.py +++ /dev/null @@ -1,23 +0,0 @@ -"""back-to-19.12 - -Revision ID: 90518bf34218 -Revises: b3bf380f5241 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '90518bf34218' -down_revision = 'b3bf380f5241' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='19.12')) - - -def downgrade(): - pass diff --git a/alembic/versions/907d4947d665_call_permission_non_unique_names.py b/alembic/versions/907d4947d665_call_permission_non_unique_names.py deleted file mode 100644 index 76af1b03..00000000 --- a/alembic/versions/907d4947d665_call_permission_non_unique_names.py +++ /dev/null @@ -1,27 +0,0 @@ -"""call_permission non unique names - -Revision ID: 907d4947d665 -Revises: cb5666745311 - -""" - -from alembic import op - - -# revision identifiers, used by Alembic. -revision = '907d4947d665' -down_revision = 'cb5666745311' - -TBL_NAME = 'rightcall' -OLD_CONSTRAINT_NAME = 'rightcall_name_key' -NEW_CONSTRAINT_NAME = 'rightcall_name_tenant_uuid_key' - - -def upgrade(): - op.create_unique_constraint(NEW_CONSTRAINT_NAME, TBL_NAME, ['name', 'tenant_uuid']) - op.drop_constraint(OLD_CONSTRAINT_NAME, TBL_NAME) - - -def downgrade(): - op.create_unique_constraint(OLD_CONSTRAINT_NAME, TBL_NAME, ['name']) - op.drop_constraint(NEW_CONSTRAINT_NAME, TBL_NAME) diff --git a/alembic/versions/90f771359c71_bump_version_19_05.py b/alembic/versions/90f771359c71_bump_version_19_05.py deleted file mode 100644 index cfe656dd..00000000 --- a/alembic/versions/90f771359c71_bump_version_19_05.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_19_05 - -Revision ID: 90f771359c71 -Revises: 454c3dfde5db - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '90f771359c71' -down_revision = '454c3dfde5db' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='19.05')) - - -def downgrade(): - pass diff --git a/alembic/versions/9142f0403c8_add_ivr_support.py b/alembic/versions/9142f0403c8_add_ivr_support.py deleted file mode 100644 index 913db280..00000000 --- a/alembic/versions/9142f0403c8_add_ivr_support.py +++ /dev/null @@ -1,115 +0,0 @@ -"""add ivr support - -Revision ID: 9142f0403c8 -Revises: 2072c1e66aa9 - -""" - -# revision identifiers, used by Alembic. -revision = '9142f0403c8' -down_revision = '2072c1e66aa9' - -from alembic import op -from sqlalchemy import sql, Column, Enum, ForeignKey, Integer, PrimaryKeyConstraint, String, Text - -dialaction = sql.table('dialaction', - sql.column('action')) - -dialaction_action = Enum( - 'none', - 'endcall:busy', - 'endcall:congestion', - 'endcall:hangup', - 'user', - 'group', - 'queue', - 'meetme', - 'voicemail', - 'trunk', - 'schedule', - 'extension', - 'outcall', - 'application:callbackdisa', - 'application:disa', - 'application:directory', - 'application:faxtomail', - 'application:voicemailmain', - 'application:password', - 'sound', - 'custom', - 'ivr', - name='dialaction_action', -) - -dialaction_category = Enum( - 'callfilter', - 'group', - 'incall', - 'queue', - 'schedule', - 'user', - 'outcall', - 'ivr', - 'ivr_choice', - name='dialaction_category', -) - - -def upgrade(): - _add_ivr_table() - _add_ivr_choice_table() - _modify_dialaction_action_type() - _modify_dialaction_category_type() - - -def _add_ivr_table(): - op.create_table( - 'ivr', - Column('id', Integer), - Column('name', String(128), nullable=False), - Column('greeting_sound', Text), - Column('menu_sound', Text, nullable=False), - Column('invalid_sound', Text), - Column('abort_sound', Text), - Column('timeout', Integer, nullable=False, server_default='5'), - Column('max_tries', Integer, nullable=False, server_default='3'), - Column('description', Text), - PrimaryKeyConstraint('id'), - ) - - -def _add_ivr_choice_table(): - op.create_table( - 'ivr_choice', - Column('id', Integer), - Column('ivr_id', Integer, ForeignKey('ivr.id'), nullable=False), - Column('exten', String(40), nullable=False), - PrimaryKeyConstraint('id'), - ) - -def _modify_dialaction_action_type(): - op.execute(dialaction.delete().where(dialaction.c.action == 'voicemenu')) - op.alter_column('schedule', 'fallback_action', server_default=None) - _modify_type(dialaction_action, - ('dialaction', 'action'), - ('schedule', 'fallback_action'), - ('schedule_time', 'action')) - op.alter_column('schedule', 'fallback_action', server_default='none') - - -def _modify_dialaction_category_type(): - _modify_type(dialaction_category, - ('dialaction', 'category')) - - -def _modify_type(type_, *table_and_columns): - op.execute('ALTER TYPE {type_name} RENAME TO tmp_{type_name}'.format(type_name=type_.name)) - type_.create(op.get_bind()) - for table, column in table_and_columns: - op.execute('ALTER TABLE {table_name} ALTER COLUMN {column_name} TYPE {type_name} USING {column_name}::text::{type_name}'.format( - type_name=type_.name, table_name=table, column_name=column)) - op.execute('DROP TYPE tmp_{type_name}'.format(type_name=type_.name)) - - -def downgrade(): - pass diff --git a/alembic/versions/92061fe1c3b8_bump_version_20_02.py b/alembic/versions/92061fe1c3b8_bump_version_20_02.py deleted file mode 100644 index a1331306..00000000 --- a/alembic/versions/92061fe1c3b8_bump_version_20_02.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_20_02 - -Revision ID: 92061fe1c3b8 -Revises: 0b694daf27e0 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '92061fe1c3b8' -down_revision = '0b694daf27e0' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='20.02')) - - -def downgrade(): - pass diff --git a/alembic/versions/92928db7221_bump_version_18_08.py b/alembic/versions/92928db7221_bump_version_18_08.py deleted file mode 100644 index 1370450c..00000000 --- a/alembic/versions/92928db7221_bump_version_18_08.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_18_08 - -Revision ID: 92928db7221 -Revises: c193f30636ff - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '92928db7221' -down_revision = 'c193f30636ff' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='18.08')) - - -def downgrade(): - pass diff --git a/alembic/versions/93ea61395eef_bump_version_22_01.py b/alembic/versions/93ea61395eef_bump_version_22_01.py deleted file mode 100644 index e33c1a47..00000000 --- a/alembic/versions/93ea61395eef_bump_version_22_01.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_22_01 - -Revision ID: 93ea61395eef -Revises: 29290c38946f - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '93ea61395eef' -down_revision = '29290c38946f' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='22.01')) - - -def downgrade(): - pass diff --git a/alembic/versions/9442da3b20b6_bump_version_21_04.py b/alembic/versions/9442da3b20b6_bump_version_21_04.py deleted file mode 100644 index f6e73227..00000000 --- a/alembic/versions/9442da3b20b6_bump_version_21_04.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_21_04 - -Revision ID: 9442da3b20b6 -Revises: 1583f90b21ad - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '9442da3b20b6' -down_revision = '1583f90b21ad' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='21.04')) - - -def downgrade(): - pass diff --git a/alembic/versions/978e620de034_bump_version_21_09.py b/alembic/versions/978e620de034_bump_version_21_09.py deleted file mode 100644 index f57484b3..00000000 --- a/alembic/versions/978e620de034_bump_version_21_09.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_21_09 - -Revision ID: 978e620de034 -Revises: 84d91026c293 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '978e620de034' -down_revision = '84d91026c293' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='21.09')) - - -def downgrade(): - pass diff --git a/alembic/versions/99082b9c0b7b_bump_version_18_13.py b/alembic/versions/99082b9c0b7b_bump_version_18_13.py deleted file mode 100644 index e24a6a11..00000000 --- a/alembic/versions/99082b9c0b7b_bump_version_18_13.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_18_13 - -Revision ID: 99082b9c0b7b -Revises: 2256e488e43c - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '99082b9c0b7b' -down_revision = '2256e488e43c' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='18.13')) - - -def downgrade(): - pass diff --git a/alembic/versions/9b0892a818e6_add_tenant_uuid_to_agentfeatures.py b/alembic/versions/9b0892a818e6_add_tenant_uuid_to_agentfeatures.py deleted file mode 100644 index 78f447f6..00000000 --- a/alembic/versions/9b0892a818e6_add_tenant_uuid_to_agentfeatures.py +++ /dev/null @@ -1,117 +0,0 @@ -"""add tenant_uuid to agentfeatures - -Revision ID: 9b0892a818e6 -Revises: 560bfca6cf85 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '9b0892a818e6' -down_revision = '560bfca6cf85' - - -agentfeatures_tbl = sa.sql.table( - 'agentfeatures', - sa.sql.column('id'), - sa.sql.column('tenant_uuid'), - sa.sql.column('context'), -) - -context_tbl = sa.sql.table( - 'context', - sa.sql.column('name'), - sa.sql.column('tenant_uuid') -) - -agent_login_status_tbl = sa.sql.table( - 'agent_login_status', - sa.sql.column('agent_id'), - sa.sql.column('context'), -) -queuefeatures_tbl = sa.sql.table( - 'queuefeatures', - sa.sql.column('id'), - sa.sql.column('tenant_uuid'), - sa.sql.column('name'), -) - -queuemember_tbl = sa.sql.table( - 'queuemember', - sa.sql.column('queue_name'), - sa.sql.column('interface'), - sa.sql.column('usertype'), - sa.sql.column('userid') -) - - -def associate_tenants(): - query = ( - sa.sql.select([agentfeatures_tbl.c.id, context_tbl.c.tenant_uuid]) - .where(context_tbl.c.name == agentfeatures_tbl.c.context) - ) - context_agent_tenants = op.get_bind().execute(query) - - query = ( - sa.sql.select([agent_login_status_tbl.c.agent_id, context_tbl.c.tenant_uuid]) - .where(context_tbl.c.name == agent_login_status_tbl.c.context) - ) - context_login_tenants = op.get_bind().execute(query) - - query = ( - sa.sql.select([queuemember_tbl.c.userid, queuefeatures_tbl.c.tenant_uuid]) - .where( - sa.sql.and_( - queuemember_tbl.c.queue_name == queuefeatures_tbl.c.name, - queuemember_tbl.c.usertype == 'agent', - ) - ) - ) - queuemember_tenants = op.get_bind().execute(query) - - tenant_sources = ( - list(context_agent_tenants) + list(queuemember_tenants) + list(context_login_tenants) - ) - - already_migrated = [] - for agent_id, tenant_uuid in tenant_sources: - if agent_id not in already_migrated: - query = ( - agentfeatures_tbl.update() - .where(agentfeatures_tbl.c.id == agent_id) - .values(tenant_uuid=tenant_uuid) - ) - op.execute(query) - already_migrated.append(agent_id) - - -def delete_no_tenants(): - query = ( - agentfeatures_tbl.delete() - .where(agentfeatures_tbl.c.tenant_uuid == None) # noqa - ) - op.execute(query) - - -def upgrade(): - op.add_column( - 'agentfeatures', - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=True - ), - ) - - associate_tenants() - delete_no_tenants() - - op.alter_column('agentfeatures', 'tenant_uuid', nullable=False) - - -def downgrade(): - op.drop_column('agentfeatures', 'tenant_uuid') diff --git a/alembic/versions/9b7e32eb0a77_bump_version_19_09.py b/alembic/versions/9b7e32eb0a77_bump_version_19_09.py deleted file mode 100644 index c700bee2..00000000 --- a/alembic/versions/9b7e32eb0a77_bump_version_19_09.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_19_09 - -Revision ID: 9b7e32eb0a77 -Revises: cac9af37c973 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '9b7e32eb0a77' -down_revision = 'cac9af37c973' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='19.09')) - - -def downgrade(): - pass diff --git a/alembic/versions/9eeb96b396a7_bump_version_21_08.py b/alembic/versions/9eeb96b396a7_bump_version_21_08.py deleted file mode 100644 index 9b93bc9a..00000000 --- a/alembic/versions/9eeb96b396a7_bump_version_21_08.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_21_08 - -Revision ID: 9eeb96b396a7 -Revises: 2b5d68fa7ab8 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '9eeb96b396a7' -down_revision = '2b5d68fa7ab8' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='21.08')) - - -def downgrade(): - pass diff --git a/alembic/versions/9f11f3abaacc_bump_version_23_03.py b/alembic/versions/9f11f3abaacc_bump_version_23_03.py deleted file mode 100644 index 0289ad4f..00000000 --- a/alembic/versions/9f11f3abaacc_bump_version_23_03.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_23_03 - -Revision ID: 9f11f3abaacc -Revises: 1264fdcb3e71 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '9f11f3abaacc' -down_revision = '1264fdcb3e71' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='23.03')) - - -def downgrade(): - pass diff --git a/alembic/versions/a10db8de6372_remove_unused_extenfeatures.py b/alembic/versions/a10db8de6372_remove_unused_extenfeatures.py deleted file mode 100644 index f6626fc1..00000000 --- a/alembic/versions/a10db8de6372_remove_unused_extenfeatures.py +++ /dev/null @@ -1,42 +0,0 @@ -"""remove-unused-extenfeatures - -Revision ID: a10db8de6372 -Revises: dfd6c02443cc - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'a10db8de6372' -down_revision = 'dfd6c02443cc' - -DEPRECATED_FEATURES = [ - 'callconference', - 'callgroup', - 'callqueue', - 'calluser', -] - -extensions_tbl = sa.sql.table( - 'extensions', - sa.sql.column('context'), - sa.sql.column('type'), - sa.sql.column('typeval'), -) - - -def upgrade(): - query = ( - extensions_tbl.delete() - .where(extensions_tbl.c.context == 'xivo-features') - .where(extensions_tbl.c.type == 'extenfeatures') - .where(extensions_tbl.c.typeval.in_(DEPRECATED_FEATURES)) - ) - op.execute(query) - - -def downgrade(): - pass diff --git a/alembic/versions/a132daff54b_drop_column_useenum.py b/alembic/versions/a132daff54b_drop_column_useenum.py deleted file mode 100644 index 016c4394..00000000 --- a/alembic/versions/a132daff54b_drop_column_useenum.py +++ /dev/null @@ -1,21 +0,0 @@ -"""drop column useenum - -Revision ID: a132daff54b -Revises: 9142f0403c8 - -""" - -# revision identifiers, used by Alembic. -revision = 'a132daff54b' -down_revision = '9142f0403c8' - -from alembic import op -from sqlalchemy import Column, Integer - - -def upgrade(): - op.drop_column('outcall', 'useenum') - - -def downgrade(): - op.add_column('outcall', Column('useenum', Integer, nullable=False, server_default='0')) diff --git a/alembic/versions/a28974a2dc19_add_pjsip_endpoints.py b/alembic/versions/a28974a2dc19_add_pjsip_endpoints.py deleted file mode 100644 index a9e3d5a4..00000000 --- a/alembic/versions/a28974a2dc19_add_pjsip_endpoints.py +++ /dev/null @@ -1,88 +0,0 @@ -"""add pjsip endpoints - -Revision ID: a28974a2dc19 -Revises: 4aa03039dd2e - -""" - -from alembic import op -from sqlalchemy import Boolean, Column, Enum, Text, ForeignKey as FK, Integer, String, text -from sqlalchemy.dialects.postgresql import UUID - - -# revision identifiers, used by Alembic. -revision = 'a28974a2dc19' -down_revision = '4aa03039dd2e' - -UUID_GEN = 'uuid_generate_v4()' - -endpoint_sip_section_type = Enum( - 'aor', - 'auth', - 'endpoint', - 'identify', - 'outbound_auth', - 'registration_outbound_auth', - 'registration', - name='endpoint_sip_section_type', -) - - -def upgrade(): - op.create_table( - 'endpoint_sip', - Column('uuid', UUID, server_default=text(UUID_GEN), primary_key=True), - Column('label', Text), - Column('name', Text, nullable=False, unique=True), - Column('asterisk_id', Text), - Column('tenant_uuid', String(36), FK('tenant.uuid', ondelete='CASCADE'), nullable=False), - Column('transport_uuid', UUID, FK('pjsip_transport.uuid')), - Column('context_id', Integer, FK('context.id')), - Column('template', Boolean, server_default=text('false')), - ) - op.create_table( - 'endpoint_sip_section', - Column('uuid', UUID, server_default=text(UUID_GEN), primary_key=True), - Column('endpoint_sip_uuid', UUID, FK('endpoint_sip.uuid', ondelete='CASCADE'), nullable=False), - Column('type', endpoint_sip_section_type, nullable=False) - ) - op.create_unique_constraint( - 'endpoint_sip_section_type_endpoint_sip_uuid_key', - 'endpoint_sip_section', - ['type', 'endpoint_sip_uuid'], - ) - op.create_table( - 'endpoint_sip_section_option', - Column('uuid', UUID, server_default=text(UUID_GEN), primary_key=True), - Column('key', Text, nullable=False), - Column('value', Text, nullable=False), - Column( - 'endpoint_sip_section_uuid', - UUID, - FK('endpoint_sip_section.uuid', ondelete='CASCADE'), - nullable=False - ), - ) - op.create_table( - 'endpoint_sip_template', - Column('child_uuid', UUID, FK('endpoint_sip.uuid', ondelete='CASCADE'), primary_key=True), - Column('parent_uuid', UUID, FK('endpoint_sip.uuid', ondelete='CASCADE'), primary_key=True), - ) - op.add_column( - 'linefeatures', - Column('endpoint_sip_uuid', UUID, FK('endpoint_sip.uuid', ondelete='SET NULL')), - ) - op.add_column( - 'trunkfeatures', - Column('endpoint_sip_uuid', UUID, FK('endpoint_sip.uuid', ondelete='SET NULL')), - ) - - -def downgrade(): - op.drop_column('trunkfeatures', 'endpoint_sip_uuid') - op.drop_column('linefeatures', 'endpoint_sip_uuid') - op.drop_table('endpoint_sip_template') - op.drop_table('endpoint_sip_section_option') - op.drop_table('endpoint_sip_section') - op.drop_table('endpoint_sip') - endpoint_sip_section_type.drop(op.get_bind()) diff --git a/alembic/versions/a3b4e1bf633b_queue_add_tenant_uuid.py b/alembic/versions/a3b4e1bf633b_queue_add_tenant_uuid.py deleted file mode 100644 index 07da3bae..00000000 --- a/alembic/versions/a3b4e1bf633b_queue_add_tenant_uuid.py +++ /dev/null @@ -1,56 +0,0 @@ -"""queue add tenant_uuid - -Revision ID: a3b4e1bf633b -Revises: 12f9880ae872 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'a3b4e1bf633b' -down_revision = '12f9880ae872' - - -TABLE = 'queuefeatures' - - -def get_context_tenant_map(): - tbl = sa.sql.table('context', sa.sql.column('name'), sa.sql.column('tenant_uuid')) - query = sa.sql.select([tbl.c.name, tbl.c.tenant_uuid]) - rows = op.get_bind().execute(query) - return {row.name: row.tenant_uuid for row in rows} - - -def associate_tenants(): - tbl = sa.sql.table(TABLE, sa.sql.column('context'), sa.sql.column('tenant_uuid')) - - for name, uuid in get_context_tenant_map().items(): - query = tbl.update().where(tbl.c.context == name).values(tenant_uuid=uuid) - op.execute(query) - - -def remove_no_tenants(): - tbl = sa.sql.table(TABLE, sa.sql.column('tenant_uuid')) - query = tbl.delete().where(tbl.c.tenant_uuid == None) - op.execute(query) - - -def upgrade(): - op.add_column( - TABLE, - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=True), - ) - associate_tenants() - remove_no_tenants() - op.alter_column(TABLE, 'tenant_uuid', nullable=False) - - -def downgrade(): - op.drop_column(TABLE, 'tenant_uuid') diff --git a/alembic/versions/a3e7fd7b670_create_func_key_park_position.py b/alembic/versions/a3e7fd7b670_create_func_key_park_position.py deleted file mode 100644 index c8ee0098..00000000 --- a/alembic/versions/a3e7fd7b670_create_func_key_park_position.py +++ /dev/null @@ -1,51 +0,0 @@ -"""create func key park position - -Revision ID: a3e7fd7b670 -Revises: 5450dd40916e - -""" - -# revision identifiers, used by Alembic. -revision = 'a3e7fd7b670' -down_revision = '5450dd40916e' - -from alembic import op -import sqlalchemy as sa - - -PARKING_TYPE_ID = 7 -PARKING_TYPE_NAME = 'park_position' - -destination_type_table = sa.sql.table('func_key_destination_type', - sa.sql.column('id'), - sa.sql.column('name')) - - -def upgrade(): - parking_type_row = {'id': PARKING_TYPE_ID, 'name': PARKING_TYPE_NAME} - op.bulk_insert(destination_type_table, [parking_type_row]) - - op.create_table( - 'func_key_dest_park_position', - sa.Column('func_key_id', sa.Integer), - sa.Column('destination_type_id', - sa.Integer, - sa.CheckConstraint('destination_type_id = %d' % PARKING_TYPE_ID), - server_default=str(PARKING_TYPE_ID)), - sa.Column('park_position', - sa.String(40), - sa.CheckConstraint("park_position ~ '^[0-9]+$'"), - nullable=False), - sa.PrimaryKeyConstraint('func_key_id', 'destination_type_id'), - sa.ForeignKeyConstraint(['func_key_id', 'destination_type_id'], - ['func_key.id', 'func_key.destination_type_id']) - ) - - -def downgrade(): - op.drop_table('func_key_dest_park_position') - - delete_query = (destination_type_table - .delete() - .where(destination_type_table.c.id == PARKING_TYPE_ID)) - op.execute(delete_query) diff --git a/alembic/versions/a46c624e7f61_bump_version_22_11.py b/alembic/versions/a46c624e7f61_bump_version_22_11.py deleted file mode 100644 index 14d0e8e2..00000000 --- a/alembic/versions/a46c624e7f61_bump_version_22_11.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_22_11 - -Revision ID: a46c624e7f61 -Revises: 049ea24c3a0f - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'a46c624e7f61' -down_revision = '049ea24c3a0f' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='22.11')) - - -def downgrade(): - pass diff --git a/alembic/versions/aaf16eeecf7f_add_indices_to_foreign_keys.py b/alembic/versions/aaf16eeecf7f_add_indices_to_foreign_keys.py deleted file mode 100644 index d21b3e69..00000000 --- a/alembic/versions/aaf16eeecf7f_add_indices_to_foreign_keys.py +++ /dev/null @@ -1,210 +0,0 @@ -"""add_indices_to_foreign_keys - -Revision ID: aaf16eeecf7f -Revises: 8bbb46a9f362 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'aaf16eeecf7f' -down_revision = '8bbb46a9f362' - - -def upgrade(): - op.create_index('agent_login_status__idx__agent_id', 'agent_login_status', ['agent_id']) - - op.create_index('agent_membership_status__idx__agent_id', 'agent_membership_status', ['agent_id']) - op.create_index('agent_membership_status__idx__queue_id', 'agent_membership_status', ['queue_id']) - - op.create_index('asterisk_file_section__idx__asterisk_file_id', 'asterisk_file_section', ['asterisk_file_id']) - op.create_index('asterisk_file_variable__idx__asterisk_file_section_id', 'asterisk_file_variable', ['asterisk_file_section_id']) - - op.create_index('func_key__idx__type_id', 'func_key', ['type_id']) - - op.create_index('func_key_dest_agent__idx__agent_id', 'func_key_dest_agent', ['agent_id']) - op.create_index('func_key_dest_agent__idx__extension_id', 'func_key_dest_agent', ['extension_id']) - - op.create_index('func_key_dest_bsfilter__idx__filtermember_id', 'func_key_dest_bsfilter', ['filtermember_id']) - - op.create_index('func_key_dest_features__idx__features_id', 'func_key_dest_features', ['features_id']) - - op.create_index('func_key_dest_forward__idx__extension_id', 'func_key_dest_forward', ['extension_id']) - - op.create_index('func_key_dest_groupmember__idx__group_id', 'func_key_dest_groupmember', ['group_id']) - op.create_index('func_key_dest_groupmember__idx__extension_id', 'func_key_dest_groupmember', ['extension_id']) - - op.create_index('func_key_dest_paging__idx__paging_id', 'func_key_dest_paging', ['paging_id']) - - op.create_index('func_key_dest_service__idx__extension_id', 'func_key_dest_service', ['extension_id']) - - op.create_index('ivr_choice__idx__ivr_id', 'ivr_choice', ['ivr_id']) - - op.create_index('line_extension__idx__line_id', 'line_extension', ['line_id']) - op.create_index('line_extension__idx__extension_id', 'line_extension', ['extension_id']) - - op.create_index('linefeatures__idx__endpoint_sccp_id', 'linefeatures', ['endpoint_sccp_id']) - op.create_index('linefeatures__idx__endpoint_custom_id', 'linefeatures', ['endpoint_custom_id']) - - op.create_index('schedule_path__idx__schedule_id', 'schedule_path', ['schedule_id']) - - op.create_index('stat_call_on_queue__idx__stat_agent_id', 'stat_call_on_queue', ['stat_agent_id']) - op.create_index('stat_call_on_queue__idx__stat_queue_id', 'stat_call_on_queue', ['stat_queue_id']) - - op.create_index('stat_queue_periodic__idx__stat_queue_id', 'stat_queue_periodic', ['stat_queue_id']) - - op.create_index('trunkfeatures__idx__endpoint_iax_id', 'trunkfeatures', ['endpoint_iax_id']) - op.create_index('trunkfeatures__idx__endpoint_custom_id', 'trunkfeatures', ['endpoint_custom_id']) - op.create_index('trunkfeatures__idx__register_iax_id', 'trunkfeatures', ['register_iax_id']) - - op.create_index('user_line__idx__user_id', 'user_line', ['user_id']) - op.create_index('user_line__idx__line_id', 'user_line', ['line_id']) - - op.create_index('userfeatures__idx__func_key_template_id', 'userfeatures', ['func_key_template_id']) - op.create_index('userfeatures__idx__func_key_private_template_id', 'userfeatures', ['func_key_private_template_id']) - - op.create_index('agentfeatures__idx__tenant_uuid', 'agentfeatures', ['tenant_uuid']) - op.create_index('application__idx__tenant_uuid', 'application', ['tenant_uuid']) - op.create_index('callfilter__idx__tenant_uuid', 'callfilter', ['tenant_uuid']) - op.create_index('conference__idx__tenant_uuid', 'conference', ['tenant_uuid']) - op.create_index('context__idx__tenant_uuid', 'context', ['tenant_uuid']) - op.create_index('endpoint_sip_section__idx__endpoint_sip_uuid', 'endpoint_sip_section', ['endpoint_sip_uuid']) - op.create_index('endpoint_sip_section_option__idx__endpoint_sip_section_uuid', 'endpoint_sip_section_option', ['endpoint_sip_section_uuid']) - op.create_index('func_key_template__idx__tenant_uuid', 'func_key_template', ['tenant_uuid']) - op.create_index('groupfeatures__idx__tenant_uuid', 'groupfeatures', ['tenant_uuid']) - op.create_index('incall__idx__tenant_uuid', 'incall', ['tenant_uuid']) - op.create_index('ingress_http__idx__tenant_uuid', 'ingress_http', ['tenant_uuid']) - op.create_index('ivr__idx__tenant_uuid', 'ivr', ['tenant_uuid']) - op.create_index('linefeatures__idx__application_uuid', 'linefeatures', ['application_uuid']) - op.create_index('linefeatures__idx__endpoint_sip_uuid', 'linefeatures', ['endpoint_sip_uuid']) - op.create_index('meeting__idx__guest_endpoint_sip_uuid', 'meeting', ['guest_endpoint_sip_uuid']) - op.create_index('meeting__idx__tenant_uuid', 'meeting', ['tenant_uuid']) - op.create_index('meeting_authorization__idx__guest_uuid', 'meeting_authorization', ['guest_uuid']) - op.create_index('meeting_authorization__idx__meeting_uuid', 'meeting_authorization', ['meeting_uuid']) - op.create_index('moh__idx__tenant_uuid', 'moh', ['tenant_uuid']) - op.create_index('outcall__idx__tenant_uuid', 'outcall', ['tenant_uuid']) - op.create_index('paging__idx__tenant_uuid', 'paging', ['tenant_uuid']) - op.create_index('parking_lot__idx__tenant_uuid', 'parking_lot', ['tenant_uuid']) - op.create_index('pickup__idx__tenant_uuid', 'pickup', ['tenant_uuid']) - op.create_index('pjsip_transport_option__idx__pjsip_transport_uuid', 'pjsip_transport_option', ['pjsip_transport_uuid']) - op.create_index('queuefeatures__idx__tenant_uuid', 'queuefeatures', ['tenant_uuid']) - op.create_index('queueskill__idx__tenant_uuid', 'queueskill', ['tenant_uuid']) - op.create_index('queueskillrule__idx__tenant_uuid', 'queueskillrule', ['tenant_uuid']) - op.create_index('rightcall__idx__tenant_uuid', 'rightcall', ['tenant_uuid']) - op.create_index('sccpline__idx__tenant_uuid', 'sccpline', ['tenant_uuid']) - op.create_index('schedule__idx__tenant_uuid', 'schedule', ['tenant_uuid']) - op.create_index('switchboard__idx__tenant_uuid', 'switchboard', ['tenant_uuid']) - op.create_index('switchboard__idx__hold_moh_uuid', 'switchboard', ['hold_moh_uuid']) - op.create_index('switchboard__idx__queue_moh_uuid', 'switchboard', ['queue_moh_uuid']) - op.create_index('switchboard_member_user__idx__user_uuid', 'switchboard_member_user', ['user_uuid']) - op.create_index('tenant__idx__global_sip_template_uuid', 'tenant', ['global_sip_template_uuid']) - op.create_index('tenant__idx__webrtc_sip_template_uuid', 'tenant', ['webrtc_sip_template_uuid']) - op.create_index('tenant__idx__registration_trunk_sip_template_uuid', 'tenant', ['registration_trunk_sip_template_uuid']) - op.create_index('tenant__idx__meeting_guest_sip_template_uuid', 'tenant', ['meeting_guest_sip_template_uuid']) - op.create_index('tenant__idx__twilio_trunk_sip_template_uuid', 'tenant', ['twilio_trunk_sip_template_uuid']) - op.create_index('trunkfeatures__idx__tenant_uuid', 'trunkfeatures', ['tenant_uuid']) - op.create_index('trunkfeatures__idx__endpoint_sip_uuid', 'trunkfeatures', ['endpoint_sip_uuid']) - op.create_index('usercustom__idx__tenant_uuid', 'usercustom', ['tenant_uuid']) - op.create_index('userfeatures__idx__tenant_uuid', 'userfeatures', ['tenant_uuid']) - op.create_index('useriax__idx__tenant_uuid', 'useriax', ['tenant_uuid']) - - -def downgrade(): - op.drop_index('agent_login_status__idx__agent_id') - - op.drop_index('agent_membership_status__idx__agent_id') - op.drop_index('agent_membership_status__idx__queue_id') - - op.drop_index('asterisk_file_section__idx__asterisk_file_id') - op.drop_index('asterisk_file_variable__idx__asterisk_file_section_id') - - op.drop_index('func_key__idx__type_id') - - op.drop_index('func_key_dest_agent__idx__agent_id') - op.drop_index('func_key_dest_agent__idx__extension_id') - - op.drop_index('func_key_dest_bsfilter__idx__filtermember_id') - - op.drop_index('func_key_dest_features__idx__features_id') - - op.drop_index('func_key_dest_forward__idx__extension_id') - - op.drop_index('func_key_dest_groupmember__idx__group_id') - op.drop_index('func_key_dest_groupmember__idx__extension_id') - - op.drop_index('func_key_dest_paging__idx__paging_id') - - op.drop_index('func_key_dest_service__idx__extension_id') - - op.drop_index('ivr_choice__idx__ivr_id') - - op.drop_index('line_extension__idx__line_id') - op.drop_index('line_extension__idx__extension_id') - - op.drop_index('linefeatures__idx__endpoint_sccp_id') - op.drop_index('linefeatures__idx__endpoint_custom_id') - - op.drop_index('schedule_path__idx__schedule_id') - - op.drop_index('stat_call_on_queue__idx__stat_agent_id') - op.drop_index('stat_call_on_queue__idx__stat_queue_id') - - op.drop_index('stat_queue_periodic__idx__stat_queue_id') - - op.drop_index('trunkfeatures__idx__endpoint_iax_id') - op.drop_index('trunkfeatures__idx__endpoint_custom_id') - op.drop_index('trunkfeatures__idx__register_iax_id') - - op.drop_index('user_line__idx__user_id') - op.drop_index('user_line__idx__line_id') - - op.drop_index('userfeatures__idx__func_key_template_id') - op.drop_index('userfeatures__idx__func_key_private_template_id') - - op.drop_index('agentfeatures__idx__tenant_uuid') - op.drop_index('application__idx__tenant_uuid') - op.drop_index('callfilter__idx__tenant_uuid') - op.drop_index('conference__idx__tenant_uuid') - op.drop_index('context__idx__tenant_uuid') - op.drop_index('endpoint_sip_section__idx__endpoint_sip_uuid') - op.drop_index('endpoint_sip_section_option__idx__endpoint_sip_section_uuid') - op.drop_index('func_key_template__idx__tenant_uuid') - op.drop_index('groupfeatures__idx__tenant_uuid') - op.drop_index('incall__idx__tenant_uuid') - op.drop_index('ingress_http__idx__tenant_uuid') - op.drop_index('ivr__idx__tenant_uuid') - op.drop_index('linefeatures__idx__application_uuid') - op.drop_index('linefeatures__idx__endpoint_sip_uuid') - op.drop_index('meeting__idx__guest_endpoint_sip_uuid') - op.drop_index('meeting__idx__tenant_uuid') - op.drop_index('meeting_authorization__idx__guest_uuid') - op.drop_index('meeting_authorization__idx__meeting_uuid') - op.drop_index('moh__idx__tenant_uuid') - op.drop_index('outcall__idx__tenant_uuid') - op.drop_index('paging__idx__tenant_uuid') - op.drop_index('parking_lot__idx__tenant_uuid') - op.drop_index('pickup__idx__tenant_uuid') - op.drop_index('pjsip_transport_option__idx__pjsip_transport_uuid') - op.drop_index('queuefeatures__idx__tenant_uuid') - op.drop_index('queueskill__idx__tenant_uuid') - op.drop_index('queueskillrule__idx__tenant_uuid') - op.drop_index('rightcall__idx__tenant_uuid') - op.drop_index('sccpline__idx__tenant_uuid') - op.drop_index('schedule__idx__tenant_uuid') - op.drop_index('switchboard__idx__tenant_uuid') - op.drop_index('switchboard__idx__hold_moh_uuid') - op.drop_index('switchboard__idx__queue_moh_uuid') - op.drop_index('switchboard_member_user__idx__user_uuid') - op.drop_index('tenant__idx__global_sip_template_uuid') - op.drop_index('tenant__idx__webrtc_sip_template_uuid') - op.drop_index('tenant__idx__registration_trunk_sip_template_uuid') - op.drop_index('tenant__idx__meeting_guest_sip_template_uuid') - op.drop_index('tenant__idx__twilio_trunk_sip_template_uuid') - op.drop_index('trunkfeatures__idx__tenant_uuid') - op.drop_index('trunkfeatures__idx__endpoint_sip_uuid') - op.drop_index('usercustom__idx__tenant_uuid') - op.drop_index('userfeatures__idx__tenant_uuid') - op.drop_index('useriax__idx__tenant_uuid') diff --git a/alembic/versions/ab2956a0168_directories_add_tenant_and_phonebook_.py b/alembic/versions/ab2956a0168_directories_add_tenant_and_phonebook_.py deleted file mode 100644 index 1aaab14f..00000000 --- a/alembic/versions/ab2956a0168_directories_add_tenant_and_phonebook_.py +++ /dev/null @@ -1,26 +0,0 @@ -"""directories_add_tenant_and_phonebook_fields - -Revision ID: ab2956a0168 -Revises: 1aef8dfb5a12 - -""" - -# revision identifiers, used by Alembic. -revision = 'ab2956a0168' -down_revision = '1aef8dfb5a12' - -from alembic import op -import sqlalchemy as sa - -t = 'directories' -columns = ['dird_tenant', 'dird_phonebook'] - - -def upgrade(): - for c in columns: - op.add_column(t, sa.Column(c, sa.Text)) - - -def downgrade(): - for c in columns: - op.drop_column(t, c) diff --git a/alembic/versions/ae5bee40e9d2_bump_version_22_08.py b/alembic/versions/ae5bee40e9d2_bump_version_22_08.py deleted file mode 100644 index 62d07974..00000000 --- a/alembic/versions/ae5bee40e9d2_bump_version_22_08.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_22_08 - -Revision ID: ae5bee40e9d2 -Revises: 0c758daee631 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'ae5bee40e9d2' -down_revision = '0c758daee631' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='22.08')) - - -def downgrade(): - pass diff --git a/alembic/versions/b0edbcc1426d_bump_version_22_16.py b/alembic/versions/b0edbcc1426d_bump_version_22_16.py deleted file mode 100644 index cfed1022..00000000 --- a/alembic/versions/b0edbcc1426d_bump_version_22_16.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_22_16 - -Revision ID: b0edbcc1426d -Revises: e04b80f8b6fc - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'b0edbcc1426d' -down_revision = 'e04b80f8b6fc' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='22.16')) - - -def downgrade(): - pass diff --git a/alembic/versions/b1c4be6f46ff_bump_version_20_16.py b/alembic/versions/b1c4be6f46ff_bump_version_20_16.py deleted file mode 100644 index 10120fbf..00000000 --- a/alembic/versions/b1c4be6f46ff_bump_version_20_16.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_20_16 - -Revision ID: b1c4be6f46ff -Revises: 2796b8c839c5 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'b1c4be6f46ff' -down_revision = '2796b8c839c5' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='20.16')) - - -def downgrade(): - pass diff --git a/alembic/versions/b1dfaf771da8_replace_automixmon_with_dynamic_feature.py b/alembic/versions/b1dfaf771da8_replace_automixmon_with_dynamic_feature.py deleted file mode 100644 index 9ab7c672..00000000 --- a/alembic/versions/b1dfaf771da8_replace_automixmon_with_dynamic_feature.py +++ /dev/null @@ -1,100 +0,0 @@ -"""replace automixmon with dynamic feature - -Revision ID: b1dfaf771da8 -Revises: b62e1eba7869 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'b1dfaf771da8' -down_revision = 'b62e1eba7869' - -features_table = sa.sql.table('features', - sa.sql.column('id'), - sa.sql.column('filename'), - sa.sql.column('category'), - sa.sql.column('var_name'), - sa.sql.column('var_val')) - -func_key_dest_features_table = sa.sql.table('func_key_dest_features', - sa.sql.column('func_key_id'), - sa.sql.column('destination_type_id'), - sa.sql.column('features_id')) - - -def upgrade(): - feature_id, dtmf = _get_feature_value('featuremap', 'automixmon') - if dtmf: - application_map = f'{dtmf},self,AGI(agi://${{XIVO_AGID_IP}}/call_recording)' - new_feature_id = _insert_feature('applicationmap', 'togglerecord', application_map) - _move_funckey_dest_feature(feature_id, new_feature_id) - _remove_feature('featuremap', 'automixmon') - - -def downgrade(): - feature_id, dtmf = applicationmap_dtmf(*_get_feature_value('applicationmap', 'togglerecord')) - if dtmf: - new_feature_id = _insert_feature('featuremap', 'automixmon', dtmf) - _move_funckey_dest_feature(feature_id, new_feature_id) - _remove_feature('applicationmap', 'togglerecord') - - -def applicationmap_dtmf(feature_id, applicationmap_value): - if not applicationmap_value: - return feature_id, None - dtmf = applicationmap_value.split(',', 1)[0] - return feature_id, dtmf - - -def _get_feature_value(category, var_name): - features_query = ( - sa.sql.select( - [features_table.c.id, - features_table.c.var_val]) - .where( - sa.sql.and_( - features_table.c.category == category, - features_table.c.var_name == var_name))) - return op.get_bind().execute(features_query).first() - - -def _insert_feature(category, var_name, var_val): - query = (features_table - .insert() - .returning(features_table.c.id) - .values(filename='features.conf', - category=category, - var_name=var_name, - var_val=var_val)) - - return op.get_bind().execute(query).scalar() - - -def _remove_feature(category, var_name): - query = (features_table - .delete() - .where( - sa.sql.and_( - features_table.c.category == category, - features_table.c.var_name == var_name, - ), - )) - - op.execute(query) - - -def _move_funckey_dest_feature(old_feature_id, new_feature_id): - query = (func_key_dest_features_table - .update() - .values( - features_id=new_feature_id - ) - .where( - func_key_dest_features_table.c.features_id == old_feature_id - )) - - op.execute(query) diff --git a/alembic/versions/b2abcc84ad_add_a_source_field_to_all_sources.py b/alembic/versions/b2abcc84ad_add_a_source_field_to_all_sources.py deleted file mode 100644 index 2b0ff763..00000000 --- a/alembic/versions/b2abcc84ad_add_a_source_field_to_all_sources.py +++ /dev/null @@ -1,40 +0,0 @@ -"""add a source field to all sources - -Revision ID: b2abcc84ad -Revises: 592e449b34ec - -""" - -# revision identifiers, used by Alembic. -revision = 'b2abcc84ad' -down_revision = '592e449b34ec' - -from alembic import op -from sqlalchemy import sql, and_ - -fields_table = sql.table('ctidirectoryfields', - sql.column('dir_id'), - sql.column('fieldname'), - sql.column('value')) -cti_directories_table = sql.table('ctidirectories', - sql.column('id'), - sql.column('description')) - - -def upgrade(): - conn = op.get_bind() - rows = conn.execute(sql.select([cti_directories_table]). - where(cti_directories_table.c.description != '')) - for dir_id, description in rows: - rows = conn.execute(sql.select([fields_table.c.dir_id]) - .where(and_(fields_table.c.dir_id == dir_id, - fields_table.c.fieldname == 'directory'))) - if rows.rowcount: - continue - op.execute(fields_table.insert().values(dir_id=dir_id, - fieldname='directory', - value=description)) - - -def downgrade(): - pass diff --git a/alembic/versions/b3bf380f5241_fix_contextinclude_include_for_context_.py b/alembic/versions/b3bf380f5241_fix_contextinclude_include_for_context_.py deleted file mode 100644 index 676d6c44..00000000 --- a/alembic/versions/b3bf380f5241_fix_contextinclude_include_for_context_.py +++ /dev/null @@ -1,72 +0,0 @@ -"""fix contextinclude include for context renames - -Revision ID: b3bf380f5241 -Revises: 34b2b6ca345e - -""" - -import re - -from alembic import op -from sqlalchemy import ( - and_, - sql, -) - - -# revision identifiers, used by Alembic. -revision = 'b3bf380f5241' -down_revision = '34b2b6ca345e' - -NOT_CONTEXT_REGEX = r"[^a-zA-Z0-9-_]" -INVALID_NAME = ( - 'authentication', - 'general', - 'global', - 'globals', - 'parkedcalls', - 'xivo-features', - 'zonemessages', -) - -context_tbl = sql.table( - 'context', - sql.column('name'), -) - -context_include_tbl = sql.table( - 'contextinclude', - sql.column('context'), - sql.column('include'), - sql.column('priority'), -) - - -def upgrade(): - available_context_query = context_tbl.select() - contexts = op.get_bind().execute(available_context_query) - existing_names = [context.name for context in contexts] - - query = context_include_tbl.select() - for include in op.get_bind().execute(query): - new_name = re.sub(NOT_CONTEXT_REGEX, '_', include.include) - if new_name == include.include and include.include not in INVALID_NAME: - continue - - if new_name not in existing_names: - continue - - old_name = include.include - op.execute( - context_include_tbl - .update() - .where(and_( - context_include_tbl.c.context == include.context, - context_include_tbl.c.priority == include.priority, - )) - .values(include=new_name) - ) - - -def downgrade(): - pass diff --git a/alembic/versions/b536a68f5505_remove_dialaction_linked_column.py b/alembic/versions/b536a68f5505_remove_dialaction_linked_column.py deleted file mode 100644 index 72f6c5c0..00000000 --- a/alembic/versions/b536a68f5505_remove_dialaction_linked_column.py +++ /dev/null @@ -1,24 +0,0 @@ -"""remove-dialaction-linked-column - -Revision ID: b536a68f5505 -Revises: 92061fe1c3b8 - -""" - -from alembic import op -import sqlalchemy as sa - -# revision identifiers, used by Alembic. -revision = 'b536a68f5505' -down_revision = '92061fe1c3b8' - - -def upgrade(): - op.drop_column('dialaction', 'linked') - - -def downgrade(): - op.add_column( - 'dialaction', - sa.Column('linked', sa.Integer, nullable=False, server_default='0'), - ) diff --git a/alembic/versions/b57ed1e30535_add_direction_constraints_to_call_log.py b/alembic/versions/b57ed1e30535_add_direction_constraints_to_call_log.py deleted file mode 100644 index f5daf9c2..00000000 --- a/alembic/versions/b57ed1e30535_add_direction_constraints_to_call_log.py +++ /dev/null @@ -1,23 +0,0 @@ -"""add_direction_constraints_to_call_log - -Revision ID: b57ed1e30535 -Revises: 29a5eab6a19b - -""" - -# revision identifiers, used by Alembic. -revision = 'b57ed1e30535' -down_revision = '29a5eab6a19b' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - op.create_check_constraint('call_log_direction_check', - 'call_log', - sa.sql.column('direction').in_(['inbound', 'internal', 'outbound'])) - - -def downgrade(): - op.drop_constraint('call_log_direction_check', 'call_log') diff --git a/alembic/versions/b5c40615bc21_context_add_the_tenant_uuid.py b/alembic/versions/b5c40615bc21_context_add_the_tenant_uuid.py deleted file mode 100644 index d42a8156..00000000 --- a/alembic/versions/b5c40615bc21_context_add_the_tenant_uuid.py +++ /dev/null @@ -1,60 +0,0 @@ -"""context: add the tenant_uuid - -Revision ID: b5c40615bc21 -Revises: 378c46e8c6fe - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'b5c40615bc21' -down_revision = '378c46e8c6fe' - -entity_table = sa.sql.table( - 'entity', - sa.sql.column('name'), - sa.sql.column('tenant_uuid'), -) - - -def associate_tenants(default_tenant): - tbl = sa.sql.table('context', sa.sql.column('entity'), sa.sql.column('tenant_uuid')) - - query = tbl.update().values(tenant_uuid=default_tenant) - op.execute(query) - - for name, uuid in get_entity_tenant_map().items(): - query = tbl.update().where(tbl.c.entity == name).values(tenant_uuid=uuid) - op.execute(query) - - query = tbl.delete().where(tbl.c.tenant_uuid == None) - op.execute(query) - - -def get_entity_tenant_map(): - query = sa.sql.select([entity_table.c.name, entity_table.c.tenant_uuid]) - rows = op.get_bind().execute(query) - return {row.name: row.tenant_uuid for row in rows} - - -def find_default_tenant_uuid(): - query = sa.sql.select([entity_table.c.tenant_uuid]) - for row in op.get_bind().execute(query): - return row.tenant_uuid - - -def upgrade(): - op.add_column( - 'context', - sa.Column('tenant_uuid', sa.String(36), sa.ForeignKey('tenant.uuid'), nullable=True), - ) - default_tenant = find_default_tenant_uuid() - associate_tenants(default_tenant) - op.alter_column('context', 'tenant_uuid', nullable=False) - - -def downgrade(): - op.drop_column('context', 'tenant_uuid') diff --git a/alembic/versions/b5f230e1e0fe_add_users_confd_acl_to_call_logd.py b/alembic/versions/b5f230e1e0fe_add_users_confd_acl_to_call_logd.py deleted file mode 100644 index 372b7ae9..00000000 --- a/alembic/versions/b5f230e1e0fe_add_users_confd_acl_to_call_logd.py +++ /dev/null @@ -1,47 +0,0 @@ -"""add_users_confd_acl_to_call_logd - -Revision ID: b5f230e1e0fe -Revises: 15fb16c0b0f8 - -""" - -# revision identifiers, used by Alembic. -revision = 'b5f230e1e0fe' -down_revision = '15fb16c0b0f8' - -from alembic import op -from sqlalchemy import sql - - -webservice = sql.table('accesswebservice', - sql.column('name'), - sql.column('acl')) - -SERVICE = 'xivo-call-logd' -NEW_ACL = set(['confd.users.*.read']) - - -def _get_current_acl(name): - return set(op.get_bind().execute( - sql.select([webservice.c.acl]).where(webservice.c.name == name) - ).scalar()) - - -def _update_web_service_acl(name, acl): - op.execute(webservice - .update() - .where( - webservice.c.name == name - ).values(acl=list(acl))) - - -def upgrade(): - current_acls = _get_current_acl(SERVICE) - new_acls = current_acls | NEW_ACL - _update_web_service_acl(SERVICE, new_acls) - - -def downgrade(): - current_acls = _get_current_acl(SERVICE) - new_acls = current_acls - NEW_ACL - _update_web_service_acl(SERVICE, new_acls) diff --git a/alembic/versions/b62e1eba7869_bump_version_20_17.py b/alembic/versions/b62e1eba7869_bump_version_20_17.py deleted file mode 100644 index ca93a34d..00000000 --- a/alembic/versions/b62e1eba7869_bump_version_20_17.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_20_17 - -Revision ID: b62e1eba7869 -Revises: 2f354a1653fc - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'b62e1eba7869' -down_revision = '2f354a1653fc' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='20.17')) - - -def downgrade(): - pass diff --git a/alembic/versions/b6a0f4cc7e49_remove_user_table.py b/alembic/versions/b6a0f4cc7e49_remove_user_table.py deleted file mode 100644 index 77540551..00000000 --- a/alembic/versions/b6a0f4cc7e49_remove_user_table.py +++ /dev/null @@ -1,52 +0,0 @@ -"""remove_user_table - -Revision ID: b6a0f4cc7e49 -Revises: 0720419573a5 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'b6a0f4cc7e49' -down_revision = '0720419573a5' - - -def upgrade(): - op.drop_table('user') - op.execute('DROP TYPE user_meta') - - -def downgrade(): - op.create_table( - 'user', - sa.Column('id', sa.Integer, nullable=False, primary_key=True), - sa.Column( - 'uuid', - sa.String(38), - nullable=False, - unique=True, - server_default=sa.text('uuid_generate_v4()'), - ), - sa.Column( - 'entity_id', - sa.Integer, - sa.ForeignKey('entity.id', ondelete='RESTRICT'), - ), - sa.Column('login', sa.String(64), nullable=False, unique=True, server_default=''), - sa.Column('passwd', sa.String(64), nullable=False, server_default=''), - sa.Column( - 'meta', - sa.Enum('user', 'admin', 'root', name='user_meta'), - nullable=False, - unique=True, - server_default='user', - ), - sa.Column('valid', sa.Integer, nullable=False, server_default='1'), - sa.Column('time', sa.Integer, nullable=False, server_default='0'), - sa.Column('dcreate', sa.Integer, nullable=False, server_default='0'), - sa.Column('dupdate', sa.Integer, nullable=False, server_default='0'), - sa.Column('obj', sa.Text, nullable=False), - ) diff --git a/alembic/versions/b6bb28f27f2_fix_schema_differences.py b/alembic/versions/b6bb28f27f2_fix_schema_differences.py deleted file mode 100644 index 52834b97..00000000 --- a/alembic/versions/b6bb28f27f2_fix_schema_differences.py +++ /dev/null @@ -1,109 +0,0 @@ -"""fix schema differences - -Revision ID: b6bb28f27f2 -Revises: 27f83f39e031 - -""" - -# revision identifiers, used by Alembic. -revision = 'b6bb28f27f2' -down_revision = '27f83f39e031' - -from alembic import op - - -def drop_constraint(constraint, table): - sql = 'ALTER TABLE {table} DROP CONSTRAINT IF EXISTS {constraint}' - op.execute(sql.format(table=table, constraint=constraint)) - - -def upgrade(): - drop_constraint('fk_entity_id', 'callfilter') - drop_constraint('callfilter_entity_id_fkey', 'callfilter') - op.create_foreign_key('callfilter_entity_id_fkey', 'callfilter', - 'entity', ['entity_id'], ['id'], - ondelete='RESTRICT') - - drop_constraint('pickup_entity_id_fkey', 'pickup') - op.create_foreign_key('pickup_entity_id_fkey', 'pickup', - 'entity', ['entity_id'], ['id'], - ondelete='RESTRICT') - - drop_constraint('schedule_entity_id_fkey', 'schedule') - op.create_foreign_key('schedule_entity_id_fkey', 'schedule', - 'entity', ['entity_id'], ['id'], - ondelete='RESTRICT') - - drop_constraint('userfeatures_entity_id_fkey', 'userfeatures') - drop_constraint('userfeatures_entityid_fkey', 'userfeatures') - op.create_foreign_key('userfeatures_entityid_fkey', 'userfeatures', - 'entity', ['entityid'], ['id'], - ondelete='RESTRICT') - - drop_constraint('fk_user_id', 'user_contact') - drop_constraint('user_contact_user_id_fkey', 'user_contact') - op.create_foreign_key('user_contact_user_id_fkey', 'user_contact', - 'userfeatures', ['user_id'], ['id'], - ondelete='CASCADE') - - drop_constraint('fk_phonebook_id', 'user_contact') - drop_constraint('user_contact_phonebook_id_fkey', 'user_contact') - op.create_foreign_key('user_contact_phonebook_id_fkey', 'user_contact', - 'phonebook', ['phonebook_id'], ['id'], - ondelete='CASCADE') - - drop_constraint('fk_phonebook_id', 'phonebooknumber') - drop_constraint('phonebooknumber_phonebookid_fkey', 'phonebooknumber') - op.create_foreign_key('phonebooknumber_phonebookid_fkey', 'phonebooknumber', - 'phonebook', ['phonebookid'], ['id'], - ondelete='CASCADE') - - drop_constraint('fk_phonebook_id', 'phonebookaddress') - drop_constraint('phonebookaddress_phonebookid_fkey', 'phonebookaddress') - op.create_foreign_key('phonebookaddress_phonebookid_fkey', 'phonebookaddress', - 'phonebook', ['phonebookid'], ['id'], - ondelete='CASCADE') - - -def downgrade(): - drop_constraint('fk_entity_id', 'callfilter') - drop_constraint('callfilter_entity_id_fkey', 'callfilter') - op.create_foreign_key('fk_entity_id', 'callfilter', - 'entity', ['entity_id'], ['id']) - - drop_constraint('pickup_entity_id_fkey', 'pickup') - op.create_foreign_key('pickup_entity_id_fkey', 'pickup', - 'entity', ['entity_id'], ['id']) - - drop_constraint('schedule_entity_id_fkey', 'schedule') - op.create_foreign_key('schedule_entity_id_fkey', 'schedule', - 'entity', ['entity_id'], ['id']) - - drop_constraint('userfeatures_entity_id_fkey', 'userfeatures') - drop_constraint('userfeatures_entityid_fkey', 'userfeatures') - op.create_foreign_key('userfeatures_entityid_fkey', 'userfeatures', - 'entity', ['entityid'], ['id']) - - drop_constraint('fk_user_id', 'user_contact') - drop_constraint('user_contact_user_id_fkey', 'user_contact') - op.create_foreign_key('fk_user_id', 'user_contact', - 'userfeatures', ['user_id'], ['id'], - ondelete='CASCADE') - - drop_constraint('fk_phonebook_id', 'user_contact') - drop_constraint('user_contact_phonebook_id_fkey', 'user_contact') - op.create_foreign_key('fk_phonebook_id', 'user_contact', - 'phonebook', ['phonebook_id'], ['id'], - ondelete='CASCADE') - - drop_constraint('fk_phonebook_id', 'phonebooknumber') - drop_constraint('phonebooknumber_phonebookid_fkey', 'phonebooknumber') - op.create_foreign_key('fk_phonebook_id', 'phonebooknumber', - 'phonebook', ['phonebookid'], ['id'], - ondelete='CASCADE') - - drop_constraint('fk_phonebook_id', 'phonebookaddress') - drop_constraint('phonebookaddress_phonebookid_fkey', 'phonebookaddress') - op.create_foreign_key('fk_phonebook_id', 'phonebookaddress', - 'phonebook', ['phonebookid'], ['id'], - ondelete='CASCADE') diff --git a/alembic/versions/b78a74e69592_bump_version_20_14.py b/alembic/versions/b78a74e69592_bump_version_20_14.py deleted file mode 100644 index 0d400a1b..00000000 --- a/alembic/versions/b78a74e69592_bump_version_20_14.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_20_14 - -Revision ID: b78a74e69592 -Revises: 040b69fd8297 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'b78a74e69592' -down_revision = '040b69fd8297' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='20.14')) - - -def downgrade(): - pass diff --git a/alembic/versions/b7d3c4701095_add_a_meeting_number.py b/alembic/versions/b7d3c4701095_add_a_meeting_number.py deleted file mode 100644 index 6a8725b1..00000000 --- a/alembic/versions/b7d3c4701095_add_a_meeting_number.py +++ /dev/null @@ -1,45 +0,0 @@ -"""add a meeting number - -Revision ID: b7d3c4701095 -Revises: 2b51ff81d388 - -""" - -import random - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'b7d3c4701095' -down_revision = '2b51ff81d388' - -TABLE_NAME = 'meeting' -COLUMN_NAME = 'number' - - -meeting_tbl = sa.sql.table( - TABLE_NAME, - sa.column('uuid'), - sa.column('number'), -) - -def random_number(length=6): - return str(random.randint(0, int('9' * length))).rjust(length, '0') - - -def upgrade(): - op.add_column(TABLE_NAME, sa.Column(COLUMN_NAME, sa.Text)) - - query = sa.sql.select([meeting_tbl.c.uuid]) - for row in op.get_bind().execute(query): - op.execute( - meeting_tbl.update().where(meeting_tbl.c.uuid==row.uuid).values(number=random_number()) - ) - - op.alter_column(TABLE_NAME, COLUMN_NAME, nullable=False) - - -def downgrade(): - op.drop_column(TABLE_NAME, COLUMN_NAME) diff --git a/alembic/versions/b8d0848e7b2_add_acls_to_xivo_ctid_ng.py b/alembic/versions/b8d0848e7b2_add_acls_to_xivo_ctid_ng.py deleted file mode 100644 index 2a8a9073..00000000 --- a/alembic/versions/b8d0848e7b2_add_acls_to_xivo_ctid_ng.py +++ /dev/null @@ -1,47 +0,0 @@ -"""add ACLs to xivo-ctid-ng - -Revision ID: b8d0848e7b2 -Revises: 3c9280e9ed5c - -""" - -# revision identifiers, used by Alembic. -revision = 'b8d0848e7b2' -down_revision = '3c9280e9ed5c' - -from alembic import op -from sqlalchemy import sql - - -webservice = sql.table('accesswebservice', - sql.column('name'), - sql.column('acl')) - -SERVICE = 'xivo-ctid-ng' -NEW_ACL = set(['amid.action.ShowDialplan.create']) - - -def upgrade(): - current_acls = _get_current_acl(SERVICE) - new_acls = current_acls | NEW_ACL - _update_web_service_acl(SERVICE, new_acls) - - -def _get_current_acl(name): - return set(op.get_bind().execute( - sql.select([webservice.c.acl]).where(webservice.c.name == name) - ).scalar()) - - -def _update_web_service_acl(name, acl): - op.execute(webservice - .update() - .where( - webservice.c.name == name - ).values(acl=list(acl))) - - -def downgrade(): - current_acls = _get_current_acl(SERVICE) - new_acls = current_acls - NEW_ACL - _update_web_service_acl(SERVICE, new_acls) diff --git a/alembic/versions/b8f8ba046d25_directories_migration_xivo_directory.py b/alembic/versions/b8f8ba046d25_directories_migration_xivo_directory.py deleted file mode 100644 index 3ee06ac1..00000000 --- a/alembic/versions/b8f8ba046d25_directories_migration_xivo_directory.py +++ /dev/null @@ -1,83 +0,0 @@ -"""directories: migration xivo directory - -Revision ID: b8f8ba046d25 -Revises: c22356e22a13 - -""" - -# revision identifiers, used by Alembic. -revision = 'b8f8ba046d25' -down_revision = 'c22356e22a13' - -from alembic import op -from sqlalchemy import sql, and_ - -directories = sql.table( - 'directories', - sql.column('id'), - sql.column('name'), - sql.column('uri'), - sql.column('dirtype'), - sql.column('description'), - sql.column('xivo_username'), - sql.column('xivo_password'), - sql.column('xivo_verify_certificate'), - sql.column('xivo_custom_ca_path'), - sql.column('auth_backend'), - sql.column('auth_host'), - sql.column('auth_port'), - sql.column('auth_verify_certificate'), - sql.column('auth_custom_ca_path'), -) -webservice = sql.table( - 'accesswebservice', - sql.column('login'), - sql.column('passwd'), -) -old_uri = 'http://localhost:9487' -new_uri = 'https://localhost:9486' -username = 'wazo-dird-xivo-backend' -default_ca_path = '/usr/share/xivo-certs/server.crt' -dirtype = 'xivo' - -def find_ws_password(conn, username): - password = None - query = sql.select([webservice.c.passwd]).where(webservice.c.login == username) - for row in conn.execute(query): - password = row.passwd - - if not password: - raise Exception('failed to find a password for user {}'.format(username)) - - return password - - -def upgrade(): - password = find_ws_password(op.get_bind(), username) - op.execute(directories.update().values( - uri=new_uri, - xivo_username=username, - xivo_password=password, - xivo_verify_certificate=True, - xivo_custom_ca_path=default_ca_path, - auth_backend='xivo_service', - auth_host='localhost', - auth_port=9497, - auth_verify_certificate=True, - auth_custom_ca_path=default_ca_path, - ).where(and_(directories.c.dirtype == dirtype, directories.c.uri == old_uri))) - - -def downgrade(): - op.execute(directories.update().values( - uri=old_uri, - xivo_username=None, - xivo_password=None, - xivo_verify_certificate=False, - xivo_custom_ca_path=None, - auth_backend=None, - auth_host=None, - auth_port=None, - auth_verify_certificate=False, - auth_custom_ca_path=None, - ).where(and_(directories.c.dirtype == dirtype, directories.c.uri == new_uri))) diff --git a/alembic/versions/ba7c6bb897b3_add_switchboard_dialaction.py b/alembic/versions/ba7c6bb897b3_add_switchboard_dialaction.py deleted file mode 100644 index e962abe8..00000000 --- a/alembic/versions/ba7c6bb897b3_add_switchboard_dialaction.py +++ /dev/null @@ -1,74 +0,0 @@ -"""add_switchboard_dialaction - -Revision ID: ba7c6bb897b3 -Revises: 06e9e3483fec - -""" - -from alembic import op -import sqlalchemy as sa - -from sqlalchemy.types import Integer -from sqlalchemy.schema import Column - -# revision identifiers, used by Alembic. -revision = 'ba7c6bb897b3' -down_revision = 'ed40a90222f0' - -old_categories = ( - 'callfilter', - 'group', - 'incall', - 'queue', - 'user', - 'ivr', - 'ivr_choice', -) -new_categories = old_categories + ('switchboard',) - -new_type = sa.Enum(*new_categories, name='dialaction_category') -old_type = sa.Enum(*old_categories, name='dialaction_category') -tmp_type = sa.Enum(*new_categories, name='dialaction_category_being_replaced') - -dialaction_table = sa.sql.table('dialaction', - sa.Column('category', new_type, nullable=False)) - - -def upgrade(): - _add_timeout() - _add_dialaction() - - -def _add_dialaction(): - op.execute('ALTER TYPE dialaction_category RENAME TO dialaction_category_being_replaced') - - new_type.create(op.get_bind()) - op.execute('ALTER TABLE dialaction ALTER COLUMN category TYPE dialaction_category USING category::text::dialaction_category') - - tmp_type.drop(op.get_bind(), checkfirst=False) - - -def _add_timeout(): - op.add_column('switchboard', Column('timeout', Integer)) - - -def downgrade(): - _remove_dialaction() - _remove_timeout() - - -def _remove_dialaction(): - op.execute(dialaction_table - .delete() - .where(dialaction_table.c.category == 'switchboard')) - - op.execute('ALTER TYPE dialaction_category RENAME TO dialaction_category_being_replaced') - - old_type.create(op.get_bind()) - op.execute('ALTER TABLE dialaction ALTER COLUMN category TYPE dialaction_category USING category::text::dialaction_category') - - tmp_type.drop(op.get_bind(), checkfirst=False) - - -def _remove_timeout(): - op.drop_column('switchboard', 'timeout') diff --git a/alembic/versions/bba3a031fd01_remove_invalid_webrtc_options.py b/alembic/versions/bba3a031fd01_remove_invalid_webrtc_options.py deleted file mode 100644 index 5b815d57..00000000 --- a/alembic/versions/bba3a031fd01_remove_invalid_webrtc_options.py +++ /dev/null @@ -1,84 +0,0 @@ -"""remove-invalid-webrtc-options - -Revision ID: bba3a031fd01 -Revises: f98e74435092 - -""" - -from alembic import op -import sqlalchemy as sa - -# revision identifiers, used by Alembic. -revision = 'bba3a031fd01' -down_revision = 'f98e74435092' - -sip_template_tbl = sa.sql.table( - 'endpoint_sip_template', - sa.sql.column('child_uuid'), - sa.sql.column('parent_uuid'), -) -sip_tbl = sa.sql.table( - 'endpoint_sip', - sa.sql.column('uuid'), - sa.sql.column('tenant_uuid'), - sa.sql.column('template'), -) -sip_section_tbl = sa.sql.table( - 'endpoint_sip_section', - sa.sql.column('uuid'), - sa.sql.column('type'), - sa.sql.column('endpoint_sip_uuid'), -) -sip_section_option_tbl = sa.sql.table( - 'endpoint_sip_section_option', - sa.sql.column('uuid'), - sa.sql.column('key'), - sa.sql.column('endpoint_sip_section_uuid'), -) -tenant_tbl = sa.sql.table( - 'tenant', - sa.sql.column('uuid'), - sa.sql.column('webrtc_sip_template_uuid'), -) - - -def upgrade(): - delete_keys = ['dtls_verify', 'dtls_cert_file', 'dtls_private_key'] - query = ( - sip_section_option_tbl - .delete() - .where( - sa.sql.and_( - sip_section_option_tbl.c.key.in_(delete_keys), - sip_section_option_tbl.c.endpoint_sip_section_uuid.in_( - sa.sql.select([sip_section_tbl.c.uuid]) - .select_from( - sip_section_tbl - .join( - sip_tbl, - sip_tbl.c.uuid == sip_section_tbl.c.endpoint_sip_uuid, - ) - .join( - sip_template_tbl, - sip_tbl.c.uuid == sip_template_tbl.c.child_uuid, - ) - .join( - tenant_tbl, - tenant_tbl.c.webrtc_sip_template_uuid == sip_template_tbl.c.parent_uuid, - ) - ) - .where( - sa.sql.and_( - sip_tbl.c.template.is_(False), - sip_section_tbl.c.type == 'endpoint', - ) - ) - ) - ) - ) - ) - op.execute(query) - - -def downgrade(): - pass diff --git a/alembic/versions/bc9e62985a0_add_wazo_plugind_acl.py b/alembic/versions/bc9e62985a0_add_wazo_plugind_acl.py deleted file mode 100644 index 7e8cd80f..00000000 --- a/alembic/versions/bc9e62985a0_add_wazo_plugind_acl.py +++ /dev/null @@ -1,38 +0,0 @@ -"""add wazo-plugind acl - -Revision ID: bc9e62985a0 -Revises: 17653c3f37ce - -""" - -# revision identifiers, used by Alembic. -revision = 'bc9e62985a0' -down_revision = '17653c3f37ce' - -from alembic import op -from sqlalchemy import sql, func - - -webservice = sql.table('accesswebservice', - sql.column('name'), - sql.column('login'), - sql.column('passwd'), - sql.column('acl'), - sql.column('description')) -ACL = '{confd.infos.read}' -DESCRIPTION = 'Automatically created during upgrade' -SERVICE = 'wazo-plugind' - - -def upgrade(): - op.execute(webservice - .insert() - .values(name=SERVICE, - login=SERVICE, - passwd=func.substring(func.gen_salt('bf', 4), 8), - acl=ACL, - description=DESCRIPTION)) - - -def downgrade(): - op.execute(webservice.delete().where(webservice.c.name == SERVICE)) diff --git a/alembic/versions/bf1aaa27b7f8_fix_default_pjsip_template_transport.py b/alembic/versions/bf1aaa27b7f8_fix_default_pjsip_template_transport.py deleted file mode 100644 index 7b50d9e0..00000000 --- a/alembic/versions/bf1aaa27b7f8_fix_default_pjsip_template_transport.py +++ /dev/null @@ -1,83 +0,0 @@ -"""fix-default-pjsip-template-transport - -Revision ID: bf1aaa27b7f8 -Revises: 73166af50deb - -""" - -from alembic import op -from sqlalchemy import sql - - -# revision identifiers, used by Alembic. -revision = 'bf1aaa27b7f8' -down_revision = '73166af50deb' - -transport_tbl = sql.table( - 'pjsip_transport', - sql.column('uuid'), - sql.column('name'), -) -sip_tbl = sql.table( - 'endpoint_sip', - sql.column('uuid'), - sql.column('transport_uuid'), -) -tenant_tbl = sql.table( - 'tenant', - sql.column('uuid'), - sql.column('global_sip_template_uuid'), - sql.column('webrtc_sip_template_uuid'), -) - - -def upgrade(): - query = sql.select([transport_tbl.c.uuid]).where(transport_tbl.c.name == 'transport-udp') - transport_udp = op.get_bind().execute(query).first() - if transport_udp: - query = ( - sip_tbl - .update() - .values(transport_uuid=transport_udp.uuid) - .where( - sip_tbl.c.uuid.in_( - sql.select([sip_tbl.c.uuid]) - .select_from( - sip_tbl - .join( - tenant_tbl, - tenant_tbl.c.global_sip_template_uuid == sip_tbl.c.uuid, - ) - ) - .where(sip_tbl.c.transport_uuid.is_(None)) - ) - ) - ) - op.execute(query) - - query = sql.select([transport_tbl.c.uuid]).where(transport_tbl.c.name == 'transport-wss') - transport_wss = op.get_bind().execute(query).first() - if transport_wss: - query = ( - sip_tbl - .update() - .values(transport_uuid=transport_wss.uuid) - .where( - sip_tbl.c.uuid.in_( - sql.select([sip_tbl.c.uuid]) - .select_from( - sip_tbl - .join( - tenant_tbl, - tenant_tbl.c.webrtc_sip_template_uuid == sip_tbl.c.uuid, - ) - ) - .where(sip_tbl.c.transport_uuid.is_(None)) - ) - ) - ) - op.execute(query) - - -def downgrade(): - pass diff --git a/alembic/versions/c04ed3f6a685_fix_pjpjsip_queuemembers.py b/alembic/versions/c04ed3f6a685_fix_pjpjsip_queuemembers.py deleted file mode 100644 index 53233895..00000000 --- a/alembic/versions/c04ed3f6a685_fix_pjpjsip_queuemembers.py +++ /dev/null @@ -1,38 +0,0 @@ -"""fix PJPJSIP queuemembers - -Revision ID: c04ed3f6a685 -Revises: 785b8cb74daa - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'c04ed3f6a685' -down_revision = '785b8cb74daa' - -queuemember_tbl = sa.sql.table( - 'queuemember', - sa.sql.column('interface'), - sa.sql.column('channel'), -) - - -def upgrade(): - op.execute( - queuemember_tbl - .update() - .where( - sa.and_( - queuemember_tbl.c.channel == 'SIP', - queuemember_tbl.c.interface.startswith('PJPJSIP/'), - ) - ) - .values(interface=sa.func.replace(queuemember_tbl.c.interface, 'PJPJSIP', 'PJSIP')) - ) - - -def downgrade(): - pass diff --git a/alembic/versions/c18e988da503_add_name_nullable_on_schedule.py b/alembic/versions/c18e988da503_add_name_nullable_on_schedule.py deleted file mode 100644 index 8f8c43a7..00000000 --- a/alembic/versions/c18e988da503_add_name_nullable_on_schedule.py +++ /dev/null @@ -1,20 +0,0 @@ -"""add_name_nullable_on_schedule - -Revision ID: c18e988da503 -Revises: 1cc52186eb47 - -""" - -# revision identifiers, used by Alembic. -revision = 'c18e988da503' -down_revision = '1cc52186eb47' - -from alembic import op - - -def upgrade(): - op.alter_column('schedule', 'name', nullable=True, server_default=None) - - -def downgrade(): - op.alter_column('schedule', 'name', nullable=False, server_default='') diff --git a/alembic/versions/c193f30636ff_add_acl_to_xivo_ctid_ng.py b/alembic/versions/c193f30636ff_add_acl_to_xivo_ctid_ng.py deleted file mode 100644 index 3c1b8e83..00000000 --- a/alembic/versions/c193f30636ff_add_acl_to_xivo_ctid_ng.py +++ /dev/null @@ -1,45 +0,0 @@ -"""add acl to xivo-ctid-ng - -Revision ID: c193f30636ff -Revises: 40e2f31cf146 - -""" - -from alembic import op -from sqlalchemy import sql -from sqlalchemy.dialects.postgresql import ARRAY, VARCHAR - - -# revision identifiers, used by Alembic. -revision = 'c193f30636ff' -down_revision = '40e2f31cf146' - -accesswebservice = sql.table('accesswebservice', - sql.column('id'), - sql.column('name'), - sql.column('acl')) - -ACLS = ['auth.tenants.read'] -SERVICE = 'xivo-ctid-ng' - - -def upgrade(): - acls = sql.cast(ACLS, ARRAY(VARCHAR)) - query = (accesswebservice - .update() - .values( - acl=sql.func.array_cat(accesswebservice.c.acl, acls)) - .where( - accesswebservice.c.name == SERVICE)) - op.execute(query) - - -def downgrade(): - for acl in ACLS: - query = (accesswebservice - .update() - .values( - acl=sql.func.array_remove(accesswebservice.c.acl, acl)) - .where( - accesswebservice.c.name == SERVICE)) - op.execute(query) diff --git a/alembic/versions/c1d845eb61b4_add_external_app_table.py b/alembic/versions/c1d845eb61b4_add_external_app_table.py deleted file mode 100644 index 954b8e11..00000000 --- a/alembic/versions/c1d845eb61b4_add_external_app_table.py +++ /dev/null @@ -1,33 +0,0 @@ -"""add_external_app_table - -Revision ID: c1d845eb61b4 -Revises: f207de52e7d0 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'c1d845eb61b4' -down_revision = 'f207de52e7d0' - - -def upgrade(): - op.create_table( - 'external_app', - sa.Column('name', sa.Text, primary_key=True), - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - primary_key=True - ), - sa.Column('label', sa.Text), - sa.Column('configuration', sa.JSON), - ) - - -def downgrade(): - op.drop_table('external_app') diff --git a/alembic/versions/c22356e22a13_directories_add_auth_columns.py b/alembic/versions/c22356e22a13_directories_add_auth_columns.py deleted file mode 100644 index 423e6ea9..00000000 --- a/alembic/versions/c22356e22a13_directories_add_auth_columns.py +++ /dev/null @@ -1,32 +0,0 @@ -"""directories: add auth columns - -Revision ID: c22356e22a13 -Revises: 4cf687f2c0eb - -""" - -# revision identifiers, used by Alembic. -revision = 'c22356e22a13' -down_revision = '4cf687f2c0eb' - - -from alembic import op -import sqlalchemy as sa - -table = 'directories' - - -def upgrade(): - op.add_column(table, sa.Column('auth_backend', sa.Text)) - op.add_column(table, sa.Column('auth_host', sa.Text)) - op.add_column(table, sa.Column('auth_port', sa.Integer)) - op.add_column( - table, - sa.Column('auth_verify_certificate', sa.Boolean, nullable=False, server_default='False'), - ) - op.add_column(table, sa.Column('auth_custom_ca_path', sa.Text)) - - -def downgrade(): - for column in ('auth_backend', 'auth_host', 'auth_port', 'auth_verify_certificate', 'auth_custom_ca_path'): - op.drop_column(table, column) diff --git a/alembic/versions/c3b40a0998c4_update_sip_realm_to_wazo.py b/alembic/versions/c3b40a0998c4_update_sip_realm_to_wazo.py deleted file mode 100644 index 2acb0f59..00000000 --- a/alembic/versions/c3b40a0998c4_update_sip_realm_to_wazo.py +++ /dev/null @@ -1,38 +0,0 @@ -"""update_sip_realm_to_wazo - -Revision ID: c3b40a0998c4 -Revises: 30d7dcbb9133 - -""" - -# revision identifiers, used by Alembic. -revision = 'c3b40a0998c4' -down_revision = '30d7dcbb9133' - -from alembic import op -from sqlalchemy import sql, func - - -staticsip = sql.table('staticsip', - sql.column('var_name'), - sql.column('var_val')) - - -def upgrade(): - query = (staticsip - .update() - .values(var_val='wazo') - .where(sql.and_( - staticsip.c.var_name == "realm", - func.lower(staticsip.c.var_val) == "xivo"))) - op.execute(query) - - -def downgrade(): - query = (staticsip - .update() - .values(var_val='xivo') - .where(sql.and_( - staticsip.c.var_name == "realm", - func.lower(staticsip.c.var_val) == "wazo"))) - op.execute(query) diff --git a/alembic/versions/c3ecaf2f9e78_fix_invalid_extension_parking_lot.py b/alembic/versions/c3ecaf2f9e78_fix_invalid_extension_parking_lot.py deleted file mode 100644 index e3f92e6f..00000000 --- a/alembic/versions/c3ecaf2f9e78_fix_invalid_extension_parking_lot.py +++ /dev/null @@ -1,49 +0,0 @@ -"""fix_invalid_extension_parking_lot - -Revision ID: c3ecaf2f9e78 -Revises: 732a9b6500da - -""" - -from alembic import op -import sqlalchemy as sa -from sqlalchemy import sql - - -# revision identifiers, used by Alembic. -revision = 'c3ecaf2f9e78' -down_revision = '732a9b6500da' - -parking_lot_table = sql.table( - 'parking_lot', - sql.column('id'), -) - -extensions_table = sql.table( - 'extensions', - sql.column('id'), - sql.column('type'), - sql.column('typeval'), -) - - -def upgrade(): - query = sql.select( - [extensions_table.c.id, extensions_table.c.typeval] - ).where(extensions_table.c.type == 'parking') - - for extension in op.get_bind().execute(query): - query = ( - sql.select([parking_lot_table.c.id]) - .where(sql.cast(parking_lot_table.c.id, sa.String) == extension.typeval) - ) - if not op.get_bind().execute(query).scalar(): - op.execute( - extensions_table.update() - .where(extensions_table.c.id == extension.id) - .values(type='user', typeval='0') - ) - - -def downgrade(): - pass diff --git a/alembic/versions/c7de783d8c8c_add_a_tenant_uuid_to_groups.py b/alembic/versions/c7de783d8c8c_add_a_tenant_uuid_to_groups.py deleted file mode 100644 index 151ce22e..00000000 --- a/alembic/versions/c7de783d8c8c_add_a_tenant_uuid_to_groups.py +++ /dev/null @@ -1,62 +0,0 @@ -"""add a tenant_uuid to groups - -Revision ID: c7de783d8c8c -Revises: 92928db7221 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'c7de783d8c8c' -down_revision = '92928db7221' - -TABLE = 'groupfeatures' - - -def find_default_tenant_uuid(): - entity_table = sa.sql.table( - 'entity', - sa.sql.column('id'), - sa.sql.column('name'), - sa.sql.column('tenant_uuid'), - ) - query = sa.sql.select([entity_table.c.tenant_uuid]).order_by(entity_table.c.id) - for row in op.get_bind().execute(query): - return row.tenant_uuid - - -def get_context_tenant_map(): - tbl = sa.sql.table('context', sa.sql.column('name'), sa.sql.column('tenant_uuid')) - query = sa.sql.select([tbl.c.name, tbl.c.tenant_uuid]) - rows = op.get_bind().execute(query) - return {row.name: row.tenant_uuid for row in rows} - - -def associate_tenants(): - tbl = sa.sql.table(TABLE, sa.sql.column('context'), sa.sql.column('tenant_uuid')) - - for name, uuid in get_context_tenant_map().items(): - query = tbl.update().where(tbl.c.context == name).values(tenant_uuid=uuid) - op.execute(query) - - -def upgrade(): - default_tenant = find_default_tenant_uuid() - op.add_column( - TABLE, - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=False, - server_default=default_tenant), - ) - associate_tenants() - op.alter_column(TABLE, 'tenant_uuid', server_default=None) - - -def downgrade(): - op.drop_column(TABLE, 'tenant_uuid') diff --git a/alembic/versions/c8415eb8bfb5_bump_version_23_01.py b/alembic/versions/c8415eb8bfb5_bump_version_23_01.py deleted file mode 100644 index e704e038..00000000 --- a/alembic/versions/c8415eb8bfb5_bump_version_23_01.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_23_01 - -Revision ID: c8415eb8bfb5 -Revises: 1108308b3fd7 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'c8415eb8bfb5' -down_revision = '1108308b3fd7' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='23.01')) - - -def downgrade(): - pass diff --git a/alembic/versions/c8abcc5497ef_bump_version_20_01.py b/alembic/versions/c8abcc5497ef_bump_version_20_01.py deleted file mode 100644 index 8737e453..00000000 --- a/alembic/versions/c8abcc5497ef_bump_version_20_01.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_20_01 - -Revision ID: c8abcc5497ef -Revises: cc9063471025 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'c8abcc5497ef' -down_revision = 'cc9063471025' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='20.01')) - - -def downgrade(): - pass diff --git a/alembic/versions/c9ed2541b284_meeting_authorization_required.py b/alembic/versions/c9ed2541b284_meeting_authorization_required.py deleted file mode 100644 index 293048e9..00000000 --- a/alembic/versions/c9ed2541b284_meeting_authorization_required.py +++ /dev/null @@ -1,22 +0,0 @@ -"""meeting authorization required - -Revision ID: c9ed2541b284 -Revises: 381de5b6a1a5 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'c9ed2541b284' -down_revision = '381de5b6a1a5' - - -def upgrade(): - op.add_column('meeting', sa.Column('require_authorization', sa.Boolean, default=False, server_default=sa.text('false'))) - - -def downgrade(): - op.drop_column('meeting', 'require_authorization') diff --git a/alembic/versions/cac9af37c973_remove_deprecated_cti_tables.py b/alembic/versions/cac9af37c973_remove_deprecated_cti_tables.py deleted file mode 100644 index 8c5ea8e7..00000000 --- a/alembic/versions/cac9af37c973_remove_deprecated_cti_tables.py +++ /dev/null @@ -1,176 +0,0 @@ -"""remove_deprecated_cti_tables - -Revision ID: cac9af37c973 -Revises: 4c1cbf778770 - -""" - -from alembic import op -import sqlalchemy as sa - -from sqlalchemy.schema import Column - - -# revision identifiers, used by Alembic. -revision = 'cac9af37c973' -down_revision = '4c1cbf778770' - - -def upgrade(): - op.drop_column('userfeatures', 'cti_profile_id') - op.drop_table('ctistatus') - op.drop_table('cti_profile_service') - op.drop_table('cti_profile_preference') - op.drop_table('cti_profile_xlet') - op.drop_table('cti_profile') - op.drop_table('ctiphonehintsgroup') - op.drop_table('ctiphonehints') - op.drop_table('ctipresences') - op.drop_table('cti_preference') - op.drop_table('cti_service') - op.drop_table('cti_xlet_layout') - op.drop_table('cti_xlet') - - -def downgrade(): - op.create_table( - 'cti_xlet', - Column('id', sa.Integer, primary_key=True), - Column('plugin_name', sa.String(40), nullable=False), - ) - op.create_table( - 'cti_xlet_layout', - Column('id', sa.Integer, primary_key=True), - Column('name', sa.String(255), nullable=False), - ) - op.create_table( - 'cti_service', - Column('id', sa.Integer, primary_key=True), - Column('key', sa.String(255), nullable=False), - ) - op.create_table( - 'cti_preference', - Column('id', sa.Integer, primary_key=True), - Column('option', sa.String(255), nullable=False), - ) - op.create_table( - 'ctipresences', - Column('id', sa.Integer, primary_key=True), - Column('name', sa.String(255), nullable=False), - Column('description', sa.String(255)), - Column('deletable', sa.Integer), - ) - op.create_table( - 'ctiphonehints', - Column('id', sa.Integer, primary_key=True), - Column('idgroup', sa.Integer), - Column('number', sa.String(8)), - Column('name', sa.String(255)), - Column('color', sa.String(128)), - ) - op.create_table( - 'ctiphonehintsgroup', - Column('id', sa.Integer, primary_key=True), - Column('name', sa.String(255), nullable=False), - Column('description', sa.String(255)), - Column('deletable', sa.Integer), - ) - op.create_table( - 'cti_profile', - Column('id', sa.Integer, primary_key=True), - Column('name', sa.String(255), nullable=False), - Column( - 'presence_id', - sa.Integer, - sa.ForeignKey('ctipresences.id', ondelete='RESTRICT'), - ), - Column( - 'phonehints_id', - sa.Integer, - sa.ForeignKey('ctiphonehintsgroup.id', ondelete='RESTRICT'), - ), - ) - op.create_table( - 'cti_profile_xlet', - Column( - 'xlet_id', - sa.Integer, - sa.ForeignKey('cti_xlet.id', ondelete='CASCADE'), - primary_key=True, - ), - Column( - 'profile_id', - sa.Integer, - sa.ForeignKey('cti_profile.id', ondelete='CASCADE'), - primary_key=True, - ), - Column( - 'layout_id', - sa.Integer, - sa.ForeignKey('cti_xlet_layout.id', ondelete='RESTRICT'), - ), - Column('closable', sa.Boolean, server_default='True'), - Column('movable', sa.Boolean, server_default='True'), - Column('floating', sa.Boolean, server_default='True'), - Column('scrollable', sa.Boolean, server_default='True'), - Column('order', sa.Integer), - ) - op.create_table( - 'cti_profile_service', - Column( - 'profile_id', - sa.Integer, - sa.ForeignKey('cti_profile.id', ondelete='CASCADE'), - primary_key=True, - ), - Column( - 'service_id', - sa.Integer, - sa.ForeignKey('cti_service.id', ondelete='CASCADE'), - primary_key=True, - ), - ) - op.create_table( - 'cti_profile_preference', - Column( - 'profile_id', - sa.Integer, - sa.ForeignKey('cti_profile.id', ondelete='CASCADE'), - primary_key=True, - ), - Column( - 'preference_id', - sa.Integer, - sa.ForeignKey('cti_preference.id', ondelete='CASCADE'), - primary_key=True, - ), - Column('value', sa.String(255)), - ) - op.create_table( - 'ctistatus', - Column('id', sa.Integer, primary_key=True), - Column( - 'presence_id', - sa.Integer, - sa.ForeignKey('ctipresences.id', ondelete='CASCADE'), - ), - Column('name', sa.String(255), nullable=False), - Column('display_name', sa.String(255)), - Column('actions', sa.String(255)), - Column('color', sa.String(20)), - Column('access_status', sa.String(255)), - Column('deletable', sa.Integer), - ) - op.create_unique_constraint( - 'ctistatus_presence_id_name_key', - 'ctistatus', - ['presence_id', 'name'], - ) - op.add_column( - 'userfeatures', - Column( - 'cti_profile_id', - sa.Integer, - sa.ForeignKey('cti_profile.id', ondelete='RESTRICT'), - ) - ) diff --git a/alembic/versions/cb5666745311_bump_version_21_10.py b/alembic/versions/cb5666745311_bump_version_21_10.py deleted file mode 100644 index 9c050be3..00000000 --- a/alembic/versions/cb5666745311_bump_version_21_10.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_21_10 - -Revision ID: cb5666745311 -Revises: 978e620de034 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'cb5666745311' -down_revision = '978e620de034' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='21.10')) - - -def downgrade(): - pass diff --git a/alembic/versions/cbd383662cc0_add_timezone_data_to_the_cel_eventtime_.py b/alembic/versions/cbd383662cc0_add_timezone_data_to_the_cel_eventtime_.py deleted file mode 100644 index 6051879a..00000000 --- a/alembic/versions/cbd383662cc0_add_timezone_data_to_the_cel_eventtime_.py +++ /dev/null @@ -1,28 +0,0 @@ -"""add timezone data to the cel.eventtime column - -Revision ID: cbd383662cc0 -Revises: fbbbf7d78ed0 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'cbd383662cc0' -down_revision = 'fbbbf7d78ed0' - - -def upgrade(): - op.alter_column('cel', 'eventtime', nullable=False, type_=sa.DateTime(timezone=True)) - op.alter_column('call_log', 'date', type_=sa.DateTime(timezone=True)) - op.alter_column('call_log', 'date_answer', type_=sa.DateTime(timezone=True)) - op.alter_column('call_log', 'date_end', type_=sa.DateTime(timezone=True)) - - -def downgrade(): - op.alter_column('call_log', 'date', type_=sa.DateTime()) - op.alter_column('call_log', 'date_answer', type_=sa.DateTime()) - op.alter_column('call_log', 'date_end', type_=sa.DateTime()) - op.alter_column('cel', 'eventtime', nullable=False, type_=sa.DateTime()) diff --git a/alembic/versions/cc9063471025_registration_options.py b/alembic/versions/cc9063471025_registration_options.py deleted file mode 100644 index ab850a1d..00000000 --- a/alembic/versions/cc9063471025_registration_options.py +++ /dev/null @@ -1,66 +0,0 @@ -"""registration options - -Revision ID: cc9063471025 -Revises: 4c4a8eaa31e7 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'cc9063471025' -down_revision = '4c4a8eaa31e7' - - -staticsip_table = sa.sql.table( - 'staticsip', - sa.sql.column('var_name'), - sa.sql.column('var_val'), - sa.sql.column('category'), - sa.sql.column('filename'), -) - -DEFAULTS = { - 'auth_rejection_permanent': 'no', - 'forbidden_retry_interval': 30, - 'fatal_retry_interval': 30, -} -DEFAULT_MAX_RETRIES = 10000 - - -def upgrade(): - query = ( - sa.sql.select( - [staticsip_table.c.var_name, staticsip_table.c.var_val], - ).where( - staticsip_table.c.category == 'general', - ) - ) - - # If registerattemps is configured and not 0 use that value - max_retries = None - existing_keys = set() - for var_name, var_val in op.get_bind().execute(query): - existing_keys.add(var_name) - if var_name == 'registerattempts' and var_val not in ('0', 0): - max_retries = var_val - DEFAULTS['max_retries'] = max_retries or DEFAULT_MAX_RETRIES - - op.execute(staticsip_table.delete().where(sa.sql.and_( - staticsip_table.c.category == 'general', - staticsip_table.c.var_name.in_(DEFAULTS.keys()), - ))) - - for key, value in DEFAULTS.items(): - op.execute(staticsip_table.insert().values( - var_name=key, - var_val=value, - filename='sip.conf', - category='general', - )) - - -def downgrade(): - pass diff --git a/alembic/versions/ce624f5d7fe2_add_auth_tenants_read_to_ctid.py b/alembic/versions/ce624f5d7fe2_add_auth_tenants_read_to_ctid.py deleted file mode 100644 index d35fdaa3..00000000 --- a/alembic/versions/ce624f5d7fe2_add_auth_tenants_read_to_ctid.py +++ /dev/null @@ -1,50 +0,0 @@ -"""add_auth_tenants_read_to_ctid - -Revision ID: ce624f5d7fe2 -Revises: 778dc763148f - -""" - -from alembic import op -from sqlalchemy import sql -from sqlalchemy.dialects.postgresql import ARRAY, VARCHAR - -# revision identifiers, used by Alembic. -revision = 'ce624f5d7fe2' -down_revision = '778dc763148f' - -accesswebservice = sql.table( - 'accesswebservice', - sql.column('id'), - sql.column('name'), - sql.column('acl'), -) - -ACLS = ['auth.tenants.read'] -SERVICE = 'xivo-ctid' - - -def upgrade(): - acls = sql.cast(ACLS, ARRAY(VARCHAR)) - query = ( - accesswebservice - .update() - .values( - acl=sql.func.array_cat(accesswebservice.c.acl, acls)) - .where( - accesswebservice.c.name == SERVICE) - ) - op.execute(query) - - -def downgrade(): - for acl in ACLS: - query = ( - accesswebservice - .update() - .values( - acl=sql.func.array_remove(accesswebservice.c.acl, acl)) - .where( - accesswebservice.c.name == SERVICE) - ) - op.execute(query) diff --git a/alembic/versions/ce76c220eaab_bump_version_21_16.py b/alembic/versions/ce76c220eaab_bump_version_21_16.py deleted file mode 100644 index e111c435..00000000 --- a/alembic/versions/ce76c220eaab_bump_version_21_16.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_21_16 - -Revision ID: ce76c220eaab -Revises: 61e3d7c65755 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'ce76c220eaab' -down_revision = '61e3d7c65755' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='21.16')) - - -def downgrade(): - pass diff --git a/alembic/versions/d0411d361d57_add_answer_to_application_dest_node.py b/alembic/versions/d0411d361d57_add_answer_to_application_dest_node.py deleted file mode 100644 index cf2d601d..00000000 --- a/alembic/versions/d0411d361d57_add_answer_to_application_dest_node.py +++ /dev/null @@ -1,26 +0,0 @@ -"""add_answer_to_application_dest_node - -Revision ID: d0411d361d57 -Revises: 4fe20686380b - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'd0411d361d57' -down_revision = '4fe20686380b' - - -def upgrade(): - op.add_column( - 'application_dest_node', - sa.Column('answer', sa.Boolean, nullable=False, server_default='True') - ) - op.alter_column('application_dest_node', 'answer', server_default=None) - - -def downgrade(): - op.drop_column('application_dest_node', 'answer') diff --git a/alembic/versions/d0f74d74eb5f_bump_version_19_11.py b/alembic/versions/d0f74d74eb5f_bump_version_19_11.py deleted file mode 100644 index edb954f9..00000000 --- a/alembic/versions/d0f74d74eb5f_bump_version_19_11.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_19_11 - -Revision ID: d0f74d74eb5f -Revises: 17ea1bc19d64 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'd0f74d74eb5f' -down_revision = '17ea1bc19d64' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='19.11')) - - -def downgrade(): - pass diff --git a/alembic/versions/d47f295009dd_remove_sipauthentication.py b/alembic/versions/d47f295009dd_remove_sipauthentication.py deleted file mode 100644 index 3327afcd..00000000 --- a/alembic/versions/d47f295009dd_remove_sipauthentication.py +++ /dev/null @@ -1,37 +0,0 @@ -"""remove-sipauthentication - -Revision ID: d47f295009dd -Revises: d90ff200ae53 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'd47f295009dd' -down_revision = 'd90ff200ae53' - -secret_mode_type = sa.Enum( - 'md5', - 'clear', - name='sipauthentication_secretmode', -) - - -def upgrade(): - op.drop_table('sipauthentication') - secret_mode_type.drop(op.get_bind(), checkfirst=False) - - -def downgrade(): - op.create_table( - 'sipauthentication', - sa.Column('id', sa.types.INTEGER, primary_key=True), - sa.Column('usersip_id', sa.types.INTEGER), - sa.Column('user', sa.types.String(255), nullable=False), - sa.Column('secretmode', secret_mode_type, nullable=False), - sa.Column('secret', sa.types.String(255), nullable=False), - sa.Column('realm', sa.types.String(1024), nullable=False), - ) diff --git a/alembic/versions/d56d7434e9f4_bump_version_20_12.py b/alembic/versions/d56d7434e9f4_bump_version_20_12.py deleted file mode 100644 index d50b605d..00000000 --- a/alembic/versions/d56d7434e9f4_bump_version_20_12.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_20_12 - -Revision ID: d56d7434e9f4 -Revises: 106159225d65 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'd56d7434e9f4' -down_revision = '106159225d65' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='20.12')) - - -def downgrade(): - pass diff --git a/alembic/versions/d6be50f692dc_add_sip_options.py b/alembic/versions/d6be50f692dc_add_sip_options.py deleted file mode 100644 index 46c96ffc..00000000 --- a/alembic/versions/d6be50f692dc_add_sip_options.py +++ /dev/null @@ -1,24 +0,0 @@ -"""add sip options - -Revision ID: d6be50f692dc -Revises: 5524f5f02959 - -""" - -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects.postgresql import ARRAY - -# revision identifiers, used by Alembic. -revision = 'd6be50f692dc' -down_revision = '5524f5f02959' - - -def upgrade(): - op.add_column('usersip', sa.Column('options', - ARRAY(sa.String, dimensions=2), - nullable=False, server_default='{}')) - - -def downgrade(): - op.drop_column('usersip', 'options') diff --git a/alembic/versions/d81a903b6d1e_ivr_add_tenant_uuid.py b/alembic/versions/d81a903b6d1e_ivr_add_tenant_uuid.py deleted file mode 100644 index 0cffcba2..00000000 --- a/alembic/versions/d81a903b6d1e_ivr_add_tenant_uuid.py +++ /dev/null @@ -1,45 +0,0 @@ -"""ivr_add_tenant_uuid - -Revision ID: d81a903b6d1e -Revises: 40e6d1e4c2c3 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'd81a903b6d1e' -down_revision = '40e6d1e4c2c3' - -TABLE = 'ivr' - - -def find_default_tenant_uuid(): - entity_table = sa.sql.table( - 'entity', - sa.sql.column('id'), - sa.sql.column('tenant_uuid'), - ) - query = sa.sql.select([entity_table.c.tenant_uuid]).order_by(entity_table.c.id) - for row in op.get_bind().execute(query): - return row.tenant_uuid - - -def upgrade(): - default_tenant = find_default_tenant_uuid() - op.add_column( - TABLE, - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=False, - server_default=default_tenant), - ) - op.alter_column(TABLE, 'tenant_uuid', server_default=None) - - -def downgrade(): - op.drop_column(TABLE, 'tenant_uuid') diff --git a/alembic/versions/d90ff200ae53_bump_version_20_09.py b/alembic/versions/d90ff200ae53_bump_version_20_09.py deleted file mode 100644 index 6bbc6678..00000000 --- a/alembic/versions/d90ff200ae53_bump_version_20_09.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_20_09 - -Revision ID: d90ff200ae53 -Revises: 06149af25f0d - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'd90ff200ae53' -down_revision = '06149af25f0d' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='20.09')) - - -def downgrade(): - pass diff --git a/alembic/versions/d9e7aac4970_add_call_log_participant_table.py b/alembic/versions/d9e7aac4970_add_call_log_participant_table.py deleted file mode 100644 index e4370621..00000000 --- a/alembic/versions/d9e7aac4970_add_call_log_participant_table.py +++ /dev/null @@ -1,32 +0,0 @@ -"""add call_log_participant table - -Revision ID: d9e7aac4970 -Revises: 42e9771685b0 - -""" - -# revision identifiers, used by Alembic. -revision = 'd9e7aac4970' -down_revision = '42e9771685b0' - -import sqlalchemy as sa -from alembic import op - - -def upgrade(): - op.create_table( - 'call_log_participant', - sa.Column('uuid', sa.String(38)), - sa.Column('call_log_id', sa.Integer), - sa.Column('user_uuid', sa.String(38), nullable=False), - sa.Column('line_id', sa.Integer), - sa.Column('role', sa.Enum('source', 'destination', name='call_log_participant_role'), nullable=False), - sa.PrimaryKeyConstraint('uuid'), - sa.ForeignKeyConstraint(['call_log_id'], ['call_log.id'], name='fk_call_log_id', ondelete='CASCADE'), - sa.Index('call_log_participant__idx__user_uuid', 'user_uuid') - ) - - -def downgrade(): - op.drop_table('call_log_participant') - op.execute('DROP_TYPE call_log_participant_role') diff --git a/alembic/versions/d9eaed7a2f42_convert_queuemember_to_pjsip.py b/alembic/versions/d9eaed7a2f42_convert_queuemember_to_pjsip.py deleted file mode 100644 index 930c1947..00000000 --- a/alembic/versions/d9eaed7a2f42_convert_queuemember_to_pjsip.py +++ /dev/null @@ -1,32 +0,0 @@ -"""convert_queuemember_to_pjsip - -Revision ID: d9eaed7a2f42 -Revises: ba7c6bb897b3 - -""" - -from alembic import op -import sqlalchemy as sa - -# revision identifiers, used by Alembic. -revision = 'd9eaed7a2f42' -down_revision = 'ba7c6bb897b3' - -queuemember_tbl = sa.sql.table( - 'queuemember', - sa.sql.column('interface'), - sa.sql.column('channel'), -) - - -def upgrade(): - op.execute( - queuemember_tbl - .update() - .where(queuemember_tbl.c.channel == 'SIP') - .values(interface='PJ' + queuemember_tbl.c.interface) - ) - - -def downgrade(): - pass diff --git a/alembic/versions/da06cfd76289_bump_version_21_15.py b/alembic/versions/da06cfd76289_bump_version_21_15.py deleted file mode 100644 index 0f552635..00000000 --- a/alembic/versions/da06cfd76289_bump_version_21_15.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_21_15 - -Revision ID: da06cfd76289 -Revises: 12b81f6c229b - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'da06cfd76289' -down_revision = '12b81f6c229b' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='21.15')) - - -def downgrade(): - pass diff --git a/alembic/versions/da53b63d9433_add_missing_pjsip_options.py b/alembic/versions/da53b63d9433_add_missing_pjsip_options.py deleted file mode 100644 index 5d5d9e38..00000000 --- a/alembic/versions/da53b63d9433_add_missing_pjsip_options.py +++ /dev/null @@ -1,151 +0,0 @@ -"""add-missing-pjsip-options - -Revision ID: da53b63d9433 -Revises: ea9cdf2d59f8 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'da53b63d9433' -down_revision = 'ea9cdf2d59f8' - -user_sip_tbl = sa.sql.table( - 'usersip', - sa.sql.column('name'), - sa.sql.column('category'), - sa.sql.column('options'), -) -endpoint_sip_tbl = sa.sql.table( - 'endpoint_sip', - sa.sql.column('uuid'), - sa.sql.column('name'), -) -endpoint_sip_section_tbl = sa.sql.table( - 'endpoint_sip_section', - sa.sql.column('uuid'), - sa.sql.column('type'), - sa.sql.column('endpoint_sip_uuid'), -) -endpoint_sip_section_option_tbl = sa.sql.table( - 'endpoint_sip_section_option', - sa.sql.column('uuid'), - sa.sql.column('key'), - sa.sql.column('value'), - sa.sql.column('endpoint_sip_section_uuid'), -) - -IDENTIFY = 'identify' -REGISTRATION = 'registration' -MISSING_OPTIONS = { - 'srv_lookups': IDENTIFY, - 'match_header': IDENTIFY, - 'contact_header_params': REGISTRATION, - 'forbidden_retry_interval': REGISTRATION, - 'fatal_retry_interval': REGISTRATION, - 'line': REGISTRATION, - 'server_uri': REGISTRATION, - 'support_path': REGISTRATION, - 'support_outbound': REGISTRATION, -} - - -def get_trunks_with_options(): - query = sa.sql.select([ - user_sip_tbl.c.name, - user_sip_tbl.c.options, - ]).where( - sa.and_( - user_sip_tbl.c.category == 'trunk', - ) - ) - rows = op.get_bind().execute(query) - return [{ - 'name': row.name, - 'options': row.options, - } for row in rows] - - -def find_missing_trunk_options(trunk): - missing = {IDENTIFY: [], REGISTRATION: []} - for key, section in MISSING_OPTIONS.items(): - for option, value in trunk['options']: - if option == key: - missing[section].append([key, value]) - return missing - - -def find_endpoint_uuid(name): - query = sa.sql.select([ - endpoint_sip_tbl.c.uuid - ]).where(endpoint_sip_tbl.c.name == name) - for row in op.get_bind().execute(query): - return row.uuid - - -def add_section_option(section_uuid, key, value): - query = endpoint_sip_section_option_tbl.insert().values( - key=key, value=value, endpoint_sip_section_uuid=section_uuid, - ) - op.execute(query) - - -def find_section(endpoint_uuid, section): - query = sa.sql.select([ - endpoint_sip_section_tbl.c.uuid - ]).where(sa.and_( - endpoint_sip_section_tbl.c.type == section, - endpoint_sip_section_tbl.c.endpoint_sip_uuid == endpoint_uuid, - )) - for row in op.get_bind().execute(query): - return row.uuid - - -def create_section(endpoint_uuid, section): - query = endpoint_sip_section_tbl.insert().returning( - endpoint_sip_section_tbl.c.uuid, - ).values( - endpoint_sip_uuid=endpoint_uuid, - type=section, - ) - return op.get_bind().execute(query).scalar() - - -def find_or_create_section(endpoint_uuid, name): - section_uuid = find_section(endpoint_uuid, name) - if not section_uuid: - section_uuid = create_section(endpoint_uuid, name) - return section_uuid - - -def insert_missing_options(name, options): - if not options[REGISTRATION] and not options[IDENTIFY]: - return - - endpoint_uuid = find_endpoint_uuid(name) - if not endpoint_uuid: - return - - if options[IDENTIFY]: - identify_section_uuid = find_or_create_section(endpoint_uuid, IDENTIFY) - for key, value in options[IDENTIFY]: - add_section_option(identify_section_uuid, key, value) - - if options[REGISTRATION]: - registration_section_uuid = find_or_create_section(endpoint_uuid, REGISTRATION) - for key, value in options[REGISTRATION]: - add_section_option(registration_section_uuid, key, value) - - -def upgrade(): - trunks = get_trunks_with_options() - for trunk in trunks: - to_insert = find_missing_trunk_options(trunk) - insert_missing_options(trunk['name'], to_insert) - - -def downgrade(): - pass diff --git a/alembic/versions/da58e9e49eb_add_transfers_acl_to_ctid.py b/alembic/versions/da58e9e49eb_add_transfers_acl_to_ctid.py deleted file mode 100644 index cac0b402..00000000 --- a/alembic/versions/da58e9e49eb_add_transfers_acl_to_ctid.py +++ /dev/null @@ -1,48 +0,0 @@ -"""add transfers acl to ctid - -Revision ID: da58e9e49eb -Revises: 49126e9fffe2 - -""" - -# revision identifiers, used by Alembic. -revision = 'da58e9e49eb' -down_revision = '49126e9fffe2' - - -from alembic import op -from sqlalchemy import sql - - -webservice = sql.table('accesswebservice', - sql.column('name'), - sql.column('acl')) - -SERVICE = 'xivo-ctid' -NEW_ACL = set(['ctid-ng.#']) - - -def _get_current_acl(name): - return set(op.get_bind().execute( - sql.select([webservice.c.acl]).where(webservice.c.name == name) - ).scalar()) - - -def _update_web_service_acl(name, acl): - op.execute(webservice - .update() - .where( - webservice.c.name == name - ).values(acl=list(acl))) - - -def upgrade(): - current_acls = _get_current_acl(SERVICE) - new_acls = current_acls | NEW_ACL - _update_web_service_acl(SERVICE, new_acls) - - -def downgrade(): - current_acls = _get_current_acl(SERVICE) - new_acls = current_acls - NEW_ACL - _update_web_service_acl(SERVICE, new_acls) diff --git a/alembic/versions/dba4e40979ae_add_date_answer_to_call_log.py b/alembic/versions/dba4e40979ae_add_date_answer_to_call_log.py deleted file mode 100644 index ad0ee4b3..00000000 --- a/alembic/versions/dba4e40979ae_add_date_answer_to_call_log.py +++ /dev/null @@ -1,21 +0,0 @@ -"""add_date_answer_to_call_log - -Revision ID: dba4e40979ae -Revises: 3612e8058d92 - -""" - -# revision identifiers, used by Alembic. -revision = 'dba4e40979ae' -down_revision = '3612e8058d92' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - op.add_column('call_log', sa.Column('date_answer', sa.DateTime)) - - -def downgrade(): - op.drop_column('call_log', 'date_answer') diff --git a/alembic/versions/dd011dfbb5_remove_mohsuggest_from_usersip.py b/alembic/versions/dd011dfbb5_remove_mohsuggest_from_usersip.py deleted file mode 100644 index a6f158ea..00000000 --- a/alembic/versions/dd011dfbb5_remove_mohsuggest_from_usersip.py +++ /dev/null @@ -1,21 +0,0 @@ -"""remove mohsuggest from UserSIP - -Revision ID: dd011dfbb5 -Revises: 5073b1fa473e - -""" - -# revision identifiers, used by Alembic. -revision = 'dd011dfbb5' -down_revision = '5073b1fa473e' - -from alembic import op -import sqlalchemy as sa - - -def upgrade(): - op.drop_column('usersip', 'mohsuggest') - - -def downgrade(): - op.add_column('usersip', sa.Column('mohsuggest', sa.String(80))) diff --git a/alembic/versions/dd0c465315d_migrate_forward_func_keys.py b/alembic/versions/dd0c465315d_migrate_forward_func_keys.py deleted file mode 100644 index 6a868e2a..00000000 --- a/alembic/versions/dd0c465315d_migrate_forward_func_keys.py +++ /dev/null @@ -1,307 +0,0 @@ -"""migrate func keys with args - -Revision ID: dd0c465315d -Revises: 4ce50bcf2a0e - -""" - -# revision identifiers, used by Alembic. -revision = 'dd0c465315d' -down_revision = '4ce50bcf2a0e' - -from alembic import op -from sqlalchemy import sql -import sqlalchemy as sa - - -TYPE_SPEEDDIAL = 'speeddial' - -DESTINATION_FORWARD_ID = 6 -DESTINATION_FORWARD_NAME = 'forward' - -FORWARD_TYPES = ('fwdrna', - 'fwdbusy', - 'fwdunc') - -phonefunckey_table = sql.table('phonefunckey', - sql.column('iduserfeatures'), - sql.column('fknum'), - sql.column('exten'), - sql.column('typeextenumbers'), - sql.column('typevalextenumbers'), - sql.column('typeextenumbersright'), - sql.column('typevalextenumbersright'), - sql.column('label'), - sql.column('supervision'), - sql.column('progfunckey')) - -func_key_table = sql.table('func_key', - sql.column('id'), - sql.column('type_id'), - sql.column('destination_type_id')) - -destination_forward_table = sql.table('func_key_dest_forward', - sql.column('func_key_id'), - sql.column('destination_type_id'), - sql.column('extension_id'), - sql.column('number')) - -func_key_type_table = sql.table('func_key_type', - sql.column('id'), - sql.column('name')) - -func_key_mapping_table = sql.table('func_key_mapping', - sql.column('template_id'), - sql.column('func_key_id'), - sql.column('destination_type_id'), - sql.column('label'), - sql.column('position'), - sql.column('blf')) - -template_table = sql.table('func_key_template', sql.column('id')) - -extensions_table = sql.table('extensions', - sql.column('id'), - sql.column('commented'), - sql.column('context'), - sql.column('exten'), - sql.column('type'), - sql.column('typeval')) - -user_table = sql.table('userfeatures', - sql.column('id'), - sql.column('func_key_private_template_id')) - -destination_type_table = sql.table('func_key_destination_type', - sql.column('id'), - sql.column('name')) - - -func_key_columns = ( - phonefunckey_table.c.iduserfeatures.label('user_id'), - phonefunckey_table.c.fknum.label('position'), - phonefunckey_table.c.label, - phonefunckey_table.c.typevalextenumbers.label('extension_type'), - phonefunckey_table.c.exten.label('number'), - sql.cast(phonefunckey_table.c.supervision, sa.Boolean).label('blf'), -) - -old_func_key_columns = ( - func_key_mapping_table.c.func_key_id, - func_key_mapping_table.c.template_id, - func_key_mapping_table.c.position, - func_key_mapping_table.c.blf, - func_key_mapping_table.c.label, - destination_forward_table.c.extension_id, - destination_forward_table.c.number, - extensions_table.c.typeval, - user_table.c.id.label('user_id') -) - -func_keys_query = (sql.select(func_key_columns) - .where( - phonefunckey_table.c.typevalextenumbers.in_(FORWARD_TYPES) - )) - - -old_func_keys_query = (sql.select(old_func_key_columns, - from_obj=[ - func_key_mapping_table.join( - destination_forward_table, - func_key_mapping_table.c.func_key_id == destination_forward_table.c.func_key_id) - .join(extensions_table, - destination_forward_table.c.extension_id == extensions_table.c.id) - .join(template_table, - func_key_mapping_table.c.template_id == template_table.c.id) - .join(user_table, - template_table.c.id == user_table.c.func_key_private_template_id) - ])) - - -def upgrade(): - delete_duplicate_fks() - migrate_func_keys() - delete_old_func_keys() - - -def delete_duplicate_fks(): - for row in get_duplicate_func_keys(): - delete_duplicate_fk(row.iduserfeatures, row.typevalextenumbers, row.fknum) - - -def get_duplicate_func_keys(): - columns = (phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.typevalextenumbers, - sa.func.min(phonefunckey_table.c.fknum).label("first_position")) - - valid_fk_subq = (sql.select(columns) - .where( - phonefunckey_table.c.typevalextenumbers.in_(FORWARD_TYPES)) - .group_by( - phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.typevalextenumbers) - .having( - sa.func.count(phonefunckey_table.c.typevalextenumbers) > 1) - .alias()) - - columns = (phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.typevalextenumbers, - phonefunckey_table.c.fknum) - - join_condition = sql.and_( - phonefunckey_table.c.typevalextenumbers == valid_fk_subq.c.typevalextenumbers, - phonefunckey_table.c.fknum > valid_fk_subq.c.first_position, - phonefunckey_table.c.iduserfeatures == valid_fk_subq.c.iduserfeatures) - - duplicate_fk_query = (sql.select(columns, - from_obj=[ - phonefunckey_table.join( - valid_fk_subq, - join_condition - ) - ])) - - return op.get_bind().execute(duplicate_fk_query) - - -def delete_duplicate_fk(iduserfeatures, typevalextenumbers, fknum): - print('[MIGRATE_FK] : Deleting func key for user "%s" (fk position %s with action %s)' % - (iduserfeatures, fknum, typevalextenumbers)) - - query = (phonefunckey_table - .delete() - .where(sql.and_( - phonefunckey_table.c.iduserfeatures == iduserfeatures, - phonefunckey_table.c.typevalextenumbers == typevalextenumbers, - phonefunckey_table.c.fknum == fknum))) - - op.get_bind().execute(query) - - -def migrate_func_keys(): - for row in op.get_bind().execute(func_keys_query): - func_key_id = create_func_key() - extension_id = get_extension_id_from_type(row.extension_type) - create_forward_destination(func_key_id, extension_id, row.number) - create_mapping(func_key_id, row) - - -def create_func_key(): - speeddial_id = get_speeddial_id() - insert_query = (func_key_table - .insert() - .returning(func_key_table.c.id) - .values(type_id=speeddial_id, - destination_type_id=DESTINATION_FORWARD_ID)) - - return op.get_bind().execute(insert_query).scalar() - - -def get_speeddial_id(): - return op.get_bind().execute( - sql.select( - [func_key_type_table.c.id]) - .where( - func_key_type_table.c.name == TYPE_SPEEDDIAL) - ).scalar() - - -def get_extension_id_from_type(extentype): - return op.get_bind().execute( - sql.select( - [extensions_table.c.id]) - .where( - extensions_table.c.typeval == extentype) - ).scalar() - - -def create_forward_destination(func_key_id, extension_id, number): - destination_query = (destination_forward_table - .insert() - .returning(destination_forward_table.c.func_key_id) - .values(func_key_id=func_key_id, - destination_type_id=DESTINATION_FORWARD_ID, - extension_id=extension_id, - number=number)) - - op.get_bind().execute(destination_query) - - -def create_mapping(func_key_id, func_key_row): - conn = op.get_bind() - - template_id = conn.execute(sql.select( - [user_table.c.func_key_private_template_id]) - .where( - user_table.c.id == func_key_row.user_id) - ).scalar() - - mapping_query = (func_key_mapping_table - .insert() - .returning(func_key_mapping_table.c.func_key_id) - .values(func_key_id=func_key_id, - template_id=template_id, - destination_type_id=DESTINATION_FORWARD_ID, - label=func_key_row.label, - position=func_key_row.position, - blf=func_key_row.blf)) - - conn.execute(mapping_query) - - -def delete_old_func_keys(): - delete_query = (phonefunckey_table - .delete() - .where(phonefunckey_table.c.typevalextenumbers - .in_(FORWARD_TYPES))) - - op.get_bind().execute(delete_query) - - -def downgrade(): - for row in op.get_bind().execute(old_func_keys_query): - create_old_func_keys(row) - delete_mapping(row.func_key_id, row.template_id) - delete_dest_forward(row.func_key_id) - delete_func_key(row.func_key_id) - - -def create_old_func_keys(row): - supervision = 1 if row.blf else 0 - - row = {'iduserfeatures': row.user_id, - 'fknum': row.position, - 'typeextenumbers': 'extenfeatures', - 'typevalextenumbers': row.typeval, - 'typeextenumbersright': None, - 'typevalextenumbersright': None, - 'label': row.label, - 'exten': row.number, - 'supervision': supervision} - - op.bulk_insert(phonefunckey_table, [row]) - - -def delete_mapping(func_key_id, template_id): - query = (func_key_mapping_table - .delete() - .where(sql.and_( - func_key_mapping_table.c.func_key_id == func_key_id, - func_key_mapping_table.c.template_id == template_id))) - - op.get_bind().execute(query) - - -def delete_dest_forward(func_key_id): - query = (destination_forward_table - .delete()) - - op.get_bind().execute(query) - - -def delete_func_key(func_key_id): - query = (func_key_table - .delete() - .where(func_key_table.c.destination_type_id == DESTINATION_FORWARD_ID)) - - op.get_bind().execute(query) diff --git a/alembic/versions/de624f81421f_add_tenant_uuid_to_stat_agent_queue.py b/alembic/versions/de624f81421f_add_tenant_uuid_to_stat_agent_queue.py deleted file mode 100644 index 0cff6131..00000000 --- a/alembic/versions/de624f81421f_add_tenant_uuid_to_stat_agent_queue.py +++ /dev/null @@ -1,162 +0,0 @@ -"""add tenant uuid to stat-agent/queue - -Revision ID: de624f81421f -Revises: b78a74e69592 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'de624f81421f' -down_revision = 'b78a74e69592' - -stat_queue_table = sa.sql.table( - 'stat_queue', - sa.sql.column('id'), - sa.sql.column('name'), - sa.sql.column('tenant_uuid'), -) -stat_call_on_queue_table = sa.sql.table( - 'stat_call_on_queue', - sa.sql.column('queue_id'), - sa.sql.column('agent_id'), -) -stat_queue_periodic_table = sa.sql.table( - 'stat_queue_periodic', - sa.sql.column('queue_id'), -) -queuefeatures_table = sa.sql.table( - 'queuefeatures', - sa.sql.column('id'), - sa.sql.column('name'), - sa.sql.column('tenant_uuid'), -) - -stat_agent_table = sa.sql.table( - 'stat_agent', - sa.sql.column('id'), - sa.sql.column('name'), - sa.sql.column('tenant_uuid'), -) -stat_agent_periodic_table = sa.sql.table( - 'stat_agent_periodic', - sa.sql.column('agent_id'), -) -agentfeatures_table = sa.sql.table( - 'agentfeatures', - sa.sql.column('id'), - sa.sql.column('number'), - sa.sql.column('tenant_uuid'), -) - - -def _add_tenant_to_queues(): - query = ( - stat_queue_table - .update() - .values(tenant_uuid=queuefeatures_table.c.tenant_uuid) - .where(stat_queue_table.c.name == queuefeatures_table.c.name) - ) - op.execute(query) - - -def _delete_queues_without_tenant(): - deleted_queue_ids_query = ( - sa.sql.select([stat_queue_table.c.id]) - .where(stat_queue_table.c.tenant_uuid == None) - ) - delete_query = ( - stat_call_on_queue_table - .delete() - .where(stat_call_on_queue_table.c.queue_id.in_(deleted_queue_ids_query)) - ) - op.execute(delete_query) - delete_query = ( - stat_queue_periodic_table - .delete() - .where(stat_queue_periodic_table.c.queue_id.in_(deleted_queue_ids_query)) - ) - op.execute(delete_query) - delete_query = ( - stat_queue_table - .delete() - .where(stat_queue_table.c.id.in_(deleted_queue_ids_query)) - ) - op.execute(delete_query) - - -def _add_tenant_to_agents(): - query = ( - stat_agent_table - .update() - .values(tenant_uuid=agentfeatures_table.c.tenant_uuid) - .where(stat_agent_table.c.name == sa.func.concat('Agent/', agentfeatures_table.c.number)) - ) - op.execute(query) - - -def _delete_agents_without_tenant(): - deleted_agent_ids_query = ( - sa.sql.select([stat_agent_table.c.id]) - .where(stat_agent_table.c.tenant_uuid == None) - ) - delete_query = ( - stat_call_on_queue_table - .delete() - .where(stat_call_on_queue_table.c.agent_id.in_(deleted_agent_ids_query)) - ) - op.execute(delete_query) - delete_query = ( - stat_agent_periodic_table - .delete() - .where(stat_agent_periodic_table.c.agent_id.in_(deleted_agent_ids_query)) - ) - op.execute(delete_query) - delete_query = ( - stat_agent_table - .delete() - .where(stat_agent_table.c.id.in_(deleted_agent_ids_query)) - ) - op.execute(delete_query) - - -def upgrade(): - op.add_column( - 'stat_queue', - sa.Column( - 'tenant_uuid', - sa.String(36), - nullable=True), - ) - _add_tenant_to_queues() - _delete_queues_without_tenant() - op.alter_column('stat_queue', 'tenant_uuid', nullable=False) - - op.add_column( - 'stat_agent', - sa.Column( - 'tenant_uuid', - sa.String(36), - nullable=True), - ) - _add_tenant_to_agents() - _delete_agents_without_tenant() - op.alter_column('stat_agent', 'tenant_uuid', nullable=False) - op.create_index( - index_name='stat_queue__idx_tenant_uuid', - table_name='stat_queue', - columns=['tenant_uuid'], - ) - op.create_index( - index_name='stat_agent__idx_tenant_uuid', - table_name='stat_agent', - columns=['tenant_uuid'], - ) - - -def downgrade(): - op.drop_column('stat_queue', 'tenant_uuid') - op.drop_column('stat_agent', 'tenant_uuid') diff --git a/alembic/versions/dfd6c02443cc_remove_deprecated_meetme.py b/alembic/versions/dfd6c02443cc_remove_deprecated_meetme.py deleted file mode 100644 index f10d9996..00000000 --- a/alembic/versions/dfd6c02443cc_remove_deprecated_meetme.py +++ /dev/null @@ -1,177 +0,0 @@ -"""remove-deprecated-meetme - -Revision ID: dfd6c02443cc -Revises: 2fe87e2b9580 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'dfd6c02443cc' -down_revision = '2fe87e2b9580' - -func_key_tbl = sa.sql.table( - 'func_key', - sa.sql.column('destination_type_id'), -) - -func_key_mapping_tbl = sa.sql.table( - 'func_key_mapping', - sa.sql.column('destination_type_id'), -) - -func_key_dest_conference_tbl = sa.sql.table( - 'func_key_dest_conference', -) - -dialaction_tbl = sa.sql.table( - 'dialaction', - sa.sql.column('action'), -) -schedule_tbl = sa.sql.table( - 'schedule', - sa.sql.column('fallback_action'), -) -schedule_time_tbl = sa.sql.table( - 'schedule_time', - sa.sql.column('action'), -) -extensions_tbl = sa.sql.table( - 'extensions', - sa.sql.column('type'), - sa.sql.column('typeval'), -) - -dialaction_action = sa.Enum( - 'none', - 'endcall:busy', - 'endcall:congestion', - 'endcall:hangup', - 'user', - 'group', - 'queue', - 'voicemail', - 'extension', - 'outcall', - 'application:callbackdisa', - 'application:disa', - 'application:directory', - 'application:faxtomail', - 'application:voicemailmain', - 'application:password', - 'sound', - 'custom', - 'ivr', - 'conference', - 'switchboard', - 'application:custom', - name='dialaction_action', -) - -extenumbers_type = sa.Enum( - 'extenfeatures', - 'featuremap', - 'generalfeatures', - 'group', - 'incall', - 'outcall', - 'queue', - 'user', - 'voicemenu', - 'conference', - 'parking', - name='extenumbers_type', -) - -contextnumbers_type = sa.Enum( - 'user', - 'group', - 'queue', - 'conference', - 'incall', - name='contextnumbers_type', -) - - -def upgrade(): - # Remove funckeys and use table to map to confbridge object - query = func_key_dest_conference_tbl.delete() - op.execute(query) - query = func_key_mapping_tbl.delete().where(func_key_mapping_tbl.c.destination_type_id == '4') - op.execute(query) - query = func_key_tbl.delete().where(func_key_tbl.c.destination_type_id == '4') - op.execute(query) - - constraint_name = 'func_key_dest_conference_conference_id_fkey' - op.drop_constraint(constraint_name, 'func_key_dest_conference') - op.create_foreign_key( - constraint_name, - 'func_key_dest_conference', - 'conference', - ['conference_id'], - ['id'], - ) - - # Rename callmeetme to callconference - query = ( - extensions_tbl.update() - .where( - sa.sql.and_( - extensions_tbl.c.type == 'extenfeatures', - extensions_tbl.c.typeval == 'callmeetme', - ) - ) - .values(typeval='callconference') - ) - op.execute(query) - - # Remove meetmetables - op.drop_table('staticmeetme') - op.drop_table('meetmeguest') - op.drop_table('meetmefeatures') - op.execute('DROP TYPE meetmefeatures_admin_typefrom;') - op.execute('DROP TYPE meetmefeatures_admin_identification;') - op.execute('DROP TYPE meetmefeatures_mode;') - op.execute('DROP TYPE meetmefeatures_announcejoinleave;') - op.drop_table('phonefunckey') - op.execute('DROP TYPE phonefunckey_typeextenumbers;') - op.execute('DROP TYPE phonefunckey_typeextenumbersright;') - - # Remove meetme from enums - query = dialaction_tbl.delete().where(dialaction_tbl.c.action == 'meetme') - op.get_bind().execute(query) - query = schedule_tbl.delete().where(schedule_tbl.c.fallback_action == 'meetme') - op.get_bind().execute(query) - query = schedule_time_tbl.delete().where(schedule_time_tbl.c.action == 'meetme') - op.get_bind().execute(query) - query = extensions_tbl.delete().where(extensions_tbl.c.type == 'meetme') - op.get_bind().execute(query) - - op.alter_column('schedule', 'fallback_action', server_default=None) - _modify_type( - dialaction_action, - ('dialaction', 'action'), - ('schedule', 'fallback_action'), - ('schedule_time', 'action') - ) - op.alter_column('schedule', 'fallback_action', server_default='none') - _modify_type(extenumbers_type, ('extensions', 'type')) - - -def _modify_type(type_, *table_and_columns): - op.execute('ALTER TYPE {type_name} RENAME TO tmp_{type_name}'.format(type_name=type_.name)) - type_.create(op.get_bind()) - for table, column in table_and_columns: - op.execute( - 'ALTER TABLE {table_name} ALTER COLUMN {column_name} TYPE {type_name} USING {column_name}::text::{type_name}'.format( - type_name=type_.name, table_name=table, column_name=column - ) - ) - op.execute('DROP TYPE tmp_{type_name}'.format(type_name=type_.name)) - - -def downgrade(): - pass diff --git a/alembic/versions/e04b80f8b6fc_merge_sip_templates_for_webrtc.py b/alembic/versions/e04b80f8b6fc_merge_sip_templates_for_webrtc.py deleted file mode 100644 index 5ec9fcfe..00000000 --- a/alembic/versions/e04b80f8b6fc_merge_sip_templates_for_webrtc.py +++ /dev/null @@ -1,319 +0,0 @@ -"""merge sip templates for webrtc - -Revision ID: e04b80f8b6fc -Revises: 495accfabe9f - -""" - -import string -import random -import sqlalchemy as sa - -from alembic import op -from sqlalchemy import sql -from sqlalchemy.dialects.postgresql import UUID - -# revision identifiers, used by Alembic. -revision = 'e04b80f8b6fc' -down_revision = '495accfabe9f' - -ALPHANUMERIC_POOL = string.ascii_lowercase + string.digits -WEBRTC_VIDEO_COLUMN_NAME = "webrtc_video_sip_template_uuid" - -endpoint_sip_tbl = sa.sql.table( - "endpoint_sip", - sa.sql.column("uuid"), - sa.sql.column("label"), - sa.sql.column("name"), - sa.sql.column("tenant_uuid"), - sa.sql.column("template"), -) -endpoint_sip_section_tbl = sa.sql.table( - "endpoint_sip_section", - sa.sql.column("uuid"), - sa.sql.column("type"), - sa.sql.column("endpoint_sip_uuid"), -) -endpoint_sip_section_option_tbl = sa.sql.table( - "endpoint_sip_section_option", - sa.sql.column("uuid"), - sa.sql.column("key"), - sa.sql.column("value"), - sa.sql.column("endpoint_sip_section_uuid"), -) -endpoint_sip_template_tbl = sa.sql.table( - "endpoint_sip_template", - sa.sql.column("child_uuid"), - sa.sql.column("parent_uuid"), -) -tenant_tbl = sa.sql.table( - "tenant", - sa.sql.column("uuid"), - sa.sql.column("webrtc_sip_template_uuid"), - sa.sql.column(WEBRTC_VIDEO_COLUMN_NAME), -) - - -def name_already_exists(name): - query = sa.sql.select([endpoint_sip_tbl.c.name]).where( - endpoint_sip_tbl.c.name == name - ) - return op.get_bind().execute(query).scalar() is not None - - -def generate_unused_name(): - while True: - data = "".join(random.choice(ALPHANUMERIC_POOL) for _ in range(8)) - if not name_already_exists(data): - return data - - -def insert_webrtc_video_endpoint(tenant_uuid, webrtc_sip_template_uuid): - query = ( - endpoint_sip_tbl.insert() - .returning(endpoint_sip_tbl.c.uuid) - .values( - label='webrtc_video', - name=generate_unused_name(), - tenant_uuid=tenant_uuid, - template=True, - ) - ) - endpoint_sip_uuid = op.get_bind().execute(query).scalar() - - query = ( - endpoint_sip_section_tbl.insert() - .returning(endpoint_sip_section_tbl.c.uuid) - .values( - endpoint_sip_uuid=endpoint_sip_uuid, - type='endpoint', - ) - ) - endpoint_section_uuid = op.get_bind().execute(query).scalar() - - options = [ - ("max_video_streams", "25"), - ("max_audio_streams", "1"), - ] - for key, value in options: - query = ( - endpoint_sip_section_option_tbl - .insert() - .values( - key=key, - value=value, - endpoint_sip_section_uuid=endpoint_section_uuid, - ) - ) - op.execute(query) - - query = ( - endpoint_sip_template_tbl - .insert() - .values( - child_uuid=endpoint_sip_uuid, - parent_uuid=webrtc_sip_template_uuid, - ) - ) - op.execute(query) - - return endpoint_sip_uuid - - -def configure_tenant(tenant_uuid, webrtc_sip_template_uuid): - # 1. Create default template and assign to tenant - webrtc_video_uuid = insert_webrtc_video_endpoint( - tenant_uuid, - webrtc_sip_template_uuid - ) - - op.execute( - tenant_tbl.update() - .values( - webrtc_video_sip_template_uuid=webrtc_video_uuid, - ) - .where(tenant_tbl.c.uuid == tenant_uuid) - ) - - -def reset_or_add_options_to_webrtc_template(): - options = [ - ("max_video_streams", "25"), - ("max_audio_streams", "1"), - ] - for key, value in options: - endpoint_sip_options_delete_subquery = ( - sql.select([ - endpoint_sip_section_option_tbl.c.uuid - ]) - .select_from( - tenant_tbl - .join( - endpoint_sip_section_tbl, - endpoint_sip_section_tbl.c.endpoint_sip_uuid == tenant_tbl.c.webrtc_sip_template_uuid, - ) - .join( - endpoint_sip_section_option_tbl, - endpoint_sip_section_option_tbl.c.endpoint_sip_section_uuid == endpoint_sip_section_tbl.c.uuid, - ) - ) - .where(endpoint_sip_section_tbl.c.type == 'endpoint') - .where(endpoint_sip_section_option_tbl.c.key == key) - ) - query = ( - endpoint_sip_section_option_tbl - .delete() - .where(endpoint_sip_section_option_tbl.c.uuid.in_(endpoint_sip_options_delete_subquery)) - ) - op.execute(query) - endpoint_sip_options_insert_subquery = ( - sql.select([ - endpoint_sip_section_tbl.c.uuid, - sql.literal(key), - sql.literal(value), - ]) - .select_from( - tenant_tbl - .join( - endpoint_sip_section_tbl, - endpoint_sip_section_tbl.c.endpoint_sip_uuid == tenant_tbl.c.webrtc_sip_template_uuid, - ) - ) - .where(endpoint_sip_section_tbl.c.type == 'endpoint') - ) - - query = ( - endpoint_sip_section_option_tbl - .insert() - .from_select( - ['endpoint_sip_section_uuid', 'key', 'value'], - endpoint_sip_options_insert_subquery - ) - ) - op.execute(query) - - -def move_templates_inheriting_from_webrtc_video_to_webrtc(): - query = ( - sql.select([ - tenant_tbl.c.webrtc_video_sip_template_uuid, - tenant_tbl.c.webrtc_sip_template_uuid, - ]) - ) - templates = op.get_bind().execute(query) - - for webrtc_video_uuid, webrtc_uuid in templates: - templates_inheriting_webrtc_subquery = ( - sql.select([ - endpoint_sip_template_tbl.c.child_uuid - ]).where( - endpoint_sip_template_tbl.c.parent_uuid == webrtc_uuid, - ) - ) - query = ( - endpoint_sip_template_tbl.update() - .values( - parent_uuid=webrtc_uuid, - ) - .where(endpoint_sip_template_tbl.c.parent_uuid == webrtc_video_uuid) - .where( - sql.not_(endpoint_sip_template_tbl.c.child_uuid.in_(templates_inheriting_webrtc_subquery)) - ) - ) - op.execute(query) - - -def delete_webrtc_video_template_if_default_values(): - sip_template_with_only_2_options = ( - sa.sql.select([endpoint_sip_tbl.c.uuid]) - .select_from( - endpoint_sip_tbl - .join( - endpoint_sip_section_tbl, - endpoint_sip_section_tbl.c.endpoint_sip_uuid == endpoint_sip_tbl.c.uuid, - ) - .join( - endpoint_sip_section_option_tbl, - endpoint_sip_section_option_tbl.c.endpoint_sip_section_uuid == endpoint_sip_section_tbl.c.uuid, - ) - ) - .group_by(endpoint_sip_tbl.c.uuid) - .having(sql.func.count(endpoint_sip_section_option_tbl.c.uuid) == 2) - ) - sip_template_with_25_video_streams = ( - sa.sql.select([endpoint_sip_tbl.c.uuid]) - .select_from( - endpoint_sip_tbl - .join( - endpoint_sip_section_tbl, - endpoint_sip_section_tbl.c.endpoint_sip_uuid == endpoint_sip_tbl.c.uuid, - ) - .join( - endpoint_sip_section_option_tbl, - endpoint_sip_section_option_tbl.c.endpoint_sip_section_uuid == endpoint_sip_section_tbl.c.uuid, - ) - ) - .where(endpoint_sip_section_tbl.c.type == 'endpoint') - .where(endpoint_sip_section_option_tbl.c.key == 'max_video_streams') - .where(endpoint_sip_section_option_tbl.c.value == '25') - ) - sip_template_with_1_audio_streams = ( - sa.sql.select([endpoint_sip_tbl.c.uuid]) - .select_from( - endpoint_sip_tbl - .join( - endpoint_sip_section_tbl, - endpoint_sip_section_tbl.c.endpoint_sip_uuid == endpoint_sip_tbl.c.uuid, - ) - .join( - endpoint_sip_section_option_tbl, - endpoint_sip_section_option_tbl.c.endpoint_sip_section_uuid == endpoint_sip_section_tbl.c.uuid, - ) - ) - .where(endpoint_sip_section_tbl.c.type == 'endpoint') - .where(endpoint_sip_section_option_tbl.c.key == 'max_audio_streams') - .where(endpoint_sip_section_option_tbl.c.value == '1') - ) - default_webrtc_video_templates_subquery = ( - sa.sql.select([endpoint_sip_tbl.c.uuid]) - .where(endpoint_sip_tbl.c.template.is_(True)) - .where(endpoint_sip_tbl.c.uuid.in_(sip_template_with_only_2_options)) - .where(endpoint_sip_tbl.c.uuid.in_(sip_template_with_25_video_streams)) - .where(endpoint_sip_tbl.c.uuid.in_(sip_template_with_1_audio_streams)) - ) - query = ( - endpoint_sip_tbl - .delete() - .where(endpoint_sip_tbl.c.uuid.in_( - sql.select([tenant_tbl.c.webrtc_video_sip_template_uuid]) - )) - .where(endpoint_sip_tbl.c.uuid.in_(default_webrtc_video_templates_subquery)) - ) - op.get_bind().execute(query) - - -def upgrade(): - reset_or_add_options_to_webrtc_template() - move_templates_inheriting_from_webrtc_video_to_webrtc() - delete_webrtc_video_template_if_default_values() - op.drop_column("tenant", WEBRTC_VIDEO_COLUMN_NAME) - - -def downgrade(): - op.add_column( - "tenant", - sa.Column( - WEBRTC_VIDEO_COLUMN_NAME, - UUID, - sa.ForeignKey( - "endpoint_sip.uuid", - ondelete="SET NULL", - name="tenant_webrtc_video_sip_template_uuid_fkey", - ), - ), - ) - - query = sa.sql.select([tenant_tbl.c.uuid, tenant_tbl.c.webrtc_sip_template_uuid]) - tenants = op.get_bind().execute(query) - for tenant in tenants: - configure_tenant(tenant.uuid, tenant.webrtc_sip_template_uuid) diff --git a/alembic/versions/e0fd01d4c2a_remove_dead_forward_func_keys.py b/alembic/versions/e0fd01d4c2a_remove_dead_forward_func_keys.py deleted file mode 100644 index f0103c36..00000000 --- a/alembic/versions/e0fd01d4c2a_remove_dead_forward_func_keys.py +++ /dev/null @@ -1,65 +0,0 @@ -"""remove dead forward func keys - -Revision ID: e0fd01d4c2a -Revises: 5a02fde67132 - -""" - -# revision identifiers, used by Alembic. -revision = 'e0fd01d4c2a' -down_revision = '5a02fde67132' - -from alembic import op -from sqlalchemy import sql - -FORWARD_DESTINATION_ID = 6 - -func_key_table = sql.table('func_key', - sql.column('id'), - sql.column('type_id'), - sql.column('destination_type_id')) - -func_key_mapping_table = sql.table('func_key_mapping', - sql.column('template_id'), - sql.column('func_key_id'), - sql.column('destination_type_id'), - sql.column('label'), - sql.column('position'), - sql.column('blf')) - -destination_forward_table = sql.table('func_key_dest_forward', - sql.column('func_key_id'), - sql.column('destination_type_id'), - sql.column('extension_id'), - sql.column('number')) - - -def upgrade(): - all_forwards = (sql.select( - [func_key_mapping_table.c.func_key_id]) - .where( - func_key_mapping_table.c.destination_type_id == FORWARD_DESTINATION_ID) - .alias() - ) - - query = (destination_forward_table - .delete() - .where( - destination_forward_table.c.func_key_id.notin_(all_forwards)) - ) - - op.execute(query) - - query = (func_key_table - .delete() - .where( - sql.and_( - func_key_table.c.destination_type_id == FORWARD_DESTINATION_ID, - func_key_table.c.id.notin_(all_forwards))) - ) - - op.execute(query) - - -def downgrade(): - pass diff --git a/alembic/versions/e3f5e62ef9dd_add_auth_tenants_read_to_ctid_ng.py b/alembic/versions/e3f5e62ef9dd_add_auth_tenants_read_to_ctid_ng.py deleted file mode 100644 index f2e4d8a1..00000000 --- a/alembic/versions/e3f5e62ef9dd_add_auth_tenants_read_to_ctid_ng.py +++ /dev/null @@ -1,45 +0,0 @@ -"""add auth.tenants.read to ctid-ng - -Revision ID: e3f5e62ef9dd -Revises: 0d74d34f7782 - -""" - -from alembic import op -from sqlalchemy import sql -from sqlalchemy.dialects.postgresql import ARRAY, VARCHAR - -# revision identifiers, used by Alembic. -revision = 'e3f5e62ef9dd' -down_revision = '0d74d34f7782' - - -accesswebservice = sql.table('accesswebservice', - sql.column('id'), - sql.column('name'), - sql.column('acl')) - -ACLS = ['auth.tenants.read'] -SERVICE = 'xivo-ctid-ng' - - -def upgrade(): - acls = sql.cast(ACLS, ARRAY(VARCHAR)) - query = (accesswebservice - .update() - .values( - acl=sql.func.array_cat(accesswebservice.c.acl, acls)) - .where( - accesswebservice.c.name == SERVICE)) - op.execute(query) - - -def downgrade(): - for acl in ACLS: - query = (accesswebservice - .update() - .values( - acl=sql.func.array_remove(accesswebservice.c.acl, acl)) - .where( - accesswebservice.c.name == SERVICE)) - op.execute(query) diff --git a/alembic/versions/e4f459f58795_bump_version_19_01.py b/alembic/versions/e4f459f58795_bump_version_19_01.py deleted file mode 100644 index 3ba54a37..00000000 --- a/alembic/versions/e4f459f58795_bump_version_19_01.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_19_01 - -Revision ID: e4f459f58795 -Revises: 1311cd6c2a63 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'e4f459f58795' -down_revision = '1311cd6c2a63' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='19.01')) - - -def downgrade(): - pass diff --git a/alembic/versions/e507e100aa92_bump_version_23_06.py b/alembic/versions/e507e100aa92_bump_version_23_06.py index dcbcf733..218cad1a 100644 --- a/alembic/versions/e507e100aa92_bump_version_23_06.py +++ b/alembic/versions/e507e100aa92_bump_version_23_06.py @@ -1,7 +1,7 @@ """bump_version_23_06 Revision ID: e507e100aa92 -Revises: aaf16eeecf7f +Revises: None """ @@ -11,7 +11,7 @@ # revision identifiers, used by Alembic. revision = 'e507e100aa92' -down_revision = 'aaf16eeecf7f' +down_revision = None def upgrade(): diff --git a/alembic/versions/e5281e98b300_add_answered_column_to_cdr_participant.py b/alembic/versions/e5281e98b300_add_answered_column_to_cdr_participant.py deleted file mode 100644 index 198d0ac7..00000000 --- a/alembic/versions/e5281e98b300_add_answered_column_to_cdr_participant.py +++ /dev/null @@ -1,24 +0,0 @@ -"""add-answered-column-to-cdr-participant - -Revision ID: e5281e98b300 -Revises: 53ad771ac875 - -""" - -from alembic import op -import sqlalchemy as sa - -# revision identifiers, used by Alembic. -revision = 'e5281e98b300' -down_revision = '53ad771ac875' - - -def upgrade(): - op.add_column( - 'call_log_participant', - sa.Column('answered', sa.Boolean, nullable=False, server_default='false'), - ) - - -def downgrade(): - op.drop_column('call_log_participant', 'answered') diff --git a/alembic/versions/e53b8ab083c0_bump_version_22_13.py b/alembic/versions/e53b8ab083c0_bump_version_22_13.py deleted file mode 100644 index 5860d649..00000000 --- a/alembic/versions/e53b8ab083c0_bump_version_22_13.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_22_13 - -Revision ID: e53b8ab083c0 -Revises: 0600c04fd4a6 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'e53b8ab083c0' -down_revision = '0600c04fd4a6' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='22.13')) - - -def downgrade(): - pass diff --git a/alembic/versions/e5da3b191742_refactor_line_protocol_to_endpoint.py b/alembic/versions/e5da3b191742_refactor_line_protocol_to_endpoint.py deleted file mode 100644 index b6e73fb9..00000000 --- a/alembic/versions/e5da3b191742_refactor_line_protocol_to_endpoint.py +++ /dev/null @@ -1,150 +0,0 @@ -"""refactor-line-protocol-to-endpoint - -Revision ID: e5da3b191742 -Revises: 7d91d22133a9v - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'e5da3b191742' -down_revision = '7d91d22133a9' - -trunk_protocol = sa.Enum(('sip', 'iax', 'sccp', 'custom'), name='trunk_protocol') - -linefeatures_tbl = sa.sql.table( - 'linefeatures', - sa.sql.column('id'), - sa.sql.column('protocol'), - sa.sql.column('protocolid'), - sa.sql.column('endpoint_sip_id'), - sa.sql.column('endpoint_sccp_id'), - sa.sql.column('endpoint_custom_id'), -) -usersip_tbl = sa.sql.table('usersip', sa.sql.column('id')) -sccpline_tbl = sa.sql.table('sccpline', sa.sql.column('id')) -usercustom_tbl = sa.sql.table('usercustom', sa.sql.column('id')) - - -def upgrade(): - op.add_column( - 'linefeatures', - sa.Column( - 'endpoint_sip_id', - sa.Integer, - sa.ForeignKey('usersip.id', ondelete='SET NULL') - ) - ) - op.add_column( - 'linefeatures', - sa.Column( - 'endpoint_sccp_id', - sa.Integer, - sa.ForeignKey('sccpline.id', ondelete='SET NULL') - ) - ) - op.add_column( - 'linefeatures', - sa.Column( - 'endpoint_custom_id', - sa.Integer, - sa.ForeignKey('usercustom.id', ondelete='SET NULL') - ) - ) - - op.create_check_constraint( - 'linefeatures_endpoints_check', - 'linefeatures', - ''' - ( CASE WHEN endpoint_sip_id IS NULL THEN 0 ELSE 1 END - + CASE WHEN endpoint_sccp_id IS NULL THEN 0 ELSE 1 END - + CASE WHEN endpoint_custom_id IS NULL THEN 0 ELSE 1 END - ) <= 1 - ''', - ) - query = sa.sql.select([ - linefeatures_tbl.c.id, - linefeatures_tbl.c.protocol, - linefeatures_tbl.c.protocolid, - ]) - for line in op.get_bind().execute(query): - if not line.protocol or not line.protocolid: - continue - - if line.protocol == 'sip': - query = sa.sql.select([usersip_tbl.c.id]).where(usersip_tbl.c.id == line.protocolid) - if op.get_bind().execute(query).scalar(): - op.execute( - linefeatures_tbl - .update() - .where(linefeatures_tbl.c.id == line.id) - .values(endpoint_sip_id=line.protocolid) - ) - elif line.protocol == 'sccp': - query = sa.sql.select([sccpline_tbl.c.id]).where(sccpline_tbl.c.id == line.protocolid) - if op.get_bind().execute(query).scalar(): - op.execute( - linefeatures_tbl - .update() - .where(linefeatures_tbl.c.id == line.id) - .values(endpoint_sccp_id=line.protocolid) - ) - elif line.protocol == 'custom': - query = sa.sql.select([usercustom_tbl.c.id]).where(usercustom_tbl.c.id == line.protocolid) - if op.get_bind().execute(query).scalar(): - op.execute( - linefeatures_tbl - .update() - .where(linefeatures_tbl.c.id == line.id) - .values(endpoint_custom_id=line.protocolid) - ) - - op.drop_column('linefeatures', 'protocol') - op.drop_column('linefeatures', 'protocolid') - - -def downgrade(): - op.add_column('linefeatures', sa.Column('protocol', trunk_protocol)) - op.add_column('linefeatures', sa.Column('protocolid', sa.Integer)) - op.create_unique_constraint( - 'linefeatures_protocol_protocolid_key', - 'linefeatures', - ['protocol', 'protocolid'], - ) - - query = sa.sql.select([ - linefeatures_tbl.c.id, - linefeatures_tbl.c.endpoint_sip_id, - linefeatures_tbl.c.endpoint_sccp_id, - linefeatures_tbl.c.endpoint_custom_id, - ]) - for line in op.get_bind().execute(query): - if line.endpoint_sip_id: - op.execute( - linefeatures_tbl - .update() - .where(linefeatures_tbl.c.id == line.id) - .values(protocol='sip', protocolid=line.endpoint_sip_id) - ) - elif line.endpoint_sccp_id: - op.execute( - linefeatures_tbl - .update() - .where(linefeatures_tbl.c.id == line.id) - .values(protocol='sccp', protocolid=line.endpoint_sccp_id) - ) - elif line.endpoint_custom_id: - op.execute( - linefeatures_tbl - .update() - .where(linefeatures_tbl.c.id == line.id) - .values(protocol='custom', protocolid=line.endpoint_custom_id) - ) - - op.drop_constraint('linefeatures_endpoints_check', 'linefeatures') - op.drop_column('linefeatures', 'endpoint_sip_id') - op.drop_column('linefeatures', 'endpoint_sccp_id') - op.drop_column('linefeatures', 'endpoint_custom_id') diff --git a/alembic/versions/e5e53b7dc5d0_add_timezone_on_call_center_stats.py b/alembic/versions/e5e53b7dc5d0_add_timezone_on_call_center_stats.py deleted file mode 100644 index 5aef7153..00000000 --- a/alembic/versions/e5e53b7dc5d0_add_timezone_on_call_center_stats.py +++ /dev/null @@ -1,126 +0,0 @@ -"""add-timezone-on-call-center-stats - -Revision ID: e5e53b7dc5d0 -Revises: 5497199c082f - -""" - -from alembic import op -import sqlalchemy as sa - -# revision identifiers, used by Alembic. -revision = 'e5e53b7dc5d0' -down_revision = '5497199c082f' - - -def upgrade(): - op.alter_column('stat_agent_periodic', 'time', type_=sa.DateTime(timezone=True)) - op.alter_column('stat_queue_periodic', 'time', type_=sa.DateTime(timezone=True)) - op.alter_column('stat_call_on_queue', 'time', type_=sa.DateTime(timezone=True)) - op.alter_column('queue_log', 'time', server_default=None, nullable=True) - op.alter_column( - 'queue_log', - 'time', - type_=sa.DateTime(timezone=True), - postgresql_using='"time"::timestamp with time zone', - ) - - op.execute('DROP FUNCTION IF EXISTS "fill_simple_calls" (text, text);') - op.execute('DROP FUNCTION IF EXISTS "fill_simple_calls" (timestamptz, timestamptz);') - op.execute(""" -CREATE FUNCTION "fill_simple_calls"(period_start timestamptz, period_end timestamptz) - RETURNS void AS -$$ - INSERT INTO "stat_call_on_queue" (callid, "time", stat_queue_id, status) - SELECT - callid, - time, - (SELECT id FROM stat_queue WHERE name=queuename) as stat_queue_id, - CASE WHEN event = 'FULL' THEN 'full'::call_exit_type - WHEN event = 'DIVERT_CA_RATIO' THEN 'divert_ca_ratio' - WHEN event = 'DIVERT_HOLDTIME' THEN 'divert_waittime' - WHEN event = 'CLOSED' THEN 'closed' - WHEN event = 'JOINEMPTY' THEN 'joinempty' - END as status - FROM queue_log - WHERE event IN ('FULL', 'DIVERT_CA_RATIO', 'DIVERT_HOLDTIME', 'CLOSED', 'JOINEMPTY') AND - "time" BETWEEN $1 AND $2; -$$ -LANGUAGE SQL; - """) - op.execute('DROP FUNCTION IF EXISTS "fill_leaveempty_calls" (text, text);') - op.execute('DROP FUNCTION IF EXISTS "fill_leaveempty_calls" (timestamptz, timestamptz);') - op.execute(""" -CREATE OR REPLACE FUNCTION "fill_leaveempty_calls" (period_start timestamptz, period_end timestamptz) - RETURNS void AS -$$ -INSERT INTO stat_call_on_queue (callid, time, waittime, stat_queue_id, status) -SELECT - callid, - enter_time as time, - EXTRACT(EPOCH FROM (leave_time - enter_time))::INTEGER as waittime, - stat_queue_id, - 'leaveempty' AS status -FROM (SELECT - time AS enter_time, - (select time from queue_log where callid=main.callid AND event='LEAVEEMPTY' LIMIT 1) AS leave_time, - callid, - (SELECT id FROM stat_queue WHERE name=queuename) AS stat_queue_id - FROM queue_log AS main - WHERE callid IN (SELECT callid FROM queue_log WHERE event = 'LEAVEEMPTY') - AND event = 'ENTERQUEUE' - AND time BETWEEN $1 AND $2) AS first; -$$ -LANGUAGE SQL; - """) - # NOTE(fblackburn): fix column to match asterisk recommends - op.alter_column( - 'queue_log', - 'callid', - type_=sa.String(80), - server_default=None, - nullable=True, - ) - op.alter_column( - 'queue_log', - 'queuename', - type_=sa.String(256), - server_default=None, - nullable=True - ) - op.alter_column('queue_log', 'agent', server_default=None, nullable=True) - op.alter_column('queue_log', 'event', server_default=None, nullable=True) - op.alter_column('queue_log', 'data1', server_default=None) - op.alter_column('queue_log', 'data2', server_default=None) - op.alter_column('queue_log', 'data3', server_default=None) - op.alter_column('queue_log', 'data4', server_default=None) - op.alter_column('queue_log', 'data5', server_default=None) - - -def downgrade(): - op.alter_column('queue_log', 'data5', server_default='') - op.alter_column('queue_log', 'data4', server_default='') - op.alter_column('queue_log', 'data3', server_default='') - op.alter_column('queue_log', 'data2', server_default='') - op.alter_column('queue_log', 'data1', server_default='') - op.alter_column('queue_log', 'event', server_default='', nullable=False) - op.alter_column('queue_log', 'agent', server_default='', nullable=False) - op.alter_column( - 'queue_log', - 'queuename', - type_=sa.String(50), - server_default='', - nullable=False, - ) - op.alter_column( - 'queue_log', - 'callid', - type_=sa.String(32), - server_default='', - nullable=False, - ) - op.alter_column('queue_log', 'time', type_=sa.String(80)) - op.alter_column('queue_log', 'time', server_default='', nullable=False) - op.alter_column('stat_call_on_queue', 'time', type_=sa.DateTime()) - op.alter_column('stat_queue_periodic', 'time', type_=sa.DateTime()) - op.alter_column('stat_agent_periodic', 'time', type_=sa.DateTime()) diff --git a/alembic/versions/e66504d94e2e_update_sip_useragent_to_wazo.py b/alembic/versions/e66504d94e2e_update_sip_useragent_to_wazo.py deleted file mode 100644 index 6b606d48..00000000 --- a/alembic/versions/e66504d94e2e_update_sip_useragent_to_wazo.py +++ /dev/null @@ -1,38 +0,0 @@ -"""update_sip_useragent_to_wazo - -Revision ID: e66504d94e2e -Revises: 1a72b3da2baf - -""" - -# revision identifiers, used by Alembic. -revision = 'e66504d94e2e' -down_revision = '1a72b3da2baf' - -from alembic import op -from sqlalchemy import sql, func - - -staticsip = sql.table('staticsip', - sql.column('var_name'), - sql.column('var_val')) - - -def upgrade(): - query = (staticsip - .update() - .values(var_val='Wazo PBX') - .where(sql.and_( - staticsip.c.var_name == "useragent", - func.lower(staticsip.c.var_val) == "xivo pbx"))) - op.execute(query) - - -def downgrade(): - query = (staticsip - .update() - .values(var_val='XiVO PBX') - .where(sql.and_( - staticsip.c.var_name == "useragent", - func.lower(staticsip.c.var_val) == "wazo pbx"))) - op.execute(query) diff --git a/alembic/versions/e6c5e0410e89_bump_version_21_05.py b/alembic/versions/e6c5e0410e89_bump_version_21_05.py deleted file mode 100644 index 1d0e33d8..00000000 --- a/alembic/versions/e6c5e0410e89_bump_version_21_05.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_21_05 - -Revision ID: e6c5e0410e89 -Revises: 4d539700bb90 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'e6c5e0410e89' -down_revision = '4d539700bb90' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='21.05')) - - -def downgrade(): - pass diff --git a/alembic/versions/e71820229900_remove_number_context_from_groupfeatures.py b/alembic/versions/e71820229900_remove_number_context_from_groupfeatures.py deleted file mode 100644 index 3e5cc23c..00000000 --- a/alembic/versions/e71820229900_remove_number_context_from_groupfeatures.py +++ /dev/null @@ -1,24 +0,0 @@ -"""remove-number-context-from-groupfeatures - -Revision ID: e71820229900 -Revises: 7f337d6ca187 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'e71820229900' -down_revision = '7f337d6ca187' - - -def upgrade(): - op.drop_column('groupfeatures', 'number') - op.drop_column('groupfeatures', 'context') - - -def downgrade(): - op.add_column('groupfeatures', sa.Column('context', sa.String(39), index=True)) - op.add_column('groupfeatures', sa.Column('number', sa.String(40), index=True)) diff --git a/alembic/versions/ea74eca400ce_sip_to_pjsip_endpoint.py b/alembic/versions/ea74eca400ce_sip_to_pjsip_endpoint.py deleted file mode 100644 index 742310ca..00000000 --- a/alembic/versions/ea74eca400ce_sip_to_pjsip_endpoint.py +++ /dev/null @@ -1,1406 +0,0 @@ -"""sip-to-pjsip-endpoint - -Revision ID: ea74eca400ce -Revises: 56a9fce34ae9 - -""" - -import string -import random - -from collections import namedtuple - -from alembic import op -import sqlalchemy as sa - -# revision identifiers, used by Alembic. -revision = 'ea74eca400ce' -down_revision = '56a9fce34ae9' - -ALPHANUMERIC_POOL = string.ascii_lowercase + string.digits - -KV = namedtuple('KV', ['key', 'value']) - -AOR_SECTION_MAPPING = { - 'qualifyfreq': 'qualify_frequency', - 'maxexpiry': 'maximum_expiration', - 'minexpiry': 'minimum_expiration', - 'defaultexpiry': 'default_expiration', -} -AUTH_SECTION_MAPPING = { - 'secret': 'password', -} -ENDPOINT_SECTION_MAPPING = { - 'allowsubscribe': 'allow_subscribe', - 'allowtransfer': 'allow_transfer', - 'autoframing': 'use_ptime', - 'avpf': 'use_avpf', - 'busylevel': 'device_state_busy_at', - 'callingpres': 'callerid_privacy', - 'cid_tag': 'callerid_tag', - 'dtlscafile': 'dtls_ca_file', - 'dtlscapath': 'dtls_ca_path', - 'dtlscertfile': 'dtls_cert_file', - 'dtlscipher': 'dtls_cipher', - 'dtlsprivatekey': 'dtls_private_key', - 'dtlsrekey': 'dtls_rekey', - 'dtlssetup': 'dtls_setup', - 'dtlsverify': 'dtls_verify', - 'fromdomain': 'from_domain', - 'fromuser': 'from_user', - 'icesupport': 'ice_support', - 'mohsuggest': 'moh_suggest', - 'mwifrom': 'mwi_from_user', - 'outboundproxy': 'outbound_proxy', - 'rtptimeout': 'rtp_timeout', - 'rtpholdtimeout': 'rtp_timeout_hold', - 'sdpowner': 'sdp_owner', - 'sdpsession': 'sdp_session', - 'session-expires': 'timers_sess_expires', - 'session-minse': 'timers_min_se', - 'subminexpiry': 'sub_min_expiry', - 'tonezone': 'tone_zone', - 'trustrpid': 'trust_id_inbound', -} -REGISTRATION_SECTION_MAPPING = { - 'registertimeout': 'retry_interval', - 'registerattempts': 'max_retries', - 'outboundproxy': 'outbound_proxy', -} - -# Commented options are in multiple sections and are not handled here and in confgend -VALID_AOR_OPTIONS = [ - # 'authenticate_qualify', - 'contact', - 'default_expiration', - # 'mailboxes', - 'max_contacts', - 'maximum_expiration', - 'minimum_expiration', - # 'outbound_proxy', - # 'qualify_frequency', - # 'qualify_timeout', - 'remove_existing', - 'support_path', - # 'voicemail_extension', -] -VALID_AUTH_OPTIONS = [ - 'auth_type', - 'nonce_lifetime', - 'md5_cred', - 'password', - 'realm', - 'username', -] -VALID_ENDPOINT_OPTIONS = [ - '100rel', - 'accept_multiple_sdp_answers', - 'accountcode', - 'acl', - 'aggregate_mwi', - 'allow', - 'allow_overlap', - 'allow_subscribe', - 'allow_transfer', - 'aors', - 'asymmetric_rtp_codec', - 'auth', - 'bind_rtp_to_media_address', - 'bundle', - 'call_group', - 'callerid', - 'callerid_privacy', - 'callerid_tag', - 'connected_line_method', - 'contact_acl', - 'contact_deny', - 'contact_permit', - 'contact_user', - # 'context', # The context of an endpoint uses the trunk or line context - 'cos_audio', - 'cos_video', - 'deny', - 'device_state_busy_at', - 'direct_media', - 'direct_media_glare_mitigation', - 'direct_media_method', - 'disable_direct_media_on_nat', - 'dtls_auto_generate_cert', - 'dtls_ca_file', - 'dtls_ca_path', - 'dtls_cert_file', - 'dtls_cipher', - 'dtls_fingerprint', - 'dtls_private_key', - 'dtls_rekey', - 'dtls_setup', - 'dtls_verify', - 'dtmf_mode', - 'fax_detect', - 'fax_detect_timeout', - 'follow_early_media_fork', - 'force_avp', - 'force_rport', - 'from_domain', - 'from_user', - 'g726_non_standard', - 'ice_support', - 'identify_by', - 'ignore_183_without_sdp', - 'inband_progress', - 'incoming_mwi_mailbox', - 'language', - # 'mailboxes', - 'max_audio_streams', - 'max_video_streams', - 'media_address', - 'media_encryption', - 'media_encryption_optimistic', - 'media_use_received_transport', - 'message_context', - 'moh_passthrough', - 'moh_suggest', - 'mwi_from_user', - 'mwi_subscribe_replaces_unsolicited', - 'named_call_group', - 'named_pickup_group', - 'notify_early_inuse_ringing', - 'one_touch_recording', - 'outbound_auth', - # 'outbound_proxy', - 'permit', - 'pickup_group', - 'preferred_codec_only', - 'record_off_feature', - 'record_on_feature', - 'redirect_method', - 'refer_blind_progress', - 'rewrite_contact', - 'rpid_immediate', - 'rtcp_mux', - 'rtp_engine', - 'rtp_ipv6', - 'rtp_keepalive', - 'rtp_symmetric', - 'rtp_timeout', - 'rtp_timeout_hold', - 'sdp_owner', - 'sdp_session', - 'send_connected_line', - 'send_diversion', - 'send_pai', - 'send_rpid', - 'set_var', - 'srtp_tag_32', - 'sub_min_expiry', - 'subscribe_context', - 'suppress_q850_reason_headers', - 't38_udptl', - 't38_udptl_ec', - 't38_udptl_ipv6', - 't38_udptl_maxdatagram', - 't38_udptl_nat', - 'timers', - 'timers_min_se', - 'timers_sess_expires', - 'tone_zone', - 'tos_audio', - 'tos_video', - # 'transport', # Transport is a relation - 'trust_connected_line', - 'trust_id_inbound', - 'trust_id_outbound', - 'use_avpf', - 'use_ptime', - 'user_eq_phone', - # 'voicemail_extension', - 'webrtc', -] -VALID_REGISTRATION_OPTIONS = [ - 'auth_rejection_permanent', - 'forbidden_retry_interval', - 'fatal_retry_interval', - 'max_retries', - 'outbound_proxy', -] - -endpoint_sip_tbl = sa.sql.table( - 'endpoint_sip', - sa.sql.column('uuid'), - sa.sql.column('label'), - sa.sql.column('name'), - sa.sql.column('asterisk_id'), - sa.sql.column('tenant_uuid'), - sa.sql.column('transport_uuid'), - sa.sql.column('template'), -) -endpoint_sip_section_tbl = sa.sql.table( - 'endpoint_sip_section', - sa.sql.column('uuid'), - sa.sql.column('type'), - sa.sql.column('endpoint_sip_uuid'), -) -endpoint_sip_section_option_tbl = sa.sql.table( - 'endpoint_sip_section_option', - sa.sql.column('uuid'), - sa.sql.column('key'), - sa.sql.column('value'), - sa.sql.column('endpoint_sip_section_uuid'), -) -endpoint_sip_template_tbl = sa.sql.table( - 'endpoint_sip_template', - sa.sql.column('child_uuid'), - sa.sql.column('parent_uuid'), -) -linefeatures_tbl = sa.sql.table( - 'linefeatures', - sa.sql.column('endpoint_sip_id'), - sa.sql.column('endpoint_sip_uuid'), -) -static_sip_tbl = sa.sql.table( - 'staticsip', - sa.sql.column('id'), - sa.sql.column('var_metric'), - sa.sql.column('commented'), - sa.sql.column('filename'), - sa.sql.column('category'), - sa.sql.column('var_name'), - sa.sql.column('var_val'), -) -tenant_tbl = sa.sql.table( - 'tenant', - sa.sql.column('uuid'), - sa.sql.column('sip_templates_generated'), - sa.sql.column('global_sip_template_uuid'), - sa.sql.column('webrtc_sip_template_uuid'), - sa.sql.column('global_trunk_sip_template_uuid'), - sa.sql.column('twilio_trunk_sip_template_uuid'), -) -transport_tbl = sa.sql.table( - 'pjsip_transport', - sa.sql.column('uuid'), - sa.sql.column('name'), -) -transport_option_tbl = sa.sql.table( - 'pjsip_transport_option', - sa.sql.column('key'), - sa.sql.column('value'), - sa.sql.column('pjsip_transport_uuid'), -) -trunkfeatures_tbl = sa.sql.table( - 'trunkfeatures', - sa.sql.column('endpoint_sip_id'), - sa.sql.column('endpoint_sip_uuid'), - sa.sql.column('twilio_incoming'), - sa.sql.column('register_sip_id'), -) -user_sip_tbl = sa.sql.table( - 'usersip', - sa.sql.column('id'), - sa.sql.column('name'), - sa.sql.column('type'), - sa.sql.column('username'), - sa.sql.column('secret'), - sa.sql.column('language'), - sa.sql.column('accountcode'), - sa.sql.column('amaflags'), - sa.sql.column('allowtransfer'), - sa.sql.column('fromuser'), - sa.sql.column('fromdomain'), - sa.sql.column('subscribemwi'), - sa.sql.column('buggymwi'), - sa.sql.column('call-limit'), - sa.sql.column('callerid'), - sa.sql.column('fullname'), - sa.sql.column('cid_number'), - sa.sql.column('maxcallbitrate'), - sa.sql.column('insecure'), - sa.sql.column('nat'), - sa.sql.column('promiscredir'), - sa.sql.column('usereqphone'), - sa.sql.column('videosupport'), - sa.sql.column('trustrpid'), - sa.sql.column('sendrpid'), - sa.sql.column('allowsubscribe'), - sa.sql.column('allowoverlap'), - sa.sql.column('dtmfmode'), - sa.sql.column('rfc2833compensate'), - sa.sql.column('qualify'), - sa.sql.column('g726nonstandard'), - sa.sql.column('disallow'), - sa.sql.column('allow'), - sa.sql.column('autoframing'), - sa.sql.column('mohinterpret'), - sa.sql.column('useclientcode'), - sa.sql.column('progressinband'), - sa.sql.column('t38pt_udptl'), - sa.sql.column('t38pt_usertpsource'), - sa.sql.column('rtptimeout'), - sa.sql.column('rtpholdtimeout'), - sa.sql.column('rtpkeepalive'), - sa.sql.column('deny'), - sa.sql.column('permit'), - sa.sql.column('defaultip'), - sa.sql.column('host'), - sa.sql.column('port'), - sa.sql.column('regexten'), - sa.sql.column('subscribecontext'), - sa.sql.column('vmexten'), - sa.sql.column('callingpres'), - sa.sql.column('parkinglot'), - sa.sql.column('protocol'), - sa.sql.column('category'), - sa.sql.column('outboundproxy'), - sa.sql.column('transport'), - sa.sql.column('remotesecret'), - sa.sql.column('directmedia'), - sa.sql.column('callcounter'), - sa.sql.column('busylevel'), - sa.sql.column('ignoresdpversion'), - sa.sql.column('session-timers'), - sa.sql.column('session-expires'), - sa.sql.column('session-minse'), - sa.sql.column('session-refresher'), - sa.sql.column('callbackextension'), - sa.sql.column('timert1'), - sa.sql.column('timerb'), - sa.sql.column('qualifyfreq'), - sa.sql.column('contactpermit'), - sa.sql.column('contactdeny'), - sa.sql.column('unsolicited_mailbox'), - sa.sql.column('use_q850_reason'), - sa.sql.column('encryption'), - sa.sql.column('snom_aoc_enabled'), - sa.sql.column('maxforwards'), - sa.sql.column('disallowed_methods'), - sa.sql.column('textsupport'), - sa.sql.column('commented'), - sa.sql.column('options'), - sa.sql.column('tenant_uuid'), -) - - -# class heavily inspired from the sip_to_pjsip.py in the Asterisk repository -# https://raw.githubusercontent.com/asterisk/asterisk/master/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py - - -class Registration(object): - """ - Class for parsing and storing information in a register line in sip.conf. - """ - def __init__(self, line, configured_transports): - self._transport_names = list(configured_transports.keys()) - - # Find a "default" transport as a fallback - for transport_name in self._transport_names: - # Start with a udp transport - if 'udp' in transport_name: - self._transport = transport_name - break - else: - # The first transport as a fallback :( - self._transport = self._transport_names[0].name - - self.parse(line) - - self.section = 'reg_' + self.user + '@' + self.host - self.registration_fields = [] - - self.auth_section = 'auth_reg_' + self.user + '@' + self.host - self.auth_fields = [] - - self._generate() - - def parse(self, line): - """ - Initial parsing routine for register lines in sip.conf. - - This splits the line into the part before the host, and the part - after the '@' symbol. These two parts are then passed to their - own parsing routines - """ - - # register => - # [peer?][transport://]user[@domain][:secret[:authuser]]@host[:port][/extension][~expiry] - - prehost, at, host_part = line.rpartition('@') - if not prehost: - raise - - self.parse_host_part(host_part) - self.parse_user_part(prehost) - - def parse_host_part(self, host_part): - """ - Parsing routine for the part after the final '@' in a register line. - The strategy is to use partition calls to peel away the data starting - from the right and working to the left. - """ - pre_expiry, sep, expiry = host_part.partition('~') - pre_extension, sep, self.extension = pre_expiry.partition('/') - self.host, sep, self.port = pre_extension.partition(':') - - self.expiry = expiry if expiry else '120' - - def parse_user_part(self, user_part): - """ - Parsing routine for the part before the final '@' in a register line. - The only mandatory part of this line is the user portion. The strategy - here is to start by using partition calls to remove everything to - the right of the user, then finish by using rpartition calls to remove - everything to the left of the user. - """ - self.peer = '' - for transport in self._transport_names: - begin, _, end = user_part.partition('://') - self.peer, _, transport = begin.rpartition('?') - if not transport: - continue - if transport not in self._transport_names: - continue - - self._transport = transport - user_part = end - break - - colons = user_part.count(':') - if (colons == 3): - # :domainport:secret:authuser - pre_auth, _, port_auth = user_part.partition(':') - self.domainport, _, auth = port_auth.partition(':') - self.secret, _, self.authuser = auth.partition(':') - elif (colons == 2): - # :secret:authuser - pre_auth, _, auth = user_part.partition(':') - self.secret, _, self.authuser = auth.partition(':') - elif (colons == 1): - # :secret - pre_auth, _, self.secret = user_part.partition(':') - elif (colons == 0): - # No port, secret, or authuser - pre_auth = user_part - else: - # Invalid setting - raise Exception('Invalid SIP register') - - self.user, _, self.domain = pre_auth.partition('@') - - def _generate(self): - """ - Write parsed registration data into a section in pjsip.conf - - Most of the data in self will get written to a registration section. - However, there will also need to be an auth section created if a - secret or authuser is present. - - General mapping of values: - A combination of self.host and self.port is server_uri - A combination of self.user, self.domain, and self.domainport is - client_uri - self.expiry is expiration - self.extension is contact_user - self._transport will map to one of the mapped transports - self.secret and self.authuser will result in a new auth section, and - outbound_auth will point to that section. - XXX self.peer really doesn't map to anything :( - """ - - if self.extension: - self.registration_fields.append(('contact_user', self.extension)) - - self.registration_fields.append(('expiration', self.expiry)) - self.registration_fields.append(('transport', self._transport)) - - if hasattr(self, 'secret') and self.secret: - self.auth_fields.append(('password', self.secret)) - self.auth_fields.append(('username', getattr(self, 'authuser', None) or self.user)) - - client_uri = "sip:%s@" % self.user - if self.domain: - client_uri += self.domain - else: - client_uri += self.host - - if hasattr(self, 'domainport') and self.domainport: - client_uri += ":" + self.domainport - elif self.port: - client_uri += ":" + self.port - self.registration_fields.append(('client_uri', client_uri)) - - server_uri = "sip:%s" % self.host - if self.port: - server_uri += ":" + self.port - self.registration_fields.append(('server_uri', server_uri)) - - -class UserSIP(object): - - twilio_incoming = False - registration = None - - def __repr__(self): - return '{}({}, {}, {}, {})'.format( - self.__class__.__name__, - self.id, - self.name, - self.tenant_uuid, - self.options, - ) - - @classmethod - def extract_options(cls, row): - options = [KV(key, value) for (key, value) in row.options] - fields = [ - 'type', - 'username', - 'secret', - 'language', - 'accountcode', - 'amaflags', - 'allowtransfer', - 'fromuser', - 'fromdomain', - 'subscribemwi', - 'buggymwi', - 'call-limit', - 'callerid', - 'fullname', - 'cid_number', - 'maxcallbitrate', - 'insecure', - 'nat', - 'promiscredir', - 'usereqphone', - 'videosupport', - 'trustrpid', - 'sendrpid', - 'allowsubscribe', - 'allowoverlap', - 'dtmfmode', - 'rfc2833compensate', - 'qualify', - 'g726nonstandard', - 'disallow', - 'allow', - 'autoframing', - 'mohinterpret', - 'useclientcode', - 'progressinband', - 't38pt_udptl', - 't38pt_usertpsource', - 'rtptimeout', - 'rtpholdtimeout', - 'rtpkeepalive', - 'deny', - 'permit', - 'defaultip', - 'host', - 'port', - 'regexten', - 'subscribecontext', - 'vmexten', - 'callingpres', - 'parkinglot', - 'protocol', - 'category', - 'outboundproxy', - 'remotesecret', - 'directmedia', - 'callcounter', - 'busylevel', - 'ignoresdpversion', - 'session-timers', - 'session-expires', - 'session-minse', - 'session-refresher', - 'callbackextension', - 'timert1', - 'timerb', - 'qualifyfreq', - 'contactpermit', - 'contactdeny', - 'unsolicited_mailbox', - 'use_q850_reason', - 'encryption', - 'snom_aoc_enabled', - 'maxforwards', - 'disallowed_methods', - 'textsupport', - ] - for field in fields: - value = getattr(row, field, None) - if value: - options.append(KV(field, value)) - - return options - - -class UserSIPTrunk(UserSIP): - - category = 'trunk' - - def __init__(self, id, name, tenant_uuid, options, registration, twilio_incoming): - self.id = id - self.name = name - self.tenant_uuid = tenant_uuid - self.options = options - self.registration = registration - self.twilio_incoming = twilio_incoming - - @classmethod - def from_row(cls, row, registers, transports): - options = cls.extract_options(row) - registration = None - twilio_incoming = False - if row.register_sip_id: - register_url = registers.get(row.register_sip_id) - if register_url: - registration = Registration(register_url, transports) - if row.twilio_incoming: - twilio_incoming = True - return cls(row.id, row.name, row.tenant_uuid, options, registration, twilio_incoming) - - -class UserSIPLine(UserSIP): - - category = 'line' - - def __init__(self, id, name, tenant_uuid, options): - self.id = id - self.name = name - self.tenant_uuid = tenant_uuid - self.options = options - - @classmethod - def from_row(cls, row): - options = cls.extract_options(row) - return cls(row.id, row.name, row.tenant_uuid, options) - - -class OptionAccumulator(object): - def __init__(self, sip_to_pjsip_mapping, valid_options): - self._sip_to_pjsip = sip_to_pjsip_mapping - self._valid_options = valid_options - self._accumulated = [] - self._codecs = [] - - def add_option(self, kv): - conversion_function_name = '_convert_{}'.format(kv.key) - if hasattr(self, conversion_function_name): - for name, value in getattr(self, conversion_function_name)(kv.value): - if name in self._valid_options: - self._add_option_no_duplicate(KV(name, value)) - elif kv.key in self._valid_options: - self._add_option_no_duplicate(kv) - elif kv.key in self._sip_to_pjsip: - new_name = self._sip_to_pjsip[kv.key] - self._add_option_no_duplicate(KV(new_name, kv.value)) - - def _add_option_no_duplicate(self, kv): - if kv in self._accumulated: - return - self._accumulated.append(kv) - - def get_options(self): - options = self._accumulated - if 'allow' in self._valid_options and self._codecs: - options.append(('allow', ','.join(self._codecs))) - return options - - def _convert_allow(self, val): - for codec in val.split(','): - if not codec: - continue - if codec == '!all': - self._codecs = ['!all'] - else: - self._codecs.append(codec) - return - yield - - def _convert_disallow(self, val): - for codec in val.split(','): - if not codec: - continue - if codec == 'all': - self._codecs = ['!all'] - else: - while codec in self._codecs: - self._codecs.remove(codec) - return - yield - - @staticmethod - def _convert_directmedia(val): - if 'yes' in val: - yield 'direct_media', 'yes' - if 'update' in val: - yield 'direct_media_method', 'update' - if 'outgoing' in val: - yield 'direct_media_glare_mitigation', 'outgoing' - if 'nonat' in val: - yield 'disable_directed_media_on_nat', 'yes' - if val == 'no': - yield 'direct_media', 'no' - - @staticmethod - def _convert_dtlsenable(val): - if val == 'yes': - yield 'media_encryption', 'dtls' - - @staticmethod - def _convert_dtmfmode(val): - key = 'dtmf_mode' - if val == 'rfc2833': - yield key, 'rfc4733' - elif val in ('inband', 'info'): - yield key, val - - @staticmethod - def _convert_encryption(val): - if val == 'yes': - yield 'media_encryption', 'sdes' - - @staticmethod - def _convert_encryption_taglen(val): - if val == 32: - return 'srtp_tag_32', 'yes' - - @staticmethod - def _convert_nat(val): - if val == 'yes': - yield 'rtp_symmetric', 'yes' - yield 'rewrite_contact', 'yes' - elif val == 'comedia': - yield 'rtp_symmetric', 'yes' - elif val == 'force_rport': - yield 'force_rport', 'yes' - yield 'rewrite_contact', 'yes' - - @staticmethod - def _convert_progressinband(val): - if val in ('no', 'never'): - yield 'inband_progress', 'no' - elif val == 'yes': - yield 'inband_progress', 'yes' - - @staticmethod - def _convert_recordonfeature(val): - if val == 'automixmon': - yield 'one_touch_recording', 'yes' - yield 'record_on_feature', val - - @staticmethod - def _convert_recordofffeature(val): - if val == 'automixmon': - yield 'one_touch_recording', 'yes' - yield 'record_off_feature', val - - @staticmethod - def _convert_sendrpid(val): - if val in ('yes', 'rpid'): - yield 'send_rpid', 'yes' - elif val == 'pai': - yield 'send_pai', 'yes' - - @staticmethod - def _convert_session_timers(val): - new_val = 'yes' - if val == 'originate': - new_val = 'always' - elif val == 'accept': - new_val = 'required' - elif val == 'never': - new_val = 'no' - - return 'timers', new_val - - -def get_static_sip(): - query = sa.sql.select([ - static_sip_tbl.c.var_name, - static_sip_tbl.c.var_val, - ]).distinct( - static_sip_tbl.c.var_metric, - static_sip_tbl.c.var_name, - static_sip_tbl.c.var_val, - ).where(sa.sql.and_( - static_sip_tbl.c.filename == 'sip.conf', - static_sip_tbl.c.category == 'general', - static_sip_tbl.c.commented == '0', - static_sip_tbl.c.var_val.isnot(None), - )).order_by( - static_sip_tbl.c.var_metric, - ) - rows = op.get_bind().execute(query) - return [KV(row.var_name, row.var_val) for row in rows] - - -def get_transports(): - query = sa.sql.select([transport_tbl.c.uuid, transport_tbl.c.name]) - rows = op.get_bind().execute(query) - return {row.name: row.uuid for row in rows} - - -def get_sip_registers(): - query = sa.sql.select([ - static_sip_tbl.c.id, - static_sip_tbl.c.var_val, - ]).where(sa.sql.and_( - static_sip_tbl.c.filename == 'sip.conf', - static_sip_tbl.c.category == 'general', - static_sip_tbl.c.var_name == 'register', - static_sip_tbl.c.commented == 0, - )) - return {row.id: row.var_val for row in op.get_bind().execute(query)} - - -def find_wss_transport(): - query = sa.sql.select([ - transport_option_tbl.c.pjsip_transport_uuid, - ]).where( - sa.sql.and_( - transport_option_tbl.c.key == 'protocol', - transport_option_tbl.c.value == 'wss', - ) - ) - rows = op.get_bind().execute(query) - for row in rows: - return row.pjsip_transport_uuid - - -def list_tenant_uuid(): - query = sa.sql.select([tenant_tbl.c.uuid]) - return [row[0] for row in op.get_bind().execute(query)] - - -def create_global_config_body(static_sip, transports): - aor_option_accumulator = OptionAccumulator( - AOR_SECTION_MAPPING, - VALID_AOR_OPTIONS, - ) - endpoint_option_accumulator = OptionAccumulator( - ENDPOINT_SECTION_MAPPING, - VALID_ENDPOINT_OPTIONS, - ) - transport = None - - aor_option_accumulator.add_option(KV('max_contacts', '1')) - aor_option_accumulator.add_option(KV('remove_existing', 'true')) - - for kv in static_sip: - aor_option_accumulator.add_option(kv) - endpoint_option_accumulator.add_option(kv) - if kv.key == 'transport': - transport = transports.get(kv.value) - - body = { - 'label': 'General', - 'aor_section_options': aor_option_accumulator.get_options(), - 'endpoint_section_options': endpoint_option_accumulator.get_options(), - 'template': True, - 'transport_uuid': transport, - } - - return body - - -def create_webrtc_config_body(): - body = { - 'label': 'WebRTC line', - 'aor_section_options': [ - KV('max_contacts', '10'), - KV('remove_existing', 'no'), - ], - 'endpoint_section_options': [ - KV('allow', '!all,opus,g722,alaw,ulaw,vp9,vp8,h264'), - KV('dtls_auto_generate_cert', 'yes'), - KV('webrtc', 'yes'), - ], - 'template': True, - 'transport_uuid': find_wss_transport() - } - - return body - - -def create_trunk_config_body(static_sip): - registration_option_accumulator = OptionAccumulator( - REGISTRATION_SECTION_MAPPING, - VALID_REGISTRATION_OPTIONS, - ) - - for kv in static_sip: - registration_option_accumulator.add_option(kv) - - body = { - 'label': 'Trunk', - 'template': True, - 'registration_section_options': registration_option_accumulator.get_options(), - } - - return body - - -def create_twilio_config_body(): - body = { - 'label': 'twilio Trunk', - 'template': True, - 'identify_section_options': [ - KV('match', '54.172.60.0'), - KV('match', '54.172.60.1'), - KV('match', '54.172.60.2'), - KV('match', '54.172.60.3'), - KV('match', '54.244.51.0'), - KV('match', '54.244.51.1'), - KV('match', '54.244.51.2'), - KV('match', '54.244.51.3'), - KV('match', '54.171.127.192'), - KV('match', '54.171.127.193'), - KV('match', '54.171.127.194'), - KV('match', '54.171.127.195'), - KV('match', '35.156.191.128'), - KV('match', '35.156.191.129'), - KV('match', '35.156.191.130'), - KV('match', '35.156.191.131'), - KV('match', '54.65.63.192'), - KV('match', '54.65.63.193'), - KV('match', '54.65.63.194'), - KV('match', '54.65.63.195'), - KV('match', '54.169.127.128'), - KV('match', '54.169.127.129'), - KV('match', '54.169.127.130'), - KV('match', '54.169.127.131'), - KV('match', '54.252.254.64'), - KV('match', '54.252.254.65'), - KV('match', '54.252.254.66'), - KV('match', '54.252.254.67'), - KV('match', '177.71.206.192'), - KV('match', '177.71.206.193'), - KV('match', '177.71.206.194'), - KV('match', '177.71.206.195'), - ], - } - - return body - - -def insert_section(endpoint_sip_uuid, type, options): - if not options: - return - - query = endpoint_sip_section_tbl.insert().returning(endpoint_sip_section_tbl.c.uuid).values( - endpoint_sip_uuid=endpoint_sip_uuid, - type=type, - ) - section_uuid = op.get_bind().execute(query).scalar() - - for key, value in options: - query = endpoint_sip_section_option_tbl.insert().values( - key=key, - value=value, - endpoint_sip_section_uuid=section_uuid, - ) - op.execute(query) - - return section_uuid - - -def insert_endpoint_config( - tenant_uuid, - body, - parents=None, -): - aor_section_options = body.get('aor_section_options') - auth_section_options = body.get('auth_section_options') - endpoint_section_options = body.get('endpoint_section_options') - identify_section_options = body.get('identify_section_options') - registration_section_options = body.get('registration_section_options') - outbound_auth_section_options = body.get('outbound_auth_section_options') - registration_outbound_auth_section_options = body.get( - 'registration_outbound_auth_section_options' - ) - - query = endpoint_sip_tbl.insert().returning(endpoint_sip_tbl.c.uuid).values( - label=body['label'], - name=body.get('name') or generate_unused_name(), - tenant_uuid=tenant_uuid, - template=body.get('template', False), - transport_uuid=body.get('transport_uuid'), - ) - body['uuid'] = op.get_bind().execute(query).scalar() - insert_section(body['uuid'], 'aor', aor_section_options) - insert_section(body['uuid'], 'auth', auth_section_options) - insert_section(body['uuid'], 'endpoint', endpoint_section_options) - insert_section(body['uuid'], 'identify', identify_section_options) - insert_section(body['uuid'], 'registration', registration_section_options) - insert_section( - body['uuid'], - 'registration_outbound_auth', - registration_outbound_auth_section_options, - ) - insert_section(body['uuid'], 'outbound_auth', outbound_auth_section_options) - - for parent in parents or []: - query = endpoint_sip_template_tbl.insert().values( - child_uuid=body['uuid'], - parent_uuid=parent['uuid'], - ) - op.execute(query) - - return body - - -def name_already_exists(name): - query = ( - sa.sql.select([endpoint_sip_tbl.c.name]) - .where(endpoint_sip_tbl.c.name == name) - ) - return op.get_bind().execute(query).scalar() is not None - - -def generate_unused_name(): - while True: - data = ''.join(random.choice(ALPHANUMERIC_POOL) for _ in range(8)) - if not name_already_exists(data): - return data - - -def insert_global_config(tenant_uuid, body): - body.update({ - 'label': 'global', - 'template': True, - }) - return insert_endpoint_config(tenant_uuid, body) - - -def insert_webrtc_config(tenant_uuid, parents, body): - body.update({ - 'label': 'webrtc', - 'template': True, - }) - return insert_endpoint_config(tenant_uuid, body, parents) - - -def insert_trunk_config(tenant_uuid, parents, body): - body.update({ - 'label': 'global_trunk', - 'template': True, - }) - return insert_endpoint_config(tenant_uuid, body, parents) - - -def insert_twilio_config(tenant_uuid, parents, body): - body.update({ - 'label': 'twilio_trunk', - 'template': True, - }) - return insert_endpoint_config(tenant_uuid, body, parents) - - -def list_existing_line_config(tenant_uuid): - query = sa.sql.select([user_sip_tbl]).where(sa.sql.and_( - user_sip_tbl.c.category == 'user', - user_sip_tbl.c.commented == 0, - user_sip_tbl.c.tenant_uuid == tenant_uuid, - )) - result = [] - - for row in op.get_bind().execute(query): - result.append(UserSIPLine.from_row(row)) - - return result - - -def list_existing_trunk_config(tenant_uuid, registers, transports): - query = sa.sql.select([ - user_sip_tbl, - trunkfeatures_tbl.c.twilio_incoming, - trunkfeatures_tbl.c.register_sip_id, - ]).where(sa.sql.and_( - user_sip_tbl.c.category == 'trunk', - user_sip_tbl.c.commented == 0, - user_sip_tbl.c.tenant_uuid == tenant_uuid, - user_sip_tbl.c.id == trunkfeatures_tbl.c.endpoint_sip_id, - )) - result = [] - for row in op.get_bind().execute(query): - result.append(UserSIPTrunk.from_row(row, registers, transports)) - return result - - -def convert_host(sip): - for name, value in sip.options: - if name == 'host': - val = value - else: - return - - if val == 'dynamic': - max_contacts = 1 - max_contacts_defined = False - - for key, value in sip.options: - if key == 'max_contacts': - max_contacts_defined = True - max_contacts = value - break - - if ['webrtc', 'yes'] in sip.options: - if not max_contacts_defined: - max_contacts = 10 - - if max_contacts == 1: - yield ('remove_existing', 'yes') - - yield ('max_contacts', max_contacts) - return - - result = 'sip:' - # More difficult case. The host will be either a hostname or - # IP address and may or may not have a port specified. pjsip.conf - # expects the contact to be a SIP URI. - - if sip.category == 'line': - user = sip.name - yield ('qualify_frequency', 0) - else: - user = sip.username - - if user: - result += user + '@' - - port = 5060 - for name, value in sip.options: - if name == 'port': - port = value - host_port = '{}:{}'.format(val, port) - result += host_port - - yield ('contact', result) - - -def sip_to_pjsip(sip_config, transports): - config = { - 'label': sip_config.name, - 'name': sip_config.name, - 'template': False, - } - - aor_option_accumulator = OptionAccumulator( - AOR_SECTION_MAPPING, - VALID_AOR_OPTIONS, - ) - auth_option_accumulator = OptionAccumulator( - AUTH_SECTION_MAPPING, - VALID_AUTH_OPTIONS, - ) - endpoint_option_accumulator = OptionAccumulator( - ENDPOINT_SECTION_MAPPING, - VALID_ENDPOINT_OPTIONS, - ) - - for kv in convert_host(sip_config): - endpoint_option_accumulator.add_option(kv) - - for kv in sip_config.options: - aor_option_accumulator.add_option(kv) - auth_option_accumulator.add_option(kv) - endpoint_option_accumulator.add_option(kv) - if kv.key == 'transport': - config['transport_uuid'] = transports.get(kv.value) - - if sip_config.registration: - registration_section_options = sip_config.registration.registration_fields - config['registration_section_options'] = registration_section_options - config['registration_outbound_auth_section_options'] = sip_config.registration.auth_fields - - config.update({ - 'aor_section_options': aor_option_accumulator.get_options(), - 'auth_section_options': auth_option_accumulator.get_options(), - 'endpoint_section_options': endpoint_option_accumulator.get_options(), - }) - - if sip_config.category == 'trunk': - config['outbound_auth_section_options'] = auth_option_accumulator.get_options() - - return config - - -def is_webrtc(pjsip_config): - endpoint_section_options = pjsip_config.get('endpoint_section_options', []) - for key, value in endpoint_section_options: - if key == 'webrtc' and value == 'yes': - return True - return False - - -def is_twilio(pjsip_config): - return pjsip_config.twilio_incoming is not None - - -def parent_has_option(parents, section_name, key, value): - for parent in parents: - section_options = parent.get(section_name) - if not section_options: - continue - if (key, value) in section_options: - return True - return False - - -def find_inherited_transport(parent_configs): - last_transport = None - for config in parent_configs: - last_transport = config.get('transport_uuid') or last_transport - return last_transport - - -def prune_pjsip_config(pjsip_config, parent_configs): - section_names = [ - 'aor_section_options', - 'auth_section_options', - 'endpoint_section_options', - 'identify_section_options', - 'registration_section_options', - 'outbound_auth_section_options', - 'registration_outbound_auth_section_options', - ] - for section_name in section_names: - section_options = pjsip_config.get(section_name) - if not section_options: - continue - to_remove = [] - for key, value in section_options: - if parent_has_option(parent_configs, section_name, key, value): - to_remove.append((key, value)) - - for pair in to_remove: - section_options.remove(pair) - - inherited_transport = find_inherited_transport(parent_configs) - if inherited_transport and inherited_transport == pjsip_config.get('transport_uuid'): - pjsip_config['transport_uuid'] = None, - - return pjsip_config - - -def update_line_associations(tenant_uuid, endpoint_uuid, old_sip_id): - op.execute( - linefeatures_tbl.update().values( - endpoint_sip_uuid=endpoint_uuid, - ).where(linefeatures_tbl.c.endpoint_sip_id == old_sip_id), - ) - - -def update_trunk_associations(tenant_uuid, endpoint_uuid, old_sip_id): - op.execute( - trunkfeatures_tbl.update().values( - endpoint_sip_uuid=endpoint_uuid, - ).where(trunkfeatures_tbl.c.endpoint_sip_id == old_sip_id), - ) - - -def configure_line(tenant_uuid, global_config, webrtc_config, sip_config, transports): - pjsip_config = sip_to_pjsip(sip_config, transports) - parent_configs = [global_config] - if is_webrtc(pjsip_config): - parent_configs.append(webrtc_config) - pruned_pjsip_config = prune_pjsip_config(pjsip_config, parent_configs) - endpoint = insert_endpoint_config(tenant_uuid, pruned_pjsip_config, parent_configs) - update_line_associations(tenant_uuid, endpoint['uuid'], sip_config.id) - - -def configure_trunk(tenant_uuid, base_trunk_config, twilio_config, trunk_config, transports): - pjsip_config = sip_to_pjsip(trunk_config, transports) - parent_configs = [base_trunk_config] - if is_twilio(trunk_config): - parent_configs.append(twilio_config) - pruned_pjsip_config = prune_pjsip_config(pjsip_config, parent_configs) - endpoint = insert_endpoint_config(tenant_uuid, pruned_pjsip_config, parent_configs) - update_trunk_associations(tenant_uuid, endpoint['uuid'], trunk_config.id) - - -def configure_tenant( - tenant_uuid, - global_config_body, - webrtc_config_body, - twilio_config_body, - trunk_config_body, - transports, - registers, -): - global_config = insert_global_config(tenant_uuid, global_config_body) - webrtc_config = insert_webrtc_config( - tenant_uuid, - parents=[global_config], - body=webrtc_config_body, - ) - base_trunk_config = insert_trunk_config( - tenant_uuid, - parents=[global_config], - body=trunk_config_body, - ) - twilio_config = insert_twilio_config( - tenant_uuid, - parents=[base_trunk_config], - body=twilio_config_body, - ) - - op.execute( - tenant_tbl.update().values( - sip_templates_generated=True, - global_sip_template_uuid=global_config['uuid'], - webrtc_sip_template_uuid=webrtc_config['uuid'], - global_trunk_sip_template_uuid=base_trunk_config['uuid'], - twilio_trunk_sip_template_uuid=twilio_config['uuid'], - ).where(tenant_tbl.c.uuid == tenant_uuid) - ) - - line_configs = list_existing_line_config(tenant_uuid) - for line_config in line_configs: - configure_line(tenant_uuid, global_config, webrtc_config, line_config, transports) - - trunk_configs = list_existing_trunk_config(tenant_uuid, registers, transports) - for trunk_config in trunk_configs: - configure_trunk(tenant_uuid, base_trunk_config, twilio_config, trunk_config, transports) - - -def remove_all_sip_endpoints(): - op.execute(endpoint_sip_tbl.delete()) - - -def upgrade(): - tenant_uuids = list_tenant_uuid() - transports = get_transports() - static_sip = get_static_sip() - registers = get_sip_registers() - - global_config_body = create_global_config_body(static_sip, transports) - webrtc_config_body = create_webrtc_config_body() - twilio_config_body = create_twilio_config_body() - trunk_config_body = create_trunk_config_body(static_sip) - - for tenant_uuid in tenant_uuids: - configure_tenant( - tenant_uuid, - global_config_body, - webrtc_config_body, - twilio_config_body, - trunk_config_body, - transports, - registers, - ) - - -def downgrade(): - op.execute( - tenant_tbl.update().values( - sip_templates_generated=False, - global_sip_template_uuid=None, - webrtc_sip_template_uuid=None, - global_trunk_sip_template_uuid=None, - twilio_trunk_sip_template_uuid=None, - ) - ) - remove_all_sip_endpoints() diff --git a/alembic/versions/ea9cdf2d59f8_add_default_template_webrtc_video.py b/alembic/versions/ea9cdf2d59f8_add_default_template_webrtc_video.py deleted file mode 100644 index dab5ce18..00000000 --- a/alembic/versions/ea9cdf2d59f8_add_default_template_webrtc_video.py +++ /dev/null @@ -1,257 +0,0 @@ -"""Add default template webrtc_video - -Revision ID: ea9cdf2d59f8 -Revises: bf1aaa27b7f8 - -""" - -import string -import random - -from alembic import op -import sqlalchemy as sa -from sqlalchemy import sql - -from sqlalchemy.dialects.postgresql import UUID - -# revision identifiers, used by Alembic. -revision = "ea9cdf2d59f8" -down_revision = "bf1aaa27b7f8" - -ALPHANUMERIC_POOL = string.ascii_lowercase + string.digits -WEBRTC_VIDEO_COLUMN_NAME = "webrtc_video_sip_template_uuid" - -transport_option_tbl = sa.sql.table( - "pjsip_transport_option", - sa.sql.column("key"), - sa.sql.column("value"), -) -endpoint_sip_tbl = sa.sql.table( - "endpoint_sip", - sa.sql.column("uuid"), - sa.sql.column("label"), - sa.sql.column("name"), - sa.sql.column("tenant_uuid"), - sa.sql.column("template"), -) -endpoint_sip_section_tbl = sa.sql.table( - "endpoint_sip_section", - sa.sql.column("uuid"), - sa.sql.column("type"), - sa.sql.column("endpoint_sip_uuid"), -) -endpoint_sip_section_option_tbl = sa.sql.table( - "endpoint_sip_section_option", - sa.sql.column("uuid"), - sa.sql.column("key"), - sa.sql.column("value"), - sa.sql.column("endpoint_sip_section_uuid"), -) -endpoint_sip_template_tbl = sa.sql.table( - "endpoint_sip_template", - sa.sql.column("child_uuid"), - sa.sql.column("parent_uuid"), -) -tenant_tbl = sa.sql.table( - "tenant", - sa.sql.column("uuid"), - sa.sql.column("webrtc_sip_template_uuid"), - sa.sql.column(WEBRTC_VIDEO_COLUMN_NAME), -) - - -def name_already_exists(name): - query = sa.sql.select([endpoint_sip_tbl.c.name]).where( - endpoint_sip_tbl.c.name == name - ) - return op.get_bind().execute(query).scalar() is not None - - -def generate_unused_name(): - while True: - data = "".join(random.choice(ALPHANUMERIC_POOL) for _ in range(8)) - if not name_already_exists(data): - return data - - -def insert_webrtc_video_endpoint(tenant_uuid, webrtc_sip_template_uuid): - query = ( - endpoint_sip_tbl.insert() - .returning(endpoint_sip_tbl.c.uuid) - .values( - label='webrtc_video', - name=generate_unused_name(), - tenant_uuid=tenant_uuid, - template=True, - ) - ) - endpoint_sip_uuid = op.get_bind().execute(query).scalar() - - query = ( - endpoint_sip_section_tbl.insert() - .returning(endpoint_sip_section_tbl.c.uuid) - .values( - endpoint_sip_uuid=endpoint_sip_uuid, - type='endpoint', - ) - ) - endpoint_section_uuid = op.get_bind().execute(query).scalar() - - options = [ - ("max_video_streams", "25"), - ("max_audio_streams", "1"), - ] - for key, value in options: - query = ( - endpoint_sip_section_option_tbl - .insert() - .values( - key=key, - value=value, - endpoint_sip_section_uuid=endpoint_section_uuid, - ) - ) - op.execute(query) - - query = ( - endpoint_sip_template_tbl - .insert() - .values( - child_uuid=endpoint_sip_uuid, - parent_uuid=webrtc_sip_template_uuid, - ) - ) - op.execute(query) - - return endpoint_sip_uuid - - -def configure_tenant(tenant_uuid, webrtc_sip_template_uuid): - # 1. Create default template and assign to tenant - webrtc_video_uuid = insert_webrtc_video_endpoint( - tenant_uuid, - webrtc_sip_template_uuid - ) - - op.execute( - tenant_tbl.update() - .values( - webrtc_video_sip_template_uuid=webrtc_video_uuid, - ) - .where(tenant_tbl.c.uuid == tenant_uuid) - ) - - # 2. Find sip endpoint with matching params - query = ( - sa.sql.select([endpoint_sip_tbl.c.uuid]) - .select_from( - endpoint_sip_tbl - .join( - endpoint_sip_section_tbl, - endpoint_sip_section_tbl.c.endpoint_sip_uuid == endpoint_sip_tbl.c.uuid, - ) - .join( - endpoint_sip_section_option_tbl, - endpoint_sip_section_option_tbl.c.endpoint_sip_section_uuid == endpoint_sip_section_tbl.c.uuid, - ) - ) - .where(endpoint_sip_tbl.c.template.is_(False)) - .where(endpoint_sip_tbl.c.tenant_uuid == tenant_uuid) - .where(endpoint_sip_section_tbl.c.type == 'endpoint') - .where( - sql.or_( - sql.and_( - endpoint_sip_section_option_tbl.c.key == 'max_video_streams', - endpoint_sip_section_option_tbl.c.value == '25', - ), - sql.and_( - endpoint_sip_section_option_tbl.c.key == 'max_audio_streams', - endpoint_sip_section_option_tbl.c.value == '1', - ), - ) - ) - .group_by(endpoint_sip_tbl.c.uuid) - ) - endpoints = op.get_bind().execute(query) - - for endpoint in endpoints: - query = ( - endpoint_sip_template_tbl - .insert() - .values( - child_uuid=endpoint.uuid, - parent_uuid=webrtc_video_uuid, - ) - ) - op.execute(query) - - -def upgrade(): - # 1. Add new column to tenant table - op.add_column( - "tenant", - sa.Column( - WEBRTC_VIDEO_COLUMN_NAME, - UUID, - sa.ForeignKey( - "endpoint_sip.uuid", - ondelete="SET NULL", - name="tenant_webrtc_video_sip_template_uuid_fkey", - ), - ), - ) - - # 2. Assign template to tenants - query = sa.sql.select([tenant_tbl.c.uuid, tenant_tbl.c.webrtc_sip_template_uuid]) - tenants = op.get_bind().execute(query) - for tenant in tenants: - configure_tenant(tenant.uuid, tenant.webrtc_sip_template_uuid) - - # 3. Delete options matching default params - query = ( - endpoint_sip_section_option_tbl - .delete() - .where(endpoint_sip_section_option_tbl.c.uuid.in_( - sql.select([endpoint_sip_section_option_tbl.c.uuid]) - .select_from( - endpoint_sip_section_option_tbl - .join( - endpoint_sip_section_tbl, - endpoint_sip_section_tbl.c.uuid == endpoint_sip_section_option_tbl.c.endpoint_sip_section_uuid, - ) - .join( - endpoint_sip_tbl, - endpoint_sip_tbl.c.uuid == endpoint_sip_section_tbl.c.endpoint_sip_uuid, - ) - ) - .where(endpoint_sip_tbl.c.template.is_(False)) - )) - .where( - sql.or_( - sql.and_( - endpoint_sip_section_option_tbl.c.key == 'max_video_streams', - endpoint_sip_section_option_tbl.c.value == '25', - ), - sql.and_( - endpoint_sip_section_option_tbl.c.key == 'max_audio_streams', - endpoint_sip_section_option_tbl.c.value == '1', - ), - ) - ) - ) - op.execute(query) - - -def downgrade(): - # 1. Drop templates webrtc_video - query = ( - endpoint_sip_tbl - .delete() - .where(endpoint_sip_tbl.c.uuid.in_( - sql.select([tenant_tbl.c.webrtc_video_sip_template_uuid]) - )) - ) - op.get_bind().execute(query) - - # 2. Drop table column - op.drop_column("tenant", WEBRTC_VIDEO_COLUMN_NAME) diff --git a/alembic/versions/eaffdf929dd1_queueskill_add_tenant_uuid.py b/alembic/versions/eaffdf929dd1_queueskill_add_tenant_uuid.py deleted file mode 100644 index 653e34eb..00000000 --- a/alembic/versions/eaffdf929dd1_queueskill_add_tenant_uuid.py +++ /dev/null @@ -1,169 +0,0 @@ -"""queueskill add tenant_uuid - -Revision ID: eaffdf929dd1 -Revises: 0aeb61795700 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'eaffdf929dd1' -down_revision = '0aeb61795700' - -queueskill_tbl = sa.sql.table( - 'queueskill', - sa.sql.column('id'), - sa.sql.column('catid'), - sa.sql.column('tenant_uuid'), - sa.sql.column('name'), - sa.sql.column('description'), -) - -agentqueueskill_tbl = sa.sql.table( - 'agentqueueskill', - sa.sql.column('agentid'), - sa.sql.column('skillid'), -) - -agentfeatures_tbl = sa.sql.table( - 'agentfeatures', - sa.sql.column('id'), - sa.sql.column('tenant_uuid'), -) - - -def associate_tenants(): - # 1. Find the agent-skill associations - query = ( - sa.sql.select([ - agentqueueskill_tbl.c.agentid, - agentqueueskill_tbl.c.skillid, - agentfeatures_tbl.c.tenant_uuid, - ]) - .where(agentfeatures_tbl.c.id == agentqueueskill_tbl.c.agentid) - ) - agent_skill_associations = op.get_bind().execute(query) - - # 2. Set the agent tenant to the skill - # skill_migrated = {skill_id: set(tenant_uuids)} - skill_migrated = dict() - for agent_id, skill_id, tenant_uuid in agent_skill_associations: - # New skill id, update the one existing in the db - if skill_id not in skill_migrated: - query = ( - queueskill_tbl.update() - .where(queueskill_tbl.c.id == skill_id) - .values(tenant_uuid=tenant_uuid) - ) - op.execute(query) - skill_migrated[skill_id] = {tenant_uuid} - else: - # create a copy of the skill if the tenant is not the same and update the relationship - # with the new id - if tenant_uuid not in skill_migrated[skill_id]: - query = ( - sa.sql.select([ - queueskill_tbl.c.catid, - queueskill_tbl.c.name, - queueskill_tbl.c.description, - ]) - .where(queueskill_tbl.c.id == skill_id) - ) - result = op.get_bind().execute(query).first() - - query = ( - queueskill_tbl.insert() - .returning(queueskill_tbl.c.id) - .values(tenant_uuid=tenant_uuid, **result) - ) - inserted_id = op.get_bind().execute(query).scalar() - - query = ( - agentqueueskill_tbl.update() - .where( - sa.sql.and_( - agentqueueskill_tbl.c.agentid == agent_id, - agentqueueskill_tbl.c.skillid == skill_id, - ) - ) - .values(skillid=inserted_id) - ) - op.execute(query) - skill_migrated[skill_id].add(tenant_uuid) - - -def delete_no_tenants(): - query = ( - queueskill_tbl.delete() - .where(queueskill_tbl.c.tenant_uuid == None) # noqa - ) - op.execute(query) - - -def upgrade(): - op.add_column( - 'queueskill', - sa.Column( - 'tenant_uuid', - sa.String(36), - sa.ForeignKey('tenant.uuid', ondelete='CASCADE'), - nullable=True - ), - ) - op.drop_constraint('queueskill_name_key', 'queueskill', type_='unique') - - op.create_unique_constraint('queueskill_name_tenant_uuid_key', 'queueskill', ['name', 'tenant_uuid']) - - associate_tenants() - delete_no_tenants() - - op.alter_column('queueskill', 'tenant_uuid', nullable=False) - - -def downgrade(): - op.drop_column('queueskill', 'tenant_uuid') - - # Find the duplicates and reassociate with the first value, delete the others - query = ( - sa.sql.select([ - queueskill_tbl.c.id, - queueskill_tbl.c.name, - ]) - ) - results = op.get_bind().execute(query) - - skills_unique = dict() - for skill_id, name in results: - if name not in skills_unique: - skills_unique[name] = [skill_id] - else: - skills_unique[name].append(skill_id) - - for name, ids in skills_unique.items(): - if len(ids) > 1: - skill_to_keep = ids[0] - skills_to_delete = ids[1:] - - for skill_id in skills_to_delete: - query = ( - agentqueueskill_tbl.update() - .where( - agentqueueskill_tbl.c.skillid == skill_id - ) - .values(skillid=skill_to_keep) - ) - op.execute(query) - - query = ( - queueskill_tbl.delete() - .where( - queueskill_tbl.c.id == skill_id - ) - ) - op.execute(query) - - op.drop_constraint('queueskill_name_tenant_uuid_key', 'queueskill', type_='unique') - op.create_unique_constraint('queueskill_name_key', 'queueskill', ['name']) diff --git a/alembic/versions/ed40a90222f0_bump_version_21_12.py b/alembic/versions/ed40a90222f0_bump_version_21_12.py deleted file mode 100644 index 86facaac..00000000 --- a/alembic/versions/ed40a90222f0_bump_version_21_12.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_21_12 - -Revision ID: ed40a90222f0 -Revises: 56a75d478edc - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'ed40a90222f0' -down_revision = '56a75d478edc' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='21.12')) - - -def downgrade(): - pass diff --git a/alembic/versions/edb58b09b15_6361_missing_acl_xivo_ctid_ng.py b/alembic/versions/edb58b09b15_6361_missing_acl_xivo_ctid_ng.py deleted file mode 100644 index 97155d64..00000000 --- a/alembic/versions/edb58b09b15_6361_missing_acl_xivo_ctid_ng.py +++ /dev/null @@ -1,50 +0,0 @@ -"""6361-missing-acl-xivo-ctid-ng - -Revision ID: edb58b09b15 -Revises: 333cd1b1d31 - -This revision duplicates revision b8d0848e7b2 to fix a desynchronisation between -a fresh install and an upgraded database. See bug #6361. - -""" - -# revision identifiers, used by Alembic. -revision = 'edb58b09b15' -down_revision = '333cd1b1d31' - -from alembic import op -from sqlalchemy import sql - - -webservice = sql.table('accesswebservice', - sql.column('name'), - sql.column('acl')) - -SERVICE = 'xivo-ctid-ng' -NEW_ACL = set(['amid.action.ShowDialplan.create']) - - -def upgrade(): - current_acls = _get_current_acl(SERVICE) - new_acls = current_acls | NEW_ACL - _update_web_service_acl(SERVICE, new_acls) - - -def _get_current_acl(name): - return set(op.get_bind().execute( - sql.select([webservice.c.acl]).where(webservice.c.name == name) - ).scalar()) - - -def _update_web_service_acl(name, acl): - op.execute(webservice - .update() - .where( - webservice.c.name == name - ).values(acl=list(acl))) - - -def downgrade(): - current_acls = _get_current_acl(SERVICE) - new_acls = current_acls - NEW_ACL - _update_web_service_acl(SERVICE, new_acls) diff --git a/alembic/versions/edca430a8373_add_the_pjsip_transport_tables.py b/alembic/versions/edca430a8373_add_the_pjsip_transport_tables.py deleted file mode 100644 index 1e18fd0d..00000000 --- a/alembic/versions/edca430a8373_add_the_pjsip_transport_tables.py +++ /dev/null @@ -1,48 +0,0 @@ -"""add the pjsip transport tables - -Revision ID: edca430a8373 -Revises: 2cbd52dd69e1 - -""" - -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import postgresql - - -# revision identifiers, used by Alembic. -revision = 'edca430a8373' -down_revision = '2cbd52dd69e1' - - -def upgrade(): - op.create_table( - 'pjsip_transport', - sa.Column( - 'uuid', - postgresql.UUID, - server_default=sa.text('uuid_generate_v4()'), - primary_key=True, - ), - sa.Column('name', sa.Text, nullable=False), - ) - op.create_unique_constraint('pjsip_transport_name_key', 'pjsip_transport', ['name']) - - op.create_table( - 'pjsip_transport_option', - sa.Column('id', sa.Integer, primary_key=True), - sa.Column('key', sa.Text, nullable=False), - sa.Column('value', sa.Text, nullable=False), - sa.Column( - 'pjsip_transport_uuid', - postgresql.UUID, - sa.ForeignKey('pjsip_transport.uuid', ondelete='CASCADE'), - nullable=False, - ), - ) - - -def downgrade(): - op.drop_table('pjsip_transport_option') - op.drop_constraint('pjsip_transport_name_key', 'pjsip_transport') - op.drop_table('pjsip_transport') diff --git a/alembic/versions/eddc1df1d57c_bump_version_20_10.py b/alembic/versions/eddc1df1d57c_bump_version_20_10.py deleted file mode 100644 index 71269be0..00000000 --- a/alembic/versions/eddc1df1d57c_bump_version_20_10.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_20_10 - -Revision ID: eddc1df1d57c -Revises: 5600ad4c00b4 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'eddc1df1d57c' -down_revision = '5600ad4c00b4' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='20.10')) - - -def downgrade(): - pass diff --git a/alembic/versions/ee27cd6ccd9_rtp_general_section.py b/alembic/versions/ee27cd6ccd9_rtp_general_section.py deleted file mode 100644 index 0f8648f9..00000000 --- a/alembic/versions/ee27cd6ccd9_rtp_general_section.py +++ /dev/null @@ -1,80 +0,0 @@ -"""rtp_general_section - -Revision ID: ee27cd6ccd9 -Revises: 4e2fb3cbc2a2 - -""" - -from alembic import op -from sqlalchemy import sql - - -# revision identifiers, used by Alembic. -revision = 'ee27cd6ccd9' -down_revision = '4e2fb3cbc2a2' - -asterisk_file_table = sql.table( - 'asterisk_file', - sql.column('id'), - sql.column('name'), -) - -asterisk_file_section_table = sql.table( - 'asterisk_file_section', - sql.column('id'), - sql.column('name'), - sql.column('priority'), - sql.column('asterisk_file_id'), -) - -asterisk_file_variable_table = sql.table( - 'asterisk_file_variable', - sql.column('id'), - sql.column('key'), - sql.column('value'), - sql.column('asterisk_file_section_id'), -) - - -def upgrade(): - file_id = _insert_asterisk_file('rtp.conf') - - section_id = _insert_asterisk_file_section(file_id, 'general', priority=0) - _insert_asterisk_file_variable(section_id, 'rtpstart', '10000') - _insert_asterisk_file_variable(section_id, 'rtpend', '20000') - - _insert_asterisk_file_section(file_id, 'ice_host_candidates') - - -def _insert_asterisk_file(name): - query = (asterisk_file_table - .insert() - .returning(asterisk_file_table.c.id) - .values(name=name)) - - return op.get_bind().execute(query).scalar() - - -def _insert_asterisk_file_section(file_id, name, priority=None): - query = (asterisk_file_section_table - .insert() - .returning(asterisk_file_section_table.c.id) - .values(name=name, - priority=priority, - asterisk_file_id=file_id)) - - return op.get_bind().execute(query).scalar() - - -def _insert_asterisk_file_variable(section_id, key, value): - query = (asterisk_file_variable_table - .insert() - .values(key=key, - value=value, - asterisk_file_section_id=section_id)) - - op.get_bind().execute(query) - - -def downgrade(): - op.execute(asterisk_file_table.delete().where(asterisk_file_table.c.name == 'rtp.conf')) diff --git a/alembic/versions/ee773d263d87_remove_endpoint_sip_context.py b/alembic/versions/ee773d263d87_remove_endpoint_sip_context.py deleted file mode 100644 index fba814b9..00000000 --- a/alembic/versions/ee773d263d87_remove_endpoint_sip_context.py +++ /dev/null @@ -1,25 +0,0 @@ -"""remove-endpoint-sip-context - -Revision ID: ee773d263d87 -Revises: 42b0914ed3e6 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'ee773d263d87' -down_revision = 'ea74eca400ce' - - -def upgrade(): - op.drop_column('endpoint_sip', 'context_id') - - -def downgrade(): - op.add_column( - 'endpoint_sip', - sa.Column('context_id', sa.Integer, sa.ForeignKey('context.id')), - ) diff --git a/alembic/versions/eee032b308b_add_xivo_confd_acl.py b/alembic/versions/eee032b308b_add_xivo_confd_acl.py deleted file mode 100644 index cf9ef874..00000000 --- a/alembic/versions/eee032b308b_add_xivo_confd_acl.py +++ /dev/null @@ -1,36 +0,0 @@ -"""add_xivo_confd_acl - -Revision ID: eee032b308b -Revises: 27040433c098 -""" - -from alembic import op -from sqlalchemy import sql, func - -# revision identifiers, used by Alembic. -revision = 'eee032b308b' -down_revision = '27040433c098' - -webservice = sql.table('accesswebservice', - sql.column('name'), - sql.column('login'), - sql.column('passwd'), - sql.column('acl'), - sql.column('description')) -ACL = '{auth.users.#,auth.admin.#}' -DESCRIPTION = 'Automatically created during upgrade' -SERVICE = 'xivo-confd' - - -def upgrade(): - op.execute(webservice - .insert() - .values(name=SERVICE, - login=SERVICE, - passwd=func.substring(func.gen_salt('bf', 4), 8), - acl=ACL, - description=DESCRIPTION)) - - -def downgrade(): - op.execute(webservice.delete().where(webservice.c.name == SERVICE)) diff --git a/alembic/versions/f055e37e6196_merge_ctimain_infos_general_tables.py b/alembic/versions/f055e37e6196_merge_ctimain_infos_general_tables.py deleted file mode 100644 index 1415fcfa..00000000 --- a/alembic/versions/f055e37e6196_merge_ctimain_infos_general_tables.py +++ /dev/null @@ -1,99 +0,0 @@ -"""merge-ctimain-infos-general-tables - -Revision ID: f055e37e6196 -Revises: 67cdc9dfc2d0 - -""" - -from alembic import op -import sqlalchemy as sa - -# revision identifiers, used by Alembic. -revision = 'f055e37e6196' -down_revision = '67cdc9dfc2d0' - -ctimain_tbl = sa.sql.table( - 'ctimain', - sa.sql.column('live_reload_conf'), -) -general_tbl = sa.sql.table( - 'general', - sa.sql.column('timezone'), - sa.sql.column('configured'), -) -infos_tbl = sa.sql.table( - 'infos', - sa.sql.column('live_reload_enabled'), - sa.sql.column('timezone'), - sa.sql.column('configured'), -) - - -def upgrade(): - op.add_column( - 'infos', - sa.Column( - 'live_reload_enabled', - sa.Boolean, - nullable=False, - server_default='True', - ) - ) - op.add_column('infos', sa.Column('timezone', sa.String(128))) - op.add_column( - 'infos', - sa.Column( - 'configured', - sa.Boolean, - nullable=False, - server_default='False', - ) - ) - ctimain = op.get_bind().execute(sa.sql.select([ctimain_tbl])).first() - general = op.get_bind().execute(sa.sql.select([general_tbl])).first() - op.execute( - infos_tbl - .update() - .values( - timezone=general.timezone, - configured=general.configured, - live_reload_enabled=ctimain.live_reload_conf == 1, - ) - ) - op.drop_table('ctimain') - op.drop_table('general') - - -def downgrade(): - op.create_table( - 'ctimain', - sa.Column('id', sa.Integer, primary_key=True), - sa.Column('ctis_active', sa.Integer, nullable=False, server_default='1'), - sa.Column('tlscertfile', sa.String(128)), - sa.Column('tlsprivkeyfile', sa.String(128)), - sa.Column('context_separation', sa.Integer), - sa.Column('live_reload_conf', sa.Integer), - ) - op.create_table( - 'general', - sa.Column('id', sa.Integer, primary_key=True), - sa.Column('timezone', sa.String(128)), - sa.Column('configured', sa.Boolean, nullable=False, server_default='False'), - ) - infos = op.get_bind().execute(sa.sql.select([infos_tbl])).first() - op.execute( - ctimain_tbl - .insert() - .values(live_reload_conf=1 if infos.live_reload_enabled else 0) - ) - op.execute( - general_tbl - .insert() - .values( - timezone=infos.timezone, - configured=infos.configured, - ) - ) - op.drop_column('infos', 'live_reload_enabled') - op.drop_column('infos', 'timezone') - op.drop_column('infos', 'configured') diff --git a/alembic/versions/f1518ec4da82_add_extension_cascade_on_line_extension.py b/alembic/versions/f1518ec4da82_add_extension_cascade_on_line_extension.py deleted file mode 100644 index ae48c395..00000000 --- a/alembic/versions/f1518ec4da82_add_extension_cascade_on_line_extension.py +++ /dev/null @@ -1,43 +0,0 @@ -"""add-extension-cascade-on-line-extension - -Revision ID: f1518ec4da82 -Revises: e53b8ab083c0 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'f1518ec4da82' -down_revision = 'e53b8ab083c0' - -FK_NAME = 'line_extension_extension_id_fkey' -SOURCE_TABLE_NAME = 'line_extension' -REF_TABLE_NAME = 'extensions' -SOURCE_COLUMN_NAME = 'extension_id' -REF_COLUMN_NAME = 'id' - - -def upgrade(): - op.drop_constraint(FK_NAME, SOURCE_TABLE_NAME) - op.create_foreign_key( - FK_NAME, - SOURCE_TABLE_NAME, - REF_TABLE_NAME, - [SOURCE_COLUMN_NAME], - [REF_COLUMN_NAME], - ondelete='CASCADE', - ) - - -def downgrade(): - op.drop_constraint(FK_NAME, SOURCE_TABLE_NAME) - op.create_foreign_key( - FK_NAME, - SOURCE_TABLE_NAME, - REF_TABLE_NAME, - [SOURCE_COLUMN_NAME], - [REF_COLUMN_NAME], - ) diff --git a/alembic/versions/f1fea68b56d9_add_priority_column_to_endpoint_sip.py b/alembic/versions/f1fea68b56d9_add_priority_column_to_endpoint_sip.py deleted file mode 100644 index 5e74c669..00000000 --- a/alembic/versions/f1fea68b56d9_add_priority_column_to_endpoint_sip.py +++ /dev/null @@ -1,22 +0,0 @@ -"""add-priority-column-to-endpoint-sip - -Revision ID: f1fea68b56d9 -Revises: ee773d263d87 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'f1fea68b56d9' -down_revision = 'ee773d263d87' - - -def upgrade(): - op.add_column('endpoint_sip_template', sa.Column('priority', sa.Integer)) - - -def downgrade(): - op.drop_column('endpoint_sip_template', 'priority') diff --git a/alembic/versions/f207de52e7d0_bump_version_20_15.py b/alembic/versions/f207de52e7d0_bump_version_20_15.py deleted file mode 100644 index 112713fa..00000000 --- a/alembic/versions/f207de52e7d0_bump_version_20_15.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_20_15 - -Revision ID: f207de52e7d0 -Revises: e5e53b7dc5d0 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'f207de52e7d0' -down_revision = 'e5e53b7dc5d0' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='20.15')) - - -def downgrade(): - pass diff --git a/alembic/versions/f2eae4a8353e_bump_version_22_06.py b/alembic/versions/f2eae4a8353e_bump_version_22_06.py deleted file mode 100644 index 6f19d4fc..00000000 --- a/alembic/versions/f2eae4a8353e_bump_version_22_06.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_22_06 - -Revision ID: f2eae4a8353e -Revises: 2b65d248c2ad - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'f2eae4a8353e' -down_revision = '2b65d248c2ad' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='22.06')) - - -def downgrade(): - pass diff --git a/alembic/versions/f33878e11ef4_bump_version_23_04.py b/alembic/versions/f33878e11ef4_bump_version_23_04.py deleted file mode 100644 index 1d116476..00000000 --- a/alembic/versions/f33878e11ef4_bump_version_23_04.py +++ /dev/null @@ -1,23 +0,0 @@ -"""bump_version_23_04 - -Revision ID: f33878e11ef4 -Revises: 9f11f3abaacc - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'f33878e11ef4' -down_revision = '9f11f3abaacc' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='23.04')) - - -def downgrade(): - pass diff --git a/alembic/versions/f3e76222b5c9_remove_dahdi_monitoring_column.py b/alembic/versions/f3e76222b5c9_remove_dahdi_monitoring_column.py deleted file mode 100644 index 9188bfc7..00000000 --- a/alembic/versions/f3e76222b5c9_remove_dahdi_monitoring_column.py +++ /dev/null @@ -1,22 +0,0 @@ -"""remove-dahdi-monitoring-column - -Revision ID: f3e76222b5c9 -Revises: 0269f5e35792 - -""" - -from alembic import op -from sqlalchemy import String, Column - - -# revision identifiers, used by Alembic. -revision = 'f3e76222b5c9' -down_revision = '0269f5e35792' - - -def upgrade(): - op.drop_column('monitoring', 'dahdi_monitor_ports') - - -def downgrade(): - op.add_column('monitoring', Column('dahdi_monitor_ports', String(255))) diff --git a/alembic/versions/f485ac649eb_migrate_transfer_function_keys.py b/alembic/versions/f485ac649eb_migrate_transfer_function_keys.py deleted file mode 100644 index 8e45fe41..00000000 --- a/alembic/versions/f485ac649eb_migrate_transfer_function_keys.py +++ /dev/null @@ -1,270 +0,0 @@ -"""migrate transfer function keys - -Revision ID: f485ac649eb -Revises: 3df184c10386 - -""" - -# revision identifiers, used by Alembic. -revision = 'f485ac649eb' -down_revision = '3df184c10386' - -from alembic import op -import sqlalchemy as sa -from sqlalchemy import sql - -FEATURE_MAP_TYPE = 'featuremap' - - -BLIND_TRANSFER_TYPE = 'blindxfer' -ATTENDED_TRANSFER_TYPE = 'atxfer' - -DESTINATION_FEATURES_ID = 8 - -phonefunckey_table = sql.table('phonefunckey', - sql.column('iduserfeatures'), - sql.column('fknum'), - sql.column('exten'), - sql.column('typeextenumbers'), - sql.column('typevalextenumbers'), - sql.column('typeextenumbersright'), - sql.column('typevalextenumbersright'), - sql.column('label'), - sql.column('supervision'), - sql.column('progfunckey')) - -func_key_table = sql.table('func_key', - sql.column('id'), - sql.column('type_id'), - sql.column('destination_type_id')) - -dest_features_table = sql.table('func_key_dest_features', - sql.column('func_key_id'), - sql.column('destination_type_id'), - sql.column('features_id')) - -func_key_type_table = sql.table('func_key_type', - sql.column('id'), - sql.column('name')) - -func_key_mapping_table = sql.table('func_key_mapping', - sql.column('template_id'), - sql.column('func_key_id'), - sql.column('destination_type_id'), - sql.column('label'), - sql.column('position'), - sql.column('blf')) - -template_table = sql.table('func_key_template', sql.column('id')) - -user_table = sql.table('userfeatures', - sql.column('id'), - sql.column('func_key_private_template_id')) - -destination_type_table = sql.table('func_key_destination_type', - sql.column('id'), - sql.column('name')) - -features_table = sql.table('features', - sql.column('id'), - sql.column('category'), - sql.column('var_name')) - - -def upgrade(): - delete_duplicate_fks() - migrate_func_keys() - delete_old_func_keys() - - -def delete_duplicate_fks(): - for row in get_duplicate_func_keys(): - delete_duplicate_fk(row.iduserfeatures, row.fknum) - - -def get_duplicate_func_keys(): - transfer_types = (BLIND_TRANSFER_TYPE, ATTENDED_TRANSFER_TYPE) - - columns = (phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.typevalextenumbers, - sa.func.min(phonefunckey_table.c.fknum).label("first_position")) - - duplicate_query = (sql.select(columns) - .where( - phonefunckey_table.c.typevalextenumbers.in_(transfer_types)) - .group_by( - phonefunckey_table.c.typevalextenumbers, - phonefunckey_table.c.iduserfeatures) - .having( - sa.func.count(phonefunckey_table.c.typevalextenumbers) > 1) - .alias()) - - columns = (phonefunckey_table.c.iduserfeatures, - phonefunckey_table.c.fknum) - - join_condition = phonefunckey_table.join( - duplicate_query, - sql.and_( - phonefunckey_table.c.typevalextenumbers == duplicate_query.c.typevalextenumbers, - phonefunckey_table.c.fknum > duplicate_query.c.first_position, - phonefunckey_table.c.iduserfeatures == duplicate_query.c.iduserfeatures)) - - duplicate_fk_query = sql.select(columns, from_obj=[join_condition]) - - return op.get_bind().execute(duplicate_fk_query) - - -def delete_duplicate_fk(iduserfeatures, fknum): - print('[MIGRATE_FK] : Deleting transfer func key for user "%s" (fk position %s)' % - (iduserfeatures, fknum)) - - query = (phonefunckey_table - .delete() - .where(sql.and_( - phonefunckey_table.c.iduserfeatures == iduserfeatures, - phonefunckey_table.c.fknum == fknum))) - - op.get_bind().execute(query) - - -def migrate_func_keys(): - for row in get_func_keys(): - func_key_id = get_transfer_func_key(row.transfer_type) - create_mapping(func_key_id, row) - - -def get_func_keys(): - columns = ( - phonefunckey_table.c.iduserfeatures.label('user_id'), - phonefunckey_table.c.fknum.label('position'), - phonefunckey_table.c.label, - phonefunckey_table.c.typevalextenumbers.label('transfer_type'), - sql.cast(phonefunckey_table.c.supervision, sa.Boolean).label('blf'), - ) - - query = (sql.select(columns) - .where( - sql.and_( - phonefunckey_table.c.typeextenumbers == FEATURE_MAP_TYPE, - phonefunckey_table.c.typevalextenumbers.in_(( - BLIND_TRANSFER_TYPE, - ATTENDED_TRANSFER_TYPE)))) - ) - - return op.get_bind().execute(query) - - -def get_transfer_func_key(transfer_type): - transfer_subquery = ( - sql.select( - [features_table.c.id]) - .where( - sql.and_( - features_table.c.category == 'featuremap', - features_table.c.var_name == transfer_type)) - .alias()) - - query = ( - sql.select( - [dest_features_table.c.func_key_id]) - .where( - dest_features_table.c.features_id == transfer_subquery)) - - return op.get_bind().execute(query).scalar() - - -def create_mapping(func_key_id, func_key_row): - conn = op.get_bind() - - template_query = ( - sql.select( - [user_table.c.func_key_private_template_id]) - .where( - user_table.c.id == func_key_row.user_id)) - - template_id = conn.execute(template_query).scalar() - - mapping_query = (func_key_mapping_table - .insert() - .returning(func_key_mapping_table.c.func_key_id) - .values(func_key_id=func_key_id, - template_id=template_id, - destination_type_id=DESTINATION_FEATURES_ID, - label=func_key_row.label, - position=func_key_row.position, - blf=func_key_row.blf)) - - conn.execute(mapping_query) - - -def delete_old_func_keys(): - delete_query = (phonefunckey_table - .delete() - .where( - phonefunckey_table.c.typevalextenumbers.in_( - (BLIND_TRANSFER_TYPE, ATTENDED_TRANSFER_TYPE))) - ) - - op.get_bind().execute(delete_query) - - -def downgrade(): - for row in get_old_func_keys(): - create_old_func_keys(row) - delete_mapping(row.func_key_id, row.template_id) - - -def get_old_func_keys(): - columns = ( - func_key_mapping_table.c.func_key_id, - func_key_mapping_table.c.template_id, - func_key_mapping_table.c.position, - func_key_mapping_table.c.blf, - func_key_mapping_table.c.label, - features_table.c.var_name.label('transfer_type'), - user_table.c.id.label('user_id') - ) - - join_conditions = (func_key_mapping_table - .join(dest_features_table, - func_key_mapping_table.c.func_key_id == dest_features_table.c.func_key_id) - .join(features_table, - dest_features_table.c.features_id == features_table.c.id) - .join(template_table, - func_key_mapping_table.c.template_id == template_table.c.id) - .join(user_table, - template_table.c.id == user_table.c.func_key_private_template_id)) - - query = (sql.select(columns, from_obj=[join_conditions]) - .where( - features_table.c.var_name.in_( - (BLIND_TRANSFER_TYPE, ATTENDED_TRANSFER_TYPE))) - ) - - return op.get_bind().execute(query) - - -def create_old_func_keys(row): - supervision = 1 if row.blf else 0 - - row = {'iduserfeatures': row.user_id, - 'fknum': row.position, - 'typeextenumbers': 'featuremap', - 'typevalextenumbers': row.transfer_type, - 'typeextenumbersright': None, - 'typevalextenumbersright': None, - 'label': row.label, - 'exten': None, - 'supervision': supervision} - - op.bulk_insert(phonefunckey_table, [row]) - - -def delete_mapping(func_key_id, template_id): - query = (func_key_mapping_table - .delete() - .where(sql.and_( - func_key_mapping_table.c.func_key_id == func_key_id, - func_key_mapping_table.c.template_id == template_id))) - - op.get_bind().execute(query) diff --git a/alembic/versions/f5f2dd21819_ast13_chan_sip.py b/alembic/versions/f5f2dd21819_ast13_chan_sip.py deleted file mode 100644 index 2f909569..00000000 --- a/alembic/versions/f5f2dd21819_ast13_chan_sip.py +++ /dev/null @@ -1,29 +0,0 @@ -"""ast13: remove chan_sip callevents - -Revision ID: f5f2dd21819 -Revises: 44af2488e95 - -""" - -# revision identifiers, used by Alembic. -revision = 'f5f2dd21819' -down_revision = '44af2488e95' - -from alembic import op -from sqlalchemy import sql - - -staticsip_table = sql.table('staticsip', - sql.column('var_name')) - - -def upgrade(): - _delete_staticsip_callevents() - - -def _delete_staticsip_callevents(): - op.execute(staticsip_table.delete().where(staticsip_table.c.var_name == 'callevents')) - - -def downgrade(): - pass diff --git a/alembic/versions/f6dab479e74_remove_column_tablename_from_directories.py b/alembic/versions/f6dab479e74_remove_column_tablename_from_directories.py deleted file mode 100644 index 4660b566..00000000 --- a/alembic/versions/f6dab479e74_remove_column_tablename_from_directories.py +++ /dev/null @@ -1,24 +0,0 @@ -"""remove column tablename from directories - -Revision ID: f6dab479e74 -Revises: 2acff5c02871 - -""" - -# revision identifiers, used by Alembic. -revision = 'f6dab479e74' -down_revision = '2acff5c02871' - -from alembic import op -import sqlalchemy as sa - -TABLE = 'directories' -COLUMN = 'tablename' - - -def upgrade(): - op.drop_column(TABLE, COLUMN) - - -def downgrade(): - op.add_column(TABLE, sa.Column(COLUMN, sa.String(255))) diff --git a/alembic/versions/f721d0482a3_create_new_dird_phonebooks.py b/alembic/versions/f721d0482a3_create_new_dird_phonebooks.py deleted file mode 100644 index 1ef55335..00000000 --- a/alembic/versions/f721d0482a3_create_new_dird_phonebooks.py +++ /dev/null @@ -1,73 +0,0 @@ -"""create new dird phonebooks - -Revision ID: f721d0482a3 -Revises: 15b236bd8060 - -""" - -# revision identifiers, used by Alembic. -revision = 'f721d0482a3' -down_revision = '4fa0a41c0327' - -from alembic import op -from sqlalchemy import and_, sql - -directories = sql.table('directories', - sql.column('id'), - sql.column('name'), - sql.column('uri'), - sql.column('dirtype'), - sql.column('description'), - sql.column('dird_tenant'), - sql.column('dird_phonebook')) -entity = sql.table('entity', - sql.column('name'), - sql.column('disable')) - -old_local_phonebook_uri = 'http://localhost/service/ipbx/json.php/private/pbx_services/phonebook' -new_dird_phonebook_uri = 'postgresql://asterisk:proformatique@localhost/asterisk' -default_dird_phonebook = 'xivo' - - -def upgrade(): - conn = op.get_bind() - - entities = list_entities(conn) - phonebooks = list_phonebooks(conn) - - add_phonebooks(entities, phonebooks) - - -def add_phonebooks(entities, phonebooks): - rows = [] - - for entity in entities: - for phonebook in phonebooks: - directory = {'uri': new_dird_phonebook_uri, - 'dirtype': 'dird_phonebook', - 'name': '{}-{}'.format(entity, phonebook.name), - 'description': phonebook.description, - 'dird_tenant': entity, - 'dird_phonebook': default_dird_phonebook} - rows.append(directory) - - op.bulk_insert(directories, rows) - - -def list_entities(conn): - entity_qry = sql.select([entity.c.name]).where(entity.c.disable == 0) - return [e.name for e in conn.execute(entity_qry)] - - -def list_phonebooks(conn): - phonebook_qry = sql.select( - [directories.c.id, - directories.c.name, - directories.c.description]).where( - and_(directories.c.uri == old_local_phonebook_uri, - directories.c.dirtype == 'phonebook')) - return [phonebook for phonebook in conn.execute(phonebook_qry)] - - -def downgrade(): - pass diff --git a/alembic/versions/f98e74435092_fix_pjsip_diff.py b/alembic/versions/f98e74435092_fix_pjsip_diff.py deleted file mode 100644 index 3cc9f703..00000000 --- a/alembic/versions/f98e74435092_fix_pjsip_diff.py +++ /dev/null @@ -1,64 +0,0 @@ -"""fix-pjsip-diff - -Revision ID: f98e74435092 -Revises: f1fea68b56d9 - -""" - -from alembic import op - - -# revision identifiers, used by Alembic. -revision = 'f98e74435092' -down_revision = 'f1fea68b56d9' - - -def upgrade(): - op.drop_constraint('trunkfeatures_registers_check', 'trunkfeatures') - - op.drop_constraint('trunkfeatures_endpoints_check', 'trunkfeatures') - op.drop_constraint('trunkfeatures_endpoint_register_check', 'trunkfeatures') - op.drop_constraint('linefeatures_endpoints_check', 'linefeatures') - - op.drop_column('linefeatures', 'endpoint_sip_id') - op.drop_column('trunkfeatures', 'endpoint_sip_id') - op.drop_column('trunkfeatures', 'register_sip_id') - - op.create_check_constraint( - 'trunkfeatures_endpoints_check', - 'trunkfeatures', - ''' - ( CASE WHEN endpoint_sip_uuid IS NULL THEN 0 ELSE 1 END - + CASE WHEN endpoint_iax_id IS NULL THEN 0 ELSE 1 END - + CASE WHEN endpoint_custom_id IS NULL THEN 0 ELSE 1 END - ) <= 1 - ''', - ) - op.create_check_constraint( - 'trunkfeatures_endpoint_register_check', - 'trunkfeatures', - ''' - ( - register_iax_id IS NULL - ) OR ( - register_iax_id IS NOT NULL AND - endpoint_sip_uuid IS NULL AND - endpoint_custom_id IS NULL - ) - ''', - ) - - op.create_check_constraint( - 'linefeatures_endpoints_check', - 'linefeatures', - ''' - ( CASE WHEN endpoint_sip_uuid IS NULL THEN 0 ELSE 1 END - + CASE WHEN endpoint_sccp_id IS NULL THEN 0 ELSE 1 END - + CASE WHEN endpoint_custom_id IS NULL THEN 0 ELSE 1 END - ) <= 1 - ''', - ) - - -def downgrade(): - pass diff --git a/alembic/versions/f9ea1046c8e5_add_line_cascade_on_line_extension.py b/alembic/versions/f9ea1046c8e5_add_line_cascade_on_line_extension.py deleted file mode 100644 index 24bee0f8..00000000 --- a/alembic/versions/f9ea1046c8e5_add_line_cascade_on_line_extension.py +++ /dev/null @@ -1,43 +0,0 @@ -"""add-line-cascade-on-line-extension - -Revision ID: f9ea1046c8e5 -Revises: f1518ec4da82 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'f9ea1046c8e5' -down_revision = 'f1518ec4da82' - -FK_NAME = 'line_extension_line_id_fkey' -SOURCE_TABLE_NAME = 'line_extension' -REF_TABLE_NAME = 'linefeatures' -SOURCE_COLUMN_NAME = 'line_id' -REF_COLUMN_NAME = 'id' - - -def upgrade(): - op.drop_constraint(FK_NAME, SOURCE_TABLE_NAME) - op.create_foreign_key( - FK_NAME, - SOURCE_TABLE_NAME, - REF_TABLE_NAME, - [SOURCE_COLUMN_NAME], - [REF_COLUMN_NAME], - ondelete='CASCADE', - ) - - -def downgrade(): - op.drop_constraint(FK_NAME, SOURCE_TABLE_NAME) - op.create_foreign_key( - FK_NAME, - SOURCE_TABLE_NAME, - REF_TABLE_NAME, - [SOURCE_COLUMN_NAME], - [REF_COLUMN_NAME], - ) diff --git a/alembic/versions/fb663a210806_pjsip_transport_migration.py b/alembic/versions/fb663a210806_pjsip_transport_migration.py deleted file mode 100644 index 2ab8b72c..00000000 --- a/alembic/versions/fb663a210806_pjsip_transport_migration.py +++ /dev/null @@ -1,285 +0,0 @@ -"""pjsip transport migration - -Revision ID: fb663a210806 -Revises: edca430a8373 - -""" - -from alembic import op -import sqlalchemy as sa -from sqlalchemy import sql -from collections import namedtuple - - -# revision identifiers, used by Alembic. -revision = 'fb663a210806' -down_revision = 'edca430a8373' - -# Special cases -# * multiple localnet/local_net can be specified -# * the "external_signaling_address" is "externhost" OR "externip" -# * "bind" for udp and wss = "udpbindaddr"[+"bindport"] -# * "externtcpport" becomes "external_signaling_port" for the tcp_transport -# * "tcpbindaddr" becomes "bind" for tcp transport -# * transport-tcp is only generated if tcpenabled is 1 -# * transport-wss is only generated if websocket_enabled is 1 - -# Fields that are actually "translated" by wazo-confgend -# SIP_TO_PJSIP_MAPPING = { -# 'media_address': 'external_media_address', -# } - -# zcat /usr/share/doc/asterisk-doc/json/pjsip.json.gz | jq .transport[].name | sort -u -# Commented options are managed individually -# TLS only options are ignored since tls transports are not managed in confgend and do not work at the moment -VERBATIM_PJSIP_TRANSPORT_OPTIONS = [ - "allow_reload", - "async_operations", - "cos", - "domain", - "external_signaling_port", - "password", - "symmetric_transport", - "tos", - "websocket_write_timeout", - # "bind", - # "ca_list_file", # TLS only - # "ca_list_path", # TLS only - # "cert_file", # TLS only - # "cipher", # TLS only - # "external_media_address", - # "external_signaling_address", - # "local_net", - # "method", # TLS only - # "priv_key_file", # TLS only - # "protocol", - # "require_client_cert", # TLS only - # "verify_client", # TLS only - # "verify_server", # TLS only -] -FALSY_VALUES = ('0', 'no', 'No', 'false', 'False') -TRANSPORT_MAP = { - 'udp': 'transport-udp', - 'wss': 'transport-wss', - 'tcp': 'transport-tcp', -} - -static_sip_table = sa.sql.table( - 'staticsip', - sa.sql.column('var_metric'), - sa.sql.column('commented'), - sa.sql.column('filename'), - sa.sql.column('category'), - sa.sql.column('var_name'), - sa.sql.column('var_val'), -) -user_sip_table = sa.sql.table( - 'usersip', - sa.sql.column('transport'), -) -transport_table = sa.sql.table( - 'pjsip_transport', - sa.sql.column('uuid'), - sa.sql.column('name'), -) -transport_option_table = sa.sql.table( - 'pjsip_transport_option', - sa.sql.column('key'), - sa.sql.column('value'), - sa.sql.column('pjsip_transport_uuid'), -) - -KV = namedtuple('KV', ['key', 'value']) - - -def _get_static_sip(): - query = sql.select([ - static_sip_table.c.var_name, - static_sip_table.c.var_val, - ]).distinct( - static_sip_table.c.var_metric, - static_sip_table.c.var_name, - static_sip_table.c.var_val, - ).where(sql.and_( - static_sip_table.c.filename == 'sip.conf', - static_sip_table.c.category == 'general', - static_sip_table.c.commented == '0', - )).order_by( - static_sip_table.c.var_metric, - ) - rows = op.get_bind().execute(query) - return [KV(row.var_name, row.var_val) for row in rows] - - -def _get_transport_wss_options(static_sip): - websocket_enabled = None - for key, value in static_sip: - if key == 'websocket_enabled': - websocket_enabled = value - - if not websocket_enabled or websocket_enabled in FALSY_VALUES: - return None - - migrated_options = [KV('protocol', 'wss')] - base_udp_options = _get_base_udp_options(static_sip) - migrated_options.extend(base_udp_options) - return migrated_options - - -def _get_transport_udp_options(static_sip): - migrated_options = [KV('protocol', 'udp')] - base_udp_options = _get_base_udp_options(static_sip) - migrated_options.extend(base_udp_options) - return migrated_options - - -def _get_base_transport_options(static_sip): - for old, new in TRANSPORT_MAP.items(): - op.execute( - static_sip_table.update().where(sa.and_( - static_sip_table.c.var_name == 'transport', - static_sip_table.c.var_val == old, - )).values(var_val=new) - ) - op.execute( - user_sip_table.update().where( - user_sip_table.c.transport == old, - ).values(transport=new) - ) - - migrated_options = [] - local_nets = set() - external_signaling_address = None - external_media_address = None - - for key, value in static_sip: - # localnet can have one or many values "1.1.1.0/24, 1.1.2.0/24" - if key in ('localnet', 'local_net'): - if ',' in value: - for local_net in value.split(','): - local_nets.add(local_net.strip()) - else: - local_nets.add(value) - - # external_signaling_address OR externhost OR externip - elif key == 'external_signaling_address': - external_signaling_address = value - elif key == 'externhost' and not external_signaling_address: - external_signaling_address = value - elif key == 'externip' and not external_signaling_address: - external_signaling_address = value - - # external_media_address or media_address - elif key == 'external_media_address': - external_media_address = value - elif key == 'media_address' and not external_media_address: - external_media_address = value - - elif key in VERBATIM_PJSIP_TRANSPORT_OPTIONS: - migrated_options.append(KV(key, value)) - - for local_net in local_nets: - migrated_options.append(KV('local_net', local_net)) - - if external_signaling_address: - migrated_options.append(KV('external_signaling_address', external_signaling_address)) - - if external_media_address: - migrated_options.append(KV('external_media_address', external_media_address)) - - return migrated_options - - -def _get_base_udp_options(static_sip): - migrated_options = _get_base_transport_options(static_sip) - bind = None - bindaddr = None - bindport = None - - for key, value in static_sip: - if key == 'udpbindaddr': - bindaddr = value - elif key == 'bindport': - bindport = value - elif key == 'bind': - bind = value - - if bind: - migrated_options.append(KV('bind', bind)) - elif bindaddr and bindport: - migrated_options.append(KV('bind', '{}:{}'.format(bindaddr, bindport))) - elif bindaddr: - migrated_options.append(KV('bind', bindaddr)) - else: - migrated_options.append(KV('bind', '0.0.0.0:5060')) - - return migrated_options - - -def _get_transport_tcp_options(static_sip): - tcp_enabled = None - for key, value in static_sip: - if key == 'tcpenabled': - tcp_enabled = value - - if not tcp_enabled or tcp_enabled in FALSY_VALUES: - return None - - migrated_options = [KV('protocol', 'tcp')] - external_signaling_port = None - for key, value in static_sip: - if key == 'external_signaling_port': - external_signaling_port = value - elif key == 'externtcpport' and not external_signaling_port: - external_signaling_port = value - elif key == 'tcpbindaddr': - migrated_options.append(KV('bind', value)) - - if external_signaling_port: - migrated_options.append(KV('external_signaling_port', external_signaling_port)) - - return migrated_options - - -def upgrade(): - transports = {} - static_sip = _get_static_sip() - - transport_udp_options = _get_transport_udp_options(static_sip) - if transport_udp_options: - transports['transport-udp'] = transport_udp_options - - transport_wss_options = _get_transport_wss_options(static_sip) - if transport_wss_options: - transports['transport-wss'] = transport_wss_options - - transport_tcp_options = _get_transport_tcp_options(static_sip) - if transport_tcp_options: - transports['transport-tcp'] = transport_tcp_options - - for name, options in transports.items(): - query = transport_table.insert().returning(transport_table.c.uuid).values(name=name) - transport_uuid = op.get_bind().execute(query).scalar() - for option in options: - query = transport_option_table.insert().values( - key=option.key, - value=option.value, - pjsip_transport_uuid=transport_uuid, - ) - op.execute(query) - - -def downgrade(): - op.execute(transport_table.delete()) - for old, new in TRANSPORT_MAP.items(): - op.execute( - user_sip_table.update().where( - user_sip_table.c.transport == new, - ).values(transport=old) - ) - op.execute( - static_sip_table.update().where(sa.and_( - static_sip_table.c.var_name == 'transport', - static_sip_table.c.var_val == new, - )).values(var_val=old) - ) diff --git a/alembic/versions/fbbbf7d78ed0_back_to_19_13.py b/alembic/versions/fbbbf7d78ed0_back_to_19_13.py deleted file mode 100644 index 18b25db2..00000000 --- a/alembic/versions/fbbbf7d78ed0_back_to_19_13.py +++ /dev/null @@ -1,23 +0,0 @@ -"""back to 19.13 - -Revision ID: fbbbf7d78ed0 -Revises: 90518bf34218 - -""" - -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'fbbbf7d78ed0' -down_revision = '90518bf34218' - - -def upgrade(): - infos = sa.sql.table('infos', sa.sql.column('wazo_version')) - op.execute(infos.update().values(wazo_version='19.13')) - - -def downgrade(): - pass diff --git a/alembic/versions/fd040214cccb_add_plugind_cli_read_acl.py b/alembic/versions/fd040214cccb_add_plugind_cli_read_acl.py deleted file mode 100644 index e075ddda..00000000 --- a/alembic/versions/fd040214cccb_add_plugind_cli_read_acl.py +++ /dev/null @@ -1,47 +0,0 @@ -"""add plugind cli read acl - -Revision ID: fd040214cccb -Revises: 324ad441b84c - -""" - -# revision identifiers, used by Alembic. -revision = 'fd040214cccb' -down_revision = '324ad441b84c' - -from alembic import op -from sqlalchemy import sql - - -webservice = sql.table('accesswebservice', - sql.column('name'), - sql.column('acl')) - -SERVICE = 'wazo-plugind-cli' -NEW_ACL = set(['plugind.plugins.read']) - - -def upgrade(): - current_acls = _get_current_acl(SERVICE) - new_acls = current_acls | NEW_ACL - _update_web_service_acl(SERVICE, new_acls) - - -def _get_current_acl(name): - return set(op.get_bind().execute( - sql.select([webservice.c.acl]).where(webservice.c.name == name) - ).scalar()) - - -def _update_web_service_acl(name, acl): - op.execute(webservice - .update() - .where( - webservice.c.name == name - ).values(acl=list(acl))) - - -def downgrade(): - current_acls = _get_current_acl(SERVICE) - new_acls = current_acls - NEW_ACL - _update_web_service_acl(SERVICE, new_acls)