def do_normal_ddl_actions(cur): import normal_ddl_actions_post cls_list = reflect_action_cls_list(normal_ddl_actions_post, 'NormalDDLActionPost') # set parameter if len(cls_list) > 0: actions.set_parameter(cur, 'enable_sys_table_ddl', 'True') ori_enable_ddl = actions.get_ori_enable_ddl(cur) if ori_enable_ddl == 0: actions.set_parameter(cur, 'enable_ddl', 'True') for cls in cls_list: logging.info('do normal ddl acion, seq_num: %d', cls.get_seq_num()) action = cls(cur) action.dump_before_do_action() if False == action.skip_action(): action.check_before_do_action() action.do_action() else: logging.info("skip ddl action, seq_num: %d", cls.get_seq_num()) action.dump_after_do_action() action.check_after_do_action() # reset parameter if len(cls_list) > 0: if ori_enable_ddl == 0: actions.set_parameter(cur, 'enable_ddl', 'False') actions.set_parameter(cur, 'enable_sys_table_ddl', 'False')
def do_each_tenant_dml_actions(cur, tenant_id_list): import each_tenant_dml_actions_post cls_list = reflect_action_cls_list(each_tenant_dml_actions_post, 'EachTenantDMLActionPost') for cls in cls_list: logging.info('do each tenant dml acion, seq_num: %d', cls.get_seq_num()) action = cls(cur, tenant_id_list) sys_tenant_id = 1 action.change_tenant(sys_tenant_id) action.dump_before_do_action() if False == action.skip_pre_check(): action.check_before_do_action() else: logging.info("skip pre check. seq_num: %d", cls.get_seq_num()) for tenant_id in action.get_tenant_id_list(): action.change_tenant(tenant_id) action.dump_before_do_each_tenant_action(tenant_id) if False == action.skip_each_tenant_action(tenant_id): action.check_before_do_each_tenant_action(tenant_id) action.do_each_tenant_action(tenant_id) else: logging.info("skip each tenant dml action, seq_num: %d, tenant_id: %d", cls.get_seq_num(), tenant_id) action.dump_after_do_each_tenant_action(tenant_id) action.check_after_do_each_tenant_action(tenant_id) action.change_tenant(sys_tenant_id) action.dump_after_do_action() action.check_after_do_action()
def do_normal_dml_actions(cur): import normal_dml_actions_pre cls_list = reflect_action_cls_list(normal_dml_actions_pre, 'NormalDMLActionPre') # check if pre upgrade script can run reentrantly query_cur = QueryCursor(cur) version = fetch_observer_version(query_cur) can_skip = False if (cmp(version, "2.2.77") >= 0 and cmp(version, "3.0.0") < 0): can_skip = True elif (cmp(version, "3.1.1") >= 0): can_skip = True else: can_skip = False for cls in cls_list: logging.info('do normal dml acion, seq_num: %d', cls.get_seq_num()) action = cls(cur) action.dump_before_do_action() if False == can_skip or False == action.skip_action(): action.check_before_do_action() action.do_action() else: logging.info("skip dml action, seq_num: %d", cls.get_seq_num()) action.dump_after_do_action() action.check_after_do_action()
def get_each_tenant_dml_actions_sqls_str(tenant_id_list): import each_tenant_dml_actions_post ret_str = '' cls_list = reflect_action_cls_list(each_tenant_dml_actions_post, 'EachTenantDMLActionPost') for i in range(0, len(cls_list)): for j in range(0, len(tenant_id_list)): if i > 0 or j > 0: ret_str += '\n' ret_str += cls_list[i].get_each_tenant_action_dml(tenant_id_list[j]) + ';' return ret_str
def get_normal_ddl_actions_sqls_str(query_cur): import normal_ddl_actions_pre ret_str = '' cls_list = reflect_action_cls_list(normal_ddl_actions_pre, 'NormalDDLActionPre') for i in range(0, len(cls_list)): if i > 0: ret_str += '\n' ret_str += cls_list[i].get_action_ddl() + ';' return ret_str
def get_normal_dml_actions_sqls_str(): import normal_dml_actions_post ret_str = '' cls_list = reflect_action_cls_list(normal_dml_actions_post, 'NormalDMLActionPost') for i in range(0, len(cls_list)): if i > 0: ret_str += '\n' ret_str += cls_list[i].get_action_dml() + ';' return ret_str
def do_each_tenant_ddl_actions(cur, tenant_id_list): import each_tenant_ddl_actions_post # 组户级系统表没法通过虚拟表暴露,需要根据版本决定查哪张实体表 query_cur = QueryCursor(cur) version = fetch_observer_version(query_cur) all_table_name = "__all_table" if (cmp(version, "2.2.60") >= 0): all_table_name = "__all_table_v2" cls_list = reflect_action_cls_list(each_tenant_ddl_actions_post, 'EachTenantDDLActionPost') # set parameter if len(cls_list) > 0: actions.set_parameter(cur, 'enable_sys_table_ddl', 'True') ori_enable_ddl = actions.get_ori_enable_ddl(cur) if ori_enable_ddl == 0: actions.set_parameter(cur, 'enable_ddl', 'True') for cls in cls_list: logging.info('do each tenant ddl acion, seq_num: %d', cls.get_seq_num()) action = cls(cur, tenant_id_list) action.set_all_table_name(all_table_name) action.dump_before_do_action() if False == action.skip_pre_check(): action.check_before_do_action() else: logging.info("skip pre check. seq_num: %d", cls.get_seq_num()) # 系统租户组户级系统表创建成功会覆盖普通租户系统表,所以系统租户要最后建表 for tenant_id in action.get_tenant_id_list(): action.dump_before_do_each_tenant_action(tenant_id) if False == action.skip_each_tenant_action(tenant_id): action.check_before_do_each_tenant_action(tenant_id) action.do_each_tenant_action(tenant_id) else: logging.info( "skip each tenant ddl action, seq_num: %d, tenant_id: %d", cls.get_seq_num(), tenant_id) action.dump_after_do_each_tenant_action(tenant_id) action.check_after_do_each_tenant_action(tenant_id) action.dump_after_do_action() action.check_after_do_action() # reset parameter if len(cls_list) > 0: if ori_enable_ddl == 0: actions.set_parameter(cur, 'enable_ddl', 'False') actions.set_parameter(cur, 'enable_sys_table_ddl', 'False')
def do_normal_dml_actions(cur): import normal_dml_actions_post cls_list = reflect_action_cls_list(normal_dml_actions_post, 'NormalDMLActionPost') for cls in cls_list: logging.info('do normal dml acion, seq_num: %d', cls.get_seq_num()) action = cls(cur) action.dump_before_do_action() if False == action.skip_action(): action.check_before_do_action() action.do_action() else: logging.info("skip dml action, seq_num: %d", cls.get_seq_num()) action.dump_after_do_action() action.check_after_do_action()
def do_each_tenant_dml_actions(cur, tenant_id_list): import each_tenant_dml_actions_pre cls_list = reflect_action_cls_list(each_tenant_dml_actions_pre, 'EachTenantDMLActionPre') # check if pre upgrade script can run reentrantly query_cur = QueryCursor(cur) version = fetch_observer_version(query_cur) can_skip = False if (cmp(version, "2.2.77") >= 0 and cmp(version, "3.0.0") < 0): can_skip = True elif (cmp(version, "3.1.1") >= 0): can_skip = True else: can_skip = False for cls in cls_list: logging.info('do each tenant dml acion, seq_num: %d', cls.get_seq_num()) action = cls(cur, tenant_id_list) sys_tenant_id = 1 action.change_tenant(sys_tenant_id) action.dump_before_do_action() if False == can_skip or False == action.skip_pre_check(): action.check_before_do_action() else: logging.info("skip pre check. seq_num: %d", cls.get_seq_num()) for tenant_id in action.get_tenant_id_list(): action.change_tenant(tenant_id) action.dump_before_do_each_tenant_action(tenant_id) if False == can_skip or False == action.skip_each_tenant_action( tenant_id): action.check_before_do_each_tenant_action(tenant_id) action.do_each_tenant_action(tenant_id) else: logging.info( "skip each tenant dml action, seq_num: %d, tenant_id: %d", cls.get_seq_num(), tenant_id) action.dump_after_do_each_tenant_action(tenant_id) action.check_after_do_each_tenant_action(tenant_id) action.change_tenant(sys_tenant_id) action.dump_after_do_action() action.check_after_do_action()
def do_normal_ddl_actions(cur): import normal_ddl_actions_pre upgrade_params = UpgradeParams() cls_list = reflect_action_cls_list(normal_ddl_actions_pre, 'NormalDDLActionPre') # check if pre upgrade script can run reentrantly query_cur = QueryCursor(cur) version = fetch_observer_version(query_cur) can_skip = False if (cmp(version, "2.2.77") >= 0 and cmp(version, "3.0.0") < 0): can_skip = True elif (cmp(version, "3.1.1") >= 0): can_skip = True else: can_skip = False # set parameter if len(cls_list) > 0: actions.set_parameter(cur, 'enable_sys_table_ddl', 'True') ori_enable_ddl = actions.get_ori_enable_ddl(cur) if ori_enable_ddl == 0: actions.set_parameter(cur, 'enable_ddl', 'True') for cls in cls_list: logging.info('do normal ddl acion, seq_num: %d', cls.get_seq_num()) action = cls(cur) action.dump_before_do_action() if False == can_skip or False == action.skip_action(): action.check_before_do_action() action.do_action() else: logging.info("skip ddl action, seq_num: %d", cls.get_seq_num()) action.dump_after_do_action() action.check_after_do_action() # reset parameter if len(cls_list) > 0: if ori_enable_ddl == 0: actions.set_parameter(cur, 'enable_ddl', 'False') actions.set_parameter(cur, 'enable_sys_table_ddl', 'False')