Skip to content

Instantly share code, notes, and snippets.

@kirillsulim
Created March 20, 2025 11:22
Show Gist options
  • Save kirillsulim/3ea9821d1b85b874c593045463bd1e66 to your computer and use it in GitHub Desktop.
Save kirillsulim/3ea9821d1b85b874c593045463bd1e66 to your computer and use it in GitHub Desktop.
Shift leading number for sql migration files
from pathlib import Path
start = 3
gap = 1
for p in sorted(Path().glob("*.sql"), key=lambda p: p.name, reverse=True):
s = p.name.split("_", maxsplit=1)
num = int(s[0])
name = s[1]
if num < start:
continue
else:
num = num + gap
new_name = f"{str(num).zfill(4)}_{name}"
print(f"{p.name} -> {new_name}")
p.rename(new_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment