"""Implementing balance and fiscal_note_items tables

Revision ID: 6099ed2a58e0
Revises: <KEY>
Create Date: 2021-10-11 14:52:44.126077

"""
import sqlalchemy as sa
import sqlmodel
from alembic import op
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = "6099ed2a58e0"
down_revision = "<KEY>"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "balance",
        sa.Column("id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
        sa.Column("value", sa.Float(), nullable=False),
        sa.Column("type", sa.Enum("DEBT", "CREDIT", name="balancetype"), nullable=False),
        sa.Column(
            "operation",
            sa.Enum(
                "PAYMENT_OF_EMPLOYEES",
                "PAYMENT_OF_SUPPLIERS",
                "ANOTHER_PAYMENTS",
                "SALE_IN_PIX",
                "SALE_IN_DEBT",
                "SALE_IN_CREDIT",
                "SALE_IN_MONEY",
                name="operationtype",
            ),
            nullable=False,
        ),
        sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=True),
        sa.Column("owner_id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
        sa.ForeignKeyConstraint(
            ["owner_id"],
            ["users.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_balance_created_at"), "balance", ["created_at"], unique=False)
    op.create_index(op.f("ix_balance_operation"), "balance", ["operation"], unique=False)
    op.create_index(op.f("ix_balance_owner_id"), "balance", ["owner_id"], unique=False)
    op.create_index(op.f("ix_balance_type"), "balance", ["type"], unique=False)
    op.create_table(
        "fiscal_note_items",
        sa.Column("id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
        sa.Column("buy_value", sa.Float(), nullable=False),
        sa.Column("sugested_sell_value", sa.Float(), nullable=False),
        sa.Column("owner_id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
        sa.Column("fiscal_note_id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
        sa.Column("item_id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
        sa.Column("file_id", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
        sa.ForeignKeyConstraint(
            ["file_id"],
            ["files.bucket_key"],
        ),
        sa.ForeignKeyConstraint(
            ["fiscal_note_id"],
            ["fiscal_notes.id"],
        ),
        sa.ForeignKeyConstraint(
            ["item_id"],
            ["items.id"],
        ),
        sa.ForeignKeyConstraint(
            ["owner_id"],
            ["users.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_fiscal_note_items_fiscal_note_id"), "fiscal_note_items", ["fiscal_note_id"], unique=False)
    op.create_index(op.f("ix_fiscal_note_items_item_id"), "fiscal_note_items", ["item_id"], unique=False)
    op.create_index(op.f("ix_fiscal_note_items_owner_id"), "fiscal_note_items", ["owner_id"], unique=False)
    op.create_index(
        op.f("ix_fiscal_note_items_sugested_sell_value"), "fiscal_note_items", ["sugested_sell_value"], unique=False
    )
    op.create_index(op.f("ix_clients_owner_id"), "clients", ["owner_id"], unique=False)
    op.create_index(op.f("ix_fiscal_notes_owner_id"), "fiscal_notes", ["owner_id"], unique=False)
    op.alter_column("items", "cost", existing_type=postgresql.DOUBLE_PRECISION(precision=53), nullable=True)
    op.create_index(op.f("ix_items_amount"), "items", ["amount"], unique=False)
    op.alter_column("order_details", "order_id", existing_type=postgresql.UUID(), nullable=True)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_users_password_hash"), table_name="users")
    op.drop_index(op.f("ix_users_name"), table_name="users")
    op.drop_index(op.f("ix_orders_description"), table_name="orders")
    op.drop_index(op.f("ix_order_details_sell_value"), table_name="order_details")
    op.drop_index(op.f("ix_order_details_item_name"), table_name="order_details")
    op.drop_index(op.f("ix_order_details_cost"), table_name="order_details")
    op.alter_column("order_details", "order_id", existing_type=postgresql.UUID(), nullable=False)
    op.drop_index(op.f("ix_items_value"), table_name="items")
    op.drop_index(op.f("ix_items_cost"), table_name="items")
    op.drop_index(op.f("ix_items_amount"), table_name="items")
    op.alter_column("items", "cost", existing_type=postgresql.DOUBLE_PRECISION(precision=53), nullable=False)
    op.drop_index(op.f("ix_fiscal_notes_owner_id"), table_name="fiscal_notes")
    op.drop_index(op.f("ix_fiscal_notes_file_id"), table_name="fiscal_notes")
    op.drop_index(op.f("ix_fiscal_notes_description"), table_name="fiscal_notes")
    op.drop_index(op.f("ix_files_uploaded_at"), table_name="files")
    op.drop_index(op.f("ix_clients_phone"), table_name="clients")
    op.drop_index(op.f("ix_clients_owner_id"), table_name="clients")
    op.drop_index(op.f("ix_clients_created_at"), table_name="clients")
    op.drop_index(op.f("ix_fiscal_note_items_sugested_sell_value"), table_name="fiscal_note_items")
    op.drop_index(op.f("ix_fiscal_note_items_owner_id"), table_name="fiscal_note_items")
    op.drop_index(op.f("ix_fiscal_note_items_item_id"), table_name="fiscal_note_items")
    op.drop_index(op.f("ix_fiscal_note_items_fiscal_note_id"), table_name="fiscal_note_items")
    op.drop_index(op.f("ix_fiscal_note_items_file_id"), table_name="fiscal_note_items")
    op.drop_index(op.f("ix_fiscal_note_items_buy_value"), table_name="fiscal_note_items")
    op.drop_table("fiscal_note_items")
    op.drop_index(op.f("ix_balance_value"), table_name="balance")
    op.drop_index(op.f("ix_balance_type"), table_name="balance")
    op.drop_index(op.f("ix_balance_owner_id"), table_name="balance")
    op.drop_index(op.f("ix_balance_operation"), table_name="balance")
    op.drop_index(op.f("ix_balance_description"), table_name="balance")
    op.drop_index(op.f("ix_balance_created_at"), table_name="balance")
    op.drop_table("balance")
    # ### end Alembic commands ###

sqlmodel.sql.sqltypes.AutoString alembic.op.drop_table sqlalchemy.Float sqlalchemy.dialects.postgresql.DOUBLE_PRECISION sqlalchemy.PrimaryKeyConstraint sqlalchemy.DateTime sqlmodel.sql.sqltypes.GUID alembic.op.f sqlalchemy.Enum sqlalchemy.dialects.postgresql.UUID sqlalchemy.ForeignKeyConstraint
[((5828, 5862), 'alembic.op.drop_table', 'op.drop_table', (['"""fiscal_note_items"""'], {}), "('fiscal_note_items')\n", (5841, 5862), False, 'from alembic import op\n'), ((6280, 6304), 'alembic.op.drop_table', 'op.drop_table', (['"""balance"""'], {}), "('balance')\n", (6293, 6304), False, 'from alembic import op\n'), ((1354, 1405), 'sqlalchemy.ForeignKeyConstraint', 'sa.ForeignKeyConstraint', (["['owner_id']", "['users.id']"], {}), "(['owner_id'], ['users.id'])\n", (1377, 1405), True, 'import sqlalchemy as sa\n'), ((1450, 1479), 'sqlalchemy.PrimaryKeyConstraint', 'sa.PrimaryKeyConstraint', (['"""id"""'], {}), "('id')\n", (1473, 1479), True, 'import sqlalchemy as sa\n'), ((1507, 1536), 'alembic.op.f', 'op.f', (['"""ix_balance_created_at"""'], {}), "('ix_balance_created_at')\n", (1511, 1536), False, 'from alembic import op\n'), ((1599, 1627), 'alembic.op.f', 'op.f', (['"""ix_balance_operation"""'], {}), "('ix_balance_operation')\n", (1603, 1627), False, 'from alembic import op\n'), ((1689, 1716), 'alembic.op.f', 'op.f', (['"""ix_balance_owner_id"""'], {}), "('ix_balance_owner_id')\n", (1693, 1716), False, 'from alembic import op\n'), ((1777, 1800), 'alembic.op.f', 'op.f', (['"""ix_balance_type"""'], {}), "('ix_balance_type')\n", (1781, 1800), False, 'from alembic import op\n'), ((2414, 2472), 'sqlalchemy.ForeignKeyConstraint', 'sa.ForeignKeyConstraint', (["['file_id']", "['files.bucket_key']"], {}), "(['file_id'], ['files.bucket_key'])\n", (2437, 2472), True, 'import sqlalchemy as sa\n'), ((2517, 2581), 'sqlalchemy.ForeignKeyConstraint', 'sa.ForeignKeyConstraint', (["['fiscal_note_id']", "['fiscal_notes.id']"], {}), "(['fiscal_note_id'], ['fiscal_notes.id'])\n", (2540, 2581), True, 'import sqlalchemy as sa\n'), ((2626, 2676), 'sqlalchemy.ForeignKeyConstraint', 'sa.ForeignKeyConstraint', (["['item_id']", "['items.id']"], {}), "(['item_id'], ['items.id'])\n", (2649, 2676), True, 'import sqlalchemy as sa\n'), ((2721, 2772), 'sqlalchemy.ForeignKeyConstraint', 'sa.ForeignKeyConstraint', (["['owner_id']", "['users.id']"], {}), "(['owner_id'], ['users.id'])\n", (2744, 2772), True, 'import sqlalchemy as sa\n'), ((2817, 2846), 'sqlalchemy.PrimaryKeyConstraint', 'sa.PrimaryKeyConstraint', (['"""id"""'], {}), "('id')\n", (2840, 2846), True, 'import sqlalchemy as sa\n'), ((2874, 2917), 'alembic.op.f', 'op.f', (['"""ix_fiscal_note_items_fiscal_note_id"""'], {}), "('ix_fiscal_note_items_fiscal_note_id')\n", (2878, 2917), False, 'from alembic import op\n'), ((2994, 3030), 'alembic.op.f', 'op.f', (['"""ix_fiscal_note_items_item_id"""'], {}), "('ix_fiscal_note_items_item_id')\n", (2998, 3030), False, 'from alembic import op\n'), ((3100, 3137), 'alembic.op.f', 'op.f', (['"""ix_fiscal_note_items_owner_id"""'], {}), "('ix_fiscal_note_items_owner_id')\n", (3104, 3137), False, 'from alembic import op\n'), ((3217, 3265), 'alembic.op.f', 'op.f', (['"""ix_fiscal_note_items_sugested_sell_value"""'], {}), "('ix_fiscal_note_items_sugested_sell_value')\n", (3221, 3265), False, 'from alembic import op\n'), ((3352, 3379), 'alembic.op.f', 'op.f', (['"""ix_clients_owner_id"""'], {}), "('ix_clients_owner_id')\n", (3356, 3379), False, 'from alembic import op\n'), ((3440, 3472), 'alembic.op.f', 'op.f', (['"""ix_fiscal_notes_owner_id"""'], {}), "('ix_fiscal_notes_owner_id')\n", (3444, 3472), False, 'from alembic import op\n'), ((3647, 3670), 'alembic.op.f', 'op.f', (['"""ix_items_amount"""'], {}), "('ix_items_amount')\n", (3651, 3670), False, 'from alembic import op\n'), ((3942, 3972), 'alembic.op.f', 'op.f', (['"""ix_users_password_hash"""'], {}), "('ix_users_password_hash')\n", (3946, 3972), False, 'from alembic import op\n'), ((4012, 4033), 'alembic.op.f', 'op.f', (['"""ix_users_name"""'], {}), "('ix_users_name')\n", (4016, 4033), False, 'from alembic import op\n'), ((4073, 4102), 'alembic.op.f', 'op.f', (['"""ix_orders_description"""'], {}), "('ix_orders_description')\n", (4077, 4102), False, 'from alembic import op\n'), ((4143, 4178), 'alembic.op.f', 'op.f', (['"""ix_order_details_sell_value"""'], {}), "('ix_order_details_sell_value')\n", (4147, 4178), False, 'from alembic import op\n'), ((4226, 4260), 'alembic.op.f', 'op.f', (['"""ix_order_details_item_name"""'], {}), "('ix_order_details_item_name')\n", (4230, 4260), False, 'from alembic import op\n'), ((4308, 4337), 'alembic.op.f', 'op.f', (['"""ix_order_details_cost"""'], {}), "('ix_order_details_cost')\n", (4312, 4337), False, 'from alembic import op\n'), ((4483, 4505), 'alembic.op.f', 'op.f', (['"""ix_items_value"""'], {}), "('ix_items_value')\n", (4487, 4505), False, 'from alembic import op\n'), ((4545, 4566), 'alembic.op.f', 'op.f', (['"""ix_items_cost"""'], {}), "('ix_items_cost')\n", (4549, 4566), False, 'from alembic import op\n'), ((4606, 4629), 'alembic.op.f', 'op.f', (['"""ix_items_amount"""'], {}), "('ix_items_amount')\n", (4610, 4629), False, 'from alembic import op\n'), ((4779, 4811), 'alembic.op.f', 'op.f', (['"""ix_fiscal_notes_owner_id"""'], {}), "('ix_fiscal_notes_owner_id')\n", (4783, 4811), False, 'from alembic import op\n'), ((4858, 4889), 'alembic.op.f', 'op.f', (['"""ix_fiscal_notes_file_id"""'], {}), "('ix_fiscal_notes_file_id')\n", (4862, 4889), False, 'from alembic import op\n'), ((4936, 4971), 'alembic.op.f', 'op.f', (['"""ix_fiscal_notes_description"""'], {}), "('ix_fiscal_notes_description')\n", (4940, 4971), False, 'from alembic import op\n'), ((5018, 5046), 'alembic.op.f', 'op.f', (['"""ix_files_uploaded_at"""'], {}), "('ix_files_uploaded_at')\n", (5022, 5046), False, 'from alembic import op\n'), ((5086, 5110), 'alembic.op.f', 'op.f', (['"""ix_clients_phone"""'], {}), "('ix_clients_phone')\n", (5090, 5110), False, 'from alembic import op\n'), ((5152, 5179), 'alembic.op.f', 'op.f', (['"""ix_clients_owner_id"""'], {}), "('ix_clients_owner_id')\n", (5156, 5179), False, 'from alembic import op\n'), ((5221, 5250), 'alembic.op.f', 'op.f', (['"""ix_clients_created_at"""'], {}), "('ix_clients_created_at')\n", (5225, 5250), False, 'from alembic import op\n'), ((5292, 5340), 'alembic.op.f', 'op.f', (['"""ix_fiscal_note_items_sugested_sell_value"""'], {}), "('ix_fiscal_note_items_sugested_sell_value')\n", (5296, 5340), False, 'from alembic import op\n'), ((5392, 5429), 'alembic.op.f', 'op.f', (['"""ix_fiscal_note_items_owner_id"""'], {}), "('ix_fiscal_note_items_owner_id')\n", (5396, 5429), False, 'from alembic import op\n'), ((5481, 5517), 'alembic.op.f', 'op.f', (['"""ix_fiscal_note_items_item_id"""'], {}), "('ix_fiscal_note_items_item_id')\n", (5485, 5517), False, 'from alembic import op\n'), ((5569, 5612), 'alembic.op.f', 'op.f', (['"""ix_fiscal_note_items_fiscal_note_id"""'], {}), "('ix_fiscal_note_items_fiscal_note_id')\n", (5573, 5612), False, 'from alembic import op\n'), ((5664, 5700), 'alembic.op.f', 'op.f', (['"""ix_fiscal_note_items_file_id"""'], {}), "('ix_fiscal_note_items_file_id')\n", (5668, 5700), False, 'from alembic import op\n'), ((5752, 5790), 'alembic.op.f', 'op.f', (['"""ix_fiscal_note_items_buy_value"""'], {}), "('ix_fiscal_note_items_buy_value')\n", (5756, 5790), False, 'from alembic import op\n'), ((5881, 5905), 'alembic.op.f', 'op.f', (['"""ix_balance_value"""'], {}), "('ix_balance_value')\n", (5885, 5905), False, 'from alembic import op\n'), ((5947, 5970), 'alembic.op.f', 'op.f', (['"""ix_balance_type"""'], {}), "('ix_balance_type')\n", (5951, 5970), False, 'from alembic import op\n'), ((6012, 6039), 'alembic.op.f', 'op.f', (['"""ix_balance_owner_id"""'], {}), "('ix_balance_owner_id')\n", (6016, 6039), False, 'from alembic import op\n'), ((6081, 6109), 'alembic.op.f', 'op.f', (['"""ix_balance_operation"""'], {}), "('ix_balance_operation')\n", (6085, 6109), False, 'from alembic import op\n'), ((6151, 6181), 'alembic.op.f', 'op.f', (['"""ix_balance_description"""'], {}), "('ix_balance_description')\n", (6155, 6181), False, 'from alembic import op\n'), ((6223, 6252), 'alembic.op.f', 'op.f', (['"""ix_balance_created_at"""'], {}), "('ix_balance_created_at')\n", (6227, 6252), False, 'from alembic import op\n'), ((524, 552), 'sqlmodel.sql.sqltypes.GUID', 'sqlmodel.sql.sqltypes.GUID', ([], {}), '()\n', (550, 552), False, 'import sqlmodel\n'), ((598, 608), 'sqlalchemy.Float', 'sa.Float', ([], {}), '()\n', (606, 608), True, 'import sqlalchemy as sa\n'), ((653, 698), 'sqlalchemy.Enum', 'sa.Enum', (['"""DEBT"""', '"""CREDIT"""'], {'name': '"""balancetype"""'}), "('DEBT', 'CREDIT', name='balancetype')\n", (660, 698), True, 'import sqlalchemy as sa\n'), ((773, 945), 'sqlalchemy.Enum', 'sa.Enum', (['"""PAYMENT_OF_EMPLOYEES"""', '"""PAYMENT_OF_SUPPLIERS"""', '"""ANOTHER_PAYMENTS"""', '"""SALE_IN_PIX"""', '"""SALE_IN_DEBT"""', '"""SALE_IN_CREDIT"""', '"""SALE_IN_MONEY"""'], {'name': '"""operationtype"""'}), "('PAYMENT_OF_EMPLOYEES', 'PAYMENT_OF_SUPPLIERS', 'ANOTHER_PAYMENTS',\n    'SALE_IN_PIX', 'SALE_IN_DEBT', 'SALE_IN_CREDIT', 'SALE_IN_MONEY', name=\n    'operationtype')\n", (780, 945), True, 'import sqlalchemy as sa\n'), ((1153, 1187), 'sqlmodel.sql.sqltypes.AutoString', 'sqlmodel.sql.sqltypes.AutoString', ([], {}), '()\n', (1185, 1187), False, 'import sqlmodel\n'), ((1238, 1251), 'sqlalchemy.DateTime', 'sa.DateTime', ([], {}), '()\n', (1249, 1251), True, 'import sqlalchemy as sa\n'), ((1299, 1327), 'sqlmodel.sql.sqltypes.GUID', 'sqlmodel.sql.sqltypes.GUID', ([], {}), '()\n', (1325, 1327), False, 'import sqlmodel\n'), ((1911, 1939), 'sqlmodel.sql.sqltypes.GUID', 'sqlmodel.sql.sqltypes.GUID', ([], {}), '()\n', (1937, 1939), False, 'import sqlmodel\n'), ((1989, 1999), 'sqlalchemy.Float', 'sa.Float', ([], {}), '()\n', (1997, 1999), True, 'import sqlalchemy as sa\n'), ((2059, 2069), 'sqlalchemy.Float', 'sa.Float', ([], {}), '()\n', (2067, 2069), True, 'import sqlalchemy as sa\n'), ((2118, 2146), 'sqlmodel.sql.sqltypes.GUID', 'sqlmodel.sql.sqltypes.GUID', ([], {}), '()\n', (2144, 2146), False, 'import sqlmodel\n'), ((2201, 2229), 'sqlmodel.sql.sqltypes.GUID', 'sqlmodel.sql.sqltypes.GUID', ([], {}), '()\n', (2227, 2229), False, 'import sqlmodel\n'), ((2277, 2305), 'sqlmodel.sql.sqltypes.GUID', 'sqlmodel.sql.sqltypes.GUID', ([], {}), '()\n', (2303, 2305), False, 'import sqlmodel\n'), ((2353, 2387), 'sqlmodel.sql.sqltypes.AutoString', 'sqlmodel.sql.sqltypes.AutoString', ([], {}), '()\n', (2385, 2387), False, 'import sqlmodel\n'), ((3569, 3610), 'sqlalchemy.dialects.postgresql.DOUBLE_PRECISION', 'postgresql.DOUBLE_PRECISION', ([], {'precision': '(53)'}), '(precision=53)\n', (3596, 3610), False, 'from sqlalchemy.dialects import postgresql\n'), ((3770, 3787), 'sqlalchemy.dialects.postgresql.UUID', 'postgresql.UUID', ([], {}), '()\n', (3785, 3787), False, 'from sqlalchemy.dialects import postgresql\n'), ((4430, 4447), 'sqlalchemy.dialects.postgresql.UUID', 'postgresql.UUID', ([], {}), '()\n', (4445, 4447), False, 'from sqlalchemy.dialects import postgresql\n'), ((4702, 4743), 'sqlalchemy.dialects.postgresql.DOUBLE_PRECISION', 'postgresql.DOUBLE_PRECISION', ([], {'precision': '(53)'}), '(precision=53)\n', (4729, 4743), False, 'from sqlalchemy.dialects import postgresql\n')]