Skip to content

Support different schema than 'doc' #64

Description

@surister

We want to be able to have tables in different schemas, currently Django does not support multiple schemas and issues the SQL statement without schema, e.g. select a,b from t. Therefore the schema is the default doc.

The schema should be settable at settings level and meta level. So there can be a global schema for everything and specific schemas for some models, for situations where the user want to access other schemas.

settings

DATABASES = {
    "default": {
        "ENGINE": "cratedb_django",
        "SERVERS": ["192.168.88.251:4200"],
        "GLOBAL_SCHEMA": "someschema"
    }
}

model

class SomeModel(CrateDBModel):
    ...
    class Meta:
        schema = 'metrics'

In this situation, migrations would run in someschema but queries on SomeModel would run on metrics.

Schema definition priority goes as follows:

  1. locally defined (Model)
  2. settings defined (Settings)

By default GLOBAL_SCHEMA will be doc. If the model does not implement schema, GLOBAL_SCHEMA is used.

Open questions

How would this behave in different databases setup?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: HardFeature/fix is complex and might require a few days worth of high quality effort.enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions