# 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/>.
-MIGRATIONS = []
+MIGRATIONS = {}
'setup': 'mediagoblin.gmg_commands.import_export:import_export_parse_setup',
'func': 'mediagoblin.gmg_commands.import_export:env_import',
'help': 'Exports the data for this MediaGoblin instance'},
+ 'dbupdate': {
+ 'setup': 'mediagoblin.gmg_commands.dbupdate:dbupdate_parse_setup',
+ 'func': 'mediagoblin.gmg_commands.dbupdate:dbupdate',
+ 'help': 'Set up or update the SQL database'},
}
# GNU MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
+# 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
# 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 sqlalchemy.orm import sessionmaker
+
from mediagoblin.db.sql.open import setup_connection_and_db_from_config
from mediagoblin.db.sql.util import (
MigrationManager, assure_migrations_table_setup)
from mediagoblin.tools.common import import_component
+def dbupdate_parse_setup(subparser):
+ pass
+
+
class DatabaseData(object):
def __init__(self, name, models, migrations):
self.name = name
self.models = models
self.migrations = migrations
- def make_migration_manager(self, db):
+ def make_migration_manager(self, session):
return MigrationManager(
- self.name, self.models, self.migrations, db)
+ self.name, self.models, self.migrations, session)
def gather_database_data(media_types):
# Set up the database
connection, db = setup_connection_and_db_from_config(app_config)
- # If migrations table not made, make it!
- assure_migrations_table_setup(db)
+ Session = sessionmaker(bind=db.engine)
# Setup media managers for all dbdata, run init/migrate and print info
# For each component, create/migrate tables
for dbdata in dbdatas:
- migration_manager = dbdata.make_migration_manager(db)
+ migration_manager = dbdata.make_migration_manager(Session())
migration_manager.init_or_migrate()
--- /dev/null
+# 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/>.
+
+MIGRATIONS = {}
--- /dev/null
+# 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.db.sql.models import Base
+
+from sqlalchemy import (
+ Column, Integer, Unicode, UnicodeText, DateTime, Boolean, ForeignKey,
+ UniqueConstraint)
+
+
+class AsciiData(Base):
+ __tablename__ = "ascii_data"
+
+ id = Column(Integer, primary_key=True)
+ media_entry = Column(
+ Integer, ForeignKey('media_entries.id'), nullable=False)
+
+
+DATA_MODEL = AsciiData
+MODELS = [AsciiData]
--- /dev/null
+# 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/>.
+
+MIGRATIONS = {}
class ImageData(Base):
- __tablename__ = "image__data"
+ __tablename__ = "image_data"
id = Column(Integer, primary_key=True)
width = Column(Integer)
height = Column(Integer)
+ media_entry = Column(
+ Integer, ForeignKey('media_entries.id'), nullable=False)
DATA_MODEL = ImageData
--- /dev/null
+# 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/>.
+
+MIGRATIONS = {}
+# 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.db.sql.models import Base
from sqlalchemy import (
class VideoData(Base):
- __tablename__ = "video__data"
+ __tablename__ = "video_data"
id = Column(Integer, primary_key=True)
- integer
+ media_entry = Column(
+ Integer, ForeignKey('media_entries.id'), nullable=False)
DATA_MODEL = VideoData