def sync(alias, only_model=None):
    engine = get_engine_from_db_alias(alias)

    if engine != 'django_cassandra_engine':
        raise CommandError('Database {} is not cassandra!'.format(alias))

    connection = connections[alias]
    connection.connect()
    keyspace = connection.settings_dict['NAME']

    _logger.info('Creating indexes in {} [CONNECTION {}] ..'.format(
        keyspace, alias))

    connection.connection.cluster.refresh_schema_metadata()
    connection.connection.cluster.schema_metadata_enabled = True

    indexes_by_model = UnifiedIndex().get_indexes()

    for app_name, app_models \
            in connection.introspection.cql_models.items():
        for model in app_models:
            # If the app model is registered as a SearchIndex
            if model in indexes_by_model:
                model_name = "{0}.{1}".format(model.__module__, model.__name__)
                if not only_model or model_name == only_model:
                    _logger.info("Creating index %s.%s".format(
                        app_name, model.__name__))
                    _logger.info(
                        "Index class associated to te model {0}.{1}".format(
                            app_name,
                            indexes_by_model.get(model).__class__.__name__))
                    create_index(model, indexes_by_model.get(model))
Example #2
0
    def handle_noargs(self, **options):
        engine = get_engine_from_db_alias(options['database'])
        if engine == 'django_cassandra_engine':
            options['load_initial_data'] = False
            options['inhibit_post_migrate'] = True

        return super(Command, self).handle_noargs(**options)
    def sync(self, alias):
        engine = get_engine_from_db_alias(alias)

        if engine != 'django_cassandra_engine':
            raise CommandError('Database {} is not cassandra!'.format(alias))

        connection = connections[alias]
        connection.connect()
        options = connection.settings_dict.get('OPTIONS', {})
        keyspace = connection.settings_dict['NAME']
        replication_opts = options.get('replication', {})
        strategy_class = replication_opts.pop('strategy_class',
                                              'SimpleStrategy')
        replication_factor = replication_opts.pop('replication_factor', 1)

        self.stdout.write('Creating keyspace {}..'.format(keyspace))

        if strategy_class == 'SimpleStrategy':
            create_keyspace_simple(keyspace, replication_factor)
        else:
            create_keyspace_network_topology(keyspace, replication_opts)

        for app_name, app_models \
                in connection.introspection.cql_models.items():
            for model in app_models:
                self.stdout.write('Syncing %s.%s' % (app_name, model.__name__))
                sync_table(model)
    def sync(self, alias):
        engine = get_engine_from_db_alias(alias)

        if engine != 'django_cassandra_engine':
            raise CommandError('Database {0} is not cassandra!'.format(alias))

        connection = connections[alias]
        connection.connect()
        options = connection.settings_dict.get('OPTIONS', {})
        keyspace = connection.settings_dict['NAME']
        replication_opts = options.get('replication', {})
        strategy_class = replication_opts.pop('strategy_class',
                                              'SimpleStrategy')
        replication_factor = replication_opts.pop('replication_factor', 1)

        self.stdout.write('Creating keyspace {0}..'.format(keyspace))

        create_keyspace(keyspace, strategy_class, replication_factor,
                        **replication_opts)

        for app_name, app_models \
                in connection.introspection.cql_models.iteritems():
            for model in app_models:
                self.stdout.write('Syncing %s.%s' % (app_name, model.__name__))
                sync_table(model)
    def sync(self, alias):
        engine = get_engine_from_db_alias(alias)

        if engine != 'django_cassandra_engine':
            raise CommandError('Database {} is not cassandra!'.format(alias))

        connection = connections[alias]
        connection.connect()
        options = connection.settings_dict.get('OPTIONS', {})
        keyspace = connection.settings_dict['NAME']
        replication_opts = options.get('replication', {})
        strategy_class = replication_opts.pop('strategy_class',
                                              'SimpleStrategy')
        replication_factor = replication_opts.pop('replication_factor', 1)

        self.stdout.write('Creating keyspace {}..'.format(keyspace))

        if strategy_class == 'SimpleStrategy':
            management.create_keyspace_simple(keyspace, replication_factor)
        else:
            management.create_keyspace_network_topology(
                keyspace, replication_opts)

        for app_name, app_models \
                in connection.introspection.cql_models.items():
            for model in app_models:
                self.stdout.write('Syncing %s.%s' % (app_name, model.__name__))
                # patch this object used for type check in management.sync_table()
                management.Model = (Model, DjangoCassandraModel)
                management.sync_table(model)
    def setup_databases(self, **kwargs):
        super().setup_databases(**kwargs)

        if not self.keep_indexes:
            for alias in connections:
                engine = get_engine_from_db_alias(alias)
                if engine == 'django_cassandra_engine':
                    sync(alias)
    def check_migrations(self):
        """
        Skip checking migrations if engine == django_cassandra_engine.
        """

        engine = get_engine_from_db_alias(DEFAULT_DB_ALIAS)
        if engine != 'django_cassandra_engine':
            return super(Command, self).check_migrations()
