def do_MIGRATE(self, domain): if self.finish: assert not self.live_migrate, "--live and --finish are mutually exclusive" elif not self.live_migrate: status = get_couch_sql_migration_status(domain) if status == MigrationStatus.DRY_RUN: log.info( "Continuing live migration. Use --finish to complete.") self.live_migrate = True set_couch_sql_migration_started(domain, self.live_migrate) do_couch_to_sql_migration( domain, self.state_dir, with_progress=not self.no_input, live_migrate=self.live_migrate, diff_process=CASE_DIFF[self.case_diff], rebuild_state=self.rebuild_state, stop_on_error=self.stop_on_error, forms=self.forms, ) return_code = 0 if self.live_migrate: print("Live migration completed.") has_diffs = True else: has_diffs = self.print_stats(domain, short=True, diffs_only=True) return_code = int(has_diffs) if has_diffs: print("\nRun `diff` or `stats [--verbose]` for more details.\n") if return_code: sys.exit(return_code)
def do_MIGRATE(self, domain): if self.finish: assert not self.live_migrate, "--live and --finish are mutually exclusive" elif not self.live_migrate: status = get_couch_sql_migration_status(domain) if status == MigrationStatus.DRY_RUN: log.info( "Continuing live migration. Use --finish to complete.") self.live_migrate = True if self.missing_docs == CACHED: self.missing_docs = RESUME if self.forms: if not couch_sql_migration_in_progress(domain): log.error("cannot migrate specific forms: migration is %s", get_couch_sql_migration_status(domain)) sys.exit(1) else: set_couch_sql_migration_started(domain, self.live_migrate) do_couch_to_sql_migration( domain, self.state_dir, with_progress=not self.no_input, live_migrate=self.live_migrate, case_diff=self.case_diff, rebuild_state=self.rebuild_state, stop_on_error=self.stop_on_error, forms=self.forms, ) has_diffs = self.print_stats(domain, short=True, diffs_only=True) if self.live_migrate: print("Live migration completed.") if has_diffs: print("\nRun `diff` or `stats [--verbose]` for more details.\n") sys.exit(1)
def migrate_domain(self, domain): if should_use_sql_backend(domain): self.stderr.write("{} already on the SQL backend".format(domain)) return True, None if couch_sql_migration_in_progress(domain, include_dry_runs=True): self.stderr.write( "{} migration is already in progress".format(domain)) return False, "in progress" set_couch_sql_migration_started(domain) do_couch_to_sql_migration(domain, with_progress=False, debug=False) stats = self.get_diff_stats(domain) if stats: self.stderr.write( "Migration has diffs, aborting for domain {}".format(domain)) self.abort(domain) writer = SimpleTableWriter(self.stdout, TableRowFormatter([50, 10, 10, 10, 10])) writer.write_table([ 'Doc Type', '# Couch', '# SQL', '# Diffs', '# Docs with Diffs' ], [(doc_type, ) + stat for doc_type, stat in stats.items()]) return False, "has diffs" assert couch_sql_migration_in_progress(domain) set_couch_sql_migration_complete(domain) self.stdout.write(shell_green("Domain migrated: {}".format(domain))) return True, None
def migrate_domain(self, domain): if should_use_sql_backend(domain): self.stderr.write("{} already on the SQL backend".format(domain)) return set_couch_sql_migration_started(domain) with SignalHandlerContext([signal.SIGTERM, signal.SIGINT], _get_sigterm_handler(domain)): do_couch_to_sql_migration(domain, with_progress=False, debug=False) stats = self.get_diff_stats(domain) if stats: self.stderr.write( "Migration has diffs, aborting for domain {}".format(domain)) self.abort(domain) writer = SimpleTableWriter(self.stdout, TableRowFormatter([50, 10, 10, 10, 10])) writer.write_table([ 'Doc Type', '# Couch', '# SQL', '# Diffs', '# Docs with Diffs' ], [(doc_type, ) + stat for doc_type, stat in stats.items()]) else: assert couch_sql_migration_in_progress(domain) set_couch_sql_migration_complete(domain) self.stdout.write(shell_green( "Domain migrated: {}".format(domain)))
def migrate_domain(self, domain): if should_use_sql_backend(domain): self.stderr.write("{} already on the SQL backend".format(domain)) return True, None if couch_sql_migration_in_progress(domain, include_dry_runs=True): self.stderr.write("{} migration is already in progress".format(domain)) return False, "in progress" set_couch_sql_migration_started(domain) do_couch_to_sql_migration(domain, with_progress=False, debug=False) stats = self.get_diff_stats(domain) if stats: self.stderr.write("Migration has diffs, aborting for domain {}".format(domain)) self.abort(domain) writer = SimpleTableWriter(self.stdout, TableRowFormatter([50, 10, 10, 10, 10])) writer.write_table(['Doc Type', '# Couch', '# SQL', '# Diffs', '# Docs with Diffs'], [ (doc_type,) + stat for doc_type, stat in stats.items() ]) return False, "has diffs" assert couch_sql_migration_in_progress(domain) set_couch_sql_migration_complete(domain) self.stdout.write(shell_green("Domain migrated: {}".format(domain))) return True, None
def do_MIGRATE(self, domain): set_couch_sql_migration_started(domain, self.dry_run) do_couch_to_sql_migration(domain, with_progress=not self.no_input) has_diffs = self.print_stats(domain, short=True, diffs_only=True) if has_diffs: print("\nRun `diff` or `stats --verbose` for more details.\n")
def handle(self, domain, **options): if should_use_sql_backend(domain): raise CommandError('It looks like {} has already been migrated.'.format(domain)) self.no_input = options.pop('no_input', False) self.debug = options.pop('debug', False) self.dry_run = options.pop('dry_run', False) if self.no_input and not settings.UNIT_TESTING: raise CommandError('no-input only allowed for unit testing') setup_logging(options['log_dir']) if options['MIGRATE']: self.require_only_option('MIGRATE', options) if options.get('run_timestamp'): if not couch_sql_migration_in_progress(domain): raise CommandError("Migration must be in progress if run_timestamp is passed in") else: set_couch_sql_migration_started(domain, self.dry_run) do_couch_to_sql_migration( domain, with_progress=not self.no_input, debug=self.debug, run_timestamp=options.get('run_timestamp')) has_diffs = self.print_stats(domain, short=True, diffs_only=True) if has_diffs: print("\nUse '--stats-short', '--stats-long', '--show-diffs' to see more info.\n") if options['blow_away']: self.require_only_option('blow_away', options) if not self.no_input: _confirm( "This will delete all SQL forms and cases for the domain {}. " "Are you sure you want to continue?".format(domain) ) set_couch_sql_migration_not_started(domain) blow_away_migration(domain) if options['stats_short'] or options['stats_long']: self.print_stats(domain, short=options['stats_short']) if options['show_diffs']: self.show_diffs(domain) if options['COMMIT']: self.require_only_option('COMMIT', options) if not couch_sql_migration_in_progress(domain, include_dry_runs=False): raise CommandError("cannot commit a migration that is not in state in_progress") if not self.no_input: _confirm( "This will convert the domain to use the SQL backend and" "allow new form submissions to be processed. " "Are you sure you want to do this for domain '{}'?".format(domain) ) set_couch_sql_migration_complete(domain)
def handle_label(self, domain, **options): if should_use_sql_backend(domain): raise CommandError( u'It looks like {} has already been migrated.'.format(domain)) self.no_input = options.pop('no_input', False) self.debug = options.pop('debug', False) if self.no_input and not settings.UNIT_TESTING: raise CommandError('no-input only allowed for unit testing') if options['MIGRATE']: self.require_only_option('MIGRATE', options) set_couch_sql_migration_started(domain) do_couch_to_sql_migration(domain, with_progress=not self.no_input, debug=self.debug) has_diffs = self.print_stats(domain, short=True, diffs_only=True) if has_diffs: print "\nUse '--stats-short', '--stats-long', '--show-diffs' to see more info.\n" if options['blow_away']: self.require_only_option('blow_away', options) if not self.no_input: _confirm( "This will delete all SQL forms and cases for the domain {}. " "Are you sure you want to continue?".format(domain)) set_couch_sql_migration_not_started(domain) _blow_away_migration(domain) if options['stats_short'] or options['stats_long']: self.print_stats(domain, short=options['stats_short']) if options['show_diffs']: self.show_diffs(domain) if options['COMMIT']: self.require_only_option('COMMIT', options) assert couch_sql_migration_in_progress(domain) if not self.no_input: _confirm( "This will allow convert the domain to use the SQL backend and" "allow new form submissions to be processed. " "Are you sure you want to do this for domain '{}'?".format( domain)) set_couch_sql_migration_complete(domain)
def handle_label(self, domain, **options): if should_use_sql_backend(domain): raise CommandError(u'It looks like {} has already been migrated.'.format(domain)) self.no_input = options.pop('no_input', False) self.debug = options.pop('debug', False) if self.no_input and not settings.UNIT_TESTING: raise CommandError('no-input only allowed for unit testing') if options['MIGRATE']: self.require_only_option('MIGRATE', options) set_couch_sql_migration_started(domain) do_couch_to_sql_migration(domain, with_progress=not self.no_input, debug=self.debug) has_diffs = self.print_stats(domain, short=True, diffs_only=True) if has_diffs: print "\nUse '--stats-short', '--stats-long', '--show-diffs' to see more info.\n" if options['blow_away']: self.require_only_option('blow_away', options) if not self.no_input: _confirm( "This will delete all SQL forms and cases for the domain {}. " "Are you sure you want to continue?".format(domain) ) set_couch_sql_migration_not_started(domain) _blow_away_migration(domain) if options['stats_short'] or options['stats_long']: self.print_stats(domain, short=options['stats_short']) if options['show_diffs']: self.show_diffs(domain) if options['COMMIT']: self.require_only_option('COMMIT', options) assert couch_sql_migration_in_progress(domain) if not self.no_input: _confirm( "This will allow convert the domain to use the SQL backend and" "allow new form submissions to be processed. " "Are you sure you want to do this for domain '{}'?".format(domain) ) set_couch_sql_migration_complete(domain)
def do_MIGRATE(self, domain): set_couch_sql_migration_started(domain, self.live_migrate) do_couch_to_sql_migration( domain, self.state_dir, with_progress=not self.no_input, live_migrate=self.live_migrate, diff_process=self.diff_process, rebuild_state=self.rebuild_state, ) return_code = 0 if self.live_migrate: print("Live migration completed.") has_diffs = True else: has_diffs = self.print_stats(domain, short=True, diffs_only=True) return_code = int(has_diffs) if has_diffs: print("\nRun `diff` or `stats [--verbose]` for more details.\n") if return_code: sys.exit(return_code)