示例#1
0
def apply_db_changes():

    with open(input_file, 'r') as f:
        plan = json.load(f)

    azconn = AzureSQLConnector.load_default()
    azconn.apply_changes(plan)
示例#2
0
def main(params: dict) -> dict:

    result = {}

    try:

        azconn = AzureSQLConnector.load_default()
        schema = params['source']
        schema_list = ([schema] if schema else CONNECTOR_MAP.keys())
        action = params['action']
        models = params['model']

        if action == 'build':
            result = azconn.create_db(schema_list)

        elif action == 'destroy':
            result = azconn.delete_db(schema_list)

        elif action == 'drop':
            result = azconn.delete_tables(schema, models)

        elif action == 'examine':
            for schema in schema_list:
                result[schema] = azconn.plan_changes(schema)

        elif action == 'apply':
            for schema in schema_list:
                plan = azconn.plan_changes(schema)
                result[schema] = azconn.apply_changes(plan)

        else:
            returnMsg = "F_db_activity :: Invalid value provided for 'action' parameter: {}".format(
                action)
            logger.warning(returnMsg)
            result = returnMsg

    except Exception as e:
        returnMsg = 'F_db_activity error :: {}'.format(traceback.print_exc())
        logger.error(returnMsg)
        result = returnMsg

    return result
示例#3
0
def main(params: dict) -> dict:

    returnStr = ""

    try:
        # params = orc_input['params']
        source, last_days, models = format_params(params)
        trigger = params['trigger']
        results = {}

        azconn = AzureSQLConnector.load_default()

        initStr = "Fetch operation started. Trigger: {} Source: {} - Models: {} - LAST_DAYS={}".format(
            trigger, source, models, last_days)
        logger.info(initStr)

        client = get_client(source)

        for model_name in models:
            logger.info('Extracting data from Model: {}'.format(model_name))
            jsonpath, dataset = client.get_data(model_name,
                                                last_days=last_days)
            # push to Azure SQL
            result = azconn.insert_dataset(dataset)
            results[model_name] = result

        returnStr = "Fetch operation ended. Trigger: {} - Source: {} - LAST_DAYS={}\nRESULTS: {}".format(
            trigger, source, last_days, results)
        logger.info(returnStr)
        output_results = {'params': params, 'results': results}

    except Exception as e:
        returnStr = 'F_fetch_data.fetch_data :: {}'.format(
            traceback.print_exc())
        logger.error(e)

        output_results = {'params': params, 'results': returnStr}

    return output_results
示例#4
0
def examine_db():

    azconn = AzureSQLConnector.load_default()
    json_plan = azconn.plan_changes(source)
    return json_plan
示例#5
0
def insert_to_azure():

    azconn = AzureSQLConnector.load_default()
    azconn.insert_from_jsonfile(input_file)
示例#6
0
def destroy_db():

    azconn = AzureSQLConnector.load_default()
    azconn.delete_db(schema_name=source)
示例#7
0
def build_db():

    azconn = AzureSQLConnector.load_default()
    source_list = ([source] if source else None)
    azconn.create_db(source_list)