Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

database.name should namespace schema names on MySQL, as it does on PostgreSQL

未關閉
#1,582 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@dimitri-yatsenko 已經在處理了。

開始於 2026年10月9日。

  • #1583 來自 @dimitri-yatsenko —— 未關閉

評估

難度
4/5
預估耗時
3-5 天
新手友好度
15/100
Issue 類型
功能
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
mysql, postgresql, python
領域
backend, databases

研究方向

Start with Connection.schema_prefix and Connection.qualify_schema_name, then Schema.activate, list_schemas and the MySQL database.name warning, which the linked PR #1583 already changes. Open design questions (separator, already-prefixed names, lineage, opt-out, removal release) need maintainer decisions before any patch. Done means the unit prefix rule and the MySQL and PostgreSQL integration tests pass, and the docs follow-up is written.

由索引模型根據 Issue 內容生成。

描述

feature
What happens now

When several projects share one database server, each project needs its own set of schemas: two pipelines that both declare dj.Schema("subject") must not write to the same tables, and an administrator wants to grant a project's users access to that project's schemas only.

  • PostgreSQL: database.name (DJ_DATABASE_NAME) selects the database. Each project gets its own database, the pipeline writes dj.Schema("subject"), and the projects stay apart.

  • MySQL: database.name is ignored, with the warning "database.name is set but the MySQL backend does not support database selection". The only way to separate projects is to put a prefix into every schema name in pipeline code:

    prefix = os.environ["MY_PREFIX"]          # or dj.config.database.database_prefix
    subject = dj.Schema(prefix + "subject")
    session = dj.Schema(prefix + "session")
    
  • database.database_prefix (DJ_DATABASE_PREFIX): it stores the value but DataJoint never applies it. It is deprecated with the message "will be removed in DataJoint 2.3. Use database.name to select a PostgreSQL database instead". That message is stale on 2.3.x, and it gives MySQL users no replacement.

So the same pipeline is written differently for the two backends. Every MySQL pipeline carries its own prefix handling, and a published example that writes dj.Schema("subject") can't be dropped into a shared MySQL server unchanged.

Proposal

Make database.name the connection's schema namespace on both backends:

Backend database.name = "lab_project" dj.Schema("subject") on the server
PostgreSQL connects to database lab_project (unchanged) schema subject in database lab_project
MySQL prefix lab_project_ schema lab_project_subject
  • Prefixing. Schema adds the prefix itself, so pipelines write plain schema names on both backends. This also covers VirtualModule, virtual_schema and Schema.activate.
  • schema.database. It is the name on the server (lab_project_subject), as it is today for any schema.
  • dj.list_schemas(). It lists the namespace's schemas under their plain names (subject), so every name it returns can be passed back to dj.Schema. A connection without database.name still lists every schema it can see.
  • Grants. Access is granted by pattern on MySQL (GRANT ... ON \lab_project_%`.*`) and by database on PostgreSQL.
  • Already-prefixed names. A name that already starts with the prefix is used as is, with a warning ("write subject instead"). Code that still prefixes by hand keeps reaching the same schemas rather than silently creating lab_project_lab_project_subject.
  • database_prefix. It stays deprecated and unapplied. Its message points to database.name, and the "removed in 2.3" text goes.

Compatibility. A MySQL user who sets database.name today gets a warning and no effect. After this change, their schema names gain the prefix: for example, an environment that sets DJ_DATABASE_NAME for a PostgreSQL database and is reused against MySQL. That is a behaviour change, so it belongs in a minor release, with a note in the release notes.

Migration for a MySQL deployment that prefixes by hand with myproject_: set database.name = "myproject", then drop the prefix from the pipeline's dj.Schema(...) calls. The schemas on the server do not change.

Questions to settle
  1. Separator. The proposal adds _ itself (name + "_"). The alternative is to take the prefix verbatim, as database_prefix did. Adding _ keeps database.name a name rather than a fragment, and matches the common project_ convention.
  2. Already-prefixed names. Should they be used as is with a warning, or raise an error? A warning makes migration safe. The cost is one edge case: with namespace lab, a schema meant to be named lab_session resolves to lab_session rather than lab_lab_session.
  3. Lineage. Lineage strings embed the schema's server name (schema.table.attribute). On MySQL the prefix becomes part of them; on PostgreSQL the database name does not. Restoring a namespace under a different name then needs schema.rebuild_lineage() on MySQL only. Should lineage record the plain name instead?
  4. Reaching outside the namespace. On PostgreSQL a connection cannot reach another database. On MySQL the prefix confines dj.Schema to the namespace. A shared reference schema outside it would need either a second connection without database.name or an explicit opt-out (e.g. dj.Schema(name, namespace=False)). The proposal leaves the opt-out out of the first version.
  5. Removing database_prefix. In which release?
Implementation

The behaviour above is implemented and tested in the linked PR:

  • Connection.schema_prefix and Connection.qualify_schema_name;
  • Schema.activate applies the prefix, and list_schemas filters and strips it;
  • the MySQL warning is removed and the deprecation message updated.

Tests:

  • Unit: the prefix rule on both backends.
  • Integration (MySQL and PostgreSQL): two namespaces each hold a subject schema with separate contents; list_schemas returns plain names; VirtualModule resolves inside the namespace; an already-prefixed name is not prefixed twice.
  • Results: unit 457 passed; integration 694 passed, 16 skipped, both backends.

Related: #1426 (added database.name for PostgreSQL and deprecated database_prefix), #1351 (renamed schema_prefix to database_prefix).

Docs follow-up: how-to/configure-database.md, how-to/deploy-production.md §Use Database Prefixes, reference/configuration.md.

主要語言
Python
星號
197
分支
99
平均合併
1 天 11 小時
30 天內合併 PR
10

環境準備

  • 提供 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

datajoint/datajoint-python 的其他 Issue

查看 datajoint/datajoint-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。