crate / crate/cratedb-django

Support different schema than 'doc'

Open
#64 4 comments 0 reactions 0 assignees View on GitHub
Difficulty: Hard enhancement
Dominant language
Python
Stars
6
Forks
4
PR merge metrics
No merged PRs in 30d

Description

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
```python
DATABASES = {
"default": {
"ENGINE": "cratedb_django",
"SERVERS": ["192.168.88.251:4200"],
"GLOBAL_SCHEMA": "someschema"
}
}
```
model
```python
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?

Contributor guide

Open the contributing guide

Research direction

Start by tracing how database settings, model Meta options, migrations, and query SQL are handled in the Django backend. Compare the requested model-level schema priority with the global GLOBAL_SCHEMA fallback, then investigate the open question about multiple database setups. Done means migrations use the global schema while model queries use an explicit schema or the configured default.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python, sql
Domain
backend, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.