Skip to content

Commit d752422

Browse files
abrookinsclaude
andcommitted
Apply final code formatting fixes
Fix line length and formatting issues caught by black linter. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent a3720fc commit d752422

File tree

3 files changed

+78
-46
lines changed

3 files changed

+78
-46
lines changed

aredis_om/model/cli/migrate.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ def run(
7575
)
7676

7777
if not os.path.exists(dir_path):
78-
if yes or click.confirm(
79-
f"Create schema migrations directory at '{dir_path}'?"
80-
):
78+
if yes or click.confirm(f"Create schema migrations directory at '{dir_path}'?"):
8179
os.makedirs(dir_path, exist_ok=True)
8280
else:
8381
click.echo("Aborted.")
@@ -119,9 +117,7 @@ def create(name: str, migrations_dir: Optional[str], yes: bool):
119117
)
120118

121119
if not os.path.exists(dir_path):
122-
if yes or click.confirm(
123-
f"Create schema migrations directory at '{dir_path}'?"
124-
):
120+
if yes or click.confirm(f"Create schema migrations directory at '{dir_path}'?"):
125121
os.makedirs(dir_path, exist_ok=True)
126122
else:
127123
click.echo("Aborted.")
@@ -161,9 +157,7 @@ def rollback(
161157
)
162158

