Ensure query_dict is a dict after the contents have been modified.
[mediagoblin.git] / mediagoblin / db / sql / migrations.py
CommitLineData
70b44584 1# GNU MediaGoblin -- federated, autonomous media hosting
b781c3c9 2# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
70b44584
CAW
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU Affero General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Affero General Public License for more details.
13#
14# You should have received a copy of the GNU Affero General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
29fdd3bb
AW
17import datetime
18
88a9662b 19from sqlalchemy import (MetaData, Table, Column, Boolean, SmallInteger,
316e1dfd
E
20 Integer, Unicode, UnicodeText, DateTime,
21 ForeignKey, UniqueConstraint)
22from sqlalchemy.ext.declarative import declarative_base
b781c3c9
JK
23
24from mediagoblin.db.sql.util import RegisterMigration
316e1dfd 25from mediagoblin.db.sql.models import MediaEntry, Collection, User
b781c3c9 26
3ea1cf36 27MIGRATIONS = {}
b781c3c9
JK
28
29
30@RegisterMigration(1, MIGRATIONS)
31def ogg_to_webm_audio(db_conn):
32 metadata = MetaData(bind=db_conn.bind)
33
34 file_keynames = Table('core__file_keynames', metadata, autoload=True,
35 autoload_with=db_conn.bind)
36
37 db_conn.execute(
38c6d441 38 file_keynames.update().where(file_keynames.c.name == 'ogg').
b781c3c9
JK
39 values(name='webm_audio')
40 )
b1055401 41 db_conn.commit()
38c6d441
JW
42
43
44@RegisterMigration(2, MIGRATIONS)
45def add_wants_notification_column(db_conn):
46 metadata = MetaData(bind=db_conn.bind)
47
48 users = Table('core__users', metadata, autoload=True,
49 autoload_with=db_conn.bind)
50
51 col = Column('wants_comment_notification', Boolean,
c4869eff 52 default=True, nullable=True)
38c6d441 53 col.create(users, populate_defaults=True)
b1055401 54 db_conn.commit()
64712915
JW
55
56
57@RegisterMigration(3, MIGRATIONS)
58def add_transcoding_progress(db_conn):
59 metadata = MetaData(bind=db_conn.bind)
60
61 media_entry = Table('core__media_entries', metadata, autoload=True,
62 autoload_with=db_conn.bind)
63
64 col = Column('transcoding_progress', SmallInteger)
65 col.create(media_entry)
66 db_conn.commit()
be5be115 67
88a9662b 68
316e1dfd
E
69class Collection_v0(declarative_base()):
70 __tablename__ = "core__collections"
71
72 id = Column(Integer, primary_key=True)
73 title = Column(Unicode, nullable=False)
74 slug = Column(Unicode)
75 created = Column(DateTime, nullable=False, default=datetime.datetime.now,
76 index=True)
77 description = Column(UnicodeText)
78 creator = Column(Integer, ForeignKey(User.id), nullable=False)
79 items = Column(Integer, default=0)
80
81class CollectionItem_v0(declarative_base()):
82 __tablename__ = "core__collection_items"
83
84 id = Column(Integer, primary_key=True)
85 media_entry = Column(
86 Integer, ForeignKey(MediaEntry.id), nullable=False, index=True)
87 collection = Column(Integer, ForeignKey(Collection.id), nullable=False)
88 note = Column(UnicodeText, nullable=True)
89 added = Column(DateTime, nullable=False, default=datetime.datetime.now)
90 position = Column(Integer)
91
92 ## This should be activated, normally.
93 ## But this would change the way the next migration used to work.
94 ## So it's commented for now.
95 # __table_args__ = (
96 # UniqueConstraint('collection', 'media_entry'),
97 # {})
98
be5be115 99@RegisterMigration(4, MIGRATIONS)
29fdd3bb 100def add_collection_tables(db_conn):
316e1dfd
E
101 Collection_v0.__table__.create(db_conn.bind)
102 CollectionItem_v0.__table__.create(db_conn.bind)
29fdd3bb
AW
103
104 db_conn.commit()
105
88a9662b 106
29fdd3bb 107@RegisterMigration(5, MIGRATIONS)
59fb87c9 108def add_mediaentry_collected(db_conn):
be5be115
AW
109 metadata = MetaData(bind=db_conn.bind)
110
111 media_entry = Table('core__media_entries', metadata, autoload=True,
112 autoload_with=db_conn.bind)
113
d8984df8 114 col = Column('collected', Integer, default=0)
be5be115
AW
115 col.create(media_entry)
116 db_conn.commit()
5354f954
JW
117
118
316e1dfd
E
119class ProcessingMetaData_v0(declarative_base()):
120 __tablename__ = 'core__processing_metadata'
939d57a0 121
316e1dfd
E
122 id = Column(Integer, primary_key=True)
123 media_entry_id = Column(Integer, ForeignKey(MediaEntry.id), nullable=False,
124 index=True)
125 callback_url = Column(Unicode)
939d57a0 126
316e1dfd
E
127@RegisterMigration(6, MIGRATIONS)
128def create_processing_metadata_table(db):
129 ProcessingMetaData_v0.__table__.create(db.bind)
5354f954 130 db.commit()