def test_forgiving_add_index(): """Test that add index will continue if index exists.""" engine = create_engine( 'sqlite://', poolclass=StaticPool ) models.Base.metadata.create_all(engine) migration._create_index(engine, "states", "ix_states_context_id")
def test_forgiving_add_index_with_other_db_types(caplog, exception_type): """Test that add index will continue if index exists on mysql and postgres.""" mocked_index = Mock() type(mocked_index).name = "ix_states_context_id" mocked_index.create = Mock(side_effect=exception_type( "CREATE INDEX ix_states_old_state_id ON states (old_state_id);", [], 'relation "ix_states_old_state_id" already exists', )) mocked_table = Mock() type(mocked_table).indexes = PropertyMock(return_value=[mocked_index]) with patch("homeassistant.components.recorder.migration.Table", return_value=mocked_table): migration._create_index(Mock(), "states", "ix_states_context_id") assert "already exists on states" in caplog.text assert "continuing" in caplog.text
def test_forgiving_add_index(): """Test that add index will continue if index exists.""" engine = create_engine("sqlite://", poolclass=StaticPool) models.Base.metadata.create_all(engine) migration._create_index(engine, "states", "ix_states_context_id")