Skip to content

Honor GEONODE_DATABASE_SCHEMA when initializing the database#14002

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-database-schema-issue
Draft

Honor GEONODE_DATABASE_SCHEMA when initializing the database#14002
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-database-schema-issue

Conversation

Copy link

Copilot AI commented Feb 27, 2026

GEONODE_DATABASE_SCHEMA and GEONODE_GEODATABASE_SCHEMA were defined in .env files but never consumed — all database objects always landed in the public schema regardless of configuration.

Changes

geonode/settings.py

  • Reads GEONODE_DATABASE_SCHEMA / GEONODE_GEODATABASE_SCHEMA (default: "public") and injects them as PostgreSQL search_path via OPTIONS["options"]
  • Fixes a pre-existing bug where the geodatastore OPTIONS dict was shared by reference with the default database, causing schema settings to silently overwrite each other
# Non-public schema produces:
_db_conf["OPTIONS"]["options"] = "-c search_path=my_schema,public"

geonode/utils.py

  • Adds get_db_schema(db_settings) — extracts the active schema from a Django DATABASES entry by reading search_path from OPTIONS["options"]

geonode/base/apps.py

  • Connects create_geonode_db_schema() to the pre_migrate signal so the configured schema is created (CREATE SCHEMA IF NOT EXISTS) before Django applies migrations
  • Validates the schema name against ^[A-Za-z_][A-Za-z0-9_$]*$ before interpolating into SQL

geonode/br/ (backup/restore)

  • get_tables, truncate_tables, dump_db, remove_existing_tables now accept a db_schema parameter (default "public") instead of hardcoding 'public'
  • backup.py and restore.py pass get_db_schema(datastore) / get_db_schema(settings.DATABASES["default"]) at call sites
Original prompt

This section details on the original issue you should resolve

<issue_title>GEONODE_DATABASE_SCHEMA isn't taken into account when creating the database</issue_title>
<issue_description>## Expected Behavior
Expecting the schema to be the one defined in the env file and not 'public'

Actual Behavior

It remains unchanged

Steps to Reproduce the Problem

  1. Assign a new schema with GEONODE_DATABASE_SCHEMA
  2. build and start docker
  3. check out the postgresql db structure

Specifications

  • GeoNode version: 5
  • Installation type (vanilla, geonode-project): geonode-project
  • Installation method (manual, docker): docker
  • Platform: Redhat 9
  • Additional details:

I added the schema at the end of the database URL instead but it creates more issues down the line where some tables aren't correctly created.
</issue_description>

<agent_instructions>some investigation already done on

https://github.com/geosolutions-it/geonode-team-internal-issues/agents/pull/231?session_id=132dae81-0334-44c0-80e8-88c00a4a0d0d</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@giohappy @lobenichou you raised a good point, also considering that usage of the `PUBLIC` schema should be avoided in recent PG versions. We are analysing the effort to refactor the configuration of the schema, and I confirm that the `GEONODE_DATABASE_SCHEMA` variable is currently not taken into account.

We haven't scheduled the activity yet. If you can contribute please let us know.</comment_new>


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI assigned Copilot and etj Feb 27, 2026
@cla-bot
Copy link

cla-bot bot commented Feb 27, 2026

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have the users @copilot on file. In order for us to review and merge your code, please contact the project maintainers to get yourself added.

…tilities

Co-authored-by: etj <717359+etj@users.noreply.github.com>
@cla-bot
Copy link

cla-bot bot commented Feb 27, 2026

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have the users @copilot on file. In order for us to review and merge your code, please contact the project maintainers to get yourself added.

Copilot AI changed the title [WIP] Fix GEONODE_DATABASE_SCHEMA not applied during database creation Honor GEONODE_DATABASE_SCHEMA when initializing the database Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GEONODE_DATABASE_SCHEMA isn't taken into account when creating the database

2 participants