Skip to content

Instantly share code, notes, and snippets.

@Omar-Gonzalez
Last active June 26, 2017 14:41
Show Gist options
  • Save Omar-Gonzalez/342066cb50fe34834a215b4f87fb27e1 to your computer and use it in GitHub Desktop.
Save Omar-Gonzalez/342066cb50fe34834a215b4f87fb27e1 to your computer and use it in GitHub Desktop.
Merge all sql files in a directory into a single migration file
# -*- coding: UTF-8 -*-
import os
path = os.getcwd()
def build_query(path):
migration = '/* Eeasy Migration Tool - Write all the querys */ \n'
files = ""
for path, subdirs, files in os.walk(path):
for file in files:
if file.endswith('.sql') and file is not path+'easy_migration.sql':
sql_file = os.path.join(path, file)
migration += '\n /* Source: ' + sql_file + " */ \n\n"
migration += open(sql_file).read() + '\n'
migration += '\n /* Consider yourself migrated (⌐■_■) */'
return migration
try:
migration = open('easy_migration.sql', 'w')
migration.write(build_query(path))
migration.close()
print('ᕦ(ò_óˇ)ᕤ easy-migration.sql was created successfully')
except:
print('(>人<) Ooops, there\'s something wrong')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment