fix(backend): rename users table to app_users
Some checks failed
CI / Unit & Component Tests (pull_request) Failing after 3m43s
CI / OCR Service Tests (pull_request) Successful in 39s
CI / Backend Unit Tests (pull_request) Failing after 3m15s
CI / Unit & Component Tests (push) Failing after 3m37s
CI / OCR Service Tests (push) Successful in 41s
CI / Backend Unit Tests (push) Failing after 3m2s

Aligns the auth-account table name with the AppUser entity. The historical
mismatch (table 'users' alongside table 'persons') misled schema-first readers
into assuming the two were related; renaming to 'app_users' makes the
deliberate split between auth accounts and historical persons explicit at the
schema layer.

Scope: the table itself, the users_groups join table, and the three FK columns
whose name was literally 'user_id'. Semantic FK columns (audit_log.actor_id,
notifications.recipient_id, document_versions.editor_id, etc.) keep their
names — the role they describe is the documentation, not the type.

Closes #418. Unblocks #407 (REFACTOR-1).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit was merged in pull request #419.
This commit is contained in:
Marcel
2026-05-04 21:44:21 +02:00
parent d4f666e981
commit eedf5e3ac1
10 changed files with 117 additions and 23 deletions

View File

@@ -104,7 +104,7 @@ public interface AuditLogQueryRepository extends JpaRepository<AuditLog, UUID> {
ag.happened_at_until AS happenedAtUntil,
(ag.payload->>'commentId')::uuid AS commentId
FROM aggregated ag
LEFT JOIN users u ON u.id = ag.actor_id
LEFT JOIN app_users u ON u.id = ag.actor_id
ORDER BY ag.happened_at DESC
LIMIT :limit
""", nativeQuery = true)
@@ -157,7 +157,7 @@ public interface AuditLogQueryRepository extends JpaRepository<AuditLog, UUID> {
COALESCE(u.color, '') AS actorColor,
CONCAT_WS(' ', u.first_name, u.last_name) AS actorName
FROM audit_log a
LEFT JOIN users u ON u.id = a.actor_id
LEFT JOIN app_users u ON u.id = a.actor_id
WHERE a.kind IN ('ANNOTATION_CREATED', 'TEXT_SAVED', 'BLOCK_REVIEWED')
AND a.document_id IN :documentIds
AND a.actor_id IS NOT NULL
@@ -189,7 +189,7 @@ public interface AuditLogQueryRepository extends JpaRepository<AuditLog, UUID> {
ORDER BY MAX(a.happened_at) DESC
) AS rn
FROM audit_log a
LEFT JOIN users u ON u.id = a.actor_id
LEFT JOIN app_users u ON u.id = a.actor_id
WHERE a.kind IN ('ANNOTATION_CREATED', 'TEXT_SAVED', 'BLOCK_REVIEWED')
AND a.document_id IN :documentIds
AND a.actor_id IS NOT NULL

View File

@@ -24,7 +24,7 @@ import jakarta.persistence.PrePersist;
import jakarta.persistence.PreUpdate;
@Entity
@Table(name = "users")
@Table(name = "app_users")
@Data
@NoArgsConstructor
@AllArgsConstructor
@@ -69,7 +69,7 @@ public class AppUser {
private boolean notifyOnMention = false;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "users_groups", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "group_id"))
@JoinTable(name = "app_users_groups", joinColumns = @JoinColumn(name = "app_user_id"), inverseJoinColumns = @JoinColumn(name = "group_id"))
@Builder.Default
@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
private Set<UserGroup> groups = new HashSet<>();

View File

@@ -71,7 +71,7 @@ public class DocumentComment {
@JoinTable(
name = "comment_mentions",
joinColumns = @JoinColumn(name = "comment_id"),
inverseJoinColumns = @JoinColumn(name = "user_id")
inverseJoinColumns = @JoinColumn(name = "app_user_id")
)
@JsonIgnore
@Builder.Default

View File

@@ -30,7 +30,7 @@ public class PasswordResetToken {
private UUID id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
@JoinColumn(name = "app_user_id", nullable = false)
private AppUser user;
@Column(nullable = false, unique = true, length = 64)

View File

@@ -0,0 +1,21 @@
-- Align the auth-account table name with the AppUser entity (issue #418).
-- The historical mismatch (table 'users' alongside table 'persons') misleads
-- schema-first readers into assuming the two are related. Renaming the table to
-- 'app_users' makes the deliberate split between auth accounts and historical
-- persons explicit at the schema layer.
--
-- Scope: the table itself, the users_groups join table, and the three FK
-- columns whose name is literally 'user_id'. Semantic FK columns
-- (audit_log.actor_id, notifications.recipient_id, document_versions.editor_id,
-- document_comments.author_id, transcription_blocks.created_by/updated_by,
-- transcription_block_versions.changed_by, document_annotations.created_by,
-- ocr_training_runs.triggered_by, invite_tokens.created_by, geschichten.author_id)
-- keep their names — the role they describe is the documentation, not the type.
ALTER TABLE users RENAME TO app_users;
ALTER TABLE users_groups RENAME TO app_users_groups;
ALTER TABLE app_users_groups RENAME COLUMN user_id TO app_user_id;
ALTER TABLE comment_mentions RENAME COLUMN user_id TO app_user_id;
ALTER TABLE password_reset_tokens RENAME COLUMN user_id TO app_user_id;