def get_indicator_model(name, indicator_doc):
    columns = [
        sqlalchemy.Column(
            'doc_id',
            sqlalchemy.Unicode(255),
            nullable=False,
            primary_key=True),
        sqlalchemy.Column(
            'date',
            sqlalchemy.Date,
            nullable=False,
            primary_key=True),
    ]

    try:
        flat_fields = indicator_doc._flat_fields
        for flat_name in flat_fields.keys():
            columns.append(sqlalchemy.Column(
                flat_name,
                sqlalchemy.String,
                nullable=True
            ))
    except __HOLE__:
        pass

    group_types = indicator_doc.get_group_types()
    for group_name in indicator_doc.get_group_names():
        columns.append(sqlalchemy.Column(
            group_name,
            get_column_type(group_types[group_name]),
            nullable=False,
            primary_key=True
        ))

    calculators = indicator_doc._calculators
    for calc_name in sorted(calculators.keys()):
        for emitter_name in calculators[calc_name]._fluff_emitters:
            col_name = '{0}_{1}'.format(calc_name, emitter_name)
            columns.append(sqlalchemy.Column(
                col_name,
                sqlalchemy.Integer,
                nullable=True,
            ))

    return sqlalchemy.Table('fluff_{0}'.format(name), metadata, *columns)
dataset/ETHPy150Open dimagi/commcare-hq/corehq/ex-submodules/fluff/util.py/get_indicator_model