
from __future__ import print_function

import sys

from alembic.script import ScriptDirectory


def detect_heads(migrations):
    heads = migrations.get_heads()
    return heads


def version_history(migrations):
    version_history = [
        (m.revision, m.doc) for m in migrations.walk_revisions()
    ]
    version_history.reverse()
    return version_history


def main(migrations_path):
    migrations = ScriptDirectory(migrations_path)

    heads = detect_heads(migrations)
    if len(heads) > 1:
        print("Migrations directory has multiple heads due to branching: {}".format(heads), file=sys.stderr)
        sys.exit(1)

    for version in version_history(migrations):
        print("{:35} {}".format(*version))


if __name__ == '__main__':
    main('migrations/')


from __future__ import print_function

import sys
import warnings

from alembic.script import ScriptDirectory

warnings.simplefilter('error')


def detect_heads(migrations):
    heads = migrations.get_heads()
    return heads


def version_history(migrations):
    version_history = [
        (m.revision, m.doc) for m in migrations.walk_revisions()
    ]
    version_history.reverse()
    return version_history


def main(migrations_path):
    migrations = ScriptDirectory(migrations_path)

    heads = detect_heads(migrations)
    if len(heads) > 1:
        print("Migrations directory has multiple heads due to branching: {}".format(heads), file=sys.stderr)
        sys.exit(1)

    for version in version_history(migrations):
        print("{:35} {}".format(*version))


if __name__ == '__main__':
    main('migrations/')

Abort migrations check if a version is present more than once
Abort migrations check if a version is present more than once

list_migrations checks whether we have more than one branch in the
list of migration versions. Since we've switched to a new revision
naming convention, pull requests open at the same time are likely
to use the same revision number when adding new migrations (ie if
the current latest migration is '500' two pull requests adding a
new one are both likely to use '510' for their revision id). When
this happens, alembic excludes on of the migrations from the tree
and doesn't consider it to be a multiple branches issue. Instead,
it prints out a warning. In order to make sure the tests fail when
this happens we transform the warning into an exception inside the
list_migrations script. This is similar to running the python
interpreter with `-W error`.

  
  from __future__ import print_function
  
  import sys
+ import warnings
  
  from alembic.script import ScriptDirectory
+ 
+ warnings.simplefilter('error')
  
  
  def detect_heads(migrations):
      heads = migrations.get_heads()
      return heads
  
  
  def version_history(migrations):
      version_history = [
          (m.revision, m.doc) for m in migrations.walk_revisions()
      ]
      version_history.reverse()
      return version_history
  
  
  def main(migrations_path):
      migrations = ScriptDirectory(migrations_path)
  
      heads = detect_heads(migrations)
      if len(heads) > 1:
          print("Migrations directory has multiple heads due to branching: {}".format(heads), file=sys.stderr)
          sys.exit(1)
  
      for version in version_history(migrations):
          print("{:35} {}".format(*version))
  
  
  if __name__ == '__main__':
      main('migrations/')
  
Abort migrations check if a version is present more than once
## Code Before:

from __future__ import print_function

import sys

from alembic.script import ScriptDirectory


def detect_heads(migrations):
    heads = migrations.get_heads()
    return heads


def version_history(migrations):
    version_history = [
        (m.revision, m.doc) for m in migrations.walk_revisions()
    ]
    version_history.reverse()
    return version_history


def main(migrations_path):
    migrations = ScriptDirectory(migrations_path)

    heads = detect_heads(migrations)
    if len(heads) > 1:
        print("Migrations directory has multiple heads due to branching: {}".format(heads), file=sys.stderr)
        sys.exit(1)

    for version in version_history(migrations):
        print("{:35} {}".format(*version))


if __name__ == '__main__':
    main('migrations/')

## Instruction:
Abort migrations check if a version is present more than once
## Code After:

from __future__ import print_function

import sys
import warnings

from alembic.script import ScriptDirectory

warnings.simplefilter('error')


def detect_heads(migrations):
    heads = migrations.get_heads()
    return heads


def version_history(migrations):
    version_history = [
        (m.revision, m.doc) for m in migrations.walk_revisions()
    ]
    version_history.reverse()
    return version_history


def main(migrations_path):
    migrations = ScriptDirectory(migrations_path)

    heads = detect_heads(migrations)
    if len(heads) > 1:
        print("Migrations directory has multiple heads due to branching: {}".format(heads), file=sys.stderr)
        sys.exit(1)

    for version in version_history(migrations):
        print("{:35} {}".format(*version))


if __name__ == '__main__':
    main('migrations/')
