PageRenderTime 107ms CodeModel.GetById 98ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/galaxy/model/migrate/versions/0023_page_published_and_deleted_columns.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 37 lines | 23 code | 10 blank | 4 comment | 0 complexity | 0c0b699a31c2160d0c697972936c345c MD5 | raw file
 1"""
 2Migration script to add columns for tracking whether pages are deleted and
 3publicly accessible.
 4"""
 5
 6from sqlalchemy import *
 7from migrate import *
 8from migrate.changeset import *
 9
10import logging
11log = logging.getLogger( __name__ )
12
13metadata = MetaData()
14
15def upgrade(migrate_engine):
16    metadata.bind = migrate_engine
17
18    print __doc__
19    metadata.reflect()
20
21    Page_table = Table( "page", metadata, autoload=True )
22
23    c = Column( "published", Boolean, index=True, default=False )
24    c.create( Page_table, index_name = 'ix_page_published' )
25    assert c is Page_table.c.published
26
27    c = Column( "deleted", Boolean, index=True, default=False )
28    c.create( Page_table, index_name='ix_page_deleted')
29    assert c is Page_table.c.deleted
30
31def downgrade(migrate_engine):
32    metadata.bind = migrate_engine
33    metadata.reflect()
34
35    Page_table = Table( "page", metadata, autoload=True )
36    Page_table.c.published.drop()
37    Page_table.c.deleted.drop()