Example #8
0
    def handle(self, **options):
        engine = get_engine_from_db_alias(options['database'])

        # Call regular syncdb if engine is different from ours
        if engine != 'django_cassandra_engine':
            return super(Command, self).handle(**options)
        else:
            return sync_cassandra.Command().execute(**options)
    def handle(self, **options):
        engine = get_engine_from_db_alias(options['database'])

        # Call regular syncdb if engine is different from ours
        if engine != 'django_cassandra_engine':
            return super(Command, self).handle(**options)
        else:
            return sync_cassandra.Command().execute(**options)
    def check_migrations(self):
        """
        Skip checking migrations if engine == django_cassandra_engine.
        """

        engine = get_engine_from_db_alias(DEFAULT_DB_ALIAS)
        if engine != 'django_cassandra_engine':
            return super(Command, self).check_migrations()
    def handle(self, *args, **options):
        engine = get_engine_from_db_alias(options["database"])

        # Call regular migrate if engine is different from ours
        if engine != "django_cassandra_engine":
            return super(Command, self).handle(*args, **options)
        else:
            self.stdout.write("Migrations are not supported in this engine. " "Calling syncdb instead..")
            call_command("syncdb", **options)
Example #12
0
    def handle_noargs(self, **options):
        engine = get_engine_from_db_alias(options['database'])
        if engine == 'django_cassandra_engine':
            options.update({
                'interactive': False,
                'inhibit_post_migrate': True
            })

        return super(Command, self).handle_noargs(**options)
Example #13
0
    def handle_noargs(self, **options):
        engine = get_engine_from_db_alias(options['database'])
        if engine == 'django_cassandra_engine':
            options.update({
                'interactive': False,
                'inhibit_post_migrate': True
            })

        return super(Command, self).handle_noargs(**options)
Example #14
0
    def handle(self, *args, **options):
        engine = get_engine_from_db_alias(options['database'])

        # Call regular migrate if engine is different from ours
        if engine != 'django_cassandra_engine':
            return super(Command, self).handle(*args, **options)
        else:
            self.stdout.write("Migrations are not supported in this engine. "
                              "Calling syncdb instead..")
            call_command('sync_cassandra', **options)
def get_keyspace(alias=None):
    if alias:
        return connections[alias]

    for alias in connections:
        engine = get_engine_from_db_alias(alias)
        if engine == "django_cassandra_engine":
            return connections[alias].settings_dict.get('NAME', '')

    raise AttributeError("Database not found!")
def get_database(model, alias=None):
    if alias:
        return connections[alias]

    for alias in connections:
        engine = get_engine_from_db_alias(alias)
        if issubclass(model, DjangoCassandraModel):
            if engine == "django_cassandra_engine":
                return connections[alias]
        elif not engine == "django_cassandra_engine":
            return connections[alias]

    raise AttributeError("Database not found!")
    def handle(self, **options):

        model = options.get("model")

        database = options.get("database")
        if database is not None:
            return sync(database, model)

        cassandra_alias = None
        for alias in connections:
            engine = get_engine_from_db_alias(alias)
            if engine == "django_cassandra_engine":
                sync(alias, model)
                cassandra_alias = alias

        if cassandra_alias is None:
            raise CommandError("Please add django_cassandra_engine backend to DATABASES!")
