def create_schemata(self): """ Go through settings.SCHEMATA_DOMAINS and create all schemata that do not already exist in the database. """ # operate in the public schema connection.set_schemata_off() cursor = connection.cursor() cursor.execute('SELECT schema_name FROM information_schema.schemata') existing_schemata = [row[0] for row in cursor.fetchall()] for sd in settings.SCHEMATA_DOMAINS.values(): schema_name = str(sd['schema_name']) _check_identifier(schema_name) if schema_name not in existing_schemata: sql = 'CREATE SCHEMA %s' % schema_name print sql cursor.execute(sql) transaction.commit_unless_managed()
def create_schemata(self): """ Go through settings.SCHEMATA_DOMAINS and create all schemata that do not already exist in the database. """ # operate in the public schema connection.set_schemata_off() cursor = connection.cursor() cursor.execute('SELECT schema_name FROM information_schema.schemata') existing_schemata = [ row[0] for row in cursor.fetchall() ] for sd in settings.SCHEMATA_DOMAINS.values(): schema_name = str(sd['schema_name']) _check_identifier(schema_name) if schema_name not in existing_schemata: sql = 'CREATE SCHEMA %s' % schema_name print sql cursor.execute(sql) transaction.commit_unless_managed()
def tearDown(self): connection.set_schemata_off()
from django import test from django.db import connection from django.core.exceptions import ImproperlyConfigured from django_schemata.postgresql_backend.base import DatabaseError from django.db.utils import DatabaseError from django.conf import settings from django.core.management import call_command from django.contrib.sites.models import Site # only run this test if the custom database wrapper is in use. if hasattr(connection, 'schema_name'): # This will fail with Django==1.3.1 AND psycopg2==2.4.2 # See https://code.djangoproject.com/ticket/16250 # Either upgrade Django to trunk or use psycopg2==2.4.1 connection.set_schemata_off() def set_schematas(domain): settings.SCHEMATA_DOMAINS = { domain: { 'schema_name': domain, } } def add_schemata(domain): settings.SCHEMATA_DOMAINS.update({domain: { 'schema_name': domain, }}) class SchemataTestCase(test.TestCase): def setUp(self):
from django import test from django.db import connection from django.core.exceptions import ImproperlyConfigured from django_schemata.postgresql_backend.base import DatabaseError from django.db.utils import DatabaseError from django.conf import settings from django.core.management import call_command from django.contrib.sites.models import Site # only run this test if the custom database wrapper is in use. if hasattr(connection, 'schema_name'): # This will fail with Django==1.3.1 AND psycopg2==2.4.2 # See https://code.djangoproject.com/ticket/16250 # Either upgrade Django to trunk or use psycopg2==2.4.1 connection.set_schemata_off() def set_schematas(domain): settings.SCHEMATA_DOMAINS = { domain: { 'schema_name': domain, } } def add_schemata(domain): settings.SCHEMATA_DOMAINS.update({ domain: { 'schema_name': domain, }