def handle(self, domain, action, **options): if should_use_sql_backend(domain): raise CommandError( 'It looks like {} has already been migrated.'.format(domain)) for opt in [ "no_input", "verbose", "state_dir", "live_migrate", "diff_process", "rebuild_state", ]: setattr(self, opt, options[opt]) if self.no_input and not settings.UNIT_TESTING: raise CommandError('--no-input only allowed for unit testing') if action != MIGRATE and self.live_migrate: raise CommandError("--live only allowed with `MIGRATE`") if action != MIGRATE and self.rebuild_state: raise CommandError("--rebuild-state only allowed with `MIGRATE`") if action != STATS and self.verbose: raise CommandError("--verbose only allowed for `stats`") assert Domain.get_by_name(domain), f'Unknown domain "{domain}"' slug = f"{action.lower()}-{domain}" setup_logging(self.state_dir, slug, options['debug']) getattr(self, "do_" + action)(domain)
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(self, domain, action, **options): if action != STATS and should_use_sql_backend(domain): raise CommandError( 'It looks like {} has already been migrated.'.format(domain)) if options["patch"]: if options["forms"]: raise CommandError( "--patch and --forms=... are mutually exclusive") if options["case_diff"] != "after": raise CommandError( "--patch and --case-diff=... are mutually exclusive") options["forms"] = "missing" options["case_diff"] = "patch" for opt in [ "no_input", "verbose", "state_dir", "live_migrate", "finish", "case_diff", "rebuild_state", "stop_on_error", "forms", "rewind", "missing_docs", ]: setattr(self, opt, options[opt]) if self.no_input and not settings.UNIT_TESTING: raise CommandError('--no-input only allowed for unit testing') if action != MIGRATE and self.live_migrate: raise CommandError(f"{action} --live not allowed") if action != MIGRATE and self.finish: raise CommandError(f"{action} --finish not allowed") if action != MIGRATE and self.rebuild_state: raise CommandError("--rebuild-state only allowed with `MIGRATE`") if action != MIGRATE and self.forms: raise CommandError("--forms only allowed with `MIGRATE`") if action != MIGRATE and self.stop_on_error: raise CommandError("--stop-on-error only allowed with `MIGRATE`") if action != STATS and self.verbose: raise CommandError("--verbose only allowed for `stats`") if action not in [MIGRATE, STATS] and self.missing_docs != CACHED: raise CommandError(f"{action} --missing-docs not allowed") if action != REWIND and self.rewind: raise CommandError("--to=... only allowed for `rewind`") if self.case_diff == "patch" and self.forms not in [None, "missing"]: raise CommandError( f"not supported: --case-diff=patch --forms={self.forms}") assert Domain.get_by_name(domain), f'Unknown domain "{domain}"' slug = f"{action.lower()}-{domain}" setup_logging(self.state_dir, slug, options['debug']) getattr(self, "do_" + action)(domain)
def handle(self, domain, action, **options): if should_use_sql_backend(domain): raise CommandError('It looks like {} has already been migrated.'.format(domain)) for opt in ["no_input", "verbose", "dry_run"]: setattr(self, opt, options[opt]) if self.no_input and not settings.UNIT_TESTING: raise CommandError('--no-input only allowed for unit testing') if action != MIGRATE and self.dry_run: raise CommandError("--dry-run only allowed for `MIGRATE`") if action != STATS and self.verbose: raise CommandError("--verbose only allowed for `stats`") setup_logging(options['log_dir'], options['debug']) getattr(self, "do_" + action)(domain)
def handle(self, domain, action, **options): if should_use_sql_backend(domain): raise CommandError('It looks like {} has already been migrated.'.format(domain)) for opt in [ "no_input", "verbose", "state_dir", "live_migrate", "case_diff", "rebuild_state", "stop_on_error", "forms", "rewind", "missing_docs", ]: setattr(self, opt, options[opt]) if self.no_input and not settings.UNIT_TESTING: raise CommandError('--no-input only allowed for unit testing') if action != MIGRATE and self.live_migrate: raise CommandError(f"{action} --live not allowed") if action != MIGRATE and self.rebuild_state: raise CommandError("--rebuild-state only allowed with `MIGRATE`") if action != MIGRATE and self.forms: raise CommandError("--forms only allowed with `MIGRATE`") if action != MIGRATE and self.stop_on_error: raise CommandError("--stop-on-error only allowed with `MIGRATE`") if action != STATS and self.verbose: raise CommandError("--verbose only allowed for `stats`") if action not in [MIGRATE, STATS] and self.missing_docs != RESUME: raise CommandError(f"{action} --missing-docs not allowed") if action != REWIND and self.rewind: raise CommandError("--to=... only allowed for `rewind`") assert Domain.get_by_name(domain), f'Unknown domain "{domain}"' slug = f"{action.lower()}-{domain}" setup_logging(self.state_dir, slug, options['debug']) getattr(self, "do_" + action)(domain)