Skip to content

Commit aff6657

Browse files
committed
Chore: fail if >1 migration scripts start with the same version
1 parent 9b04f45 commit aff6657

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@ repos:
2323
files: *files
2424
require_serial: true
2525
exclude: ^(tests/fixtures)
26+
- id: check-migration-duplicates
27+
name: Check migration duplicates
28+
language: script
29+
entry: ./scripts/check_migration_duplicates.sh
30+
files: ^sqlmesh/migrations/v\d{4}_.*\.py$
31+
pass_filenames: false
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
# Check for duplicate migration version numbers in SQLMesh
3+
4+
# Extract version numbers from migration files and check for duplicates
5+
duplicates=$(ls sqlmesh/migrations/v[0-9][0-9][0-9][0-9]_*.py 2>/dev/null | \
6+
sed 's/.*\/v\([0-9]\{4\}\)_.*/\1/' | \
7+
sort | uniq -d)
8+
9+
if [ -n "$duplicates" ]; then
10+
echo "Error: Duplicate migration version(s) found:" >&2
11+
for version in $duplicates; do
12+
echo " Version v$version appears in:" >&2
13+
ls sqlmesh/migrations/v${version}_*.py | sed 's/^/ - /' >&2
14+
done
15+
exit 1
16+
fi
17+
18+
exit 0

0 commit comments

Comments
 (0)