43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
import os
|
|
import re
|
|
|
|
schema_path = 'database/schema/mysql-schema.sql'
|
|
with open(schema_path, 'r') as f:
|
|
schema_content = f.read()
|
|
|
|
# Find all tables created in the schema dump
|
|
schema_tables = set(re.findall(r'CREATE TABLE `([^`]+)`', schema_content))
|
|
print("Tables in schema dump:", len(schema_tables))
|
|
|
|
# Scan all migrations <= 2026_03_10
|
|
migrations = []
|
|
backdated_migrations = []
|
|
|
|
for f in sorted(os.listdir('database/migrations')):
|
|
if f.endswith('.php'):
|
|
m = re.match(r'^(\d{4}_\d{2}_\d{2}_\d{6})_(.+)\.php$', f)
|
|
if m:
|
|
timestamp = m.group(1)
|
|
name = f[:-4]
|
|
if timestamp <= '2026_03_10_235959':
|
|
# Check if it creates any table
|
|
with open(os.path.join('database/migrations', f), 'r') as mf:
|
|
content = mf.read()
|
|
|
|
created_tables = re.findall(r"Schema::create\s*\(\s*['\"]([^'\"]+)['\"]", content)
|
|
|
|
# If it creates a table that is NOT in the schema dump, it is backdated/missing!
|
|
is_missing = False
|
|
for t in created_tables:
|
|
if t not in schema_tables:
|
|
is_missing = True
|
|
print(f"Migration {name} creates table '{t}' which is NOT in schema dump!")
|
|
|
|
if is_missing:
|
|
backdated_migrations.append(name)
|
|
else:
|
|
migrations.append(name)
|
|
|
|
print("\nRegular migrations to mark completed:", len(migrations))
|
|
print("Backdated migrations to execute:", len(backdated_migrations))
|