예제 #1
0
 def test_it_prompts_migrations(self, tmpdir):
     with patch("yoyo.scripts.migrate.prompt_migrations"
                ) as prompt_migrations, patch(
                    "yoyo.scripts.migrate.get_backend") as get_backend:
         main(["apply", tmpdir, "--database", dburi])
         migrations = get_backend().to_apply()
         assert migrations in prompt_migrations.call_args[0]
예제 #2
0
    def test_it_unmarks_to_selected_revision(self, tmpdir):
        from yoyo.connections import get_backend

        self.confirm.return_value = True
        migrations = read_migrations(tmpdir)
        backend = get_backend(self.dburi)
        backend.apply_migrations(migrations)

        main(["unmark", "-r", "m2", tmpdir, "--database", self.dburi])
        assert backend.is_applied(migrations[0])
        assert not backend.is_applied(migrations[1])
        assert not backend.is_applied(migrations[2])
예제 #3
0
    def test_it_prompts_only_unapplied(self, tmpdir):
        from yoyo.connections import get_backend

        migrations = read_migrations(tmpdir)
        backend = get_backend(self.dburi)
        backend.apply_migrations(migrations[:1])

        with patch(
                "yoyo.scripts.migrate.prompt_migrations") as prompt_migrations:
            main(["mark", tmpdir, "--database", self.dburi])
            _, prompted, _ = prompt_migrations.call_args[0]
            prompted = [m.id for m in prompted]
            assert prompted == ["m2", "m3"]
예제 #4
0
 def test_it_breaks_lock(self, dburi):
     if dburi.startswith("sqlite"):
         pytest.skip("Test not supported for sqlite databases")
     backend = get_backend(dburi)
     backend.execute(
         "INSERT INTO yoyo_lock (locked, ctime, pid) "
         "VALUES (1, :now, 1)",
         {"now": datetime.utcnow()},
     )
     backend.commit()
     main(["break-lock", "--database", dburi])
     assert backend.execute(
         "SELECT COUNT(1) FROM yoyo_lock").fetchone()[0] == 0
예제 #5
0
    def test_it_marks_at_selected_version(self, tmpdir):
        from yoyo.connections import get_backend

        self.confirm.return_value = True
        migrations = read_migrations(tmpdir)
        backend = get_backend(self.dburi)
        with backend.transaction():
            backend.execute("CREATE TABLE t (id INT)")

        main(["mark", "-r", "m2", tmpdir, "--database", self.dburi])
        assert backend.is_applied(migrations[0])
        assert backend.is_applied(migrations[1])
        assert not backend.is_applied(migrations[2])

        # Check that migration steps have not been applied
        c = backend.execute("SELECT * FROM t")
        assert len(c.fetchall()) == 0
예제 #6
0
 def test_it_reapplies_migrations(self, tmpdir):
     with patch("yoyo.scripts.migrate.get_backend") as get_backend:
         main(["-b", "reapply", tmpdir, "--database", dburi])
         assert get_backend().rollback_migrations.call_count == 1
         assert get_backend().apply_migrations.call_count == 1