_extract_schema.py 865 B

123456789101112131415161718192021222324
  1. import re
  2. with open('e:/Base/sj/sj.sql', 'r', encoding='utf-8') as f:
  3. content = f.read()
  4. tables = [
  5. 'main_post_candidate_review',
  6. 'main_student_education',
  7. 'main_student_experience',
  8. 'main_back_interview',
  9. ]
  10. with open('_schema_out.txt', 'w', encoding='utf-8') as fout:
  11. for table in tables:
  12. match = re.search(r'CREATE TABLE `' + table + r'`\s*\((.*?)\)\s*ENGINE', content, re.DOTALL | re.IGNORECASE)
  13. if match:
  14. fout.write(f"=== {table} ===\n")
  15. lines = match.group(1).strip().split('\n')
  16. for line in lines:
  17. line = line.strip()
  18. if line and not line.startswith('PRIMARY KEY') and not line.startswith('KEY') and not line.startswith('UNIQUE KEY'):
  19. fout.write(line + "\n")
  20. else:
  21. fout.write(f"=== {table} NOT FOUND ===\n")