Configuration¶
CodegenDatabaseConfig is the central object for
project-wide codegen_database settings. Create one per project and pass it to
every factory and to configure_metadata().
Creating a config¶
from codegen_database.config import CodegenDatabaseConfig
config = CodegenDatabaseConfig()
Fields¶
plugins¶
A list of Plugin instances that are prepended
to every factory’s plugin list. Use register()
to add plugins after construction:
config.register(TimestampPlugin(), TenantPlugin())
# or at construction time
config = CodegenDatabaseConfig(plugins=[TimestampPlugin(), TenantPlugin()])
See Plugin architecture for details on plugin resolution order.
extensions¶
A list of CodegenDatabaseExtension instances.
Use use() to add extensions:
See Extension system for the full extension guide.
auto_discover¶
When True (the default), codegen_database discovers extensions registered
under the codegen_database.ext entry point group. Manually
registered extensions take precedence over discovered ones with the
same name.
Set to False to disable automatic discovery:
config = CodegenDatabaseConfig(auto_discover=False)
utility_schema¶
The PostgreSQL schema for codegen_database-managed shared objects. One
setting governs them all – the codegen_database_date_bin chart polyfill
(Chart extension) and the autogenerated_identifier_pointers
table that backs CodegenDatabaseAutogeneratedIdentifierColumn.
Defaults to "codegen_database".
Override this only if your project already uses a schema named
codegen_database:
config = CodegenDatabaseConfig(utility_schema="my_utils")
Methods¶
- CodegenDatabaseConfig.register(*plugins) CodegenDatabaseConfig¶
Add one or more plugins to the global plugin list. Returns
selffor chaining.
- CodegenDatabaseConfig.use(*extensions) CodegenDatabaseConfig¶
Register one or more extensions. Returns
selffor chaining.
- CodegenDatabaseConfig.all_plugins¶
Combined list of extension plugins followed by direct plugins. Extension plugins are prepended so they run first.
Typical project setup¶
A common pattern is to create one config module and import it wherever factories are defined:
# codegen_database_setup.py
from codegen_database.config import CodegenDatabaseConfig
from myapp.plugins import TimestampPlugin, TenantPlugin
codegen_database_cfg = CodegenDatabaseConfig()
codegen_database_cfg.register(TimestampPlugin(), TenantPlugin())
# models.py
from myapp.codegen_database_setup import codegen_database_cfg
from codegen_database.factory import CodegenDatabaseSimple
CodegenDatabaseSimple(
"users", "app", metadata, schema_items,
config=codegen_database_cfg,
)
# migrations/env.py
from codegen_database.alembic.register import configure_metadata
from myapp.codegen_database_setup import codegen_database_cfg
configure_metadata(
target_metadata, config=codegen_database_cfg,
)