Skip to content

Commit f256c5b

Browse files
committed
Simplify
1 parent df69cff commit f256c5b

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

backend/alembic/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ For multi-tenant deployments, you can use additional options:
3030
alembic -x upgrade_all_tenants=true upgrade head
3131
```
3232

33-
**Upgrade a specific tenant schema:**
33+
**Upgrade specific schemas:**
3434
```bash
35-
alembic -x schema=tenant_12345678-1234-1234-1234-123456789012 upgrade head
35+
# Single schema
36+
alembic -x schemas=tenant_12345678-1234-1234-1234-123456789012 upgrade head
37+
38+
# Multiple schemas (comma-separated)
39+
alembic -x schemas=tenant_12345678-1234-1234-1234-123456789012,public,another_tenant upgrade head
3640
```
3741

3842
**Upgrade tenants within an alphabetical range:**

backend/alembic/env.py

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -168,34 +168,32 @@ def get_schema_options() -> (
168168
)
169169

170170
# Specific schema names filtering (replaces both schema_name and the old tenant_ids approach)
171-
specific_schema_names = None
172-
if "specific_schema_names" in x_args:
173-
schema_names_str = x_args["specific_schema_names"].strip()
171+
schemas = None
172+
if "schemas" in x_args:
173+
schema_names_str = x_args["schemas"].strip()
174174
if schema_names_str:
175175
# Split by comma and strip whitespace
176-
specific_schema_names = [
176+
schemas = [
177177
name.strip() for name in schema_names_str.split(",") if name.strip()
178178
]
179-
if specific_schema_names:
180-
logger.info(f"Specific schema names specified: {specific_schema_names}")
179+
if schemas:
180+
logger.info(f"Specific schema names specified: {schemas}")
181181

182182
# Validate that only one method is used at a time
183183
range_filtering = tenant_range_start is not None or tenant_range_end is not None
184-
specific_filtering = (
185-
specific_schema_names is not None and len(specific_schema_names) > 0
186-
)
184+
specific_filtering = schemas is not None and len(schemas) > 0
187185

188186
if range_filtering and specific_filtering:
189187
raise ValueError(
190188
"Cannot use both tenant range filtering (tenant_range_start/tenant_range_end) "
191-
"and specific schema filtering (specific_schema_names) at the same time. "
189+
"and specific schema filtering (schemas) at the same time. "
192190
"Please use only one filtering method."
193191
)
194192

195193
if upgrade_all_tenants and specific_filtering:
196194
raise ValueError(
197-
"Cannot use both upgrade_all_tenants=true and specific_schema_names at the same time. "
198-
"Use either upgrade_all_tenants=true for all tenants, or specific_schema_names for specific schemas."
195+
"Cannot use both upgrade_all_tenants=true and schemas at the same time. "
196+
"Use either upgrade_all_tenants=true for all tenants, or schemas for specific schemas."
199197
)
200198

201199
# If any filtering parameters are specified, we're not doing the default single schema migration
@@ -206,7 +204,7 @@ def get_schema_options() -> (
206204
if MULTI_TENANT and not upgrade_all_tenants and not specific_filtering:
207205
raise ValueError(
208206
"In multi-tenant mode, you must specify either upgrade_all_tenants=true "
209-
"or provide specific_schema_names. Cannot run default migration."
207+
"or provide schemas. Cannot run default migration."
210208
)
211209

212210
return (
@@ -215,7 +213,7 @@ def get_schema_options() -> (
215213
continue_on_error,
216214
tenant_range_start,
217215
tenant_range_end,
218-
specific_schema_names,
216+
schemas,
219217
)
220218

221219

@@ -268,7 +266,7 @@ async def run_async_migrations() -> None:
268266
continue_on_error,
269267
tenant_range_start,
270268
tenant_range_end,
271-
specific_schema_names,
269+
schemas,
272270
) = get_schema_options()
273271

274272
# without init_engine, subsequent engine calls fail hard intentionally
@@ -287,13 +285,13 @@ def event_provide_iam_token_for_alembic(
287285
) -> None:
288286
provide_iam_token_for_alembic(dialect, conn_rec, cargs, cparams)
289287

290-
if specific_schema_names:
288+
if schemas:
291289
# Use specific schema names directly without fetching all tenants
292-
logger.info(f"Migrating specific schema names: {specific_schema_names}")
290+
logger.info(f"Migrating specific schema names: {schemas}")
293291

294292
i_schema = 0
295-
num_schemas = len(specific_schema_names)
296-
for schema in specific_schema_names:
293+
num_schemas = len(schemas)
294+
for schema in schemas:
297295
i_schema += 1
298296
logger.info(
299297
f"Migrating schema: index={i_schema} num_schemas={num_schemas} schema={schema}"
@@ -352,11 +350,11 @@ def event_provide_iam_token_for_alembic(
352350

353351
else:
354352
# This should not happen in the new design since we require either
355-
# upgrade_all_tenants=true or specific_schema_names in multi-tenant mode
356-
# and for non-multi-tenant mode, we should use specific_schema_names with the default schema
353+
# upgrade_all_tenants=true or schemas in multi-tenant mode
354+
# and for non-multi-tenant mode, we should use schemas with the default schema
357355
raise ValueError(
358356
"No migration target specified. Use either upgrade_all_tenants=true for all tenants "
359-
"or specific_schema_names for specific schemas."
357+
"or schemas for specific schemas."
360358
)
361359

362360
await engine.dispose()
@@ -384,15 +382,15 @@ def run_migrations_offline() -> None:
384382
continue_on_error,
385383
tenant_range_start,
386384
tenant_range_end,
387-
specific_schema_names,
385+
schemas,
388386
) = get_schema_options()
389387
url = build_connection_string()
390388

391-
if specific_schema_names:
389+
if schemas:
392390
# Use specific schema names directly without fetching all tenants
393-
logger.info(f"Migrating specific schema names: {specific_schema_names}")
391+
logger.info(f"Migrating specific schema names: {schemas}")
394392

395-
for schema in specific_schema_names:
393+
for schema in schemas:
396394
logger.info(f"Migrating schema: {schema}")
397395
context.configure(
398396
url=url,
@@ -453,7 +451,7 @@ def event_provide_iam_token_for_alembic_offline(
453451
# This should not happen in the new design
454452
raise ValueError(
455453
"No migration target specified. Use either upgrade_all_tenants=true for all tenants "
456-
"or specific_schema_names for specific schemas."
454+
"or schemas for specific schemas."
457455
)
458456

459457

0 commit comments

Comments
 (0)