# -*- coding: utf-8 -*-
import codecs

import os


def absolute_path(relative_path):
    """
    :param relative_path: the path relative to alembic migration folder
    :return: the absolute path
    """
    from alembic import context
    current_path = context.config.get_main_option('here')

    if current_path:
        return os.path.normpath(os.path.join(current_path, relative_path))
    else:
        raise Exception('%(here) config in alembic cannot be found')


def parse_csv_with_header(csv_file_path):
    """
    :param csv_file_path: the path of csv file
    :return: a dict having csv header as key, and row value as value
    """
    with codecs.open(csv_file_path, 'r', 'utf-8') as csv_file:
        from csv import DictReader
        return [row for row in DictReader(csv_file)]


def bulk_insert_data(tablename, data_in_dict):
    """
    insert data in dict using key as columnn name and value as corresponding data
    :param tablename: The table name of the data will be inserted.
    :param data_in_dict: data to be inserted. key is column name and value is the corresponding data
    :return:
    """
    from sqlalchemy import table
    from sqlalchemy import column
    from alembic import op
    import sqlalchemy as sa

    t = table(tablename, *[column(field, sa.String) for field in data_in_dict.keys()])
    op.bulk_insert(t, data_in_dict)

@@ -828,64 +828,98 @@
 me, 
-data_in_dict):%0A    %22%22%22%0A    insert data in dict using
+rows, multiinsert=True):%0A    %22%22%22%0A    Construct a table schema using tablename and row
  key
+s
  as 
@@ -928,46 +928,51 @@
 lumn
-n name and value as corresponding data
+s. Then insert the rows against the schema.
 %0A   
@@ -1012,20 +1012,20 @@
  of the 
-data
+rows
  will be
@@ -1050,118 +1050,306 @@
 ram 
-data_in_dict: data to be inserted. key is column name and valu
+rows: a list of dictionaries indicating rows%0A    :return:%0A    %22%22%22%0A    if not isinstance(rows, list):%0A        raise TypeError('rows parameter is expected to b
 e 
+l
 is
+t
  t
-he corresponding data%0A    :return:%0A    %22%22%22
+ype')%0A    elif rows and not isinstance(rows%5B0%5D, dict):%0A        raise TypeError(%22rows parameter is expected to be list of dict type%22)%0A
 %0A   
@@ -1533,28 +1533,23 @@
 ield in 
-data_in_dict
+rows%5B0%5D
 .keys()%5D
@@ -1576,18 +1576,23 @@
 (t, 
-data_in_dic
+rows, multiinser
 t)%0A

add params validation for bulk_insert_data and fix schema extraction issue