from sqlalchemy import Column, String, MetaData, Table


def upgrade(migrate_engine):
    metadata = MetaData(bind=migrate_engine)

    def add_alias(table):
        alias = Column('alias', String(50), unique=True)
        alias.create(table)
    add_alias(Table('rules', metadata, autoload=True))
    add_alias(Table('rules_history', metadata, autoload=True))


def downgrade(migrate_engine):
    metadata = MetaData(bind=migrate_engine)
    Table('rules', metadata, autoload=True).c.alias.drop()
    Table('rules_history', metadata, autoload=True).c.alias.drop()

from sqlalchemy import Column, String, MetaData, Table


def upgrade(migrate_engine):
    metadata = MetaData(bind=migrate_engine)

    alias = Column("alias", String(50), unique=True)
    alias.create(Table("rules", metadata, autoload=True), unique_name="alias_unique")

    history_alias = Column("alias", String(50))
    history_alias.create(Table('rules_history', metadata, autoload=True))


def downgrade(migrate_engine):
    metadata = MetaData(bind=migrate_engine)
    Table('rules', metadata, autoload=True).c.alias.drop()
    Table('rules_history', metadata, autoload=True).c.alias.drop()

Fix migration script to make column unique+add index.
Fix migration script to make column unique+add index.

  from sqlalchemy import Column, String, MetaData, Table
  
  
  def upgrade(migrate_engine):
      metadata = MetaData(bind=migrate_engine)
  
-     def add_alias(table):
-         alias = Column('alias', String(50), unique=True)
+     alias = Column("alias", String(50), unique=True)
-         alias.create(table)
-     add_alias(Table('rules', metadata, autoload=True))
+     alias.create(Table("rules", metadata, autoload=True), unique_name="alias_unique")
+ 
+     history_alias = Column("alias", String(50))
-     add_alias(Table('rules_history', metadata, autoload=True))
+     history_alias.create(Table('rules_history', metadata, autoload=True))
  
  
  def downgrade(migrate_engine):
      metadata = MetaData(bind=migrate_engine)
      Table('rules', metadata, autoload=True).c.alias.drop()
      Table('rules_history', metadata, autoload=True).c.alias.drop()
  
Fix migration script to make column unique+add index.
## Code Before:
from sqlalchemy import Column, String, MetaData, Table


def upgrade(migrate_engine):
    metadata = MetaData(bind=migrate_engine)

    def add_alias(table):
        alias = Column('alias', String(50), unique=True)
        alias.create(table)
    add_alias(Table('rules', metadata, autoload=True))
    add_alias(Table('rules_history', metadata, autoload=True))


def downgrade(migrate_engine):
    metadata = MetaData(bind=migrate_engine)
    Table('rules', metadata, autoload=True).c.alias.drop()
    Table('rules_history', metadata, autoload=True).c.alias.drop()

## Instruction:
Fix migration script to make column unique+add index.
## Code After:
from sqlalchemy import Column, String, MetaData, Table


def upgrade(migrate_engine):
    metadata = MetaData(bind=migrate_engine)

    alias = Column("alias", String(50), unique=True)
    alias.create(Table("rules", metadata, autoload=True), unique_name="alias_unique")

    history_alias = Column("alias", String(50))
    history_alias.create(Table('rules_history', metadata, autoload=True))


def downgrade(migrate_engine):
    metadata = MetaData(bind=migrate_engine)
    Table('rules', metadata, autoload=True).c.alias.drop()
    Table('rules_history', metadata, autoload=True).c.alias.drop()
