Commits

Marcin Kuzminski  committed 5b2cf21

Synced with latest sqlalchemy-migrate, added new upcomming migration for 1.3

  • Participants
  • Parent commits 5cacb51

Comments (0)

Files changed (12)

File rhodecode/lib/dbmigrate/migrate/__init__.py

 from rhodecode.lib.dbmigrate.migrate.versioning import *
 from rhodecode.lib.dbmigrate.migrate.changeset import *
 
-__version__ = '0.7.2.dev'
+__version__ = '0.7.3.dev'

File rhodecode/lib/dbmigrate/migrate/changeset/databases/sqlite.py

 
         insertion_string = self._modify_table(table, column, delta)
 
-        table.create()
+        table.create(bind=self.connection)
         self.append(insertion_string % {'table_name': table_name})
         self.execute()
         self.append('DROP TABLE migration_tmp')

File rhodecode/lib/dbmigrate/migrate/exceptions.py

 class InvalidConstraintError(Error):
     """Invalid constraint error"""
 
-
 class MigrateDeprecationWarning(DeprecationWarning):
     """Warning for deprecated features in Migrate"""

File rhodecode/lib/dbmigrate/migrate/versioning/api.py

 
     For instance, manage.py script_sql postgresql description creates:
     repository/versions/001_description_postgresql_upgrade.sql and
-    repository/versions/001_description_postgresql_postgres.sql
+    repository/versions/001_description_postgresql_downgrade.sql
     """
     repo = Repository(repository)
     repo.create_script_sql(database, description, **opts)
     """
     engine = opts.pop('engine')
     repos = Repository(repository)
-    script = repos.version(None).script()
 
     # Upgrade
     log.info("Upgrading...")
+    script = repos.version(None).script(engine.name, 'upgrade')
     script.run(engine, 1)
     log.info("done")
 
     log.info("Downgrading...")
+    script = repos.version(None).script(engine.name, 'downgrade')
     script.run(engine, -1)
     log.info("done")
     log.info("Success")

File rhodecode/lib/dbmigrate/migrate/versioning/repository.py

         options.setdefault('version_table', 'migrate_version')
         options.setdefault('repository_id', name)
         options.setdefault('required_dbs', [])
-        options.setdefault('use_timestamp_numbering', '0')
+        options.setdefault('use_timestamp_numbering', False)
 
         tmpl = open(os.path.join(tmpl_dir, cls._config)).read()
         ret = TempitaTemplate(tmpl).substitute(options)
     @property
     def use_timestamp_numbering(self):
         """Returns use_timestamp_numbering specified in config"""
-        ts_numbering = self.config.get('db_settings', 'use_timestamp_numbering', raw=True)
-        
-        return ts_numbering
+        if self.config.has_option('db_settings', 'use_timestamp_numbering'):
+            return self.config.getboolean('db_settings', 'use_timestamp_numbering')
+        return False
 
     def version(self, *p, **k):
         """API to :attr:`migrate.versioning.version.Collection.version`"""

File rhodecode/lib/dbmigrate/migrate/versioning/schemadiff.py

     :return: object which will evaluate to :keyword:`True` if there \
       are differences else :keyword:`False`.
     """
-    return SchemaDiff(metadata,
-                      sqlalchemy.MetaData(engine, reflect=True),
+    db_metadata = sqlalchemy.MetaData(engine, reflect=True)
+
+    # sqlite will include a dynamically generated 'sqlite_sequence' table if
+    # there are autoincrement sequences in the database; this should not be
+    # compared.
+    if engine.dialect.name == 'sqlite':
+        if 'sqlite_sequence' in db_metadata.tables:
+            db_metadata.remove(db_metadata.tables['sqlite_sequence'])
+
+    return SchemaDiff(metadata, db_metadata,
                       labelA='model',
                       labelB='database',
                       excludeTables=excludeTables)

File rhodecode/lib/dbmigrate/migrate/versioning/templates/manage/default.py_tmpl

 _vars.pop('repository_name', None)
 defaults = ", ".join(["%s='%s'" % var for var in _vars.iteritems()])
 }}
-main({{ defaults }})
+
+if __name__ == '__main__':
+    main({{ defaults }})

File rhodecode/lib/dbmigrate/migrate/versioning/templates/manage/pylons.py_tmpl

 
 # migrate supports passing url as an existing Engine instance (since 0.6.0)
 # usage: migrate -c path/to/config.ini COMMANDS
-main(url=engine_from_config(conf_dict), repository=migrations.__path__[0],{{ defaults }})
+if __name__ == '__main__':
+    main(url=engine_from_config(conf_dict), repository=migrations.__path__[0],{{ defaults }})

File rhodecode/lib/dbmigrate/migrate/versioning/version.py

         return max([VerNum(0)] + self.versions.keys())
 
     def _next_ver_num(self, use_timestamp_numbering):
-        print use_timestamp_numbering
         if use_timestamp_numbering == True:
-            print "Creating new timestamp version!"
             return VerNum(int(datetime.utcnow().strftime('%Y%m%d%H%M%S')))
         else:
             return self.latest + 1

File rhodecode/lib/dbmigrate/schema/db_1_3_0.py

+# -*- coding: utf-8 -*-
+"""
+    rhodecode.model.db
+    ~~~~~~~~~~~~~~~~~~
+
+    Database Models for RhodeCode
+
+    :created_on: Apr 08, 2010
+    :author: marcink
+    :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
+    :license: GPLv3, see COPYING for more details.
+"""
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.

File rhodecode/lib/dbmigrate/versions/003_version_1_2_0.py

     #==========================================================================
     # Add table `groups``
     #==========================================================================
-    from rhodecode.lib.dbmigrate.schema.db_1_2_0 import Group
+    from rhodecode.lib.dbmigrate.schema.db_1_2_0 import RepoGroup as Group
     Group().__table__.create()
 
     #==========================================================================

File rhodecode/lib/dbmigrate/versions/004_version_1_3_0.py

+import logging
+import datetime
+
+from sqlalchemy import *
+from sqlalchemy.exc import DatabaseError
+from sqlalchemy.orm import relation, backref, class_mapper
+from sqlalchemy.orm.session import Session
+
+from rhodecode.lib.dbmigrate.migrate import *
+from rhodecode.lib.dbmigrate.migrate.changeset import *
+
+from rhodecode.model.meta import Base
+
+log = logging.getLogger(__name__)
+
+def upgrade(migrate_engine):
+    """ Upgrade operations go here.
+    Don't create your own engine; bind migrate_engine to your metadata
+    """
+
+    
+
+    return
+
+
+def downgrade(migrate_engine):
+    meta = MetaData()
+    meta.bind = migrate_engine