Skip to content

Commit

Permalink
fix: add missing indexes for FKs (second part) (#2613)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anty0 authored Oct 22, 2024
1 parent 985f2e0 commit 1158f79
Show file tree
Hide file tree
Showing 35 changed files with 442 additions and 22 deletions.
13 changes: 12 additions & 1 deletion backend/data/src/main/kotlin/io/tolgee/model/Pat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.tolgee.model

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table
import jakarta.persistence.Temporal
Expand All @@ -12,7 +13,17 @@ import jakarta.validation.constraints.NotNull
import java.util.*

@Entity
@Table(uniqueConstraints = [UniqueConstraint(columnNames = ["tokenHash"], name = "pat_token_hash_unique")])
@Table(
uniqueConstraints = [
UniqueConstraint(
columnNames = ["tokenHash"],
name = "pat_token_hash_unique",
),
],
indexes = [
Index(columnList = "user_account_id"),
],
)
class Pat(
@field:NotEmpty
@field:NotNull
Expand Down
1 change: 1 addition & 0 deletions backend/data/src/main/kotlin/io/tolgee/model/Project.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import kotlin.jvm.Transient
),
],
indexes = [
Index(columnList = "user_owner_id"),
Index(columnList = "organization_owner_id"),
],
)
Expand Down
7 changes: 7 additions & 0 deletions backend/data/src/main/kotlin/io/tolgee/model/QuickStart.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ import io.tolgee.dtos.queryResults.organization.IQuickStart
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.Index
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import jakarta.persistence.MapsId
import jakarta.persistence.OneToOne
import jakarta.persistence.Table
import org.hibernate.annotations.Type

