Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
- "3306:3306"

faf-db-migrations:
image: faforever/faf-db-migrations:v140
image: faforever/faf-db-migrations:v144
command: migrate
environment:
FLYWAY_URL: jdbc:mysql://faf-db/faf?useSSL=false
Expand All @@ -35,7 +35,7 @@ services:
condition: service_completed_successfully

minio:
image: docker.io/bitnami/minio:2025
image: docker.io/alpine/minio:latest-release
Comment thread
Brutus5000 marked this conversation as resolved.
ports:
- '9000:9000'
- '9001:9001'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@Configuration
public class MainDbTestContainers {
private static final MariaDBContainer<?> fafDBContainer = new MariaDBContainer<>("mariadb:11.7");
private static final GenericContainer<?> flywayMigrationsContainer = new GenericContainer<>("faforever/faf-db-migrations:v140");
private static final GenericContainer<?> flywayMigrationsContainer = new GenericContainer<>("faforever/faf-db-migrations:v144");
private static final Network sharedNetwork = Network.newNetwork();

@Bean
Expand Down
6 changes: 3 additions & 3 deletions src/inttest/resources/sql/prepMapData.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ INSERT INTO map (id, display_name, map_type, battle_type, author, license) VALUE
(1, 'SCMP_001', 'FFA', 'skirmish', 1, 1),
(2, 'SCMP_002', 'FFA', 'skirmish', 1, 1);

INSERT INTO map_version (id, description, max_players, width, height, version, filename, hidden, map_id) VALUES
(1, 'SCMP 001', 8, 5, 5, 1, 'maps/scmp_001.v0001.zip', 0, 1),
(2, 'SCMP 002', 8, 5, 5, 1, 'maps/scmp_002.v0001.zip', 0, 2);
INSERT INTO map_version (id, description, max_players, width, height, version, folder_name, hidden, map_id) VALUES
(1, 'SCMP 001', 8, 5, 5, 1, 'scmp_001.v0001', 0, 1),
(2, 'SCMP 002', 8, 5, 5, 1, 'scmp_002.v0001', 0, 2);

INSERT INTO map_pool (id, name) VALUES
(1, 'Ladder 1v1 <300'),
Expand Down
4 changes: 2 additions & 2 deletions src/inttest/resources/sql/prepMapVersion.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
INSERT INTO map (id, display_name, map_type, battle_type, author, recommended, license) VALUES (1, 'display name', 'mtype', 'btype', 1, false, 1);
INSERT INTO map_version (id, description, max_players, width, height, version, filename, map_id, hidden, ranked)
VALUES (1, 'des', 2, 2, 2, 1, 'map/ghb.zip', 1, 0, 1);
INSERT INTO map_version (id, description, max_players, width, height, version, folder_name, map_id, hidden, ranked)
VALUES (1, 'des', 2, 2, 2, 1, 'ghb', 1, 0, 1);
INSERT INTO map_reviews_summary (id, map_id, positive, negative, score, reviews, lower_bound)
VALUES (1, 1, 0, 0, 2, 1, 0);
INSERT INTO map_version_reviews_summary (id, map_version_id, positive, negative, score, reviews, lower_bound)
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/com/faforever/api/data/domain/MapVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.yahoo.elide.annotation.Include;
import com.yahoo.elide.annotation.UpdatePermission;
import lombok.Setter;
import org.hibernate.annotations.Generated;
import org.hibernate.generator.EventType;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down Expand Up @@ -82,8 +84,10 @@ public int getVersion() {
return version;
}

@Column(name = "filename")
@NotNull
// DB-generated from folderName (CONCAT('maps/', folder_name, '.zip')); read-only here.
// No @NotNull: bean validation runs pre-insert before the DB populates this value.
@Column(name = "filename", insertable = false, updatable = false)
@Generated(event = EventType.INSERT)
public String getFilename() {
return filename;
}
Expand Down Expand Up @@ -138,8 +142,10 @@ public String getDownloadUrl() {
return downloadUrl;
}

@Transient
@ComputedAttribute
// Immutable after insert: the DB-generated filename and the derived download/
// thumbnail URLs are all computed from this, so it must not change post-creation.
@Column(name = "folder_name", updatable = false)
@NotNull
public String getFolderName() {
return folderName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ public void init(FafApiProperties apiProperties, EntityCacheEvictor cacheEvictor

@PostLoad
public void enhance(MapVersion mapVersion) {
String filename = mapVersion.getFilename();
mapVersion.setDownloadUrl(String.format(apiProperties.getMap().getDownloadUrlFormat(), filename.replace("maps/", "")));
mapVersion.setThumbnailUrlLarge(String.format(apiProperties.getMap().getLargePreviewsUrlFormat(), filename.replace("maps/", "").replace(".zip", ".png")));
mapVersion.setThumbnailUrlSmall(String.format(apiProperties.getMap().getSmallPreviewsUrlFormat(), filename.replace("maps/", "").replace(".zip", ".png")));
mapVersion.setFolderName(filename.substring(filename.indexOf('/') + 1, filename.indexOf(".zip")));
String folderName = mapVersion.getFolderName();
mapVersion.setDownloadUrl(String.format(apiProperties.getMap().getDownloadUrlFormat(), folderName + ".zip"));
mapVersion.setThumbnailUrlLarge(String.format(apiProperties.getMap().getLargePreviewsUrlFormat(), folderName + ".png"));
mapVersion.setThumbnailUrlSmall(String.format(apiProperties.getMap().getSmallPreviewsUrlFormat(), folderName + ".png"));
}

@PostUpdate
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/faforever/api/map/MapService.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public class MapService {
};

private static final Charset MAP_CHARSET = StandardCharsets.ISO_8859_1;
private static final String LEGACY_FOLDER_PREFIX = "maps/";
private final FafApiProperties fafApiProperties;
private final MapRepository mapRepository;
private final LicenseRepository licenseRepository;
Expand Down Expand Up @@ -413,7 +412,7 @@ private Map updateHibernateMapEntities(MapLuaAccessor mapLua, Optional<Map> exis
.setMaxPlayers(standardTeamsConfig.get(CONFIGURATION_STANDARD_TEAMS_ARMIES).length())
.setVersion(mapLua.getMapVersion$())
.setMap(map)
.setFilename(LEGACY_FOLDER_PREFIX + mapNameBuilder.buildFinalZipName(mapLua.getMapVersion$()));
.setFolderName(mapNameBuilder.buildFolderName(mapLua.getMapVersion$()));

map.getVersions().add(version);

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/faforever/api/map/MapServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ void positiveUploadTest() throws Exception {
assertEquals(256, mapVersion.getHeight());
assertEquals(256, mapVersion.getWidth());
assertEquals(8, mapVersion.getMaxPlayers());
assertEquals("maps/command_conquer_rush.v0007.zip", mapVersion.getFilename());
assertEquals("command_conquer_rush.v0007", mapVersion.getFolderName());

assertFalse(Files.exists(tmpDir));

Expand Down
Loading