You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To avoid issues like #4260 and #4271, we need to create integration tests to validate migration scripts. For PostgreSQL, it could be something like this:
/* * Copyright 2020-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */packageorg.springframework.batch.core.test.repository;
importorg.junit.jupiter.api.Assertions;
importorg.junit.jupiter.api.Test;
importorg.postgresql.ds.PGSimpleDataSource;
importorg.testcontainers.containers.PostgreSQLContainer;
importorg.testcontainers.junit.jupiter.Container;
importorg.testcontainers.junit.jupiter.Testcontainers;
importorg.testcontainers.utility.DockerImageName;
importorg.springframework.core.io.ClassPathResource;
importorg.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
/** * @author Mahmoud Ben Hassine */@TestcontainersclassPostgreSQLMigrationScriptIntegrationTests {
@ContainerpublicstaticPostgreSQLContainer<?> postgres = newPostgreSQLContainer<>(DockerImageName.parse("postgres:13.3"));
@TestvoidmigrationScriptShouldBeValid() {
PGSimpleDataSourcedatasource = newPGSimpleDataSource();
datasource.setURL(postgres.getJdbcUrl());
datasource.setUser(postgres.getUsername());
datasource.setPassword(postgres.getPassword());
ResourceDatabasePopulatordatabasePopulator = newResourceDatabasePopulator();
databasePopulator.addScript(newClassPathResource("/org/springframework/batch/core/schema-postgresql-4.sql"));
databasePopulator.addScript(newClassPathResource("/org/springframework/batch/core/migration/5.0/migration-postgresql.sql"));
Assertions.assertDoesNotThrow(() -> databasePopulator.execute(datasource));
}
}
For embedded databases, it could be something like this:
/* * Copyright 2020-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */packageorg.springframework.batch.core.repository;
importorg.junit.jupiter.api.Assertions;
importorg.junit.jupiter.api.Test;
importorg.springframework.core.io.ClassPathResource;
importorg.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
importorg.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
importorg.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
importorg.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
/** * @author Mahmoud Ben Hassine */classH2MigrationScriptIntegrationTests {
@TestvoidmigrationScriptShouldBeValid() {
EmbeddedDatabasedatasource = newEmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2)
.addScript("/org/springframework/batch/core/schema-h2-v4.sql")
.build();
ResourceDatabasePopulatordatabasePopulator = newResourceDatabasePopulator();
databasePopulator.addScript(newClassPathResource("/org/springframework/batch/core/migration/5.0/migration-h2.sql"));
Assertions.assertDoesNotThrow(() -> databasePopulator.execute(datasource));
}
}
NB: Those tests should not be part of the CI/CD build. They can be used on demand to validate a migration script when needed.
The text was updated successfully, but these errors were encountered:
To avoid issues like #4260 and #4271, we need to create integration tests to validate migration scripts. For PostgreSQL, it could be something like this:
For embedded databases, it could be something like this:
NB: Those tests should not be part of the CI/CD build. They can be used on demand to validate a migration script when needed.
The text was updated successfully, but these errors were encountered: