1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
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.
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.
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/>.
19 from sqlalchemy
import (MetaData
, Table
, Column
, Boolean
, SmallInteger
,
20 Integer
, Unicode
, UnicodeText
, DateTime
,
21 ForeignKey
, UniqueConstraint
)
22 from sqlalchemy
.ext
.declarative
import declarative_base
24 from mediagoblin
.db
.sql
.util
import RegisterMigration
25 from mediagoblin
.db
.sql
.models
import MediaEntry
, Collection
, User
30 @RegisterMigration(1, MIGRATIONS
)
31 def ogg_to_webm_audio(db_conn
):
32 metadata
= MetaData(bind
=db_conn
.bind
)
34 file_keynames
= Table('core__file_keynames', metadata
, autoload
=True,
35 autoload_with
=db_conn
.bind
)
38 file_keynames
.update().where(file_keynames
.c
.name
== 'ogg').
39 values(name
='webm_audio')
44 @RegisterMigration(2, MIGRATIONS
)
45 def add_wants_notification_column(db_conn
):
46 metadata
= MetaData(bind
=db_conn
.bind
)
48 users
= Table('core__users', metadata
, autoload
=True,
49 autoload_with
=db_conn
.bind
)
51 col
= Column('wants_comment_notification', Boolean
,
52 default
=True, nullable
=True)
53 col
.create(users
, populate_defaults
=True)
57 @RegisterMigration(3, MIGRATIONS
)
58 def add_transcoding_progress(db_conn
):
59 metadata
= MetaData(bind
=db_conn
.bind
)
61 media_entry
= Table('core__media_entries', metadata
, autoload
=True,
62 autoload_with
=db_conn
.bind
)
64 col
= Column('transcoding_progress', SmallInteger
)
65 col
.create(media_entry
)
69 class Collection_v0(declarative_base()):
70 __tablename__
= "core__collections"
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
,
77 description
= Column(UnicodeText
)
78 creator
= Column(Integer
, ForeignKey(User
.id), nullable
=False)
79 items
= Column(Integer
, default
=0)
81 class CollectionItem_v0(declarative_base()):
82 __tablename__
= "core__collection_items"
84 id = Column(Integer
, primary_key
=True)
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
)
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.
96 # UniqueConstraint('collection', 'media_entry'),
99 @RegisterMigration(4, MIGRATIONS
)
100 def add_collection_tables(db_conn
):
101 Collection_v0
.__table__
.create(db_conn
.bind
)
102 CollectionItem_v0
.__table__
.create(db_conn
.bind
)
107 @RegisterMigration(5, MIGRATIONS
)
108 def add_mediaentry_collected(db_conn
):
109 metadata
= MetaData(bind
=db_conn
.bind
)
111 media_entry
= Table('core__media_entries', metadata
, autoload
=True,
112 autoload_with
=db_conn
.bind
)
114 col
= Column('collected', Integer
, default
=0)
115 col
.create(media_entry
)
119 class ProcessingMetaData_v0(declarative_base()):
120 __tablename__
= 'core__processing_metadata'
122 id = Column(Integer
, primary_key
=True)
123 media_entry_id
= Column(Integer
, ForeignKey(MediaEntry
.id), nullable
=False,
125 callback_url
= Column(Unicode
)
127 @RegisterMigration(6, MIGRATIONS
)
128 def create_processing_metadata_table(db
):
129 ProcessingMetaData_v0
.__table__
.create(db
.bind
)