示例#1
0
def schema_selection(db_alias: str):
    """Asynchronously computes the list of schemas with foreign key constraints"""
    schemas_with_fk_constraints = schemas_with_foreign_key_constraints(db_alias)

    if not schemas_with_fk_constraints or len(schemas_with_fk_constraints) == 0:
        return str(_.i['No schemas with foreign key constraints found'])

    return ''.join(xml.render([
        [_.div(class_='form-check form-check-inline')[
             _.label(class_='form-check-label')[
                 _.input(class_="form-check-input schema-checkbox", type="checkbox", value=schema_name)[
                     ''], ' ', schema_name]]
         for schema_name in sorted(schemas_with_fk_constraints)],
        '   ',
        _.div(class_='form-check form-check-inline')[
            _.label(class_='form-check-label')[
                _.input(class_="form-check-input", id='hide-columns-checkbox', type="checkbox")[
                    ''], ' ', 'hide columns']],
        '   ',
        _.div(class_='form-check form-check-inline')[
            _.label(class_='form-check-label')[
                'graphviz engine ',
                _.select(id='engine', style='border:none;background-color:white;')[
                    [_.option(value=engine)[engine] for engine in ['neato', 'dot', 'twopi', 'fdp']]
                ]]],
        _.script['''
var schemaPage = SchemaPage("''' + flask.url_for('mara_db.index_page', db_alias=db_alias) + '''", "''' + db_alias + '''");
''']]))
示例#2
0
文件: views.py 项目: nostream/mara-db
def schema_selection(db_alias: str):
    """Asynchronously computes the list of schemas with foreign key constraints"""
    schemas_with_fk_constraints = []
    with mara_db.postgresql.postgres_cursor_context(db_alias) as cursor:
        cursor.execute('''
SELECT
  array_cat(array_agg(DISTINCT constrained_table_schema.nspname), array_agg(DISTINCT referenced_table_schema.nspname))
FROM pg_constraint
  JOIN pg_class constrained_table ON constrained_table.oid = pg_constraint.conrelid
  JOIN pg_namespace constrained_table_schema ON constrained_table.relnamespace = constrained_table_schema.oid
  JOIN pg_class referenced_table ON referenced_table.oid = pg_constraint.confrelid
  JOIN pg_namespace referenced_table_schema ON referenced_table.relnamespace = referenced_table_schema.oid'''
                       )
        result = cursor.fetchone()
        if result != (None, ):
            schemas_with_fk_constraints = sorted(list(set(result[0])))

    if len(schemas_with_fk_constraints) == 0:
        return str(_.i['No schemas with foreign key constraints found'])

    return ''.join(
        xml.render(
            [[
                _.div(class_='form-check form-check-inline')[_.label(
                    class_='form-check-label')[
                        _.input(class_="form-check-input schema-checkbox",
                                type="checkbox",
                                value=schema_name)[''], ' ', schema_name]]
                for schema_name in sorted(schemas_with_fk_constraints)
            ], '   ',
             _.div(class_='form-check form-check-inline')[_.label(
                 class_='form-check-label')[_.input(class_="form-check-input",
                                                    id='hide-columns-checkbox',
                                                    type="checkbox")[''], ' ',
                                            'hide columns']], '   ',
             _.div(class_='form-check form-check-inline')[_.label(
                 class_='form-check-label'
             )['graphviz engine ',
               _.select(id='engine',
                        style='border:none;background-color:white;')[[
                            _.option(value=engine)[engine]
                            for engine in ['neato', 'dot', 'twopi', 'fdp']
                        ]]]], _.script['''
var schemaPage = SchemaPage("''' + flask.url_for('mara_db.index_page',
                                                 db_alias=db_alias) +
                                       '''", "''' + db_alias + '''");
''']]))
示例#3
0
def last_runs_selector(path: str):
    """
    Returns a html select element for selecting among the last runs of a node

    Args:
        path: The path of the node

    Returns:
        A `<select..><option ../><option ../></select>` element
    """
    from ..logging import node_cost

    node, __ = pipelines.find_node(path.split('/'))

    with mara_db.postgresql.postgres_cursor_context(
            'mara') as cursor:  # type: psycopg2.extensions.cursor
        cursor.execute(
            f'''
SELECT
  run_id,
  to_char(start_time, 'Mon DD HH24:MI') AS start_time,
  extract(EPOCH FROM (end_time - start_time)) AS duration,
  succeeded,
  label_filter
FROM data_integration_node_run
WHERE node_path = {"%s"}
ORDER BY run_id DESC;''', (node.path(), ))

        return str(
            _.select(id='last-runs-selector',
                     class_='custom-select',
                     style="border:none",
                     onchange=f"nodePage.switchRun(this.value, '{path}')")
            [[
                _.option(value=str(run_id))
                [start_time, ' (',
                 f'{node_cost.format_duration(duration)}, {"succeeded" if succeeded else "failed"}'
                 if succeeded is not None else 'unfinished',
                 (f', label-filter: {label_filter}' if label_filter else ''),
                 ')'] for run_id, start_time, duration, succeeded, label_filter
                in cursor.fetchall()
            ]])