Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. from __future__ import unicode_literals
  2. from django.db import migrations
  3.  
  4. def load_sql(apps, schema_editor):
  5.  
  6. from os.path import normpath, dirname, isfile, join
  7. from os import listdir
  8.  
  9. sql_folder_path = '/backoffice/sql/'
  10.  
  11. def load_raw_sql(folder_inside):
  12. folder_path = join(sql_folder_path, folder_inside)
  13. sql_files = [join(folder_path, f) for f in listdir(folder_path) if isfile(join(folder_path, f))]
  14. for sql_file in sql_files:
  15. with open(sql_file, 'r') as g:
  16. migrations.RunSQL(g.read())
  17.  
  18. folders = ['functions', 'index', 'triggers']
  19.  
  20. for folder in folders:
  21. load_raw_sql(folder)
  22.  
  23.  
  24. class Migration(migrations.Migration):
  25. dependencies = [
  26. ('app1', '0001_squashed_0018_auto_20150616_0708'),
  27. ]
  28.  
  29. operations = [
  30. migrations.RunPython(load_sql),
  31. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement