-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: 1. Add database migration function. 2. Add download speed sta…
…tistics persistence and area chart display.
- Loading branch information
Showing
33 changed files
with
1,932 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package telegram.files; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class MessyUtils { | ||
|
||
public static LocalDateTime withGrouping5Minutes(LocalDateTime time) { | ||
int minute = time.getMinute(); | ||
int minuteGroup = minute / 5; | ||
int newMinute = minuteGroup * 5; | ||
return time.withMinute(newMinute).withSecond(0).withNano(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
api/src/main/java/telegram/files/repository/Definition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package telegram.files.repository; | ||
|
||
import cn.hutool.core.lang.Version; | ||
import cn.hutool.log.Log; | ||
import cn.hutool.log.LogFactory; | ||
import io.vertx.core.Future; | ||
import io.vertx.sqlclient.SqlConnection; | ||
|
||
import java.util.TreeMap; | ||
import java.util.stream.Stream; | ||
|
||
public interface Definition { | ||
|
||
Log log = LogFactory.get(); | ||
|
||
String getScheme(); | ||
|
||
default TreeMap<Version, String[]> getMigrations() { | ||
return new TreeMap<>(); | ||
} | ||
|
||
default Future<Void> createTable(SqlConnection conn) { | ||
return conn | ||
.query(getScheme()) | ||
.execute() | ||
.onFailure(err -> log.error("Failed to create table: %s".formatted(err.getMessage()))) | ||
.mapEmpty(); | ||
} | ||
|
||
default Future<Void> migrate(SqlConnection conn, Version lastVersion, Version currentVersion) { | ||
TreeMap<Version, String[]> migrations = getMigrations(); | ||
if (migrations.isEmpty()) { | ||
return Future.succeededFuture(); | ||
} | ||
return Future.all(migrations.subMap(lastVersion, false, currentVersion, true).values() | ||
.stream() | ||
.flatMap(arr -> Stream.of(arr) | ||
.map(sql -> conn.query(sql) | ||
.execute() | ||
.onFailure(e -> log.error("Failed to apply migration: %s".formatted(sql), e))) | ||
) | ||
.toList() | ||
) | ||
.onFailure(err -> log.error("Failed to migrate table: %s".formatted(err.getMessage()))) | ||
.mapEmpty(); | ||
} | ||
} |
Oops, something went wrong.