root/galaxy-central/lib/galaxy/model/migrate/versions/0024_page_slug_unique_constraint.py

リビジョン 2, 1.0 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
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( migrate_engine )
17
18def upgrade():
19    print __doc__
20    metadata.reflect()
21
22    Page_table = Table( "page", metadata, autoload=True )
23
24    try:
25
26        # Sqlite doesn't support .alter, so we need to drop an recreate
27   
28        i = Index( "ix_page_slug", Page_table.c.slug )
29        i.drop()
30   
31        i = Index( "ix_page_slug", Page_table.c.slug, unique=False )
32        i.create()
33
34    except:
35
36        # Mysql doesn't have a named index, but alter should work
37
38        Page_table.c.slug.alter( unique=False )
39
40def downgrade():
41    metadata.reflect()
42    #Page_table = Table( "page", metadata, autoload=True )
43    #Page_table.c.slug.alter( unique=True )
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。