Beispiel #1
0
def run (args):
  """Commits current repository changes."""
  cmds.init.require_init()
  repo.allow_if_at_tip()
  try:
    message = args[0]
  except IndexError:
    print """== No message specified. Using the following message to commit: ==\n"""
    message = auto_commit_message()
    print message
  print "Commiting current changes."
  
  src = Database().parseString(repo.revision.latest())
  dest = Database().parseString(db.dump.dump())
  
  if src == dest:
    print """No changes, nothing to commit."""
    sys.exit()
  
  number = repo.revision.latest_number() + 1
  repo.migration.add (number, dest - src, src - dest, message)
  repo.revision.save()
    
  print """Migration #%s successfully created.""" % number
  
  if cmds.init.config()["vcs"] == "hg":
    add_to_hg (number)
Beispiel #2
0
def run (args):
  """Show changed tables since latest commit."""
  cmds.init.require_init()

  (options, args) = optargs (args)

  revision = repo.revision.latest_number() if not options.revision else int(options.revision)

  repo.allow_if_at_tip(die = False)

  src = Database().parseString(repo.revision.by_number(revision))
  dest = Database().parseString(db.dump.dump())
  if src == dest:
    print """No changes since revision %s.""" % (revision)
    sys.exit()
  Diff = dest - src
  Status = { }
  Info = { }
  
  for tbl in Diff.TablesAdded:
    Status[tbl.name] = "A"
  for tbl in Diff.TablesDropped:
    Status[tbl.name] = "R"
  for (tbl, dstTable) in Diff.TablesModified:
    Status[tbl.name] = "M"
    if dstTable > tbl:
      Status[tbl.name] = "M+"
    if dstTable < tbl:
      Status[tbl.name] = "M-"
    diffSt = dstTable - tbl
    Info[tbl.name] = { }
    for (field, prev) in diffSt.FieldsAdded:
      Info[tbl.name][field.name] = "+"
    for field in diffSt.FieldsDropped:
      Info[tbl.name][field.name] = "-"
    for field in diffSt.FieldsModified:
      Info[tbl.name][field.name] = "m"
     
    
  for tbl in sorted(Status.keys()):
    print " %s %s" % (Status[tbl].ljust (2, " "), tbl)
    if not tbl in Info.keys():
      continue
    for info in Info[tbl].keys():
      print "    %s %s" % (Info[tbl][info], info)