-from sqlalchemy import create_engine
-from sqlalchemy.orm import sessionmaker
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
from mediagoblin.init import setup_global_and_app_config, setup_database
-from mediagoblin.db.util import ObjectId
+from mediagoblin.db.mongo.util import ObjectId
from mediagoblin.db.sql.models import (Base, User, MediaEntry, MediaComment,
- Tag, MediaTag)
-
-# Session = sessionmaker()
+ Tag, MediaTag, MediaFile)
+from mediagoblin.db.sql.open import setup_connection_and_db_from_config as \
+ sql_connect
+from mediagoblin.db.mongo.open import setup_connection_and_db_from_config as \
+ mongo_connect
from mediagoblin.db.sql.base import Session
copy_attrs(entry, new_entry,
('username', 'email', 'created', 'pw_hash', 'email_verified',
'status', 'verification_key', 'is_admin', 'url',
- 'bio', 'bio_html',
+ 'bio',
'fp_verification_key', 'fp_token_expire',))
# new_entry.fp_verification_expire = entry.fp_token_expire
new_entry = MediaEntry()
copy_attrs(entry, new_entry,
('title', 'slug', 'created',
- 'description', 'description_html',
- 'media_type',
- 'fail_error',
+ 'description',
+ 'media_type', 'state', 'license',
+ 'fail_error', 'fail_metadata',
'queued_task_id',))
copy_reference_attr(entry, new_entry, "uploader")
session.flush()
add_obj_ids(entry, new_entry)
+ for key, value in entry.media_files.iteritems():
+ new_file = MediaFile(name=key, file_path=value)
+ new_file.media_entry = new_entry.id
+ Session.add(new_file)
+
session.commit()
session.close()
new_entry = MediaComment()
copy_attrs(entry, new_entry,
('created',
- 'content', 'content_html',))
+ 'content',))
copy_reference_attr(entry, new_entry, "media_entry")
copy_reference_attr(entry, new_entry, "author")
def main():
- engine = create_engine('sqlite:///mediagoblin.db', echo=True)
- Session.configure(bind=engine)
-
- setup_global_and_app_config("mediagoblin.ini")
+ global_config, app_config = setup_global_and_app_config("mediagoblin.ini")
- mk_conn, mk_db = setup_database()
+ sql_conn, sql_db = sql_connect(app_config)
+ mk_conn, mk_db = mongo_connect(app_config)
- Base.metadata.create_all(engine)
+ Base.metadata.create_all(sql_db.engine)
convert_users(mk_db)
Session.remove()