Browse Source

implement data conversion and add scripts to convert the SQLITE db. todo: mysql/pgsql.

Natenom/support-murmur-13-1446181288462
Michael Ziegler 15 years ago
parent
commit
45dc3ac55b
  1. 2
      pyweb/mumble/conversionsql/sqlite/01-schema-mumble-server_id.sql
  2. 2
      pyweb/mumble/conversionsql/sqlite/02-schema-mumble_mumbleuser.sql
  3. 3
      pyweb/mumble/conversionsql/sqlite/11-data-mumble_mumbleserver.sql
  4. 6
      pyweb/mumble/conversionsql/sqlite/12-data-mumble_mumble.sql
  5. 32
      pyweb/mumble/management/__init__.py
  6. 62
      pyweb/mumble/management/update_schema.py

2
pyweb/mumble/conversionsql/sqlite/01-schema-mumble-server_id.sql

@ -0,0 +1,2 @@
ALTER TABLE "mumble_mumble"
ADD "server_id" integer;

2
pyweb/mumble/conversionsql/sqlite/02-schema-mumble_mumbleuser.sql

@ -0,0 +1,2 @@
ALTER TABLE "mumble_mumble"
ADD "display" varchar(200);

3
pyweb/mumble/conversionsql/sqlite/11-data-mumble_mumbleserver.sql

@ -0,0 +1,3 @@
INSERT INTO "mumble_mumbleserver" ( "dbus", "secret" )
SELECT DISTINCT "dbus", ''
FROM "mumble_mumble";

6
pyweb/mumble/conversionsql/sqlite/12-data-mumble_mumble.sql

@ -0,0 +1,6 @@
UPDATE "mumble_mumble"
SET "server_id"=(
SELECT "id"
FROM "mumble_mumbleserver"
WHERE "mumble_mumbleserver"."dbus" = "mumble_mumble"."dbus"
);

32
pyweb/mumble/management/__init__.py

@ -14,9 +14,39 @@
* GNU General Public License for more details.
"""
from server_detect import find_existing_instances
from django.db import connection, transaction
from django.db.models import signals
from mumble import models
from update_schema import update_schema
from server_detect import find_existing_instances
if not transaction.is_managed():
managed_before = False
transaction.enter_transaction_management(True)
transaction.managed(True)
else:
managed_before = True
cursor = connection.cursor()
try:
cursor.execute( "SELECT server_id FROM mumble_mumble;" )
except cursor.db.connection.Error:
# server_id field does not exist -> DB needs to be updated.
transaction.rollback()
signals.post_syncdb.connect( update_schema, sender=models );
else:
transaction.rollback()
signals.post_syncdb.connect( find_existing_instances, sender=models );
finally:
if not managed_before:
transaction.managed(False)
transaction.leave_transaction_management()

62
pyweb/mumble/management/update_schema.py

@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
"""
* Copyright © 2010, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
*
* Mumble-Django is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
"""
import os
from os.path import join
from django.db import connection, transaction
from django.db.models import signals
from django.conf import settings
from mumble import models
from mumble.management.server_detect import find_existing_instances
def update_schema( **kwargs ):
cursor = connection.cursor()
scriptpath = join(
settings.MUMBLE_DJANGO_ROOT, "pyweb", "mumble", "conversionsql", {
'postgresql_psycopg2': 'pgsql',
'postgresql': 'pgsql',
'mysql': 'mysql',
'sqlite3': 'sqlite',
}[settings.DATABASE_ENGINE]
)
scripts = [ filename for filename in os.listdir( scriptpath ) if filename.endswith( ".sql" ) ]
scripts.sort()
for filename in scripts:
scriptfile = open( os.path.join( scriptpath, filename ), "r" )
try:
stmt = scriptfile.read()
cursor.execute( stmt )
transaction.commit()
except IOError, err:
print "Error reading file '%s':" % filename
print err
except cursor.db.connection.Error, err:
print "Error executing file '%s':" % filename
print err
transaction.rollback()
finally:
scriptfile.close()
find_existing_instances( **kwargs )
Loading…
Cancel
Save