Beispiel #1
0
def drop_table(ctx, table_name):
    """
    Create a copy of a source table.
    """
    loader = BaseLoader(warnings=ctx.obj['warnings'])
    DROP_TABLE_DDL = f"DROP TABLE {table_name}"
    loader.connect(**ctx.obj['db_credentials'])
    loader._submit_single_q(DROP_TABLE_DDL)
    print(f"Dropped table {table_name}")
Beispiel #2
0
def prod_all(ctx):
    """
    Create all production tables using default names.
    """
    loader = BaseLoader(warnings=ctx.obj['warnings'])
    loader.connect(**ctx.obj['db_credentials'])

    product_table_name = "product"
    productmaster_table_name = "product_master"
    devicemaster_table_name = "device_master"
    servicemaster_table_name = "service_master"
    ndcmaster_table_name = "ndc_master"

    q1 = CREATE_PRODUCT_DDL.format(table_name=product_table_name)
    q2 = CREATE_PRODUCT_MASTER_DDL.format(table_name=productmaster_table_name)
    q3 = CREATE_DEVICEMASTER_DDL.format(table_name=devicemaster_table_name)
    q4 = CREATE_NDCMASTER_DDL.format(table_name=ndcmaster_table_name)
    q5 = CREATE_SERVICEMASTER_DDL.format(table_name=servicemaster_table_name)
    loader._query(q1)
    loader._query(q2)
    loader._query(q3)
    loader._query(q4)
    loader._query(q5)

    product_master_archive_table_name = productmaster_table_name + "_archive"
    ndc_archive_table_name = ndcmaster_table_name + "_archive"
    devicemaster_archive_table_name = devicemaster_table_name + "_archive"
    ndc_stage_table_name = ndcmaster_table_name + "_stage"
    devicemaster_stage_table_name = devicemaster_table_name + "_stage"

    # Create product master archive
    loader._submit_single_q(
        CREATE_TABLE_LIKE_IFNE_DDL.format(target_table_name=product_master_archive_table_name, source_table_name=productmaster_table_name)
    )

    # Create NDC master archive
    loader._submit_single_q(
        CREATE_TABLE_LIKE_IFNE_DDL.format(target_table_name=ndc_archive_table_name, source_table_name=ndcmaster_table_name)
    )

    # Create Device Master archive table
    loader._submit_single_q(
        CREATE_TABLE_LIKE_IFNE_DDL.format(target_table_name=devicemaster_archive_table_name, source_table_name=devicemaster_table_name)
    )

    # Create NDC stage table
    loader._submit_single_q(
        CREATE_TABLE_LIKE_IFNE_DDL.format(target_table_name=ndc_stage_table_name, source_table_name=ndcmaster_table_name)
    )

    # Create Device master stage table
    loader._submit_single_q(
        CREATE_TABLE_LIKE_IFNE_DDL.format(target_table_name=devicemaster_stage_table_name, source_table_name=devicemaster_table_name)
    )
    print("Create prod tables")
Beispiel #3
0
def prod_productmaster(ctx, table_name):
    loader = BaseLoader(warnings=ctx.obj['warnings'])
    loader.connect(**ctx.obj['db_credentials'])

    q = CREATE_PRODUCT_MASTER_DDL.format(table_name=table_name)
    loader._query(q)

    product_master_archive_table_name = table_name + "_archive"

    # Create archive table
    loader._submit_single_q(
        CREATE_TABLE_LIKE_IFNE_DDL.format(target_table_name=product_master_archive_table_name, source_table_name=table_name)
    )
Beispiel #4
0
def prod_ndc(ctx, table_name):
    loader = BaseLoader(warnings=ctx.obj['warnings'])
    loader.connect(**ctx.obj['db_credentials'])

    q = CREATE_NDCMASTER_DDL.format(table_name=table_name)
    loader._query(q)

    archive_table_name = table_name + "_archive"
    stage_table_name = table_name + "_stage"

    # Create NDC archive table
    loader._submit_single_q(
        CREATE_TABLE_LIKE_IFNE_DDL.format(target_table_name=archive_table_name, source_table_name=table_name)
    )

    # Create NDC stage table
    loader._submit_single_q(
        CREATE_TABLE_LIKE_IFNE_DDL.format(target_table_name=stage_table_name, source_table_name=table_name)
    )
Beispiel #5
0
def prod_devicemaster(ctx, table_name):
    loader = BaseLoader(warnings=ctx.obj['warnings'])
    loader.connect(**ctx.obj['db_credentials'])

    archive_table_name = table_name + "_archive"
    stage_table_name = table_name + "_stage"

    q = CREATE_DEVICEMASTER_DDL.format(table_name=table_name)
    loader._query(q)

    # Create Device Master archive table
    loader._submit_single_q(
        CREATE_TABLE_LIKE_IFNE_DDL.format(target_table_name=archive_table_name, source_table_name=table_name)
    )

    # Create Device Master stage table
    loader._submit_single_q(
        CREATE_TABLE_LIKE_IFNE_DDL.format(target_table_name=stage_table_name, source_table_name=table_name)
    )
    print("Created device master tables.")
Beispiel #6
0
def masterid_to_ndc(ctx, ndc_table_name, product_table_name):
    query = MASTER_IDS_TO_NDC_TABLE.format(
        ndc_table_name=ndc_table_name, product_table_name=product_table_name)
    loader = BaseLoader()
    loader.connect(**ctx.obj['db_credentials'])
    loader._submit_single_q(query)