Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
refactor: models and services to remove user session handling
Kyle Mendellfeb9dfbd9506
diff --git a/backend/internal/api/template_handler.go b/backend/internal/api/template_handler.goindex 71f666021..83a17fbd3 100644--- a/backend/internal/api/template_handler.go+++ b/backend/internal/api/template_handler.go@@ -10,7 +10,6 @@ import ("time""github.com/gin-gonic/gin"- "github.com/google/uuid""github.com/ofkm/arcane-backend/internal/models""github.com/ofkm/arcane-backend/internal/services")@@ -135,12 +134,10 @@ func (h *TemplateHandler) CreateTemplate(c *gin.Context) {}template := &models.ComposeTemplate{- // Generate a UUID for the new template- ID: uuid.NewString(),Name: req.Name,Description: req.Description,Content: req.Content,- IsCustom: true, // New templates created via API are custom+ IsCustom: true,IsRemote: false,}@@ -336,8 +333,6 @@ func (h *TemplateHandler) CreateRegistry(c *gin.Context) {}registry := &models.TemplateRegistry{- // Generate a UUID for the registry ID- ID: uuid.NewString(),Name: req.Name,URL: req.URL,Description: req.Description,diff --git a/backend/internal/api/user_handler.go b/backend/internal/api/user_handler.goindex 5e0b905b3..51c64b09b 100644--- a/backend/internal/api/user_handler.go+++ b/backend/internal/api/user_handler.go@@ -5,7 +5,6 @@ import ("time""github.com/gin-gonic/gin"- "github.com/google/uuid""github.com/ofkm/arcane-backend/internal/dto""github.com/ofkm/arcane-backend/internal/models""github.com/ofkm/arcane-backend/internal/services"@@ -105,7 +104,6 @@ func (h *UserHandler) CreateUser(c *gin.Context) {}user := &models.User{- ID: uuid.New().String(),Username: req.Username,PasswordHash: hashedPassword,DisplayName: req.DisplayName,diff --git a/backend/internal/models/actions.go b/backend/internal/models/actions.godeleted file mode 100644index 350bd7eb3..000000000--- a/backend/internal/models/actions.go+++ /dev/null@@ -1,52 +0,0 @@-package models--type StackAction string--const (- StackActionStart StackAction = "start"- StackActionStop StackAction = "stop"- StackActionRestart StackAction = "restart"- StackActionRedeploy StackAction = "redeploy"- StackActionImport StackAction = "import"- StackActionDestroy StackAction = "destroy"- StackActionPull StackAction = "pull"- StackActionMigrate StackAction = "migrate"-)--type ContainerAction string--const (- ContainerActionStart ContainerAction = "start"- ContainerActionStop ContainerAction = "stop"- ContainerActionRestart ContainerAction = "restart"- ContainerActionPull ContainerAction = "pull"- ContainerActionRemove ContainerAction = "remove"-)--type PruneType string--const (- PruneTypeContainers PruneType = "containers"- PruneTypeImages PruneType = "images"- PruneTypeNetworks PruneType = "networks"- PruneTypeVolumes PruneType = "volumes"-)--type LoadingStates struct {- Start *bool `json:"start,omitempty"`- Stop *bool `json:"stop,omitempty"`- Restart *bool `json:"restart,omitempty"`- Pull *bool `json:"pull,omitempty"`- Deploy *bool `json:"deploy,omitempty"`- Redeploy *bool `json:"redeploy,omitempty"`- Remove *bool `json:"remove,omitempty"`- Validating *bool `json:"validating,omitempty"`-}--type PruneResult struct {- ContainersDeleted []string `json:"containersDeleted,omitempty"`- ImagesDeleted []any `json:"imagesDeleted,omitempty"`- NetworksDeleted []string `json:"networksDeleted,omitempty"`- VolumesDeleted []string `json:"volumesDeleted,omitempty"`- SpaceReclaimed int64 `json:"spaceReclaimed,omitempty"`-}diff --git a/backend/internal/models/auto_update.go b/backend/internal/models/auto_update.goindex 638c29601..a872433e3 100644--- a/backend/internal/models/auto_update.go+++ b/backend/internal/models/auto_update.go@@ -16,7 +16,6 @@ const ()type AutoUpdateRecord struct {- ID string `json:"id" gorm:"primaryKey"`ResourceID string `json:"resourceId" gorm:"index;not null"`ResourceType string `json:"resourceType" gorm:"not null"` // "container" or "stack"ResourceName string `json:"resourceName" gorm:"not null"`diff --git a/backend/internal/models/base.go b/backend/internal/models/base.goindex b89dbe6c1..10f3a98a7 100644--- a/backend/internal/models/base.go+++ b/backend/internal/models/base.go@@ -3,31 +3,21 @@ package modelsimport ("database/sql/driver""encoding/json"- "fmt"- "reflect""time""github.com/google/uuid""gorm.io/gorm")-// Base model with common fieldstype BaseModel struct {+ ID string `json:"id" gorm:"primaryKey;type:text;not null"`CreatedAt time.Time `json:"createdAt" gorm:"not null"`UpdatedAt *time.Time `json:"updatedAt,omitempty"`}-// Ensure a UUID is set on the parent model's `ID` field before create-func (m *BaseModel) BeforeCreate(tx *gorm.DB) (err error) {- v := tx.Statement.ReflectValue- if v.Kind() == reflect.Ptr {- v = v.Elem()- }- if v.IsValid() && v.Kind() == reflect.Struct {- f := v.FieldByName("ID")- if f.IsValid() && f.CanSet() && f.Kind() == reflect.String && f.Len() == 0 {- f.SetString(uuid.New().String())- }+func (m *BaseModel) BeforeCreate(_ *gorm.DB) (err error) {+ if m.ID == "" {+ m.ID = uuid.New().String()}if m.CreatedAt.IsZero() {m.CreatedAt = time.Now()@@ -35,7 +25,12 @@ func (m *BaseModel) BeforeCreate(tx *gorm.DB) (err error) {return nil}-// JSON type for handling JSON columns+func (m *BaseModel) BeforeUpdate(_ *gorm.DB) (err error) {+ now := time.Now()+ m.UpdatedAt = &now+ return nil+}+type JSON map[string]interface{}func (j JSON) Value() (driver.Value, error) {@@ -50,21 +45,16 @@ func (j *JSON) Scan(value interface{}) error {*j = nilreturn nil}-- var bytes []byteswitch v := value.(type) {case []byte:- bytes = v+ return json.Unmarshal(v, j)case string:- bytes = []byte(v)+ return json.Unmarshal([]byte(v), j)default:- return fmt.Errorf("cannot scan %T into JSON", value)+ return json.Unmarshal(nil, j)}-- return json.Unmarshal(bytes, j)}-// StringSlice for handling []string columnstype StringSlice []stringfunc (s StringSlice) Value() (driver.Value, error) {@@ -79,16 +69,12 @@ func (s *StringSlice) Scan(value interface{}) error {*s = nilreturn nil}-- var bytes []byteswitch v := value.(type) {case []byte:- bytes = v+ return json.Unmarshal(v, s)case string:- bytes = []byte(v)+ return json.Unmarshal([]byte(v), s)default:- return fmt.Errorf("cannot scan %T into StringSlice", value)+ return json.Unmarshal(nil, s)}-- return json.Unmarshal(bytes, s)}diff --git a/backend/internal/models/container.go b/backend/internal/models/container.gonew file mode 100644index 000000000..fb8b8e341--- /dev/null+++ b/backend/internal/models/container.go@@ -0,0 +1,27 @@+package models++import "time"++type Container struct {+ Name string `json:"name" gorm:"not null" sortable:"true"`+ Image string `json:"image" gorm:"not null" sortable:"true"`+ Status string `json:"status" gorm:"not null" sortable:"true"`+ State string `json:"state" gorm:"not null" sortable:"true"`+ Ports JSON `json:"ports,omitempty" gorm:"type:text"`+ Mounts JSON `json:"mounts,omitempty" gorm:"type:text"`+ Networks StringSlice `json:"networks,omitempty" gorm:"type:text"`+ Labels JSON `json:"labels,omitempty" gorm:"type:text"`+ Environment StringSlice `json:"environment,omitempty" gorm:"type:text"`+ Command StringSlice `json:"command,omitempty" gorm:"type:text"`+ StackID *string `json:"stackId,omitempty" gorm:"column:stack_id;index"`+ CreatedAt time.Time `json:"createdAt" gorm:"not null" sortable:"true"`+ StartedAt *time.Time `json:"startedAt,omitempty" gorm:"column:started_at" sortable:"true"`++ Stack *Stack `json:"stack,omitempty" gorm:"foreignKey:StackID;references:ID"`++ BaseModel+}++func (Container) TableName() string {+ return "containers_table"+}diff --git a/backend/internal/models/container_registry.go b/backend/internal/models/container_registry.goindex 4709e7d74..81807107a 100644--- a/backend/internal/models/container_registry.go+++ b/backend/internal/models/container_registry.go@@ -5,7 +5,6 @@ import ()type ContainerRegistry struct {- ID string `json:"id" gorm:"primaryKey" sortable:"true"`URL string `json:"url" gorm:"not null" sortable:"true"`Username string `json:"username" gorm:"not null" sortable:"true"`Token string `json:"token" gorm:"not null"`@@ -14,6 +13,7 @@ type ContainerRegistry struct {Enabled bool `json:"enabled" gorm:"default:true" sortable:"true"`CreatedAt time.Time `json:"createdAt" sortable:"true"`UpdatedAt time.Time `json:"updatedAt" sortable:"true"`+ BaseModel}func (ContainerRegistry) TableName() string {diff --git a/backend/internal/models/converter.go b/backend/internal/models/converter.goindex 0c029a5a2..5a793a1b4 100644--- a/backend/internal/models/converter.go+++ b/backend/internal/models/converter.go@@ -1,6 +1,5 @@package models-// DockerRunCommand represents a parsed docker run commandtype DockerRunCommand struct {Image string `json:"image"`Name string `json:"name,omitempty"`@@ -24,28 +23,23 @@ type DockerRunCommand struct {CPULimit string `json:"cpuLimit,omitempty"`}-// DockerComposeHealthcheck represents healthcheck configurationtype DockerComposeHealthcheck struct {Test string `yaml:"test" json:"test"`}-// DockerComposeResources represents resource limitstype DockerComposeResources struct {Limits *DockerComposeResourceLimits `yaml:"limits,omitempty" json:"limits,omitempty"`}-// DockerComposeResourceLimits represents resource limit valuestype DockerComposeResourceLimits struct {Memory string `yaml:"memory,omitempty" json:"memory,omitempty"`CPUs string `yaml:"cpus,omitempty" json:"cpus,omitempty"`}-// DockerComposeDeploy represents deployment configurationtype DockerComposeDeploy struct {Resources *DockerComposeResources `yaml:"resources,omitempty" json:"resources,omitempty"`}-// DockerComposeService represents a single service in docker-composetype DockerComposeService struct {Image string `yaml:"image" json:"image"`ContainerName string `yaml:"container_name,omitempty" json:"container_name,omitempty"`@@ -66,17 +60,14 @@ type DockerComposeService struct {Deploy *DockerComposeDeploy `yaml:"deploy,omitempty" json:"deploy,omitempty"`}-// DockerComposeConfig represents the entire docker-compose configurationtype DockerComposeConfig struct {Services map[string]DockerComposeService `yaml:"services" json:"services"`}-// ConvertDockerRunRequest represents the request to convert a docker run commandtype ConvertDockerRunRequest struct {DockerRunCommand string `json:"dockerRunCommand" binding:"required"`}-// ConvertDockerRunResponse represents the response from converting a docker run commandtype ConvertDockerRunResponse struct {Success bool `json:"success"`DockerCompose string `json:"dockerCompose"`diff --git a/backend/internal/models/docker.go b/backend/internal/models/docker.godeleted file mode 100644index eb6f9b262..000000000--- a/backend/internal/models/docker.go+++ /dev/null@@ -1,156 +0,0 @@-package models--import (- "fmt"- "time"-- "github.com/docker/docker/api/types/container"-)--type Container struct {- ID string `json:"id" gorm:"primaryKey;type:text"`- Name string `json:"name" gorm:"not null" sortable:"true"`- Image string `json:"image" gorm:"not null" sortable:"true"`- Status string `json:"status" gorm:"not null" sortable:"true"`- State string `json:"state" gorm:"not null" sortable:"true"`- Ports JSON `json:"ports,omitempty" gorm:"type:text"`- Mounts JSON `json:"mounts,omitempty" gorm:"type:text"`- Networks StringSlice `json:"networks,omitempty" gorm:"type:text"`- Labels JSON `json:"labels,omitempty" gorm:"type:text"`- Environment StringSlice `json:"environment,omitempty" gorm:"type:text"`- Command StringSlice `json:"command,omitempty" gorm:"type:text"`- StackID *string `json:"stackId,omitempty" gorm:"column:stack_id;index"`- CreatedAt time.Time `json:"createdAt" gorm:"not null" sortable:"true"`- StartedAt *time.Time `json:"startedAt,omitempty" gorm:"column:started_at" sortable:"true"`-- Stack *Stack `json:"stack,omitempty" gorm:"foreignKey:StackID;references:ID"`-- BaseModel-}--func (Container) TableName() string {- return "containers_table"-}--func CreateContainerFromJSON(containerJSON *container.InspectResponse) *Container {- container := &Container{- ID: containerJSON.ID,- Name: containerJSON.Name,- Image: containerJSON.Config.Image,- Status: containerJSON.State.Status,- State: containerJSON.State.Status,- BaseModel: BaseModel{- CreatedAt: time.Now(),- },- }-- if createdTime, err := time.Parse(time.RFC3339Nano, containerJSON.Created); err == nil {- container.CreatedAt = createdTime- }-- if containerJSON.State.StartedAt != "" {- if startedTime, err := time.Parse(time.RFC3339Nano, containerJSON.State.StartedAt); err == nil {- container.StartedAt = &startedTime- }- }-- return container-}--type ContainerPort struct {- PrivatePort int `json:"privatePort"`- PublicPort *int `json:"publicPort,omitempty"`- Type string `json:"type"`- IP string `json:"ip,omitempty"`-}--type ContainerMount struct {- Source string `json:"source"`- Destination string `json:"destination"`- Mode string `json:"mode"`- RW bool `json:"rw"`-}--type Image struct {- ID string `json:"id" gorm:"primaryKey;type:text"`- RepoTags StringSlice `json:"repoTags" gorm:"type:text"`- RepoDigests StringSlice `json:"repoDigests,omitempty" gorm:"type:text"`- Size int64 `json:"size" gorm:"not null" sortable:"true"`- VirtualSize int64 `json:"virtualSize" gorm:"column:virtual_size"`- Labels JSON `json:"labels,omitempty" gorm:"type:text"`- Created time.Time `json:"created" gorm:"not null" sortable:"true"`-- Repo string `json:"repo" gorm:"column:repo;index" sortable:"true"`- Tag string `json:"tag" gorm:"column:tag;index" sortable:"true"`- InUse bool `json:"inUse" gorm:"column:in_use;default:false" sortable:"true"`-- UpdateRecord *ImageUpdateRecord `json:"updateInfo,omitempty" gorm:"foreignKey:ID;references:ID"`-- BaseModel-}--func (i *Image) TableName() string {- return "images_table"-}--func (i *Image) GetFullName() string {- if i.Repo == "<none>" || i.Tag == "<none>" {- return i.ID[:12]- }- return fmt.Sprintf("%s:%s", i.Repo, i.Tag)-}--func (i *Image) IsTagged() bool {- return i.Repo != "<none>" && i.Tag != "<none>"-}--type Volume struct {- Name string `json:"name" gorm:"primaryKey;type:text"`- Driver string `json:"driver" gorm:"not null"`- Mountpoint string `json:"mountpoint" gorm:"not null"`- Labels JSON `json:"labels,omitempty" gorm:"type:text"`- Scope string `json:"scope" gorm:"not null"`- Options JSON `json:"options,omitempty" gorm:"type:text"`- CreatedAt time.Time `json:"createdAt" gorm:"not null"`-- InUse bool `json:"inUse" gorm:"column:in_use;default:false"`-- BaseModel-}--func (Volume) TableName() string {- return "volumes_table"-}--type Network struct {- ID string `json:"id" gorm:"primaryKey;type:text"`- Name string `json:"name" gorm:"uniqueIndex;not null"`- Driver string `json:"driver" gorm:"not null"`- Scope string `json:"scope" gorm:"not null"`- Internal bool `json:"internal" gorm:"default:false"`- Attachable bool `json:"attachable" gorm:"default:false"`- Ingress bool `json:"ingress" gorm:"default:false"`- IPAM JSON `json:"ipam" gorm:"type:text"`- Labels JSON `json:"labels,omitempty" gorm:"type:text"`- Options JSON `json:"options,omitempty" gorm:"type:text"`- CreatedAt time.Time `json:"createdAt" gorm:"not null"`-- BaseModel-}--func (Network) TableName() string {- return "networks_table"-}--type NetworkIPAM struct {- Driver string `json:"driver"`- Config []NetworkIPAMConfig `json:"config,omitempty"`- Options map[string]string `json:"options,omitempty"`-}--type NetworkIPAMConfig struct {- Subnet string `json:"subnet,omitempty"`- IPRange string `json:"ipRange,omitempty"`- Gateway string `json:"gateway,omitempty"`- AuxAddress string `json:"auxAddress,omitempty"`-}diff --git a/backend/internal/models/event.go b/backend/internal/models/event.goindex 8aabc1048..4e0e3299b 100644--- a/backend/internal/models/event.go+++ b/backend/internal/models/event.go@@ -47,7 +47,6 @@ const ()type Event struct {- ID string `json:"id" gorm:"primaryKey" sortable:"true"`Type EventType `json:"type" gorm:"not null" sortable:"true"`Severity EventSeverity `json:"severity" gorm:"not null" sortable:"true"`Title string `json:"title" gorm:"not null" sortable:"true"`diff --git a/backend/internal/models/image.go b/backend/internal/models/image.gonew file mode 100644index 000000000..3b52494b7--- /dev/null+++ b/backend/internal/models/image.go@@ -0,0 +1,24 @@+package models++import "time"++type Image struct {+ RepoTags StringSlice `json:"repoTags" gorm:"type:text"`+ RepoDigests StringSlice `json:"repoDigests,omitempty" gorm:"type:text"`+ Size int64 `json:"size" gorm:"not null" sortable:"true"`+ VirtualSize int64 `json:"virtualSize" gorm:"column:virtual_size"`+ Labels JSON `json:"labels,omitempty" gorm:"type:text"`+ Created time.Time `json:"created" gorm:"not null" sortable:"true"`++ Repo string `json:"repo" gorm:"column:repo;index" sortable:"true"`+ Tag string `json:"tag" gorm:"column:tag;index" sortable:"true"`+ InUse bool `json:"inUse" gorm:"column:in_use;default:false" sortable:"true"`++ UpdateRecord *ImageUpdateRecord `json:"updateInfo,omitempty" gorm:"foreignKey:ID;references:ID"`++ BaseModel+}++func (i *Image) TableName() string {+ return "images_table"+}diff --git a/backend/internal/models/network.go b/backend/internal/models/network.gonew file mode 100644index 000000000..baae9e9f3--- /dev/null+++ b/backend/internal/models/network.go@@ -0,0 +1,22 @@+package models++import "time"++type Network struct {+ Name string `json:"name" gorm:"uniqueIndex;not null"`+ Driver string `json:"driver" gorm:"not null"`+ Scope string `json:"scope" gorm:"not null"`+ Internal bool `json:"internal" gorm:"default:false"`+ Attachable bool `json:"attachable" gorm:"default:false"`+ Ingress bool `json:"ingress" gorm:"default:false"`+ IPAM JSON `json:"ipam" gorm:"type:text"`+ Labels JSON `json:"labels,omitempty" gorm:"type:text"`+ Options JSON `json:"options,omitempty" gorm:"type:text"`+ CreatedAt time.Time `json:"createdAt" gorm:"not null"`++ BaseModel+}++func (Network) TableName() string {+ return "networks_table"+}diff --git a/backend/internal/models/session.go b/backend/internal/models/session.godeleted file mode 100644index fdd21b383..000000000--- a/backend/internal/models/session.go+++ /dev/null@@ -1,23 +0,0 @@-package models--import "time"--type UserSession struct {- ID string `json:"id" gorm:"primaryKey;type:text"`- UserID string `json:"userId" gorm:"column:user_id;not null;index"`- Username string `json:"username" gorm:"not null"`- Token string `json:"token" gorm:"uniqueIndex;not null"`- CreatedAt time.Time `json:"createdAt" gorm:"not null"`- LastAccessed time.Time `json:"lastAccessed" gorm:"column:last_accessed;not null"`- ExpiresAt *time.Time `json:"expiresAt,omitempty" gorm:"column:expires_at"`- IsActive bool `json:"isActive" gorm:"column:is_active;default:true"`-- // Relationships- User User `json:"user" gorm:"foreignKey:UserID;references:ID"`-- BaseModel-}--func (UserSession) TableName() string {- return "user_sessions_table"-}diff --git a/backend/internal/models/settings.go b/backend/internal/models/settings.goindex 8bee0658f..1da95f002 100644--- a/backend/internal/models/settings.go+++ b/backend/internal/models/settings.go@@ -11,6 +11,11 @@ import ("time")+const (+ redactionMask = "XXXXXXXXXX"+ keyAuthOidcConfig = "authOidcConfig"+)+type SettingVariable struct {Key string `gorm:"primaryKey;not null"`Value string@@ -74,7 +79,7 @@ func (s *Settings) ToSettingVariableSlice(showAll bool, redactSensitiveValues bovar res []SettingVariable- for i := range cfgType.NumField() {+ for i := 0; i < cfgType.NumField(); i++ {field := cfgType.Field(i)key, attrs, _ := strings.Cut(field.Tag.Get("key"), ",")@@ -87,32 +92,12 @@ func (s *Settings) ToSettingVariableSlice(showAll bool, redactSensitiveValues bo}value := cfgValue.Field(i).FieldByName("Value").String()-- // Redact sensitive values if requested- if value != "" && redactSensitiveValues && attrs == "sensitive" {- if key == "authOidcConfig" {- // Redact only the clientSecret field while keeping the rest visible- var cfg OidcConfig- if err := json.Unmarshal([]byte(value), &cfg); err == nil {- cfg.ClientSecret = ""- if redacted, err := json.Marshal(cfg); err == nil {- value = string(redacted)- } else {- value = "XXXXXXXXXX"- }- } else {- value = "XXXXXXXXXX"- }- } else {- value = "XXXXXXXXXX"- }- }+ value = redactSettingValue(key, value, attrs, redactSensitiveValues)settingVariable := SettingVariable{Key: key,Value: value,}-res = append(res, settingVariable)}@@ -123,7 +108,7 @@ func (s *Settings) FieldByKey(key string) (defaultValue string, isPublic bool, irv := reflect.ValueOf(s).Elem()rt := rv.Type()- for i := range rt.NumField() {+ for i := 0; i < rt.NumField(); i++ {tagValue := strings.Split(rt.Field(i).Tag.Get("key"), ",")keyFromTag := tagValue[0]isPublic = slices.Contains(tagValue, "public")@@ -144,7 +129,7 @@ func (s *Settings) UpdateField(key string, value string, noSensitive bool) errorrv := reflect.ValueOf(s).Elem()rt := rv.Type()- for i := range rt.NumField() {+ for i := 0; i < rt.NumField(); i++ {tagValue, attrs, _ := strings.Cut(rt.Field(i).Tag.Get("key"), ",")if tagValue != key {continue@@ -167,6 +152,27 @@ func (s *Settings) UpdateField(key string, value string, noSensitive bool) errorreturn SettingKeyNotFoundError{field: key}}+// helper keeps redaction logic in one place; behavior unchanged+func redactSettingValue(key, value, attrs string, redact bool) string {+ if value == "" || !redact || attrs != "sensitive" {+ return value+ }++ if key == keyAuthOidcConfig {+ var cfg OidcConfig+ if err := json.Unmarshal([]byte(value), &cfg); err == nil {+ cfg.ClientSecret = ""+ if redacted, err := json.Marshal(cfg); err == nil {+ return string(redacted)+ }+ return redactionMask+ }+ return redactionMask+ }++ return redactionMask+}+type SettingKeyNotFoundError struct {field string}@@ -193,21 +199,6 @@ func (e SettingSensitiveForbiddenError) Is(target error) bool {return errors.As(target, &x)}-// Legacy types for backward compatibility-type RegistryCredential struct {- URL string `json:"url"`- Username string `json:"username"`- Password string `json:"password"`-}--type TemplateRegistryConfig struct {- URL string `json:"url"`- Name string `json:"name"`- Enabled bool `json:"enabled"`- LastUpdated *int64 `json:"lastUpdated,omitempty"`- CacheTTL *int `json:"cacheTtl,omitempty"`-}-type OidcConfig struct {ClientID string `json:"clientId"`ClientSecret string `json:"clientSecret"`diff --git a/backend/internal/models/stack.go b/backend/internal/models/stack.goindex 18cace19e..9d618b115 100644--- a/backend/internal/models/stack.go+++ b/backend/internal/models/stack.go@@ -2,37 +2,6 @@ package modelsimport "time"-type StackPort struct {- PublicPort *int `json:"publicPort,omitempty"`- PrivatePort *int `json:"privatePort,omitempty"`- Type string `json:"type"`-}--type StackService struct {- ID string `json:"id"`- Name string `json:"name"`- State *StackServiceState `json:"state,omitempty"`- Ports []StackPort `json:"ports,omitempty"`- NetworkSettings *NetworkSettings `json:"networkSettings,omitempty"`-}--type StackServiceState struct {- Running bool `json:"running"`- Status string `json:"status"`- ExitCode int `json:"exitCode"`-}--type NetworkSettings struct {- Networks map[string]NetworkConfig `json:"networks,omitempty"`-}--type NetworkConfig struct {- IPAddress *string `json:"ipAddress,omitempty"`- Gateway *string `json:"gateway,omitempty"`- MacAddress *string `json:"macAddress,omitempty"`- Driver *string `json:"driver,omitempty"`-}-type StackStatus stringconst (@@ -46,7 +15,6 @@ const ()type Stack struct {- ID string `json:"id" gorm:"primaryKey"`Name string `json:"name" gorm:"not null" sortable:"true"`DirName *string `json:"dir_name" gorm:"unique"`Path string `json:"path" gorm:"not null"`diff --git a/backend/internal/models/template.go b/backend/internal/models/template.goindex 45d76c3f2..d24575144 100644--- a/backend/internal/models/template.go+++ b/backend/internal/models/template.go@@ -1,21 +1,15 @@package models-import (- "time"-)-type TemplateRegistry struct {- ID string `json:"id" gorm:"primaryKey"`- Name string `json:"name" gorm:"not null"`- URL string `json:"url" gorm:"not null;unique"`- Enabled bool `json:"enabled" gorm:"default:true"`- Description string `json:"description"`- CreatedAt time.Time `json:"createdAt"`- UpdatedAt time.Time `json:"updatedAt"`+ BaseModel+ Name string `json:"name" gorm:"not null"`+ URL string `json:"url" gorm:"not null;unique"`+ Enabled bool `json:"enabled" gorm:"default:true"`+ Description string `json:"description"`}type ComposeTemplate struct {- ID string `json:"id" gorm:"primaryKey"`+ BaseModelName string `json:"name" gorm:"not null"`Description string `json:"description"`Content string `json:"content" gorm:"type:text"`@@ -23,10 +17,8 @@ type ComposeTemplate struct {IsCustom bool `json:"isCustom" gorm:"default:true"`IsRemote bool `json:"isRemote" gorm:"default:false"`RegistryID *string `json:"registryId,omitempty"`- Registry *TemplateRegistry `json:"registry,omitempty" gorm:"foreignKey:RegistryID"`+ Registry *TemplateRegistry `json:"registry,omitempty" gorm:"foreignKey:RegistryID;references:ID"`Metadata *ComposeTemplateMetadata `json:"metadata,omitempty" gorm:"embedded;embeddedPrefix:meta_"`- CreatedAt time.Time `json:"createdAt"`- UpdatedAt time.Time `json:"updatedAt"`}type ComposeTemplateMetadata struct {diff --git a/backend/internal/models/user.go b/backend/internal/models/user.goindex e819178e7..207a5229c 100644--- a/backend/internal/models/user.go+++ b/backend/internal/models/user.go@@ -5,7 +5,6 @@ import ()type User struct {- ID string `json:"id" gorm:"primaryKey;type:text"`Username string `json:"username" gorm:"uniqueIndex;not null"`PasswordHash string `json:"-" gorm:"column:password_hash"`DisplayName *string `json:"displayName,omitempty" gorm:"column:display_name"`diff --git a/backend/internal/models/volume.go b/backend/internal/models/volume.gonew file mode 100644index 000000000..6ba2ca80d--- /dev/null+++ b/backend/internal/models/volume.go@@ -0,0 +1,21 @@+package models++import "time"++type Volume struct {+ Name string `json:"name" gorm:"primaryKey;type:text"`+ Driver string `json:"driver" gorm:"not null"`+ Mountpoint string `json:"mountpoint" gorm:"not null"`+ Labels JSON `json:"labels,omitempty" gorm:"type:text"`+ Scope string `json:"scope" gorm:"not null"`+ Options JSON `json:"options,omitempty" gorm:"type:text"`+ CreatedAt time.Time `json:"createdAt" gorm:"not null"`++ InUse bool `json:"inUse" gorm:"column:in_use;default:false"`++ BaseModel+}++func (Volume) TableName() string {+ return "volumes_table"+}diff --git a/backend/internal/services/auth_service.go b/backend/internal/services/auth_service.goindex dba5e5dc8..665ba017e 100644--- a/backend/internal/services/auth_service.go+++ b/backend/internal/services/auth_service.go@@ -2,8 +2,6 @@ package servicesimport ("context"- "crypto/rand"- "encoding/base64""encoding/json""errors""fmt"@@ -296,7 +294,6 @@ func (s *AuthService) OidcLogin(ctx context.Context, userInfo dto.OidcUserInfo)email := userInfo.Emailuser = &models.User{- ID: generateUserId(),Username: username,DisplayName: &displayName,Email: &email,@@ -411,7 +408,6 @@ func (s *AuthService) VerifyToken(ctx context.Context, accessToken string) (*mod}user := &models.User{- ID: claims.UserID,Username: claims.Username,Roles: models.StringSlice(claims.Roles),}@@ -504,15 +500,6 @@ func (s *AuthService) generateTokenPair(ctx context.Context, user *models.User)}, nil}-func generateUserId() string {- b := make([]byte, 16)- _, err := rand.Read(b)- if err != nil {- panic(err)- }- return fmt.Sprintf("usr_%s", base64.RawURLEncoding.EncodeToString(b))-}-func generateUsernameFromEmail(email, subject string) string {if email != "" {parts := strings.Split(email, "@")diff --git a/backend/internal/services/auto_update_service.go b/backend/internal/services/auto_update_service.goindex 259dd075e..e64abdd5c 100644--- a/backend/internal/services/auto_update_service.go+++ b/backend/internal/services/auto_update_service.go@@ -16,7 +16,6 @@ import ("github.com/docker/docker/api/types/image""github.com/docker/docker/api/types/network""github.com/docker/docker/api/types/registry"- "github.com/google/uuid""gopkg.in/yaml.v3""github.com/ofkm/arcane-backend/internal/database"@@ -1033,7 +1032,6 @@ func (s *AutoUpdateService) serviceHasAutoUpdateLabel(service interface{}) boolfunc (s *AutoUpdateService) recordAutoUpdate(ctx context.Context, result dto.AutoUpdateResourceResult) error {record := &models.AutoUpdateRecord{- ID: uuid.New().String(),ResourceID: result.ResourceID,ResourceType: result.ResourceType,ResourceName: result.ResourceName,diff --git a/backend/internal/services/container_registry_service.go b/backend/internal/services/container_registry_service.goindex c83981de0..0df2b1c36 100644--- a/backend/internal/services/container_registry_service.go+++ b/backend/internal/services/container_registry_service.go@@ -6,7 +6,6 @@ import ("strings""time"- "github.com/google/uuid""github.com/ofkm/arcane-backend/internal/database""github.com/ofkm/arcane-backend/internal/models""github.com/ofkm/arcane-backend/internal/utils"@@ -20,10 +19,6 @@ func NewContainerRegistryService(db *database.DB) *ContainerRegistryService {return &ContainerRegistryService{db: db}}-func generateID() string {- return uuid.New().String()-}-func (s *ContainerRegistryService) GetAllRegistries(ctx context.Context) ([]models.ContainerRegistry, error) {var registries []models.ContainerRegistryif err := s.db.WithContext(ctx).Find(®istries).Error; err != nil {@@ -65,7 +60,6 @@ func (s *ContainerRegistryService) CreateRegistry(ctx context.Context, req model}registry := &models.ContainerRegistry{- ID: generateID(),URL: req.URL,Username: req.Username,Token: encryptedToken,diff --git a/backend/internal/services/event_service.go b/backend/internal/services/event_service.goindex 0457a692b..37ff03035 100644--- a/backend/internal/services/event_service.go+++ b/backend/internal/services/event_service.go@@ -5,7 +5,6 @@ import ("fmt""time"- "github.com/google/uuid""github.com/ofkm/arcane-backend/internal/database""github.com/ofkm/arcane-backend/internal/dto""github.com/ofkm/arcane-backend/internal/models"@@ -41,7 +40,6 @@ func (s *EventService) CreateEvent(ctx context.Context, req CreateEventRequest)}event := &models.Event{- ID: uuid.New().String(),Type: req.Type,Severity: severity,Title: req.Title,diff --git a/backend/internal/services/image_service.go b/backend/internal/services/image_service.goindex bf8de6728..1420b2c7d 100644--- a/backend/internal/services/image_service.go+++ b/backend/internal/services/image_service.go@@ -380,7 +380,6 @@ func (s *ImageService) syncSingleImage(ctx context.Context, di image.Summary, infunc (s *ImageService) buildImageModel(di image.Summary, isInUse bool) models.Image {imageModel := models.Image{- ID: di.ID,RepoTags: models.StringSlice(di.RepoTags),RepoDigests: models.StringSlice(di.RepoDigests),Size: di.Size,diff --git a/backend/internal/services/stack_service.go b/backend/internal/services/stack_service.goindex d4fb94080..99abf8f05 100644--- a/backend/internal/services/stack_service.go+++ b/backend/internal/services/stack_service.go@@ -15,11 +15,11 @@ import ("time""github.com/compose-spec/compose-go/v2/cli"- "github.com/google/uuid""github.com/ofkm/arcane-backend/internal/database""github.com/ofkm/arcane-backend/internal/models""github.com/ofkm/arcane-backend/internal/utils""gorm.io/gorm"+ "gorm.io/gorm/clause")type StackServiceInfo struct {@@ -45,7 +45,6 @@ func NewStackService(db *database.DB, settingsService *SettingsService, eventSer}func (s *StackService) CreateStack(ctx context.Context, name, composeContent string, envContent *string, user models.User) (*models.Stack, error) {- stackID := uuid.New().String()folderName := s.sanitizeStackName(name)stacksDir, err := s.getStacksDirectory(ctx)@@ -67,7 +66,6 @@ func (s *StackService) CreateStack(ctx context.Context, name, composeContent str}stack := &models.Stack{- ID: stackID,Name: name,DirName: &folderName,Path: stackPath,@@ -85,14 +83,14 @@ func (s *StackService) CreateStack(ctx context.Context, name, composeContent strreturn nil, fmt.Errorf("failed to save stack files: %w", err)}- // Log stack creation event+ // Log stack creation event (use the DB-assigned BaseModel.ID)metadata := models.JSON{"action": "create",- "stackId": stackID,+ "stackId": stack.ID,"stackName": name,"path": stackPath,}- if logErr := s.eventService.LogStackEvent(ctx, models.EventTypeStackCreate, stackID, name, user.ID, user.Username, "0", metadata); logErr != nil {+ if logErr := s.eventService.LogStackEvent(ctx, models.EventTypeStackCreate, stack.ID, name, user.ID, user.Username, "0", metadata); logErr != nil {fmt.Printf("Could not log stack creation action: %s\n", logErr)}@@ -1170,7 +1168,6 @@ func (s *StackService) importExternalStack(ctx context.Context, dirName, stackNa}stack := &models.Stack{- ID: uuid.New().String(),Name: stackName,DirName: &dirName,Path: path,@@ -1234,7 +1231,7 @@ func (s *StackService) updateProjectCache(ctx context.Context, stacks []models.Sfor _, stack := range stacks {select {case <-ctx.Done():- return // Stop if context is canceled+ returndefault:}@@ -1255,9 +1252,25 @@ func (s *StackService) updateProjectCache(ctx context.Context, stacks []models.SCachedAt: time.Now(),}- if err := s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {- return tx.Where("stack_id = ?", stack.ID).Save(&cache).Error- }); err != nil {+ // Upsert on stack_id to avoid UNIQUE(stack_id) violations+ err = s.db.WithContext(ctx).+ Clauses(clause.OnConflict{+ Columns: []clause.Column{{Name: "stack_id"}},+ DoUpdates: clause.Assignments(map[string]interface{}{+ "name": cache.Name,+ "status": cache.Status,+ "service_count": cache.ServiceCount,+ "running_count": cache.RunningCount,+ "auto_update": cache.AutoUpdate,+ "last_modified": cache.LastModified,+ "compose_hash": cache.ComposeHash,+ "cached_at": cache.CachedAt,+ "updated_at": time.Now(),+ }),+ }).+ Create(&cache).Error++ if err != nil {fmt.Printf("Warning: failed to update cache for stack %s: %v\n", stack.ID, err)}}diff --git a/backend/internal/services/system_service.go b/backend/internal/services/system_service.goindex f0784a2e6..6e9738537 100644--- a/backend/internal/services/system_service.go+++ b/backend/internal/services/system_service.go@@ -44,7 +44,6 @@ func NewSystemService(var systemUser = models.User{Username: "System",- ID: "0",}func (s *SystemService) PruneAll(ctx context.Context, req dto.PruneSystemDto) (*dto.PruneAllResult, error) {diff --git a/backend/internal/services/template_service.go b/backend/internal/services/template_service.goindex d5caab58b..39b5546cb 100644--- a/backend/internal/services/template_service.go+++ b/backend/internal/services/template_service.go@@ -330,8 +330,6 @@ func (s *TemplateService) convertRemoteToLocal(remote dto.RemoteTemplate, regist}return models.ComposeTemplate{- // Use the combined ID format here- ID: fmt.Sprintf("%s-%s", registry.ID, remote.ID),Name: remote.Name,Description: remote.Description,Content: "", // Content is not stored for remote templates initially@@ -439,14 +437,12 @@ func (s *TemplateService) DownloadTemplate(ctx context.Context, remoteTemplate *}localTemplate := &models.ComposeTemplate{- // Generate a new ID for the local copy, distinct from the remote ID- ID: s.generateTemplateID(remoteTemplate.Name), // Use a local-specific ID generationName: remoteTemplate.Name,Description: fmt.Sprintf("%s (Downloaded from %s)", remoteTemplate.Description, remoteTemplate.Registry.Name),Content: composeContent,- IsCustom: true, // Downloaded templates are custom local copies+ IsCustom: true,IsRemote: false,- RegistryID: nil, // No longer linked to a remote registry+ RegistryID: nil,Registry: nil,}@@ -454,7 +450,6 @@ func (s *TemplateService) DownloadTemplate(ctx context.Context, remoteTemplate *localTemplate.EnvContent = &envContent}- // Copy relevant metadataif remoteTemplate.Metadata != nil {localTemplate.Metadata = &models.ComposeTemplateMetadata{Version: remoteTemplate.Metadata.Version,@@ -462,7 +457,6 @@ func (s *TemplateService) DownloadTemplate(ctx context.Context, remoteTemplate *Tags: remoteTemplate.Metadata.Tags,DocumentationURL: remoteTemplate.Metadata.DocumentationURL,IconURL: remoteTemplate.Metadata.IconURL,- // Do not copy RemoteURL, EnvURL, UpdatedAt as it's now local}}@@ -477,16 +471,3 @@ func (s *TemplateService) DownloadTemplate(ctx context.Context, remoteTemplate *return localTemplate, nil}--// Helper to remove a template from the remote cache (optional)-// func (s *TemplateService) removeRemoteTemplateFromCache(id string) {-// s.remoteFetchMutex.Lock()-// defer s.remoteFetchMutex.Unlock()-// var updatedCache []models.ComposeTemplate-// for _, t := range s.remoteTemplatesCache {-// if t.ID != id {-// updatedCache = append(updatedCache, t)-// }-// }-// s.remoteTemplatesCache = updatedCache-// }diff --git a/backend/internal/services/user_service.go b/backend/internal/services/user_service.goindex 5c6145652..b2b3d95f2 100644--- a/backend/internal/services/user_service.go+++ b/backend/internal/services/user_service.go@@ -16,7 +16,6 @@ import ("crypto/subtle"- "github.com/google/uuid""github.com/ofkm/arcane-backend/internal/database""github.com/ofkm/arcane-backend/internal/dto""github.com/ofkm/arcane-backend/internal/models"@@ -145,7 +144,6 @@ func (s *UserService) CreateUserWithPassword(username, password, email, role str}user := &models.User{- ID: uuid.New().String(),Username: username,Email: &email,DisplayName: &displayName,diff --git a/backend/resources/migrations/postgres/005_drop_user_sessions_table.down.sql b/backend/resources/migrations/postgres/005_drop_user_sessions_table.down.sqlnew file mode 100644index 000000000..20c1409f5--- /dev/null+++ b/backend/resources/migrations/postgres/005_drop_user_sessions_table.down.sql@@ -0,0 +1,16 @@+-- Recreate user_sessions_table (matches initial schema)+CREATE TABLE IF NOT EXISTS user_sessions_table (+ id TEXT PRIMARY KEY,+ user_id TEXT NOT NULL,+ username TEXT NOT NULL,+ token TEXT NOT NULL UNIQUE,+ created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,+ last_accessed DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,+ expires_at DATETIME,+ is_active BOOLEAN NOT NULL DEFAULT true,+ updated_at DATETIME,+ FOREIGN KEY (user_id) REFERENCES users_table(id) ON DELETE CASCADE+);++CREATE INDEX IF NOT EXISTS idx_user_sessions_user_id ON user_sessions_table(user_id);+CREATE INDEX IF NOT EXISTS idx_user_sessions_token ON user_sessions_table(token);\ No newline at end of filediff --git a/backend/resources/migrations/postgres/005_drop_user_sessions_table.up.sql b/backend/resources/migrations/postgres/005_drop_user_sessions_table.up.sqlnew file mode 100644index 000000000..73c49bd0b--- /dev/null+++ b/backend/resources/migrations/postgres/005_drop_user_sessions_table.up.sql@@ -0,0 +1,5 @@+-- Drop indexes first (safe if they exist), then drop the table+DROP INDEX IF EXISTS idx_user_sessions_token;+DROP INDEX IF EXISTS idx_user_sessions_user_id;++DROP TABLE IF EXISTS user_sessions_table;\ No newline at end of filediff --git a/backend/resources/migrations/sqlite/005_drop_user_sessions_table.down.sql b/backend/resources/migrations/sqlite/005_drop_user_sessions_table.down.sqlnew file mode 100644index 000000000..20c1409f5--- /dev/null+++ b/backend/resources/migrations/sqlite/005_drop_user_sessions_table.down.sql@@ -0,0 +1,16 @@+-- Recreate user_sessions_table (matches initial schema)+CREATE TABLE IF NOT EXISTS user_sessions_table (+ id TEXT PRIMARY KEY,+ user_id TEXT NOT NULL,+ username TEXT NOT NULL,+ token TEXT NOT NULL UNIQUE,+ created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,+ last_accessed DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,+ expires_at DATETIME,+ is_active BOOLEAN NOT NULL DEFAULT true,+ updated_at DATETIME,+ FOREIGN KEY (user_id) REFERENCES users_table(id) ON DELETE CASCADE+);++CREATE INDEX IF NOT EXISTS idx_user_sessions_user_id ON user_sessions_table(user_id);+CREATE INDEX IF NOT EXISTS idx_user_sessions_token ON user_sessions_table(token);\ No newline at end of filediff --git a/backend/resources/migrations/sqlite/005_drop_user_sessions_table.up.sql b/backend/resources/migrations/sqlite/005_drop_user_sessions_table.up.sqlnew file mode 100644index 000000000..73c49bd0b--- /dev/null+++ b/backend/resources/migrations/sqlite/005_drop_user_sessions_table.up.sql@@ -0,0 +1,5 @@+-- Drop indexes first (safe if they exist), then drop the table+DROP INDEX IF EXISTS idx_user_sessions_token;+DROP INDEX IF EXISTS idx_user_sessions_user_id;++DROP TABLE IF EXISTS user_sessions_table;\ No newline at end of file