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.

76 lines
2.1 KiB

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