"""empty message

Revision ID: b88ba80940cb
Revises: 9b782438e315
Create Date: 2018-01-09 04:20:20.038724

"""

# revision identifiers, used by Alembic.
revision = 'b88ba80940cb'
down_revision = '9b782438e315'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa

from sqlalchemy_utils.types import TSVectorType
from sqlalchemy_searchable import make_searchable
import sqlalchemy_utils

# Patch in knowledge of the citext type, so it reflects properly.
from sqlalchemy.dialects.postgresql.base import ischema_names
import citext
import queue
import datetime
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy.dialects.postgresql import JSON
from sqlalchemy.dialects.postgresql import TSVECTOR
ischema_names['citext'] = citext.CIText

from sqlalchemy.dialects import postgresql

from alembic import op
from flask_sqlalchemy import _SessionSignalEvents
import sqlalchemy as sa
from sqlalchemy import event
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, Session as BaseSession, relationship

from sqlalchemy import Table

from sqlalchemy import Column
from sqlalchemy import BigInteger
from sqlalchemy import Integer
from sqlalchemy import Text
from sqlalchemy import Float
from sqlalchemy import Boolean
from sqlalchemy import DateTime
from sqlalchemy import ForeignKey
from sqlalchemy import PrimaryKeyConstraint
from sqlalchemy import UniqueConstraint
from sqlalchemy.orm import relationship
from sqlalchemy.schema import UniqueConstraint

Session = sessionmaker()
Base = declarative_base()

class NuReleaseItem(Base):
    __tablename__ = 'nu_release_item'
    id               = Column(BigInteger, primary_key=True)

    release_date     = Column(DateTime, nullable=False, default=datetime.datetime.utcnow)
    first_seen       = Column(DateTime, nullable=False, default=datetime.datetime.min)



class NuResolvedOutbound(Base):
    __tablename__ = 'nu_resolved_outbound'
    id               = Column(BigInteger, primary_key=True)

    disabled         = Column(Boolean, nullable=False, default=False)



def upgrade():
    bind = op.get_bind()
    sess = Session(bind=bind)

    op.add_column('nu_resolved_outbound', sa.Column('disabled', sa.Boolean(), nullable=True))

    print("Setting value for new column 1")
    sess.query(NuReleaseItem).filter(NuReleaseItem.release_date == None).update({"first_seen" : datetime.datetime.min})
    print("Setting value for new column 2")
    sess.query(NuResolvedOutbound).update({"disabled" : False})
    sess.commit()
    print("Setting nullability")
    op.alter_column('nu_resolved_outbound', 'disabled',
               existing_type=sa.Boolean(),
               nullable=False)

    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('nu_resolved_outbound', 'disabled')
    op.alter_column('nu_release_item', 'release_date',
               existing_type=postgresql.TIMESTAMP(),
               nullable=True)
    ### end Alembic commands ###
