Schema¶
Schema is the registry helper that performs database-schema operations such as
creating and dropping schemas.
It matters most in multi-schema and multi-tenant deployments where the application needs to provision or tear down schema-scoped tables explicitly.
Typical use¶
Most application code reaches Schema through the registry:
await models.schema.create_schema("tenant_a", if_not_exists=True)
await models.schema.drop_schema("tenant_a", cascade=True, if_exists=True)
Important distinction¶
This helper manages database schemas, not Saffier model field schemas or JSON schemas.
saffier.core.connection.schemas.Schema
¶
Schema(registry)
Schema management helper bound to a registry.
The object centralizes low-level schema creation, teardown, and schema-path switching so the registry can reuse the same logic for migrations, tenancy, and table-creation helpers.
Source code in saffier/core/connection/schemas.py
22 23 | |
get_default_schema
¶
get_default_schema()
Return the database dialect's default schema name.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
str | None: Default schema reported by the active dialect. |
Source code in saffier/core/connection/schemas.py
29 30 31 32 33 34 35 36 37 | |
activate_schema_path
async
¶
activate_schema_path(database, schema, is_shared=True)
Source code in saffier/core/connection/schemas.py
39 40 41 42 43 44 45 46 47 48 | |
create_schema
async
¶
create_schema(
schema,
if_not_exists=False,
init_models=False,
init_tenant_models=False,
update_cache=True,
databases=(None,),
)
Create a schema and optionally create model tables inside it.
| PARAMETER | DESCRIPTION |
|---|---|
schema
|
Schema name to create.
TYPE:
|
if_not_exists
|
Whether schema and table creation should be idempotent.
TYPE:
|
init_models
|
Whether registered model tables should be created after the schema exists.
TYPE:
|
init_tenant_models
|
Reserved for backward compatibility.
TYPE:
|
update_cache
|
Whether schema-specific table caches should be refreshed when building tables.
TYPE:
|
databases
|
Database aliases that should receive the operation.
TYPE:
|
Source code in saffier/core/connection/schemas.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
drop_schema
async
¶
drop_schema(
schema,
cascade=False,
if_exists=False,
databases=(None,),
)
Drop a schema or all tables from the selected databases.
| PARAMETER | DESCRIPTION |
|---|---|
schema
|
Schema name to drop, or
TYPE:
|
cascade
|
Whether the schema drop should cascade.
TYPE:
|
if_exists
|
Whether missing schema/table objects should be ignored.
TYPE:
|
databases
|
Database aliases that should receive the operation.
TYPE:
|
Source code in saffier/core/connection/schemas.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
_execute_create_schema
¶
_execute_create_schema(
connection,
schema,
if_not_exists,
schema_tables_by_metadata,
init_models,
)
Source code in saffier/core/connection/schemas.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
_execute_drop_schema
¶
_execute_drop_schema(
connection, database_name, schema, cascade, if_exists
)
Source code in saffier/core/connection/schemas.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |