root/galaxy-central/lib/galaxy/model/migrate/versions/0014_pages.py

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

import galaxy-central

行番号 
1"""
2Migration script to add support for "Pages".
3  1) Creates Page and PageRevision tables
4  2) Adds username column to User table
5"""
6
7from sqlalchemy import *
8from migrate import *
9from migrate.changeset import *
10
11import datetime
12now = datetime.datetime.utcnow
13
14import logging
15log = logging.getLogger( __name__ )
16
17metadata = MetaData( migrate_engine )
18
19Page_table = Table( "page", metadata,
20    Column( "id", Integer, primary_key=True ),
21    Column( "create_time", DateTime, default=now ),
22    Column( "update_time", DateTime, default=now, onupdate=now ),
23    Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=False ),
24    Column( "latest_revision_id", Integer,
25            ForeignKey( "page_revision.id", use_alter=True, name='page_latest_revision_id_fk' ), index=True ),
26    Column( "title", TEXT ),
27    Column( "slug", TEXT, unique=True, index=True ),
28    )
29
30PageRevision_table = Table( "page_revision", metadata,
31    Column( "id", Integer, primary_key=True ),
32    Column( "create_time", DateTime, default=now ),
33    Column( "update_time", DateTime, default=now, onupdate=now ),
34    Column( "page_id", Integer, ForeignKey( "page.id" ), index=True, nullable=False ),
35    Column( "title", TEXT ),
36    Column( "content", TEXT )
37    )
38
39def upgrade():
40    print __doc__
41    metadata.reflect()
42    try:
43        Page_table.create()
44    except:
45        log.debug( "Could not create page table" )
46    try:
47        PageRevision_table.create()
48    except:
49        log.debug( "Could not create page_revision table" )
50   
51    # Add 1 column to the user table
52    User_table = Table( "galaxy_user", metadata, autoload=True )
53    col = Column( 'username', String(255), index=True, unique=True, default=False )
54    col.create( User_table )
55    assert col is User_table.c.username
56
57def downgrade():
58    metadata.reflect()
59    Page_table.drop()
60    PageRevision_table.drop()
61    User_table = Table( "galaxy_user", metadata, autoload=True )
62    User_table.c.username.drop()
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。