From 3ea1cf36fcfec9a381f2c425e626c4107e7dca43 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 18 Feb 2012 23:19:09 -0600 Subject: [PATCH] Updates so that dbupdate command works - Various fixes to dbupdate itself - Switching db/sql/migrations.py to use a dict instead of a list - Registering the function --- mediagoblin/db/sql/migrations.py | 2 +- mediagoblin/gmg_commands/__init__.py | 4 +++ mediagoblin/gmg_commands/dbupdate.py | 17 +++++++---- mediagoblin/media_types/ascii/migrations.py | 17 +++++++++++ mediagoblin/media_types/ascii/models.py | 34 +++++++++++++++++++++ mediagoblin/media_types/image/migrations.py | 17 +++++++++++ mediagoblin/media_types/image/models.py | 4 ++- mediagoblin/media_types/video/migrations.py | 17 +++++++++++ mediagoblin/media_types/video/models.py | 22 +++++++++++-- 9 files changed, 124 insertions(+), 10 deletions(-) create mode 100644 mediagoblin/media_types/ascii/migrations.py create mode 100644 mediagoblin/media_types/ascii/models.py create mode 100644 mediagoblin/media_types/image/migrations.py create mode 100644 mediagoblin/media_types/video/migrations.py diff --git a/mediagoblin/db/sql/migrations.py b/mediagoblin/db/sql/migrations.py index 67a02c96..98d0d0aa 100644 --- a/mediagoblin/db/sql/migrations.py +++ b/mediagoblin/db/sql/migrations.py @@ -14,4 +14,4 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -MIGRATIONS = [] +MIGRATIONS = {} diff --git a/mediagoblin/gmg_commands/__init__.py b/mediagoblin/gmg_commands/__init__.py index db944b3c..d804376b 100644 --- a/mediagoblin/gmg_commands/__init__.py +++ b/mediagoblin/gmg_commands/__init__.py @@ -53,6 +53,10 @@ SUBCOMMAND_MAP = { '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'}, } diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py index 1fc5121a..27698170 100644 --- a/mediagoblin/gmg_commands/dbupdate.py +++ b/mediagoblin/gmg_commands/dbupdate.py @@ -1,5 +1,5 @@ # 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 @@ -14,6 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +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) @@ -21,15 +23,19 @@ from mediagoblin.init import setup_global_and_app_config 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): @@ -74,11 +80,10 @@ def dbupdate(args): # 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() diff --git a/mediagoblin/media_types/ascii/migrations.py b/mediagoblin/media_types/ascii/migrations.py new file mode 100644 index 00000000..f54c23ea --- /dev/null +++ b/mediagoblin/media_types/ascii/migrations.py @@ -0,0 +1,17 @@ +# 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 . + +MIGRATIONS = {} diff --git a/mediagoblin/media_types/ascii/models.py b/mediagoblin/media_types/ascii/models.py new file mode 100644 index 00000000..324794b9 --- /dev/null +++ b/mediagoblin/media_types/ascii/models.py @@ -0,0 +1,34 @@ +# 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 . + + +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] diff --git a/mediagoblin/media_types/image/migrations.py b/mediagoblin/media_types/image/migrations.py new file mode 100644 index 00000000..f54c23ea --- /dev/null +++ b/mediagoblin/media_types/image/migrations.py @@ -0,0 +1,17 @@ +# 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 . + +MIGRATIONS = {} diff --git a/mediagoblin/media_types/image/models.py b/mediagoblin/media_types/image/models.py index 96b5cdf2..296eca0a 100644 --- a/mediagoblin/media_types/image/models.py +++ b/mediagoblin/media_types/image/models.py @@ -6,11 +6,13 @@ from sqlalchemy import ( 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 diff --git a/mediagoblin/media_types/video/migrations.py b/mediagoblin/media_types/video/migrations.py new file mode 100644 index 00000000..f54c23ea --- /dev/null +++ b/mediagoblin/media_types/video/migrations.py @@ -0,0 +1,17 @@ +# 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 . + +MIGRATIONS = {} diff --git a/mediagoblin/media_types/video/models.py b/mediagoblin/media_types/video/models.py index c44f1919..741c329b 100644 --- a/mediagoblin/media_types/video/models.py +++ b/mediagoblin/media_types/video/models.py @@ -1,3 +1,20 @@ +# 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 . + + from mediagoblin.db.sql.models import Base from sqlalchemy import ( @@ -6,10 +23,11 @@ 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 -- 2.25.1