|
26 | 26 |
|
27 | 27 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
28 | 28 |
|
29 |
| -import com.fasterxml.jackson.databind.JsonNode; |
30 |
| -import io.airbyte.commons.enums.Enums; |
31 |
| -import java.nio.file.Path; |
32 |
| -import java.util.Comparator; |
33 |
| -import java.util.List; |
34 |
| -import java.util.Map; |
35 |
| -import java.util.Map.Entry; |
36 |
| -import java.util.stream.Collectors; |
37 |
| -import org.junit.jupiter.api.Disabled; |
38 | 29 | import org.junit.jupiter.api.Test;
|
39 | 30 |
|
40 | 31 | public class MigrationCurrentSchemaTest {
|
41 | 32 |
|
42 |
| - // get all of the "current" configs (in other words the one airbyte-config). get all of the configs |
43 |
| - // from the output schema of the last migration. make sure they match. |
| 33 | + /** |
| 34 | + * The file-based migration is deprecated. We need to ensure that v0.29.0 is the last one. All new |
| 35 | + * migrations should be written in Flyway. |
| 36 | + */ |
44 | 37 | @Test
|
45 |
| - void testConfigsOfLastMigrationMatchSource() { |
46 |
| - final Map<ResourceId, JsonNode> lastMigrationSchema = getSchemaOfLastMigration(ResourceType.CONFIG); |
47 |
| - final Map<ResourceId, JsonNode> currentSchema = MigrationUtils.getNameToSchemasFromResourcePath( |
48 |
| - Path.of("types"), |
49 |
| - ResourceType.CONFIG, |
50 |
| - Enums.valuesAsStrings(ConfigKeys.class)); |
51 |
| - |
52 |
| - assertSameSchemas(currentSchema, lastMigrationSchema); |
53 |
| - } |
54 |
| - |
55 |
| - private static Map<ResourceId, JsonNode> getSchemaOfLastMigration(ResourceType resourceType) { |
| 38 | + public void testLastMigration() { |
56 | 39 | final Migration lastMigration = Migrations.MIGRATIONS.get(Migrations.MIGRATIONS.size() - 1);
|
57 |
| - final Map<ResourceId, JsonNode> lastMigrationOutputSchema = lastMigration.getOutputSchema(); |
58 |
| - |
59 |
| - return lastMigrationOutputSchema.entrySet() |
60 |
| - .stream() |
61 |
| - .filter(entry -> entry.getKey().getType() == resourceType) |
62 |
| - .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); |
63 |
| - } |
64 |
| - |
65 |
| - // get all of the "current" jobs (in other words the one airbyte-db). get all of the configs |
66 |
| - // from the output schema of the last migration. make sure they match. |
67 |
| - @Test |
68 |
| - @Disabled |
69 |
| - // TODO(#5902): Liren will adapt this to the new migration system. |
70 |
| - void testJobsOfLastMigrationMatchSource() { |
71 |
| - final Map<ResourceId, JsonNode> lastMigrationSchema = getSchemaOfLastMigration(ResourceType.JOB); |
72 |
| - final Map<ResourceId, JsonNode> currentSchema = MigrationUtils.getNameToSchemasFromResourcePath( |
73 |
| - Path.of("jobs_database"), |
74 |
| - ResourceType.JOB, |
75 |
| - Enums.valuesAsStrings(JobKeys.class)); |
76 |
| - |
77 |
| - assertSameSchemas(currentSchema, lastMigrationSchema); |
78 |
| - } |
79 |
| - |
80 |
| - private static void assertSameSchemas(Map<ResourceId, JsonNode> currentSchemas, Map<ResourceId, JsonNode> lastMigrationSchema) { |
81 |
| - assertEquals(currentSchemas.size(), lastMigrationSchema.size()); |
82 |
| - |
83 |
| - final List<Entry<ResourceId, JsonNode>> lastMigrationOutputSchemaCleanedSorted = lastMigrationSchema.entrySet() |
84 |
| - .stream() |
85 |
| - .sorted(Comparator.comparing((v) -> v.getKey().getType())) |
86 |
| - .collect(Collectors.toList()); |
87 |
| - |
88 |
| - // break out element-wise assertion so it is easier to read any failed tests. |
89 |
| - for (Map.Entry<ResourceId, JsonNode> lastMigrationEntry : lastMigrationOutputSchemaCleanedSorted) { |
90 |
| - assertEquals(currentSchemas.get(lastMigrationEntry.getKey()), lastMigrationEntry.getValue()); |
91 |
| - } |
92 |
| - } |
93 |
| - |
94 |
| - public enum ConfigKeys { |
95 |
| - STANDARD_WORKSPACE, |
96 |
| - STANDARD_SOURCE_DEFINITION, |
97 |
| - STANDARD_DESTINATION_DEFINITION, |
98 |
| - SOURCE_CONNECTION, |
99 |
| - DESTINATION_CONNECTION, |
100 |
| - STANDARD_SYNC, |
101 |
| - STANDARD_SYNC_SCHEDULE, |
102 |
| - STANDARD_SYNC_OPERATION, |
103 |
| - } |
104 |
| - |
105 |
| - public enum JobKeys { |
106 |
| - JOBS, |
107 |
| - ATTEMPTS, |
108 |
| - AIRBYTE_METADATA |
| 40 | + assertEquals(Migrations.MIGRATION_V_0_29_0.getVersion(), lastMigration.getVersion()); |
109 | 41 | }
|
110 | 42 |
|
111 | 43 | }
|
0 commit comments