Example #1
0
def update_task_schedule(id,
                         commit=True,
                         session=None,
                         no_changes=False,
                         **kwargs):

    task_schedule = get_task_schedule_by_id(id, session=session)

    if not task_schedule:
        raise Exception("unable to find any schedules for id {}".format(id))

    update_model_fields(
        task_schedule,
        field_names=[
            "task",
            "cron",
            "start_time",
            "args",
            "kwargs",
            "last_run_at",
            "total_run_count",
            "enabled",
            "no_changes",
        ],
        no_changes=no_changes,
        **kwargs,
    )

    if commit:
        session.commit()
    task_schedule.id
    return task_schedule
Example #2
0
def update_data_cell(
    id, commit=True, session=None, **fields,
):
    data_cell = get_data_cell_by_id(id, session=session)
    if not data_cell:
        return

    if "meta" in fields:
        fields["meta"] = sanitize_data_cell_meta(
            data_cell.cell_type.name, fields["meta"]
        )

    updated = update_model_fields(
        data_cell, skip_if_value_none=True, field_names=["meta", "context"], **fields
    )
    if updated:
        data_cell.updated_at = datetime.datetime.now()
        data_cell.doc.updated_at = datetime.datetime.now()

        if commit:
            session.commit()
            if data_cell.doc:
                update_es_data_doc_by_id(data_cell.doc.id)

    return data_cell
def update_column_by_id(
    id=None,
    description=None,
    commit=True,
    session=None,
):

    table_column = get_column_by_id(id, session=session)
    if not table_column:
        return

    column_updated = update_model_fields(model=table_column,
                                         skip_if_value_none=True,
                                         description=description)

    if column_updated:
        table_column.updated_at = datetime.datetime.now()

        if commit:
            session.commit()
            update_es_tables_by_id(table_column.table_id)
        else:
            session.flush()
        session.refresh(table_column)

    return table_column
Example #4
0
def update_data_doc(id, commit=True, session=None, **fields):
    data_doc = get_data_doc_by_id(id, session=session)

    if not data_doc:
        return

    updated = update_model_fields(
        data_doc,
        skip_if_value_none=True,
        field_names=["public", "archived", "owner_uid", "title", "meta"],
        **fields,
    )

    if updated:
        data_doc.updated_at = datetime.datetime.now()

        if commit:
            session.commit()
            update_es_data_doc_by_id(data_doc.id)

            # update es queries if doc is switched between public/private
            if "public" in fields:
                update_es_queries_by_datadoc_id(data_doc.id, session=session)
            # update es query cells if doc is archived
            elif fields.get("archived") is True:
                update_es_query_cells_by_data_doc_id(data_doc.id,
                                                     session=session)
        else:
            session.flush()
        session.refresh(data_doc)
    return data_doc
def create_table(
    name=None,
    type=None,
    owner=None,
    table_created_at=None,
    table_updated_by=None,
    table_updated_at=None,
    data_size_bytes=None,
    location=None,
    column_count=None,
    schema_id=None,
    commit=True,
    session=None,
):
    """ Create a new table row given settings. """
    fields_to_update = {
        "name":
        name,
        "type":
        type,
        "owner":
        owner,
        "table_created_at":
        datetime.datetime.fromtimestamp(float(table_created_at))
        if table_created_at else None,
        "table_updated_by":
        datetime.datetime.fromtimestamp(float(table_updated_at))
        if table_updated_at else None,
        "data_size_bytes":
        data_size_bytes,
        "location":
        location,
        "column_count":
        column_count,
        "schema_id":
        schema_id,
    }

    table = get_table_by_schema_id_and_name(schema_id, name, session=session)
    should_update_es = True
    if not table:
        table = DataTable(**fields_to_update)
        session.add(table)
    else:
        should_update_es = update_model_fields(model=table,
                                               skip_if_value_none=True,
                                               **fields_to_update)
        table.updated_at = datetime.datetime.now()

    if commit:
        session.commit()
        if should_update_es:
            update_es_tables_by_id(table.id)
    else:
        session.flush()

    session.refresh(table)
    return table
Example #6
0
def update_data_doc_editor(
    id, read=None, write=None, commit=True, session=None, **fields,
):
    editor = get_data_doc_editor_by_id(id, session=session)
    if editor:
        updated = update_model_fields(
            editor, skip_if_value_none=True, read=read, write=write
        )

        if updated:
            if commit:
                session.commit()
            else:
                session.flush()
            session.refresh(editor)
        return editor
def update_table_information(data_table_id=None,
                             description=None,
                             commit=True,
                             session=None):
    table_information = get_table_information_by_table_id(data_table_id,
                                                          session=session)

    if not table_information:
        return

    should_update_es = update_model_fields(model=table_information,
                                           skip_if_value_none=True,
                                           description=description)

    if commit:
        session.commit()
        if should_update_es:
            update_es_tables_by_id(data_table_id)

    session.refresh(table_information)
    return table_information
Example #8
0
def update_data_doc(id, commit=True, session=None, **fields):
    data_doc = get_data_doc_by_id(id, session=session)

    if not data_doc:
        return

    updated = update_model_fields(
        data_doc,
        skip_if_value_none=True,
        field_names=["public", "archived", "owner_uid", "title", "meta"],
        **fields,
    )

    if updated:
        data_doc.updated_at = datetime.datetime.now()

        if commit:
            session.commit()
            update_es_data_doc_by_id(data_doc.id)
        else:
            session.flush()
        session.refresh(data_doc)
    return data_doc