Skip to content

Commit

Permalink
#50: Added '-i' or '--interactive' option to execute each migration a…
Browse files Browse the repository at this point in the history
…t once.
  • Loading branch information
guilhermechapiewski committed Oct 5, 2009
1 parent b9e92a6 commit aef5f9a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/__init__.py
Expand Up @@ -28,7 +28,13 @@ def run():
config.put('show_sql_only', options.show_sql_only)
config.put('new_migration', options.new_migration)
config.put('drop_db_first', options.drop_db_first)
config.put('log_level', int(options.log_level))
config.put('interactive_mode', options.interactive_mode)

log_level = int(options.log_level)
if options.interactive_mode:
log_level = 2

config.put('log_level', log_level)

# If CLI was correctly parsed, execute db-migrate.
Main(config).execute()
Expand Down
6 changes: 6 additions & 0 deletions src/cli.py
Expand Up @@ -81,6 +81,12 @@ def __config_parser(self):
default=1,
help="Log level: 0-no log; 1-migrations log; 2-statement execution log (default: %default)")

self.__parser.add_option("-i", "--interactive",
action="store_true",
dest="interactive_mode",
default=False,
help="Execute in interactive mode. In this mode you will need to press <enter> key in order to execute each SQL command, making it easier to see what is being executed and helping debug.")


def get_parser(self):
return self.__parser
Expand Down
11 changes: 9 additions & 2 deletions src/main.py
Expand Up @@ -103,8 +103,15 @@ def execute_migrations(self, current_version, destination_version, is_migration_
log = self.cli.msg

self.mysql.change(sql, migration_version, is_migration_up, execution_log=log)

#recording the last statement executed

# interactive mode
if self.config.get("interactive_mode"):
try:
raw_input("* press <enter> to continue... ")
except KeyboardInterrupt:
self.cli.info_and_exit("\nExecution interrupted by the user...")

# recording the last statement executed
sql_statements_executed.append(sql)

if self.config.get("show_sql") or self.config.get("show_sql_only"):
Expand Down

0 comments on commit aef5f9a

Please sign in to comment.