Example #18
0
    def handle(self, *args, **options):
        self._import_management()

        database = options.get('database')
        if database is not None:
            return self.sync(database)

        cassandra_alias = None
        for alias in connections:
            engine = get_engine_from_db_alias(alias)
            if engine == 'django_cassandra_engine':
                self.sync(alias)
                cassandra_alias = alias

        if cassandra_alias is None:
            raise CommandError(
                'Please add django_cassandra_engine backend to DATABASES!')
    def handle_noargs(self, **options):

        self._import_management()

        database = options.get('database')
        if database is not None:
            return self.sync(database)

        cassandra_alias = None
        for alias in connections:
            engine = get_engine_from_db_alias(alias)
            if engine == 'django_cassandra_engine':
                self.sync(alias)
                cassandra_alias = alias

        if cassandra_alias is None:
            raise CommandError(
                'Please add django_cassandra_engine backend to DATABASES!')
    def handle(self, *args, **options):
        self._import_management()

        database = options.get('database')
        if database is not None:
            return self.sync(database)

        cassandra_alias = None
        for alias in connections:
            engine = get_engine_from_db_alias(alias)
            if engine == 'django_cassandra_engine':
                self.sync(alias)
                cassandra_alias = alias

        if cassandra_alias is None:
            raise CommandError(
                'Please add django_cassandra_engine backend to DATABASES!')

        # Send the post_migrate signal, so individual apps can do whatever
        # they need to do at this point.
        emit_post_migrate_signal(1, False, cassandra_alias)
    def sync(self, alias):
        engine = get_engine_from_db_alias(alias)

        if engine != 'django_cassandra_engine':
            raise CommandError('Database {} is not cassandra!'.format(alias))

        connection = connections[alias]
        connection.connect()
        options = connection.settings_dict.get('OPTIONS', {})
        keyspace = connection.settings_dict['NAME']
        replication_opts = options.get('replication', {})
        strategy_class = replication_opts.pop('strategy_class',
                                              'SimpleStrategy')
        replication_factor = replication_opts.pop('replication_factor', 1)

        self.stdout.write('Creating keyspace {} [CONNECTION {}] ..'.format(
            keyspace, alias))

        if strategy_class == 'SimpleStrategy':
            management.create_keyspace_simple(
                keyspace,
                replication_factor,
                connections=[alias])
        else:
            management.create_keyspace_network_topology(
                keyspace,
                replication_opts,
                connections=[alias])

        connection.connection.cluster.refresh_schema_metadata()
        connection.connection.cluster.schema_metadata_enabled = True

        for app_name, app_models \
                in connection.introspection.cql_models.items():
            for model in app_models:
                self.stdout.write('Syncing %s.%s' % (app_name, model.__name__))
                # patch this object used for type check in management.sync_table()
                management.Model = (Model, DjangoCassandraModel)
                management.sync_table(model, keyspaces=[keyspace],
                                      connections=[alias])
 def emit_post_syncdb(verbosity, interactive, database):
     engine = get_engine_from_db_alias(database)
     if engine != "django_cassandra_engine":
         return FlushCommand.emit_post_syncdb(verbosity, interactive, database)
    def handle_noargs(self, **options):
        engine = get_engine_from_db_alias(options["database"])
        if engine == "django_cassandra_engine":
            options.update({"load_initial_data": False, "interactive": False, "inhibit_post_migrate": True})

        return super(Command, self).handle_noargs(**options)
Example #24
0
 def emit_post_migrate(verbosity, interactive, database):
     engine = get_engine_from_db_alias(database)
     if engine != 'django_cassandra_engine':
         return FlushCommand.emit_post_migrate(verbosity, interactive,
                                               database)
Example #25
0
 def emit_post_migrate(verbosity, interactive, database):
     engine = get_engine_from_db_alias(database)
     if engine != 'django_cassandra_engine':
         return FlushCommand.emit_post_migrate(verbosity, interactive,
                                               database)