"""Adding description to Roast Level

Revision ID: d58f5bd1c00f
Revises: 
Create Date: 2021-09-01 07:36:03.040758

"""
from alembic import op
import sqlalchemy as sa
from flask_sqlalchemy import SQLAlchemy
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
import os

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


def upgrade():
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///roastly.db'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    SECRET_KEY = os.urandom(32)
    app.config['SECRET_KEY'] = SECRET_KEY
    db = SQLAlchemy(app)

    class RoastLevel(db.Model):
        id = db.Column(db.Integer, primary_key=True)
        ordering = db.Column(db.Integer, nullable=False)
        name = db.Column(db.String(80), unique=True, nullable=False)
        description = db.Column(db.String(256), unique=True, nullable=False)

        def __str__(self):
            return self.name

    roast_levels = [
        (0, 'Light', 'Roast stops while first crack is underway'),
        (1, 'City', 'Roast completes along with first crack'), 
        (2, 'City+', 'First crack has completed, Second crack has not yet started'),
        (3, 'Full City', 'Roast stops just before second crack begins (maybe some outliers have cracked)'),
        (4, 'Full City+', 'Roast stops while second crack is underway'),
        (5, 'Vienna', 'Roast concludes after second crack has just completed'),
        (6, 'French', 'Roast finishes well after second crack'),
    ]

    db.session.query(RoastLevel).delete()

    for r in roast_levels:
        degree = RoastLevel(ordering=r[0], name=r[1], description=r[2])
        db.session.add(degree)

    db.session.commit()


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'roast_level', type_='unique')
    op.drop_column('roast_level', 'description')
    # ### end Alembic commands ###
