migration.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:flasky 作者: RoseOu 项目源码 文件源码
def run_migrations(self, **kw):
        """Run the migration scripts established for this :class:`.MigrationContext`,
        if any.

        The commands in :mod:`alembic.command` will set up a function
        that is ultimately passed to the :class:`.MigrationContext`
        as the ``fn`` argument.  This function represents the "work"
        that will be done when :meth:`.MigrationContext.run_migrations`
        is called, typically from within the ``env.py`` script of the
        migration environment.  The "work function" then provides an iterable
        of version callables and other version information which
        in the case of the ``upgrade`` or ``downgrade`` commands are the
        list of version scripts to invoke.  Other commands yield nothing,
        in the case that a command wants to run some other operation
        against the database such as the ``current`` or ``stamp`` commands.

        :param \**kw: keyword arguments here will be passed to each
         migration callable, that is the ``upgrade()`` or ``downgrade()``
         method within revision scripts.

        """
        current_rev = rev = False
        self.impl.start_migrations()
        for change, prev_rev, rev, doc in self._migrations_fn(
                                            self.get_current_revision(),
                                            self):
            if current_rev is False:
                current_rev = prev_rev
                if self.as_sql and not current_rev:
                    self._version.create(self.connection)
            if doc:
                log.info("Running %s %s -> %s, %s", change.__name__, prev_rev,
                    rev, doc)
            else:
                log.info("Running %s %s -> %s", change.__name__, prev_rev, rev)
            if self.as_sql:
                self.impl.static_output(
                        "-- Running %s %s -> %s" %
                        (change.__name__, prev_rev, rev)
                    )
            change(**kw)
            if not self.impl.transactional_ddl:
                self._update_current_rev(prev_rev, rev)
            prev_rev = rev

        if rev is not False:
            if self.impl.transactional_ddl:
                self._update_current_rev(current_rev, rev)

            if self.as_sql and not rev:
                self._version.drop(self.connection)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号