def _rewrite(self, context, revision, directive): try: _rewriter = self.dispatch.dispatch(directive) except ValueError: _rewriter = None yield directive else: for r_directive in util.to_list( _rewriter(context, revision, directive)): yield r_directive
def _rewrite(self, context, revision, directive): try: _rewriter = self.dispatch.dispatch(directive) except ValueError: _rewriter = None yield directive else: for r_directive in util.to_list( _rewriter(context, revision, directive)): yield r_directive
def _fixture( self, m1, m2, include_schemas=False, opts=None, object_filters=_default_object_filters, name_filters=_default_name_filters, return_ops=False, max_identifier_length=None, ): if max_identifier_length: dialect = self.bind.dialect existing_length = dialect.max_identifier_length dialect.max_identifier_length = ( dialect._user_defined_max_identifier_length ) = max_identifier_length try: self._alembic_metadata, model_metadata = m1, m2 for m in util.to_list(self._alembic_metadata): m.create_all(self.bind) with self.bind.connect() as conn: ctx_opts = { "compare_type": True, "compare_server_default": True, "target_metadata": model_metadata, "upgrade_token": "upgrades", "downgrade_token": "downgrades", "alembic_module_prefix": "op.", "sqlalchemy_module_prefix": "sa.", "include_object": object_filters, "include_name": name_filters, "include_schemas": include_schemas, } if opts: ctx_opts.update(opts) self.context = context = MigrationContext.configure( connection=conn, opts=ctx_opts) autogen_context = api.AutogenContext(context, model_metadata) uo = ops.UpgradeOps(ops=[]) autogenerate._produce_net_changes(autogen_context, uo) if return_ops: return uo else: return uo.as_diffs() finally: if max_identifier_length: dialect = self.bind.dialect dialect.max_identifier_length = ( dialect._user_defined_max_identifier_length ) = existing_length
def _rewrite(self, context, revision, directive): try: _rewriter = self.dispatch.dispatch(directive) except ValueError: _rewriter = None yield directive else: if self in directive._mutations: yield directive else: for r_directive in util.to_list( _rewriter(context, revision, directive)): r_directive._mutations = r_directive._mutations.union( [self]) yield r_directive
def _rewrite( self, context: "MigrationContext", revision: "Revision", directive: "MigrateOperation", ) -> Iterator["MigrateOperation"]: try: _rewriter = self.dispatch.dispatch(directive) except ValueError: _rewriter = None yield directive else: if self in directive._mutations: yield directive else: for r_directive in util.to_list( _rewriter(context, revision, directive), [] ): r_directive._mutations = r_directive._mutations.union( [self] ) yield r_directive
def _fixture( self, m1, m2, include_schemas=False, opts=None, object_filters=_default_object_filters, return_ops=False): self.metadata, model_metadata = m1, m2 for m in util.to_list(self.metadata): m.create_all(self.bind) with self.bind.connect() as conn: ctx_opts = { 'compare_type': True, 'compare_server_default': True, 'target_metadata': model_metadata, 'upgrade_token': "upgrades", 'downgrade_token': "downgrades", 'alembic_module_prefix': 'op.', 'sqlalchemy_module_prefix': 'sa.', 'include_object': object_filters, 'include_schemas': include_schemas } if opts: ctx_opts.update(opts) self.context = context = MigrationContext.configure( connection=conn, opts=ctx_opts ) autogen_context = api.AutogenContext(context, model_metadata) uo = ops.UpgradeOps(ops=[]) autogenerate._produce_net_changes( autogen_context, uo ) if return_ops: return uo else: return uo.as_diffs()
def _fixture(self, m1, m2, include_schemas=False, opts=None, object_filters=_default_object_filters, return_ops=False): self.metadata, model_metadata = m1, m2 for m in util.to_list(self.metadata): m.create_all(self.bind) with self.bind.connect() as conn: ctx_opts = { 'compare_type': True, 'compare_server_default': True, 'target_metadata': model_metadata, 'upgrade_token': "upgrades", 'downgrade_token': "downgrades", 'alembic_module_prefix': 'op.', 'sqlalchemy_module_prefix': 'sa.', 'include_object': object_filters, 'include_schemas': include_schemas } if opts: ctx_opts.update(opts) self.context = context = MigrationContext.configure( connection=conn, opts=ctx_opts) autogen_context = api.AutogenContext(context, model_metadata) uo = ops.UpgradeOps(ops=[]) autogenerate._produce_net_changes(autogen_context, uo) if return_ops: return uo else: return uo.as_diffs()
def tearDown(self): if hasattr(self, "_alembic_metadata"): for m in util.to_list(self._alembic_metadata): m.drop_all(self.bind) clear_staging_env()
def tearDown(self): if hasattr(self, 'metadata'): for m in util.to_list(self.metadata): m.drop_all(self.bind) clear_staging_env()
def tearDown(self): if hasattr(self, 'metadata'): for m in util.to_list(self.metadata): m.drop_all(self.bind) clear_staging_env()
def stamp(self, revision, sql=False, tag=None, purge=False): """'stamp' the revision table with the given revision; don't run any migrations. :param revision: target revision or list of revisions. May be a list to indicate stamping of multiple branch heads. .. note:: this parameter is called "revisions" in the command line interface. .. versionchanged:: 1.2 The revision may be a single revision or list of revisions when stamping multiple branch heads. :param sql: use ``--sql`` mode :param tag: an arbitrary "tag" that can be intercepted by custom ``env.py`` scripts via the :class:`.EnvironmentContext.get_tag_argument` method. :param purge: delete all entries in the version table before stamping. .. versionadded:: 1.2 """ config = self.config script = self.script_directory config.attributes["engine"] = self.engine output_buffer = io.StringIO() config.attributes["output_buffer"] = output_buffer starting_rev = None if sql: destination_revs = [] for _revision in util.to_list(revision): if ":" in _revision: srev, _revision = _revision.split(":", 2) if starting_rev != srev: if starting_rev is None: starting_rev = srev else: raise util.CommandError( "Stamp operation with --sql only supports a " "single starting revision at a time") destination_revs.append(_revision) else: destination_revs = util.to_list(revision) def do_stamp(rev, context): return script._stamp_revs(util.to_tuple(destination_revs), rev) with EnvironmentContext( config, script, fn=do_stamp, as_sql=sql, starting_rev=starting_rev if sql else None, destination_rev=util.to_tuple(destination_revs), tag=tag, purge=purge, ): script.run_env() output_buffer.seek(0) return output_buffer.read()