Forked mumble-django project from https://bitbucket.org/Svedrin/mumble-django
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # kate: space-indent on; indent-width 4; replace-tabs on;
  3. """
  4. * Copyright © 2010, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
  5. *
  6. * Mumble-Django is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This package is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. """
  16. import os
  17. from os.path import join
  18. from django.db import connection, transaction
  19. from django.db.models import signals
  20. from django.conf import settings
  21. from mumble import models
  22. from mumble.management.server_detect import find_existing_instances
  23. def update_schema( **kwargs ):
  24. if "verbosity" in kwargs:
  25. v = kwargs['verbosity']
  26. else:
  27. v = 1
  28. if v:
  29. print "Migrating Database schema for Mumble-Django 2.0 now."
  30. scriptdir = join( settings.CONVERSIONSQL_ROOT, {
  31. 'postgresql_psycopg2': 'pgsql',
  32. 'postgresql': 'pgsql',
  33. 'mysql': 'mysql',
  34. 'sqlite3': 'sqlite',
  35. }[settings.DATABASE_ENGINE] )
  36. if v > 1:
  37. print "Reading migration scripts for %s from '%s'" % ( settings.DATABASE_ENGINE, scriptdir )
  38. scripts = [ filename for filename in os.listdir( scriptdir ) if filename.endswith( ".sql" ) ]
  39. scripts.sort()
  40. for filename in scripts:
  41. cursor = connection.cursor()
  42. scriptpath = os.path.join( scriptdir, filename )
  43. scriptfile = open( scriptpath, "r" )
  44. try:
  45. if v > 1:
  46. print "Running migration script '%s'..." % scriptpath
  47. stmt = scriptfile.read()
  48. cursor.execute( stmt )
  49. except IOError, err:
  50. print "Error reading file '%s':" % filename
  51. print err
  52. except cursor.db.connection.Error, err:
  53. print "Error executing file '%s':" % filename
  54. print err
  55. finally:
  56. scriptfile.close()
  57. cursor.close()
  58. if v:
  59. print "Database migration finished successfully."
  60. find_existing_instances( **kwargs )