A few more tweaks as requested by Andreas.

This commit is contained in:
Raoul Snyman 2011-08-25 22:14:02 +02:00
parent bcf9b174ff
commit 4b1ce7102e
2 changed files with 16 additions and 3 deletions

View File

@ -54,12 +54,24 @@ def upgrade_setup(metadata):
def upgrade_1(session, metadata, tables): def upgrade_1(session, metadata, tables):
"""
Version 1 upgrade.
This upgrade removes the many-to-many relationship between songs and
media_files and replaces it with a one-to-many, which is far more
representative of the real relationship between the two entities.
In order to facilitate this one-to-many relationship, a song_id column is
added to the media_files table, and a weight column so that the media
files can be ordered.
"""
Table(u'media_files_songs', metadata, autoload=True).drop(checkfirst=True) Table(u'media_files_songs', metadata, autoload=True).drop(checkfirst=True)
Column(u'song_id', types.Integer(), default=None)\ Column(u'song_id', types.Integer(), default=None)\
.create(table=tables[u'media_files'], populate_default=True) .create(table=tables[u'media_files'], populate_default=True)
Column(u'weight', types.Integer(), default=0)\ Column(u'weight', types.Integer(), default=0)\
.create(table=tables[u'media_files'], populate_default=True) .create(table=tables[u'media_files'], populate_default=True)
if metadata.bind.url.get_dialect().name != 'sqlite': if metadata.bind.url.get_dialect().name != 'sqlite':
# SQLite doesn't support ALTER TABLE ADD CONSTRAINT
ForeignKeyConstraint([u'song_id'], [u'songs.id'], ForeignKeyConstraint([u'song_id'], [u'songs.id'],
table=tables[u'media_files']).create() table=tables[u'media_files']).create()

View File

@ -72,6 +72,7 @@ MODULES = [
'enchant', 'enchant',
'BeautifulSoup', 'BeautifulSoup',
'mako', 'mako',
'migrate',
] ]