@Entity
@Table(
indexes = [
Index(columnList = "organization_id"),
],
)
data class QuickStart(
@OneToOne
@MapsId
Expand Down
10 changes: 9 additions & 1 deletion backend/data/src/main/kotlin/io/tolgee/model/UploadedImage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@ package io.tolgee.model

import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table
import jakarta.persistence.UniqueConstraint
import org.hibernate.annotations.ColumnDefault

@Entity
@Table(uniqueConstraints = [UniqueConstraint(columnNames = ["filename"], name = "uploaded_image_filename")])
@Table(
uniqueConstraints = [
UniqueConstraint(columnNames = ["filename"], name = "uploaded_image_filename"),
],
indexes = [
Index(columnList = "user_account_id"),
],
)
class UploadedImage(
var filename: String,
@ManyToOne(fetch = FetchType.LAZY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.Id
import jakarta.persistence.Index
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import jakarta.persistence.MapsId
import jakarta.persistence.OneToOne
import jakarta.persistence.Table

@Entity
@Table(
indexes = [
Index(columnList = "preferred_organization_id"),
],
)
class UserPreferences(
@OneToOne
@MapsId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ import io.tolgee.model.Project
import io.tolgee.model.StandardAuditModel
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.OneToMany
import jakarta.persistence.Table

@Entity
@Table(
indexes = [
Index(columnList = "project_id"),
],
)
class Automation(
@ManyToOne(fetch = FetchType.LAZY)
var project: Project,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ import io.tolgee.model.slackIntegration.SlackConfig
import io.tolgee.model.webhook.WebhookConfig
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table

@Entity
@Table(
indexes = [
Index(columnList = "automation_id"),
Index(columnList = "content_delivery_config_id"),
Index(columnList = "webhook_config_id"),
Index(columnList = "slack_config_id"),
],
)
class AutomationAction(
@ManyToOne(fetch = FetchType.LAZY)
var automation: Automation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ import jakarta.persistence.Entity
import jakarta.persistence.EnumType.STRING
import jakarta.persistence.Enumerated
import jakarta.persistence.FetchType
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table

@Entity
@Table(
indexes = [
Index(columnList = "automation_id"),
],
)
class AutomationTrigger(
@ManyToOne(fetch = FetchType.LAZY)
var automation: Automation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@ import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import jakarta.persistence.FetchType
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.OneToMany
import jakarta.persistence.Table
import org.hibernate.annotations.ColumnDefault
import org.hibernate.annotations.Type
import java.util.*

@Entity
@ActivityLoggedEntity
@Table(
indexes = [
Index(columnList = "project_id"),
Index(columnList = "content_storage_id"),
],
)
class ContentDeliveryConfig(
@ManyToOne(fetch = FetchType.LAZY)
var project: Project,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ import io.tolgee.model.Project
import io.tolgee.model.StandardAuditModel
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.OneToOne
import jakarta.persistence.Table
import jakarta.validation.constraints.NotBlank

@Entity
@ActivityLoggedEntity
@Table(
indexes = [
Index(columnList = "project_id"),
],
)
class ContentStorage(
@ManyToOne(fetch = FetchType.LAZY)
var project: Project,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ import io.tolgee.model.SoftDeletable
import io.tolgee.model.StandardAuditModel
import io.tolgee.model.UserAccount
import jakarta.persistence.Entity
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.OneToMany
import jakarta.persistence.Table
import jakarta.validation.constraints.NotNull
import java.util.*

@Entity
@Table(
indexes = [
Index(columnList = "project_id"),
Index(columnList = "author_id"),
],
)
class Import(
@field:NotNull
@ManyToOne(optional = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ImportFile(
@Column(length = 2000)
var name: String?,
@field:ManyToOne(optional = false)
@get:ManyToOne(optional = false)
val import: Import,
) : StandardAuditModel() {
@OneToMany(mappedBy = "file", orphanRemoval = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ import io.tolgee.model.Language
import io.tolgee.model.StandardAuditModel
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.OneToMany
import jakarta.persistence.Table
import jakarta.validation.constraints.Size

@Entity
@Table(
indexes = [
Index(columnList = "file_id"),
Index(columnList = "existing_language_id"),
],
)
class ImportLanguage(
@Size(max = 2000)
@Column(length = 2000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ import io.tolgee.model.UserAccount
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.IdClass
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table
import org.hibernate.annotations.ColumnDefault

@Entity
@IdClass(ImportSettingsId::class)
@Table(
indexes = [
Index(columnList = "project_id"),
Index(columnList = "user_account_id"),
],
)
class ImportSettings(
@Id
@ManyToOne
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import java.util.*
name = "import_translation_language_id_id",
columnList = "language_id",
),
Index(columnList = "key_id"),
Index(columnList = "conflict_id"),
],
)
class ImportTranslation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ import io.tolgee.model.dataImport.ImportFile
import io.tolgee.model.dataImport.issues.issueTypes.FileIssueType
import jakarta.persistence.Entity
import jakarta.persistence.Enumerated
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.OneToMany
import jakarta.persistence.Table
import jakarta.validation.constraints.NotNull

@Entity
@Table(
indexes = [
Index(columnList = "file_id"),
],
)
class ImportFileIssue(
@ManyToOne(optional = false)
@field:NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ import io.tolgee.model.StandardAuditModel
import io.tolgee.model.dataImport.issues.paramTypes.FileIssueParamType
import jakarta.persistence.Entity
import jakarta.persistence.Enumerated
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table
import jakarta.validation.constraints.NotBlank

@Entity
@Table(
indexes = [
Index(columnList = "issue_id"),
],
)
class ImportFileIssueParam(
@ManyToOne(optional = false)
val issue: ImportFileIssue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import jakarta.validation.constraints.NotNull
@Table(
indexes = [
Index(columnList = "key_meta_id"),
Index(columnList = "author_id"),
],
)
class KeyCodeReference(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import jakarta.validation.constraints.NotNull
@Table(
indexes = [
Index(columnList = "key_meta_id"),
Index(columnList = "author_id"),
],
)
class KeyComment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.IdClass
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table
import org.hibernate.annotations.Type

@Entity
@IdClass(KeyScreenshotReferenceId::class)
@Table(
indexes = [
Index(columnList = "key_id"),
Index(columnList = "screenshot_id"),
],
)
class KeyScreenshotReference {
@ManyToOne(optional = false)
@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.springframework.data.domain.Persistable
@Entity
@Table(
indexes = [
Index(columnList = "project_id"),
Index(columnList = "key1Id, key2Id", unique = true),
Index(columnList = "key1Id"),
Index(columnList = "key2Id"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import jakarta.persistence.FetchType
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.OneToOne
import jakarta.persistence.Table
import org.hibernate.annotations.ColumnDefault

@Entity
@Table(
indexes = [
Index(columnList = "project_id"),
],
)
class MtServiceConfig : StandardAuditModel() {
@ManyToOne
lateinit var project: Project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.tolgee.model.StandardAuditModel
import io.tolgee.model.UserAccount
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.Index
import jakarta.persistence.ManyToOne
import jakarta.persistence.OneToMany
import jakarta.persistence.Table
Expand All @@ -18,6 +19,10 @@ import jakarta.persistence.UniqueConstraint
name = "organization_slack_workspace_slack_team_id_unique",
),
],
indexes = [
Index(columnList = "organization_id"),
Index(columnList = "author_id"),
],
)
class OrganizationSlackWorkspace : StandardAuditModel() {
@ManyToOne(fetch = FetchType.LAZY)
Expand Down
Loading

0 comments on commit 1158f79

Please sign in to comment.