1 | """ |
---|
2 | Migration script to add column for a history slug. |
---|
3 | """ |
---|
4 | |
---|
5 | from sqlalchemy import * |
---|
6 | from migrate import * |
---|
7 | from migrate.changeset import * |
---|
8 | |
---|
9 | import logging |
---|
10 | log = logging.getLogger( __name__ ) |
---|
11 | |
---|
12 | metadata = MetaData( migrate_engine ) |
---|
13 | |
---|
14 | def upgrade(): |
---|
15 | |
---|
16 | print __doc__ |
---|
17 | metadata.reflect() |
---|
18 | |
---|
19 | History_table = Table( "history", metadata, autoload=True ) |
---|
20 | |
---|
21 | # Create slug column. |
---|
22 | c = Column( "slug", TEXT, index=True ) |
---|
23 | c.create( History_table ) |
---|
24 | assert c is History_table.c.slug |
---|
25 | |
---|
26 | # Create slug index. |
---|
27 | try: |
---|
28 | i = Index( "ix_history_slug", History_table.c.slug ) |
---|
29 | i.create() |
---|
30 | except: |
---|
31 | # Mysql doesn't have a named index, but alter should work |
---|
32 | History_table.c.slug.alter( unique=False ) |
---|
33 | |
---|
34 | def downgrade(): |
---|
35 | metadata.reflect() |
---|
36 | |
---|
37 | History_table = Table( "history", metadata, autoload=True ) |
---|
38 | History_table.c.slug.drop() |
---|