def test_lookup_legacy(self): self.cfg.set_main_option("file_template", "%%(rev)s") script = ScriptDirectory.from_config(self.cfg) a = util.rev_id() script.generate_revision(a, None, refresh=True) write_script( script, a, """ down_revision = None from alembic import op def upgrade(): op.execute("CREATE TABLE foo(id integer)") def downgrade(): op.execute("DROP TABLE foo") """, ) script = ScriptDirectory.from_config(self.cfg) rev = script._get_rev(a) eq_(rev.revision, a) eq_(os.path.basename(rev.path), "%s.py" % a)
def test_option(self): self.cfg.set_main_option("file_template", "myfile_%%(slug)s") script = ScriptDirectory.from_config(self.cfg) a = util.rev_id() script.generate_revision(a, "some message", refresh=True) write_script( script, a, """ revision = '%s' down_revision = None from alembic import op def upgrade(): op.execute("CREATE TABLE foo(id integer)") def downgrade(): op.execute("DROP TABLE foo") """ % a, ) script = ScriptDirectory.from_config(self.cfg) rev = script._get_rev(a) eq_(rev.revision, a) eq_(os.path.basename(rev.path), "myfile_some_message.py")
def _inline_enum_script(self): write_script(self.script, self.rid, """ revision = '%s' down_revision = None from alembic import op from sqlalchemy.dialects.postgresql import ENUM from sqlalchemy import Column def upgrade(): op.create_table("sometable", Column("data", ENUM("one", "two", "three", name="pgenum")) ) def downgrade(): op.drop_table("sometable") """ % self.rid)
def _distinct_enum_script(self): write_script(self.script, self.rid, """ revision = '%s' down_revision = None from alembic import op from sqlalchemy.dialects.postgresql import ENUM from sqlalchemy import Column def upgrade(): enum = ENUM("one", "two", "three", name="pgenum", create_type=False) enum.create(op.get_bind(), checkfirst=False) op.create_table("sometable", Column("data", enum) ) def downgrade(): op.drop_table("sometable") ENUM(name="pgenum").drop(op.get_bind(), checkfirst=False) """ % self.rid)
def test_lookup_legacy(self): self.cfg.set_main_option("file_template", "%%(rev)s") script = ScriptDirectory.from_config(self.cfg) a = util.rev_id() script.generate_revision(a, None, refresh=True) write_script( script, a, """ down_revision = None from alembic import op def upgrade(): op.execute("CREATE TABLE foo(id integer)") def downgrade(): op.execute("DROP TABLE foo") """) script = ScriptDirectory.from_config(self.cfg) rev = script._get_rev(a) eq_(rev.revision, a) eq_(os.path.basename(rev.path), "%s.py" % a)
def setUp(self): global cfg, env, a env = staging_env() cfg = _no_sql_testing_config() cfg.set_main_option('dialect_name', 'sqlite') cfg.remove_main_option('url') a = util.rev_id() script = ScriptDirectory.from_config(cfg) script.generate_revision(a, "revision a", refresh=True) write_script(script, a, """# coding: utf-8 from __future__ import unicode_literals revision = '%s' down_revision = None from alembic import op def upgrade(): op.execute("« S’il vous plaît…") def downgrade(): op.execute("drôle de petite voix m’a réveillé") """.encode('utf-8') % a)
def test_option(self): self.cfg.set_main_option("file_template", "myfile_%%(slug)s") script = ScriptDirectory.from_config(self.cfg) a = util.rev_id() script.generate_revision(a, "some message", refresh=True) write_script( script, a, """ revision = '%s' down_revision = None from alembic import op def upgrade(): op.execute("CREATE TABLE foo(id integer)") def downgrade(): op.execute("DROP TABLE foo") """ % a) script = ScriptDirectory.from_config(self.cfg) rev = script._get_rev(a) eq_(rev.revision, a) eq_(os.path.basename(rev.path), "myfile_some_message.py")
def test_001_revisions(self): global a, b, c a = util.rev_id() b = util.rev_id() c = util.rev_id() script = ScriptDirectory.from_config(self.cfg) script.generate_revision(a, None, refresh=True) write_script( script, a, """ revision = '%s' down_revision = None from alembic import op def upgrade(): op.execute("CREATE TABLE foo(id integer)") def downgrade(): op.execute("DROP TABLE foo") """ % a) script.generate_revision(b, None, refresh=True) write_script( script, b, """ revision = '%s' down_revision = '%s' from alembic import op def upgrade(): op.execute("CREATE TABLE bar(id integer)") def downgrade(): op.execute("DROP TABLE bar") """ % (b, a)) script.generate_revision(c, None, refresh=True) write_script( script, c, """ revision = '%s' down_revision = '%s' from alembic import op def upgrade(): op.execute("CREATE TABLE bat(id integer)") def downgrade(): op.execute("DROP TABLE bat") """ % (c, b))
def test_001_revisions(self): global a, b, c a = util.rev_id() b = util.rev_id() c = util.rev_id() script = ScriptDirectory.from_config(self.cfg) script.generate_revision(a, None, refresh=True) write_script(script, a, """ revision = '%s' down_revision = None from alembic import op def upgrade(): op.execute("CREATE TABLE foo(id integer)") def downgrade(): op.execute("DROP TABLE foo") """ % a) script.generate_revision(b, None, refresh=True) write_script(script, b, """ revision = '%s' down_revision = '%s' from alembic import op def upgrade(): op.execute("CREATE TABLE bar(id integer)") def downgrade(): op.execute("DROP TABLE bar") """ % (b, a)) script.generate_revision(c, None, refresh=True) write_script(script, c, """ revision = '%s' down_revision = '%s' from alembic import op def upgrade(): op.execute("CREATE TABLE bat(id integer)") def downgrade(): op.execute("DROP TABLE bat") """ % (c, b))
def write_scripts(self): self.a = util.rev_id() self.b = util.rev_id() self.c = util.rev_id() script = ScriptDirectory.from_config(self.cfg) script.generate_revision(self.a, None, refresh=True) write_script(script, self.a, """ revision = '%s' down_revision = None import uuid from cqlengine import columns, management, models class TestTable(models.Model): __table_name__ = 'test_table' partition = columns.Text(primary_key=True) uuid = columns.UUID(primary_key=True, default=uuid.uuid4) title = columns.Text() def upgrade(): management.create_table(TestTable) def downgrade(): management.drop_table(TestTable) """ % self.a) script.generate_revision(self.b, None, refresh=True) write_script(script, self.b, """ revision = '%s' down_revision = '%s' import uuid from alembic.ddl.cqe import add_column from cqlengine import columns, management, models class TestTable(models.Model): __table_name__ = 'test_table' partition = columns.Text(primary_key=True) uuid = columns.UUID(primary_key=True, default=uuid.uuid4) title = columns.Text() new_col = columns.Float() def upgrade(): add_column(TestTable, 'new_col') def downgrade(): # drop column not supported in cassandra 1.2 pass """ % (self.b, self.a)) script.generate_revision(self.c, None, refresh=True) write_script(script, self.c, """ revision = '%s' down_revision = '%s' import uuid from alembic.ddl.cqe import add_column from cqlengine import columns, management, models class TestTable(models.Model): __table_name__ = 'test_table' partition = columns.Text(primary_key=True) uuid = columns.UUID(primary_key=True, default=uuid.uuid4) new_col2 = columns.Float() def upgrade(): add_column(TestTable, 'new_col2') def downgrade(): # drop column not supported in cassandra 1.2 pass """ % (self.c, self.b))