PageRenderTime 28ms CodeModel.GetById 23ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/galaxy/model/migrate/versions/0024_page_slug_unique_constraint.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 45 lines | 23 code | 14 blank | 8 comment | 0 complexity | 3ef5b1186617ff75373e2e4fda180769 MD5 | raw file
 1"""
 2Remove unique constraint from page slugs to allow creating a page with
 3the same slug as a deleted page.
 4"""
 5
 6from sqlalchemy import *
 7from migrate import *
 8from migrate.changeset import *
 9
10import datetime
11now = datetime.datetime.utcnow
12
13import logging
14log = logging.getLogger( __name__ )
15
16metadata = MetaData()
17
18def upgrade(migrate_engine):
19    metadata.bind = migrate_engine
20    print __doc__
21    metadata.reflect()
22
23    Page_table = Table( "page", metadata, autoload=True )
24
25    try:
26
27        # Sqlite doesn't support .alter, so we need to drop an recreate
28
29        i = Index( "ix_page_slug", Page_table.c.slug )
30        i.drop()
31
32        i = Index( "ix_page_slug", Page_table.c.slug, unique=False )
33        i.create()
34
35    except:
36
37        # Mysql doesn't have a named index, but alter should work
38
39        Page_table.c.slug.alter( unique=False )
40
41def downgrade(migrate_engine):
42    metadata.bind = migrate_engine
43    metadata.reflect()
44    #Page_table = Table( "page", metadata, autoload=True )
45    #Page_table.c.slug.alter( unique=True )