Repository navigation
feat: database.name namespaces schema names on MySQL - #1583
Open
dimitri-yatsenko wants to merge 3 commits into
Open
dimitri-yatsenko wants to merge 3 commits into
dimitri-yatsenko wants to merge 3 commits into
Conversation
On PostgreSQL, database.name selects the database, so two namespaces can hold schemas with the same name. On MySQL it was ignored with a warning. It now becomes a prefix that Schema adds to every schema name (name + '_'), and list_schemas lists the namespace's schemas under their plain names. A name that already carries the prefix is used as is, with a warning. The database_prefix deprecation message no longer says it is removed in 2.3; it points to database.name.
dimitri-yatsenko
requested review from
MilagrosMarin,
lum-agilyti and
ttngu207
October 9, 2026 21:22
|
A few things I noticed while reading, in case they're useful for the open questions:
|
Review follow-up. On MySQL, `database.name` becomes the prefix `name + "_"` of every schema name, and `list_schemas()` lists the schemas that start with it. If the name could contain an underscore, one namespace's prefix could begin another's: `lab_` begins `lab_proj_`, so a connection in `lab` would list `lab_proj`'s schemas as `proj_*` and open them as its own. A MySQL `database.name` with an underscore now raises a DataJointError that explains this. PostgreSQL, where the name selects a database, is unchanged. A schema name that already starts with the prefix is still used as is, with a warning, so pipelines that add the prefix themselves keep reaching the same schemas. The docstring now states the consequence: with `database.name = "lab"`, `"lab_notes"` and `"notes"` name the same schema. The unit tests cover the refusal, and the namespace tests use names without underscores.
Member
Author
|
Thanks, @lum-agilyti. Both cases were real. bd3910e addresses them:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1582.
Why
On PostgreSQL,
database.nameselects the database, so projects sharing a server keep their schemas apart while pipelines write plain names likedj.Schema("subject"). On MySQL the setting was ignored with a warning, so every pipeline had to build prefixed schema names itself. The deprecateddatabase_prefixstores a value DataJoint never applies, and its message still says it is removed in 2.3.This PR gives
database.namethe same role on MySQL: it becomes a prefix thatSchemaadds to schema names. A pipeline is then written the same way for both backends.Changes
Connection.schema_prefix:name + "_"on MySQL whendatabase.nameis set; otherwise"", including always on PostgreSQL. On MySQL the name may not contain_, so one namespace's prefix can never begin another's (lab_beginslab_proj_); such a name raises aDataJointError.Connection.qualify_schema_name(name): returns the name on the server. A name that already starts with the prefix is returned unchanged with aUserWarning("writesubjectinstead"), so code that still prefixes by hand keeps reaching the same schemas.Schema.activate: qualifies the name before use, which coversdj.Schema(...),VirtualModuleandvirtual_schema.schema.databaseis the name on the server.dj.list_schemas(): with a prefix, lists only the namespace's schemas, under their plain names.database_prefixdeprecation message points todatabase.nameand no longer mentions 2.3.database.nameanddatabase_prefixare updated.Compatibility
A MySQL user who sets
database.nametoday gets a warning and no effect. After this change, their schema names gain the prefix. Hence the v2.4 milestone, and a line in the release notes.PostgreSQL behaviour is unchanged.
Open questions (from #1582)
_: decided: kept, with_refused inside a MySQLdatabase.name, so listing a namespace is exact;lab,"lab_notes"and"notes"name the same schema; the docstring says so;database_prefix.The PR implements the proposal's defaults, and each one is easy to change.
Tests
tests/unit/test_schema_prefix.py: the prefix rule on both backends, without a server.tests/integration/test_schema_namespace.py: runs on MySQL and PostgreSQL.subjectschema with separate contents.list_schemasreturns plain names, while a connection without a namespace sees the prefixed ones on MySQL.VirtualModuleresolves inside the namespace.database.nameon MySQL no longer warns.Local results: unit 457 passed; integration 694 passed, 16 skipped (testcontainers, both backends).
Docs: datajoint/datajoint-docs#301 (
configure-database.md,deploy-production.md,reference/configuration.md), to land with the release.