def _fixture(self, m1, m2, include_schemas=False, opts=None, object_filters=_default_object_filters): self.metadata, model_metadata = m1, m2 self.metadata.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) return uo.as_diffs()
def setUp(self): self.conn = self.bind.connect() self.migration_context = MigrationContext.configure( connection=self.conn, opts={"compare_type": True, "compare_server_default": True}, ) self.autogen_context = api.AutogenContext(self.migration_context)
def test_alter_column_modify_programmatic_default(self): # test issue #736 # when autogenerate.compare creates the operation object # programmatically, the server_default of the op has the full # DefaultClause present. make sure the usual renderer works. context = op_fixture("mysql") m1 = MetaData() autogen_context = api.AutogenContext(context, m1) operation = ops.AlterColumnOp("t", "c") for fn in ( compare._compare_nullable, compare._compare_type, compare._compare_server_default, ): fn( autogen_context, operation, None, "t", "c", Column("c", Float(), nullable=False, server_default=text("0")), Column("c", Float(), nullable=True, default=0), ) op.invoke(operation) context.assert_("ALTER TABLE t MODIFY c FLOAT NULL DEFAULT 0")
def upgrade(): ''' First migration. Generates a migration script by difference between model and database and executes it ''' target_metadata = Base.metadata mc = context.get_context() migration_script = produce_migrations(mc, target_metadata) autogen_context = api.AutogenContext( mc, autogenerate=True ) # Seems to be the only way to apply changes to the database template_args = {} render._render_python_into_templatevars( autogen_context, migration_script, template_args ) code = template_args['upgrades'] code = code.replace('\n ', '\n') print('\nPerforming database changes:') print(code) exec(code)
def setUp(self): ctx_opts = { "sqlalchemy_module_prefix": "sa.", "alembic_module_prefix": "op.", "target_metadata": MetaData(), } context = MigrationContext.configure(dialect_name="postgresql", opts=ctx_opts) self.autogen_context = api.AutogenContext(context)
def setUp(self): ctx_opts = { 'sqlalchemy_module_prefix': 'sa.', 'alembic_module_prefix': 'op.', 'target_metadata': MetaData() } context = MigrationContext.configure(dialect_name="postgresql", opts=ctx_opts) self.autogen_context = api.AutogenContext(context)
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 setUp(self): self.conn = conn = self.bind.connect() ctx_opts = { 'compare_type': True, 'compare_server_default': True, 'target_metadata': self.m2, 'upgrade_token': "upgrades", 'downgrade_token': "downgrades", 'alembic_module_prefix': 'op.', 'sqlalchemy_module_prefix': 'sa.', 'include_object': _default_object_filters } if self.configure_opts: ctx_opts.update(self.configure_opts) self.context = context = MigrationContext.configure(connection=conn, opts=ctx_opts) self.autogen_context = api.AutogenContext(context, self.m2)
def setUp(self): self.conn = conn = self.bind.connect() ctx_opts = { "compare_type": True, "compare_server_default": True, "target_metadata": self.m2, "upgrade_token": "upgrades", "downgrade_token": "downgrades", "alembic_module_prefix": "op.", "sqlalchemy_module_prefix": "sa.", "include_object": _default_object_filters, } if self.configure_opts: ctx_opts.update(self.configure_opts) self.context = context = MigrationContext.configure(connection=conn, opts=ctx_opts) self.autogen_context = api.AutogenContext(context, self.m2)
def setUp(self): self.metadata = MetaData() self.autogen_context = api.AutogenContext(self.migration_context)
def setUp(self): self.autogen_context = api.AutogenContext(self.migration_context)