163159
if not os.path.exists(dir_path):
164-
if yes or click.confirm(
165-
f"Create schema migrations directory at '{dir_path}'?"
166-
):
160+
if yes or click.confirm(f"Create schema migrations directory at '{dir_path}'?"):
167161
os.makedirs(dir_path, exist_ok=True)
168162
else:
169163
click.echo("Aborted.")
@@ -176,9 +170,9 @@ def rollback(
176170
click.echo("Aborted.")
177171
return
178172

179-
success = run_async(migrator.rollback(
180-
migration_id, dry_run=dry_run, verbose=verbose
181-
))
173+
success = run_async(
174+
migrator.rollback(migration_id, dry_run=dry_run, verbose=verbose)
175+
)
182176
if success:
183177
if verbose:
184178
click.echo(f"Successfully rolled back migration: {migration_id}")

aredis_om/model/cli/migrate_data.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,14 @@ def run(
137137
# Confirm unless --yes is specified
138138
if not yes:
139139
migration_list = "\n".join(f"- {m.migration_id}" for m in pending)
140-
if not click.confirm(
141-
f"Run {count_to_run} migration(s)?\n{migration_list}"
142-
):
140+
if not click.confirm(f"Run {count_to_run} migration(s)?\n{migration_list}"):
143141
click.echo("Aborted.")
144142
return
145143

146144
# Run migrations
147-
count = run_async(migrator.run_migrations(
148-
dry_run=False, limit=limit, verbose=verbose
149-
))
145+
count = run_async(
146+
migrator.run_migrations(dry_run=False, limit=limit, verbose=verbose)
147+
)
150148

151149
if verbose:
152150
click.echo(f"Successfully applied {count} migration(s).")
@@ -251,9 +249,9 @@ def rollback(
251249
return
252250

253251
# Attempt rollback
254-
success = run_async(migrator.rollback_migration(
255-
migration_id, dry_run=False, verbose=verbose
256-
))
252+
success = run_async(
253+
migrator.rollback_migration(migration_id, dry_run=False, verbose=verbose)
254+
)
257255

258256
if success:
259257
if verbose:

tests/test_schema_migrator.py

Lines changed: 65 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
def get_worker_id():
1616
"""Get pytest-xdist worker ID for test isolation."""
17-
return os.environ.get('PYTEST_XDIST_WORKER', 'main')
17+
return os.environ.get("PYTEST_XDIST_WORKER", "main")
1818

1919

2020
def get_worker_prefix():
@@ -30,11 +30,11 @@ def get_worker_prefix():
3030
async def clean_redis(redis):
3131
"""Provide a clean Redis instance for schema migration tests."""
3232
worker_prefix = get_worker_prefix()
33-
33+
3434
# Worker-specific Redis keys
3535
applied_migrations_key = f"redis_om:schema_applied_migrations:{worker_prefix}"
3636
schema_key_pattern = f"redis_om:schema:*:{worker_prefix}"
37-
37+
3838
# Cleanup before test
3939
await redis.delete(applied_migrations_key)
4040
keys = await redis.keys(schema_key_pattern)
@@ -79,7 +79,9 @@ async def test_create_migration_file_when_no_ops(redis, monkeypatch):
7979

8080
try:
8181
with tempfile.TemporaryDirectory() as tmp:
82-
migrator = _WorkerAwareSchemaMigrator(redis_client=redis, migrations_dir=tmp)
82+
migrator = _WorkerAwareSchemaMigrator(
83+
redis_client=redis, migrations_dir=tmp
84+
)
8385
fp = await migrator.create_migration_file("noop")
8486
assert fp is None
8587
finally:
@@ -90,7 +92,9 @@ async def test_create_migration_file_when_no_ops(redis, monkeypatch):
9092

9193
async def test_create_and_status_empty(clean_redis):
9294
with tempfile.TemporaryDirectory() as tmp:
93-
migrator = _WorkerAwareSchemaMigrator(redis_client=clean_redis, migrations_dir=tmp)
95+
migrator = _WorkerAwareSchemaMigrator(
96+
redis_client=clean_redis, migrations_dir=tmp
97+
)
9498
status = await migrator.status()
9599
assert status["total_migrations"] == 0
96100
assert status["applied_count"] == 0
@@ -107,13 +111,15 @@ async def test_rollback_noop(redis):
107111

108112
class _WorkerAwareSchemaMigrator(SchemaMigrator):
109113
"""SchemaMigrator that uses worker-specific Redis keys for test isolation."""
110-
114+
111115
def __init__(self, redis_client, migrations_dir):
112116
super().__init__(redis_client, migrations_dir)
113117
self.worker_prefix = get_worker_prefix()
114118
# Override the class constant with worker-specific key
115-
self.APPLIED_MIGRATIONS_KEY = f"redis_om:schema_applied_migrations:{self.worker_prefix}"
116-
119+
self.APPLIED_MIGRATIONS_KEY = (
120+
f"redis_om:schema_applied_migrations:{self.worker_prefix}"
121+
)
122+
117123
async def mark_unapplied(self, migration_id: str):
118124
"""Mark migration as unapplied using worker-specific key."""
119125
await self.redis.srem(self.APPLIED_MIGRATIONS_KEY, migration_id)
@@ -138,8 +144,12 @@ async def up(self) -> None:
138144
await self.redis.execute_command(f"FT.CREATE {index_name} {new_schema}")
139145
# Update tracking keys with worker isolation
140146
new_hash = hashlib.sha1(new_schema.encode("utf-8")).hexdigest()
141-
await self.redis.set(f"{schema_hash_key(index_name)}:{worker_prefix}", new_hash)
142-
await self.redis.set(f"{schema_text_key(index_name)}:{worker_prefix}", new_schema)
147+
await self.redis.set(
148+
f"{schema_hash_key(index_name)}:{worker_prefix}", new_hash
149+
)
150+
await self.redis.set(
151+
f"{schema_text_key(index_name)}:{worker_prefix}", new_schema
152+
)
143153

144154
async def down(self) -> None:
145155
"""Rollback the migration operations."""
@@ -156,8 +166,12 @@ async def down(self) -> None:
156166
f"FT.CREATE {index_name} {prev_schema}"
157167
)
158168
prev_hash = hashlib.sha1(prev_schema.encode("utf-8")).hexdigest()
159-
await self.redis.set(f"{schema_hash_key(index_name)}:{worker_prefix}", prev_hash)
160-
await self.redis.set(f"{schema_text_key(index_name)}:{worker_prefix}", prev_schema)
169+
await self.redis.set(
170+
f"{schema_hash_key(index_name)}:{worker_prefix}", prev_hash
171+
)
172+
await self.redis.set(
173+
f"{schema_text_key(index_name)}:{worker_prefix}", prev_schema
174+
)
161175

162176

163177
class _TestSchemaMigrationNoRollback(BaseSchemaMigration):
@@ -176,7 +190,9 @@ async def up(self) -> None:
176190
async def test_rollback_successful_single_operation(clean_redis):
177191
"""Test successful rollback of migration with single operation."""
178192
with tempfile.TemporaryDirectory() as tmp:
179-
migrator = _WorkerAwareSchemaMigrator(redis_client=clean_redis, migrations_dir=tmp)
193+
migrator = _WorkerAwareSchemaMigrator(
194+
redis_client=clean_redis, migrations_dir=tmp
195+
)
180196
redis = clean_redis
181197
worker_prefix = get_worker_prefix()
182198

@@ -189,7 +205,9 @@ async def test_rollback_successful_single_operation(clean_redis):
189205
await redis.execute_command(f"FT.CREATE {index_name} {original_schema}")
190206
original_hash = hashlib.sha1(original_schema.encode("utf-8")).hexdigest()
191207
await redis.set(f"{schema_hash_key(index_name)}:{worker_prefix}", original_hash)
192-
await redis.set(f"{schema_text_key(index_name)}:{worker_prefix}", original_schema)
208+
await redis.set(
209+
f"{schema_text_key(index_name)}:{worker_prefix}", original_schema
210+
)
193211

194212
# Create and apply migration
195213
migration = _TestSchemaMigration(
@@ -226,8 +244,12 @@ async def mock_discover():
226244
assert success is True
227245

228246
# Verify rollback restored original schema
229-
restored_hash = await redis.get(f"{schema_hash_key(index_name)}:{worker_prefix}")
230-
restored_text = await redis.get(f"{schema_text_key(index_name)}:{worker_prefix}")
247+
restored_hash = await redis.get(
248+
f"{schema_hash_key(index_name)}:{worker_prefix}"
249+
)
250+
restored_text = await redis.get(
251+
f"{schema_text_key(index_name)}:{worker_prefix}"
252+
)
231253
assert restored_hash == original_hash
232254
assert restored_text == original_schema
233255

@@ -314,9 +336,13 @@ async def test_rollback_multiple_operations(redis):
314336
hash1 = hashlib.sha1(original_schema1.encode("utf-8")).hexdigest()
315337
hash2 = hashlib.sha1(original_schema2.encode("utf-8")).hexdigest()
316338
await redis.set(f"{schema_hash_key(index1_name)}:{worker_prefix}", hash1)
317-
await redis.set(f"{schema_text_key(index1_name)}:{worker_prefix}", original_schema1)
339+
await redis.set(
340+
f"{schema_text_key(index1_name)}:{worker_prefix}", original_schema1
341+
)
318342
await redis.set(f"{schema_hash_key(index2_name)}:{worker_prefix}", hash2)
319-
await redis.set(f"{schema_text_key(index2_name)}:{worker_prefix}", original_schema2)
343+
await redis.set(
344+
f"{schema_text_key(index2_name)}:{worker_prefix}", original_schema2
345+
)
320346

321347
# Create migration with multiple operations
322348
migration = _TestSchemaMigration(
@@ -353,10 +379,18 @@ async def mock_discover():
353379
assert success is True
354380

355381
# Verify both indices were rolled back to original schemas
356-
restored_hash1 = await redis.get(f"{schema_hash_key(index1_name)}:{worker_prefix}")
357-
restored_text1 = await redis.get(f"{schema_text_key(index1_name)}:{worker_prefix}")
358-
restored_hash2 = await redis.get(f"{schema_hash_key(index2_name)}:{worker_prefix}")
359-
restored_text2 = await redis.get(f"{schema_text_key(index2_name)}:{worker_prefix}")
382+
restored_hash1 = await redis.get(
383+
f"{schema_hash_key(index1_name)}:{worker_prefix}"
384+
)
385+
restored_text1 = await redis.get(
386+
f"{schema_text_key(index1_name)}:{worker_prefix}"
387+
)
388+
restored_hash2 = await redis.get(
389+
f"{schema_hash_key(index2_name)}:{worker_prefix}"
390+
)
391+
restored_text2 = await redis.get(
392+
f"{schema_text_key(index2_name)}:{worker_prefix}"
393+
)
360394

361395
assert restored_hash1 == hash1
362396
assert restored_text1 == original_schema1
@@ -556,7 +590,9 @@ async def test_rollback_state_consistency(redis):
556590
await redis.execute_command(f"FT.CREATE {index_name} {original_schema}")
557591
original_hash = hashlib.sha1(original_schema.encode("utf-8")).hexdigest()
558592
await redis.set(f"{schema_hash_key(index_name)}:{worker_prefix}", original_hash)
559-
await redis.set(f"{schema_text_key(index_name)}:{worker_prefix}", original_schema)
593+
await redis.set(
594+
f"{schema_text_key(index_name)}:{worker_prefix}", original_schema
595+
)
560596

561597
migration = _TestSchemaMigration(
562598
migration_id="008_consistency_test",
@@ -593,8 +629,12 @@ async def mock_discover():
593629
assert success is True
594630

595631
# Verify complete state consistency after rollback
596-
restored_hash = await redis.get(f"{schema_hash_key(index_name)}:{worker_prefix}")
597-
restored_text = await redis.get(f"{schema_text_key(index_name)}:{worker_prefix}")
632+
restored_hash = await redis.get(
633+
f"{schema_hash_key(index_name)}:{worker_prefix}"
634+
)
635+
restored_text = await redis.get(
636+
f"{schema_text_key(index_name)}:{worker_prefix}"
637+
)
598638

599639
# Hash and text should match original exactly
600640
assert restored_hash == original_hash

0 commit comments

Comments
 (0)