dev use authtoken
Test Workflow / test (push) Successful in 5s

This commit is contained in:
vladp
2026-02-24 18:35:35 +07:00
parent ba6464147a
commit 87b97c39ea
4 changed files with 55 additions and 1 deletions
+18
View File
@@ -151,3 +151,21 @@ INSERT INTO referral_levels (id, name, min_invitees, reward_percentage) VALUES
('silver', 'SILVER', 6, 18), ('silver', 'SILVER', 6, 18),
('gold', 'GOLD', 16, 22), ('gold', 'GOLD', 16, 22),
('platinum', 'PLATINUM', 50, 25); ('platinum', 'PLATINUM', 50, 25);
-----------------
Скрипт,для нумерации для уже сохданных файлов
WITH max_id AS (
SELECT COALESCE(MAX(support_id), 0) as max_val FROM file_entities
),
-- Нумеруем только NULL записи, начиная с max_val + 1
numbered AS (
SELECT
f.id,
(SELECT max_val FROM max_id) + ROW_NUMBER() OVER (ORDER BY f.created_at, f.id) as new_support_id
FROM file_entities f
WHERE f.support_id IS NULL
)
UPDATE file_entities
SET support_id = numbered.new_support_id
FROM numbered
WHERE file_entities.id = numbered.id;
@@ -8,6 +8,7 @@ import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener; import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.concurrent.atomic.AtomicInteger;
@Data @Data
@Builder @Builder
@@ -17,6 +18,9 @@ import java.time.LocalDateTime;
@Table(name = "file_entities") @Table(name = "file_entities")
@EntityListeners(AuditingEntityListener.class) @EntityListeners(AuditingEntityListener.class)
public class FileEntity { public class FileEntity {
private static AtomicInteger supportIdCounter = new AtomicInteger(0);
@Id @Id
@GeneratedValue(strategy = GenerationType.UUID) @GeneratedValue(strategy = GenerationType.UUID)
private String id; private String id;
@@ -83,6 +87,10 @@ public class FileEntity {
@PrePersist @PrePersist
public void prePersist() { public void prePersist() {
if (this.supportId == null) {
this.supportId = supportIdCounter.incrementAndGet();
}
if (this.status == null) { if (this.status == null) {
this.status = FileStatus.ACTIVE; this.status = FileStatus.ACTIVE;
} }
@@ -101,4 +109,8 @@ public class FileEntity {
public void preUpdate() { public void preUpdate() {
this.updatedAt = LocalDateTime.now(); this.updatedAt = LocalDateTime.now();
} }
public static void initializeCounter(int maxId) {
supportIdCounter = new AtomicInteger(maxId);
}
} }
@@ -0,0 +1,21 @@
package ru.soune.nocopy.entity.file;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import ru.soune.nocopy.repository.FileEntityRepository;
@Component
public class SupportIdInitializer {
@Autowired
private FileEntityRepository fileRepository;
@PostConstruct
public void init() {
Integer maxId = fileRepository.findMaxSupportId();
if (maxId != null) {
FileEntity.initializeCounter(maxId);
}
}
}
@@ -58,4 +58,7 @@ public interface FileEntityRepository extends JpaRepository<FileEntity, String>
@Query("SELECT f FROM FileEntity f WHERE f.mimeType = :mimeType") @Query("SELECT f FROM FileEntity f WHERE f.mimeType = :mimeType")
List<FileEntity> findByMimeType(String mimeType); List<FileEntity> findByMimeType(String mimeType);
@Query("SELECT MAX(f.supportId) FROM FileEntity f")
Integer findMaxSupportId();
} }