From 9eb75081741e9673b36cb855bf27659137ceaaa4 Mon Sep 17 00:00:00 2001 From: hackzoho <91518395+hackzoho@users.noreply.github.com> Date: Sat, 2 Oct 2021 21:46:22 +0530 Subject: [PATCH] Oracle to h2DB migration in python --- src/chit_main_app/migrations/Oracle_h2.py | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/chit_main_app/migrations/Oracle_h2.py diff --git a/src/chit_main_app/migrations/Oracle_h2.py b/src/chit_main_app/migrations/Oracle_h2.py new file mode 100644 index 0000000..1faa105 --- /dev/null +++ b/src/chit_main_app/migrations/Oracle_h2.py @@ -0,0 +1,29 @@ +#file for oracle db migration +from __future__ import with_statement +from fabric.api import * +import os, sys, imp, re; +APP_ROOT = os.path.join(os.path.dirname(__file__), os.path.pardir) +sys.path += [APP_ROOT, os.path.join(APP_ROOT, 'lib')] +from support import config, get_db_handler + +def list(): + migrations = [ + file for file in os.listdir('.') + if re.match('\d{4}-\d{2}-\d{2}.*(py|sql)$', file) + ] + print('Migrations in descending order:') + print('') + for migration in sorted(migrations)[::-1]: + print(' - %s' % migration) + +def migrate(migration): + filepath, extension = os.path.splitext(migration) + if extension == '.py': + migration = load_source('migration', os.path.join(APP_ROOT, 'migrations', migration)) + migration.migrate(get_db_handler(config['db'])) + elif extension == '.sql': + local('mysql -u root -p %s < %s' % ( + config.db.database, + os.path.join(APP_ROOT, 'migrations', migration) + ) + )