database.name should namespace schema names on MySQL, as it does on PostgreSQL
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 15/100
調査の方向性
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 の本文から書いたものです。
説明
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 writesdj.Schema("subject"), and the projects stay apart. -
MySQL:
database.nameis 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.
Schemaadds the prefix itself, so pipelines write plain schema names on both backends. This also coversVirtualModule,virtual_schemaandSchema.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 todj.Schema. A connection withoutdatabase.namestill 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
subjectinstead"). Code that still prefixes by hand keeps reaching the same schemas rather than silently creatinglab_project_lab_project_subject. database_prefix. It stays deprecated and unapplied. Its message points todatabase.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
- Separator. The proposal adds
_itself (name + "_"). The alternative is to take the prefix verbatim, asdatabase_prefixdid. Adding_keepsdatabase.namea name rather than a fragment, and matches the commonproject_convention. - 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 namedlab_sessionresolves tolab_sessionrather thanlab_lab_session. - 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 needsschema.rebuild_lineage()on MySQL only. Should lineage record the plain name instead? - Reaching outside the namespace. On PostgreSQL a connection cannot reach another database. On MySQL the prefix confines
dj.Schemato the namespace. A shared reference schema outside it would need either a second connection withoutdatabase.nameor an explicit opt-out (e.g.dj.Schema(name, namespace=False)). The proposal leaves the opt-out out of the first version. - Removing
database_prefix. In which release?
Implementation
The behaviour above is implemented and tested in the linked PR:
Connection.schema_prefixandConnection.qualify_schema_name;Schema.activateapplies the prefix, andlist_schemasfilters 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
subjectschema with separate contents;list_schemasreturns plain names;VirtualModuleresolves 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
- フォーク
- 98
- 平均マージ
- 15時間 31分
- マージ済み PR(30日)
- 9
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
datajoint/datajoint-python のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
datajoint/datajoint-python#1581 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
datajoint/datajoint-python#1539 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
_job_start_time records the populating host's local time, with no zone対応中かも @dimitri-yatsenko が 1 日前に担当しました。 オープン
datajoint/datajoint-python#1584 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 40/100
datajoint/datajoint-python#1580 ·
メンテナーはふだん 1 日以内に返信
-
A column copied by a foreign key loses the parent's core type (int32 becomes int)対応中かも @dimitri-yatsenko が 4 日前に担当しました。 オープン
難易度 3/5 半日 初心者へのやさしさ 25/100
datajoint/datajoint-python#1578 ·
メンテナーはふだん 1 日以内に返信
datajoint/datajoint-python の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
aws-samples/sample-per-model-bedrock#191 ·
メンテナーはふだん 1 日以内に返信
-
Docs viewer: inverted grey colormap, Phantom CT window -20 to 35 HU, smoothing up to 40 mm対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンarea: docs enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
PyTomography/PyTomography#331 ·
メンテナーはふだん 1 日以内に返信
-
effort: low prio: low ready
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
digitalfabrik/integreat-cms#4616 ·
メンテナーはふだん 5 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
FuRongJun-1999/dsh-memory#226 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug difficulty:2 good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
MakazhanAlpamys/Soup#1865 ·
メンテナーはふだん 1 日以内に返信