"""empty message

Revision ID: 738b49f416f0
Revises: 
Create Date: 2021-03-08 20:37:17.267232

"""

import json
from os.path import expanduser

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = '738b49f416f0'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('movie',
                    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
                    sa.Column('name', sa.String(length=255), nullable=True),
                    sa.Column('99popularity', sa.Float(), nullable=True),
                    sa.Column('director', sa.String(length=255), nullable=True),
                    sa.Column('genre', sa.String(length=255), nullable=True),
                    sa.Column('imdb_score', sa.Float(), nullable=True),
                    sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
                    sa.Column('modified_at', sa.DateTime(),
                              server_default=sa.text('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), nullable=False),
                    sa.Column('is_deleted', sa.SmallInteger(), server_default=sa.text('0'), nullable=True),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_table('permission',
                    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
                    sa.Column('name', sa.String(length=255), nullable=True),
                    sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
                    sa.Column('modified_at', sa.DateTime(),
                              server_default=sa.text('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), nullable=False),
                    sa.Column('is_deleted', sa.SmallInteger(), server_default=sa.text('0'), nullable=True),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_table('role_permission',
                    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
                    sa.Column('user_role_id', sa.Integer(), nullable=True),
                    sa.Column('permission_id', sa.Integer(), nullable=True),
                    sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
                    sa.Column('is_deleted', sa.SmallInteger(), server_default=sa.text('0'), nullable=True),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_table('user',
                    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
                    sa.Column('user_name', sa.String(length=255), nullable=True),
                    sa.Column('email', sa.String(length=255), nullable=True),
                    sa.Column('password', sa.String(length=255), nullable=True),
                    sa.Column('user_role', sa.Integer(), nullable=True),
                    sa.Column('pwd_attempt', sa.Integer(), server_default=sa.text('0'), nullable=True),
                    sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
                    sa.Column('modified_at', sa.DateTime(),
                              server_default=sa.text('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), nullable=False),
                    sa.Column('is_deleted', sa.SmallInteger(), server_default=sa.text('0'), nullable=True),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_index(op.f('ix_user_email'), 'user', ['email'], unique=False)
    op.create_index(op.f('ix_user_user_name'), 'user', ['user_name'], unique=False)
    op.create_index(op.f('ix_user_user_role'), 'user', ['user_role'], unique=False)
    op.create_index('user_role', 'user', ['id', 'user_role'], unique=False)
    op.create_table('user_role',
                    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
                    sa.Column('role_name', sa.String(length=255), nullable=True),
                    sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
                    sa.Column('modified_at', sa.DateTime(),
                              server_default=sa.text('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), nullable=False),
                    sa.Column('is_deleted', sa.SmallInteger(), server_default=sa.text('0'), nullable=True),
                    sa.PrimaryKeyConstraint('id')
                    )

    # ### end Alembic commands ###

    def seed_data():
        def _read_json_file():
            home_path = expanduser('~')
            json_path = "".join([home_path, "/workspace/imdb-movie/imdb.json"])
            with open(json_path, ) as file:
                raw_data = json.load(file)

                print("raw_data length :: {}".format(len(raw_data)))
                return raw_data

        def _prepare_bulk_insert():
            raw_data = _read_json_file()
            final_data = list()
            for raw in raw_data:
                final_data.append({
                    "name": raw.get("name"),
                    "99popularity": raw.get("99popularity"),
                    "director": raw.get("director"),
                    "genre": str(raw.get("genre")),
                    "imdb_score": raw.get("imdb_score")
                })
            print(final_data[0])
            return final_data

        def _bulk_insert():
            movie = sa.sql.table(
                'movie',
                sa.Column('name', sa.String(length=255), nullable=True),
                sa.Column('99popularity', sa.Float(), nullable=True),
                sa.Column('director', sa.String(length=255), nullable=True),
                sa.Column('genre', sa.String(length=255), nullable=True),
                sa.Column('imdb_score', sa.Float(), nullable=True)
            )
            op.bulk_insert(
                movie, _prepare_bulk_insert()
            )

        return _bulk_insert()

    seed_data()


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('user_role')
    op.drop_index('user_role', table_name='user')
    op.drop_index(op.f('ix_user_user_role'), table_name='user')
    op.drop_index(op.f('ix_user_user_name'), table_name='user')
    op.drop_index(op.f('ix_user_email'), table_name='user')
    op.drop_table('user')
    op.drop_table('role_permission')
    op.drop_table('permission')
    op.drop_table('movie')
    # ### end Alembic commands ###

15eba84a3cc157814f63fdcf332cfcebd878d86d
<mask token>


def downgrade():
    op.drop_table('user_role')
    op.drop_index('user_role', table_name='user')
    op.drop_index(op.f('ix_user_user_role'), table_name='user')
    op.drop_index(op.f('ix_user_user_name'), table_name='user')
    op.drop_index(op.f('ix_user_email'), table_name='user')
    op.drop_table('user')
    op.drop_table('role_permission')
    op.drop_table('permission')
    op.drop_table('movie')

<mask token>


def upgrade():
    op.create_table('movie', sa.Column('id', sa.Integer(), autoincrement=
        True, nullable=False), sa.Column('name', sa.String(length=255),
        nullable=True), sa.Column('99popularity', sa.Float(), nullable=True
        ), sa.Column('director', sa.String(length=255), nullable=True), sa.
        Column('genre', sa.String(length=255), nullable=True), sa.Column(
        'imdb_score', sa.Float(), nullable=True), sa.Column('created_at',
        sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'),
        nullable=False), sa.Column('modified_at', sa.DateTime(),
        server_default=sa.text(
        'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), nullable=False),
        sa.Column('is_deleted', sa.SmallInteger(), server_default=sa.text(
        '0'), nullable=True), sa.PrimaryKeyConstraint('id'))
    op.create_table('permission', sa.Column('id', sa.Integer(),
        autoincrement=True, nullable=False), sa.Column('name', sa.String(
        length=255), nullable=True), sa.Column('created_at', sa.DateTime(),
        server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.
        Column('modified_at', sa.DateTime(), server_default=sa.text(
        'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), nullable=False),
        sa.Column('is_deleted', sa.SmallInteger(), server_default=sa.text(
        '0'), nullable=True), sa.PrimaryKeyConstraint('id'))
    op.create_table('role_permission', sa.Column('id', sa.Integer(),
        autoincrement=True, nullable=False), sa.Column('user_role_id', sa.
        Integer(), nullable=True), sa.Column('permission_id', sa.Integer(),
        nullable=True), sa.Column('created_at', sa.DateTime(),
        server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.
        Column('is_deleted', sa.SmallInteger(), server_default=sa.text('0'),
        nullable=True), sa.PrimaryKeyConstraint('id'))
    op.create_table('user', sa.Column('id', sa.Integer(), autoincrement=
        True, nullable=False), sa.Column('user_name', sa.String(length=255),
        nullable=True), sa.Column('email', sa.String(length=255), nullable=
        True), sa.Column('password', sa.String(length=255), nullable=True),
        sa.Column('user_role', sa.Integer(), nullable=True), sa.Column(
        'pwd_attempt', sa.Integer(), server_default=sa.text('0'), nullable=
        True), sa.Column('created_at', sa.DateTime(), server_default=sa.
        text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('modified_at',
        sa.DateTime(), server_default=sa.text(
        'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), nullable=False),
        sa.Column('is_deleted', sa.SmallInteger(), server_default=sa.text(
        '0'), nullable=True), sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_user_email'), 'user', ['email'], unique=False)
    op.create_index(op.f('ix_user_user_name'), 'user', ['user_name'],
        unique=False)
    op.create_index(op.f('ix_user_user_role'), 'user', ['user_role'],
        unique=False)
    op.create_index('user_role', 'user', ['id', 'user_role'], unique=False)
    op.create_table('user_role', sa.Column('id', sa.Integer(),
        autoincrement=True, nullable=False), sa.Column('role_name', sa.
        String(length=255), nullable=True), sa.Column('created_at', sa.
        DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=
        False), sa.Column('modified_at', sa.DateTime(), server_default=sa.
        text('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), nullable=
        False), sa.Column('is_deleted', sa.SmallInteger(), server_default=
        sa.text('0'), nullable=True), sa.PrimaryKeyConstraint('id'))

    def seed_data():

        def _read_json_file():
            home_path = expanduser('~')
            json_path = ''.join([home_path, '/workspace/imdb-movie/imdb.json'])
            with open(json_path) as file:
                raw_data = json.load(file)
                print('raw_data length :: {}'.format(len(raw_data)))
                return raw_data

        def _prepare_bulk_insert():
            raw_data = _read_json_file()
            final_data = list()
            for raw in raw_data:
                final_data.append({'name': raw.get('name'), '99popularity':
                    raw.get('99popularity'), 'director': raw.get('director'
                    ), 'genre': str(raw.get('genre')), 'imdb_score': raw.
                    get('imdb_score')})
            print(final_data[0])
            return final_data

        def _bulk_insert():
            movie = sa.sql.table('movie', sa.Column('name', sa.String(
                length=255), nullable=True), sa.Column('99popularity', sa.
                Float(), nullable=True), sa.Column('director', sa.String(
                length=255), nullable=True), sa.Column('genre', sa.String(
                length=255), nullable=True), sa.Column('imdb_score', sa.
                Float(), nullable=True))
            op.bulk_insert(movie, _prepare_bulk_insert())
        return _bulk_insert()
    seed_data()


def downgrade():
    op.drop_table('user_role')
    op.drop_index('user_role', table_name='user')
    op.drop_index(op.f('ix_user_user_role'), table_name='user')
    op.drop_index(op.f('ix_user_user_name'), table_name='user')
    op.drop_index(op.f('ix_user_email'), table_name='user')
    op.drop_table('user')
    op.drop_table('role_permission')
    op.drop_table('permission')
    op.drop_table('movie')

<mask token>
revision = '738b49f416f0'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    op.create_table('movie', sa.Column('id', sa.Integer(), autoincrement=
        True, nullable=False), sa.Column('name', sa.String(length=255),
        nullable=True), sa.Column('99popularity', sa.Float(), nullable=True
        ), sa.Column('director', sa.String(length=255), nullable=True), sa.
        Column('genre', sa.String(length=255), nullable=True), sa.Column(
        'imdb_score', sa.Float(), nullable=True), sa.Column('created_at',
        sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'),
        nullable=False), sa.Column('modified_at', sa.DateTime(),
        server_default=sa.text(
        'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), nullable=False),
        sa.Column('is_deleted', sa.SmallInteger(), server_default=sa.text(
        '0'), nullable=True), sa.PrimaryKeyConstraint('id'))
    op.create_table('permission', sa.Column('id', sa.Integer(),
        autoincrement=True, nullable=False), sa.Column('name', sa.String(
        length=255), nullable=True), sa.Column('created_at', sa.DateTime(),
        server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.
        Column('modified_at', sa.DateTime(), server_default=sa.text(
        'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), nullable=False),
        sa.Column('is_deleted', sa.SmallInteger(), server_default=sa.text(
        '0'), nullable=True), sa.PrimaryKeyConstraint('id'))
    op.create_table('role_permission', sa.Column('id', sa.Integer(),
        autoincrement=True, nullable=False), sa.Column('user_role_id', sa.
        Integer(), nullable=True), sa.Column('permission_id', sa.Integer(),
        nullable=True), sa.Column('created_at', sa.DateTime(),
        server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.
        Column('is_deleted', sa.SmallInteger(), server_default=sa.text('0'),
        nullable=True), sa.PrimaryKeyConstraint('id'))
    op.create_table('user', sa.Column('id', sa.Integer(), autoincrement=
        True, nullable=False), sa.Column('user_name', sa.String(length=255),
        nullable=True), sa.Column('email', sa.String(length=255), nullable=
        True), sa.Column('password', sa.String(length=255), nullable=True),
        sa.Column('user_role', sa.Integer(), nullable=True), sa.Column(
        'pwd_attempt', sa.Integer(), server_default=sa.text('0'), nullable=
        True), sa.Column('created_at', sa.DateTime(), server_default=sa.
        text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('modified_at',
        sa.DateTime(), server_default=sa.text(
        'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), nullable=False),
        sa.Column('is_deleted', sa.SmallInteger(), server_default=sa.text(
        '0'), nullable=True), sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_user_email'), 'user', ['email'], unique=False)
    op.create_index(op.f('ix_user_user_name'), 'user', ['user_name'],
        unique=False)
    op.create_index(op.f('ix_user_user_role'), 'user', ['user_role'],
        unique=False)
    op.create_index('user_role', 'user', ['id', 'user_role'], unique=False)
    op.create_table('user_role', sa.Column('id', sa.Integer(),
        autoincrement=True, nullable=False), sa.Column('role_name', sa.
        String(length=255), nullable=True), sa.Column('created_at', sa.
        DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=
        False), sa.Column('modified_at', sa.DateTime(), server_default=sa.
        text('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), nullable=
        False), sa.Column('is_deleted', sa.SmallInteger(), server_default=
        sa.text('0'), nullable=True), sa.PrimaryKeyConstraint('id'))

    def seed_data():

        def _read_json_file():
            home_path = expanduser('~')
            json_path = ''.join([home_path, '/workspace/imdb-movie/imdb.json'])
            with open(json_path) as file:
                raw_data = json.load(file)
                print('raw_data length :: {}'.format(len(raw_data)))
                return raw_data

        def _prepare_bulk_insert():
            raw_data = _read_json_file()
            final_data = list()
            for raw in raw_data:
                final_data.append({'name': raw.get('name'), '99popularity':
                    raw.get('99popularity'), 'director': raw.get('director'
                    ), 'genre': str(raw.get('genre')), 'imdb_score': raw.
                    get('imdb_score')})
            print(final_data[0])
            return final_data

        def _bulk_insert():
            movie = sa.sql.table('movie', sa.Column('name', sa.String(
                length=255), nullable=True), sa.Column('99popularity', sa.
                Float(), nullable=True), sa.Column('director', sa.String(
                length=255), nullable=True), sa.Column('genre', sa.String(
                length=255), nullable=True), sa.Column('imdb_score', sa.
                Float(), nullable=True))
            op.bulk_insert(movie, _prepare_bulk_insert())
        return _bulk_insert()
    seed_data()


def downgrade():
    op.drop_table('user_role')
    op.drop_index('user_role', table_name='user')
    op.drop_index(op.f('ix_user_user_role'), table_name='user')
    op.drop_index(op.f('ix_user_user_name'), table_name='user')
    op.drop_index(op.f('ix_user_email'), table_name='user')
    op.drop_table('user')
    op.drop_table('role_permission')
    op.drop_table('permission')
    op.drop_table('movie')

<mask token>
import json
from os.path import expanduser
import sqlalchemy as sa
from alembic import op
revision = '738b49f416f0'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    op.create_table('movie', sa.Column('id', sa.Integer(), autoincrement=
        True, nullable=False), sa.Column('name', sa.String(length=255),
        nullable=True), sa.Column('99popularity', sa.Float(), nullable=True
        ), sa.Column('director', sa.String(length=255), nullable=True), sa.
        Column('genre', sa.String(length=255), nullable=True), sa.Column(
        'imdb_score', sa.Float(), nullable=True), sa.Column('created_at',
        sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'),
        nullable=False), sa.Column('modified_at', sa.DateTime(),
        server_default=sa.text(
        'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), nullable=False),
        sa.Column('is_deleted', sa.SmallInteger(), server_default=sa.text(
        '0'), nullable=True), sa.PrimaryKeyConstraint('id'))
    op.create_table('permission', sa.Column('id', sa.Integer(),
        autoincrement=True, nullable=False), sa.Column('name', sa.String(
        length=255), nullable=True), sa.Column('created_at', sa.DateTime(),
        server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.
        Column('modified_at', sa.DateTime(), server_default=sa.text(
        'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), nullable=False),
        sa.Column('is_deleted', sa.SmallInteger(), server_default=sa.text(
        '0'), nullable=True), sa.PrimaryKeyConstraint('id'))
    op.create_table('role_permission', sa.Column('id', sa.Integer(),
        autoincrement=True, nullable=False), sa.Column('user_role_id', sa.
        Integer(), nullable=True), sa.Column('permission_id', sa.Integer(),
        nullable=True), sa.Column('created_at', sa.DateTime(),
        server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False), sa.
        Column('is_deleted', sa.SmallInteger(), server_default=sa.text('0'),
        nullable=True), sa.PrimaryKeyConstraint('id'))
    op.create_table('user', sa.Column('id', sa.Integer(), autoincrement=
        True, nullable=False), sa.Column('user_name', sa.String(length=255),
        nullable=True), sa.Column('email', sa.String(length=255), nullable=
        True), sa.Column('password', sa.String(length=255), nullable=True),
        sa.Column('user_role', sa.Integer(), nullable=True), sa.Column(
        'pwd_attempt', sa.Integer(), server_default=sa.text('0'), nullable=
        True), sa.Column('created_at', sa.DateTime(), server_default=sa.
        text('CURRENT_TIMESTAMP'), nullable=False), sa.Column('modified_at',
        sa.DateTime(), server_default=sa.text(
        'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), nullable=False),
        sa.Column('is_deleted', sa.SmallInteger(), server_default=sa.text(
        '0'), nullable=True), sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_user_email'), 'user', ['email'], unique=False)
    op.create_index(op.f('ix_user_user_name'), 'user', ['user_name'],
        unique=False)
    op.create_index(op.f('ix_user_user_role'), 'user', ['user_role'],
        unique=False)
    op.create_index('user_role', 'user', ['id', 'user_role'], unique=False)
    op.create_table('user_role', sa.Column('id', sa.Integer(),
        autoincrement=True, nullable=False), sa.Column('role_name', sa.
        String(length=255), nullable=True), sa.Column('created_at', sa.
        DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=
        False), sa.Column('modified_at', sa.DateTime(), server_default=sa.
        text('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), nullable=
        False), sa.Column('is_deleted', sa.SmallInteger(), server_default=
        sa.text('0'), nullable=True), sa.PrimaryKeyConstraint('id'))

    def seed_data():

        def _read_json_file():
            home_path = expanduser('~')
            json_path = ''.join([home_path, '/workspace/imdb-movie/imdb.json'])
            with open(json_path) as file:
                raw_data = json.load(file)
                print('raw_data length :: {}'.format(len(raw_data)))
                return raw_data

        def _prepare_bulk_insert():
            raw_data = _read_json_file()
            final_data = list()
            for raw in raw_data:
                final_data.append({'name': raw.get('name'), '99popularity':
                    raw.get('99popularity'), 'director': raw.get('director'
                    ), 'genre': str(raw.get('genre')), 'imdb_score': raw.
                    get('imdb_score')})
            print(final_data[0])
            return final_data

        def _bulk_insert():
            movie = sa.sql.table('movie', sa.Column('name', sa.String(
                length=255), nullable=True), sa.Column('99popularity', sa.
                Float(), nullable=True), sa.Column('director', sa.String(
                length=255), nullable=True), sa.Column('genre', sa.String(
                length=255), nullable=True), sa.Column('imdb_score', sa.
                Float(), nullable=True))
            op.bulk_insert(movie, _prepare_bulk_insert())
        return _bulk_insert()
    seed_data()


def downgrade():
    op.drop_table('user_role')
    op.drop_index('user_role', table_name='user')
    op.drop_index(op.f('ix_user_user_role'), table_name='user')
    op.drop_index(op.f('ix_user_user_name'), table_name='user')
    op.drop_index(op.f('ix_user_email'), table_name='user')
    op.drop_table('user')
    op.drop_table('role_permission')
    op.drop_table('permission')
    op.drop_table('movie')

"""empty message

Revision ID: 738b49f416f0
Revises: 
Create Date: 2021-03-08 20:37:17.267232

"""

import json
from os.path import expanduser

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = '738b49f416f0'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('movie',
                    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
                    sa.Column('name', sa.String(length=255), nullable=True),
                    sa.Column('99popularity', sa.Float(), nullable=True),
                    sa.Column('director', sa.String(length=255), nullable=True),
                    sa.Column('genre', sa.String(length=255), nullable=True),
                    sa.Column('imdb_score', sa.Float(), nullable=True),
                    sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
                    sa.Column('modified_at', sa.DateTime(),
                              server_default=sa.text('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), nullable=False),
                    sa.Column('is_deleted', sa.SmallInteger(), server_default=sa.text('0'), nullable=True),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_table('permission',
                    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
                    sa.Column('name', sa.String(length=255), nullable=True),
                    sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
                    sa.Column('modified_at', sa.DateTime(),
                              server_default=sa.text('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), nullable=False),
                    sa.Column('is_deleted', sa.SmallInteger(), server_default=sa.text('0'), nullable=True),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_table('role_permission',
                    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
                    sa.Column('user_role_id', sa.Integer(), nullable=True),
                    sa.Column('permission_id', sa.Integer(), nullable=True),
                    sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
                    sa.Column('is_deleted', sa.SmallInteger(), server_default=sa.text('0'), nullable=True),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_table('user',
                    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
                    sa.Column('user_name', sa.String(length=255), nullable=True),
                    sa.Column('email', sa.String(length=255), nullable=True),
                    sa.Column('password', sa.String(length=255), nullable=True),
                    sa.Column('user_role', sa.Integer(), nullable=True),
                    sa.Column('pwd_attempt', sa.Integer(), server_default=sa.text('0'), nullable=True),
                    sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
                    sa.Column('modified_at', sa.DateTime(),
                              server_default=sa.text('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), nullable=False),
                    sa.Column('is_deleted', sa.SmallInteger(), server_default=sa.text('0'), nullable=True),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.create_index(op.f('ix_user_email'), 'user', ['email'], unique=False)
    op.create_index(op.f('ix_user_user_name'), 'user', ['user_name'], unique=False)
    op.create_index(op.f('ix_user_user_role'), 'user', ['user_role'], unique=False)
    op.create_index('user_role', 'user', ['id', 'user_role'], unique=False)
    op.create_table('user_role',
                    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
                    sa.Column('role_name', sa.String(length=255), nullable=True),
                    sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False),
                    sa.Column('modified_at', sa.DateTime(),
                              server_default=sa.text('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), nullable=False),
                    sa.Column('is_deleted', sa.SmallInteger(), server_default=sa.text('0'), nullable=True),
                    sa.PrimaryKeyConstraint('id')
                    )

    # ### end Alembic commands ###

    def seed_data():
        def _read_json_file():
            home_path = expanduser('~')
            json_path = "".join([home_path, "/workspace/imdb-movie/imdb.json"])
            with open(json_path, ) as file:
                raw_data = json.load(file)

                print("raw_data length :: {}".format(len(raw_data)))
                return raw_data

        def _prepare_bulk_insert():
            raw_data = _read_json_file()
            final_data = list()
            for raw in raw_data:
                final_data.append({
                    "name": raw.get("name"),
                    "99popularity": raw.get("99popularity"),
                    "director": raw.get("director"),
                    "genre": str(raw.get("genre")),
                    "imdb_score": raw.get("imdb_score")
                })
            print(final_data[0])
            return final_data

        def _bulk_insert():
            movie = sa.sql.table(
                'movie',
                sa.Column('name', sa.String(length=255), nullable=True),
                sa.Column('99popularity', sa.Float(), nullable=True),
                sa.Column('director', sa.String(length=255), nullable=True),
                sa.Column('genre', sa.String(length=255), nullable=True),
                sa.Column('imdb_score', sa.Float(), nullable=True)
            )
            op.bulk_insert(
                movie, _prepare_bulk_insert()
            )

        return _bulk_insert()

    seed_data()


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('user_role')
    op.drop_index('user_role', table_name='user')
    op.drop_index(op.f('ix_user_user_role'), table_name='user')
    op.drop_index(op.f('ix_user_user_name'), table_name='user')
    op.drop_index(op.f('ix_user_email'), table_name='user')
    op.drop_table('user')
    op.drop_table('role_permission')
    op.drop_table('permission')
    op.drop_table('movie')
    # ### end Alembic commands ###
