mirror of
https://github.com/yweber/lodel2.git
synced 2026-11-18 00:51:38 +01:00
Add settings.py with default value, add migration_handler options + modify migration_handler to handle settings
This commit is contained in:
parent
c7756f5ea2
commit
8133e6c45b
4 changed files with 28 additions and 20 deletions
|
|
@ -44,7 +44,7 @@ class MysqlMigrationHandler(DummyMigrationHandler):
|
|||
## @brief Construct a MysqlMigrationHandler
|
||||
# @param module : sql module
|
||||
# @param conn_args dict : A dict containing connection options
|
||||
def __init__(self, module=pymysql, conn_args=None, db_engine='InnoDB', foreign_keys=True, debug=None, dryrun=False, drop_if_exists=False):
|
||||
def __init__(self, module=pymysql, conn_args=None, db_engine='InnoDB', **kwargs):
|
||||
# Database connection
|
||||
self._dbmodule = module
|
||||
if conn_args is None:
|
||||
|
|
@ -53,11 +53,12 @@ class MysqlMigrationHandler(DummyMigrationHandler):
|
|||
del conn_args['module']
|
||||
self.db_conn = self._dbmodule.connect(**conn_args)
|
||||
# Fetch options
|
||||
self.debug = Settings.get('debug') if debug is None else debug
|
||||
self.dryrun = dryrun
|
||||
mh_settings = Settings.migration_options
|
||||
self.debug = kwargs['debug'] if 'debug' in kwargs else Settings.debug
|
||||
self.dryrun = kwargs['dryrun'] if 'dryrun' in kwargs else mh_settings['dryrun']
|
||||
self.foreign_keys = kwargs['foreign_keys'] if 'foreign_keys' in kwargs else mh_settings['foreign_keys']
|
||||
self.drop_if_exists = kwargs['drop_if_exists'] if 'drop_if_exists' in kwargs else mh_settings['drop_if_exists']
|
||||
self.db_engine = db_engine
|
||||
self.foreign_keys = foreign_keys if db_engine == 'InnoDB' else False
|
||||
self.drop_if_exists = drop_if_exists
|
||||
#Create default tables
|
||||
self._create_default_tables(self.drop_if_exists)
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ MANDATORY = [
|
|||
'ds_package',
|
||||
'datasource',
|
||||
'mh_classname',
|
||||
'migration_options',
|
||||
]
|
||||
|
||||
ALLOWED = []
|
||||
|
|
|
|||
21
settings.py
Normal file
21
settings.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#-*- coding:utf8 -*-
|
||||
|
||||
import pymysql
|
||||
|
||||
debug = False
|
||||
|
||||
datasource = {
|
||||
'default': {
|
||||
'module':pymysql,
|
||||
'host': None,
|
||||
'user': None,
|
||||
'passwd': None,
|
||||
'db': None,
|
||||
}
|
||||
}
|
||||
|
||||
migration_options = {
|
||||
'dryrun': False,
|
||||
'foreign_keys': True,
|
||||
'drop_if_exists': False,
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
#-*- coding:utf8 -*-
|
||||
|
||||
import pymysql
|
||||
import os
|
||||
|
||||
base_path = os.path.dirname(os.path.abspath(__file__))
|
||||
datasource = {
|
||||
'default': {
|
||||
'module': pymysql,
|
||||
'host': '127.0.0.1',
|
||||
'user': 'lodel',
|
||||
'passwd': 'lodel',
|
||||
'db': 'lodel'
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue