| 1 | """ | 
|---|
| 2 | Remove unique constraint from page slugs to allow creating a page with | 
|---|
| 3 | the same slug as a deleted page. | 
|---|
| 4 | """ | 
|---|
| 5 |  | 
|---|
| 6 | from sqlalchemy import * | 
|---|
| 7 | from migrate import * | 
|---|
| 8 | from migrate.changeset import * | 
|---|
| 9 |  | 
|---|
| 10 | import datetime | 
|---|
| 11 | now = datetime.datetime.utcnow | 
|---|
| 12 |  | 
|---|
| 13 | import logging | 
|---|
| 14 | log = logging.getLogger( __name__ ) | 
|---|
| 15 |  | 
|---|
| 16 | metadata = MetaData( migrate_engine ) | 
|---|
| 17 |  | 
|---|
| 18 | def 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 |  | 
|---|
| 40 | def downgrade(): | 
|---|
| 41 | metadata.reflect() | 
|---|
| 42 | #Page_table = Table( "page", metadata, autoload=True ) | 
|---|
| 43 | #Page_table.c.slug.alter( unique=True ) | 
|---|