Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
refactor: remove enabled field from git syncs (#1457)
Kyle Mendellf4a04cb3afd0
diff --git a/backend/internal/models/gitops_sync.go b/backend/internal/models/gitops_sync.goindex 4146ffb28..196bb9284 100644--- a/backend/internal/models/gitops_sync.go+++ b/backend/internal/models/gitops_sync.go@@ -21,7 +21,6 @@ type GitOpsSync struct {LastSyncStatus *string `json:"lastSyncStatus,omitempty" search:"status,success,failed,pending,error"`LastSyncError *string `json:"lastSyncError,omitempty"`LastSyncCommit *string `json:"lastSyncCommit,omitempty" search:"commit,hash,sha,revision"`- Enabled bool `json:"enabled" sortable:"true" search:"enabled,active,disabled"`BaseModel}diff --git a/backend/internal/services/gitops_sync_service.go b/backend/internal/services/gitops_sync_service.goindex 9c6cb516b..ff9e974a1 100644--- a/backend/internal/services/gitops_sync_service.go+++ b/backend/internal/services/gitops_sync_service.go@@ -45,7 +45,6 @@ func (s *GitOpsSyncService) GetSyncsPaginated(ctx context.Context, environmentID)}- q = pagination.ApplyBooleanFilter(q, "enabled", params.Filters["enabled"])q = pagination.ApplyBooleanFilter(q, "auto_sync", params.Filters["autoSync"])q = pagination.ApplyFilter(q, "repository_id", params.Filters["repositoryId"])@@ -102,7 +101,6 @@ func (s *GitOpsSyncService) CreateSync(ctx context.Context, environmentID stringProjectID: nil, // Will be set during first syncAutoSync: false,SyncInterval: 60,- Enabled: true,}if req.AutoSync != nil {@@ -111,9 +109,6 @@ func (s *GitOpsSyncService) CreateSync(ctx context.Context, environmentID stringif req.SyncInterval != nil {sync.SyncInterval = *req.SyncInterval}- if req.Enabled != nil {- sync.Enabled = *req.Enabled- }if err := s.db.WithContext(ctx).Create(&sync).Error; err != nil {return nil, fmt.Errorf("failed to create sync: %w", err)@@ -133,11 +128,9 @@ func (s *GitOpsSyncService) CreateSync(ctx context.Context, environmentID stringUsername: &systemUser.Username,})- if sync.Enabled {- if _, err := s.PerformSync(ctx, sync.EnvironmentID, sync.ID); err != nil {- slog.ErrorContext(ctx, "Failed to perform initial sync after creation", "syncId", sync.ID, "error", err)- // Don't fail the entire creation - the sync config exists and can be retried- }+ if _, err := s.PerformSync(ctx, sync.EnvironmentID, sync.ID); err != nil {+ slog.ErrorContext(ctx, "Failed to perform initial sync after creation", "syncId", sync.ID, "error", err)+ // Don't fail the entire creation - the sync config exists and can be retried}return s.GetSyncByID(ctx, "", sync.ID)@@ -177,9 +170,6 @@ func (s *GitOpsSyncService) UpdateSync(ctx context.Context, environmentID, id stif req.SyncInterval != nil {updates["sync_interval"] = *req.SyncInterval}- if req.Enabled != nil {- updates["enabled"] = *req.Enabled- }if len(updates) > 0 {if err := s.db.WithContext(ctx).Model(sync).Updates(updates).Error; err != nil {@@ -341,7 +331,6 @@ func (s *GitOpsSyncService) GetSyncStatus(ctx context.Context, environmentID, idstatus := &gitops.SyncStatus{ID: sync.ID,- Enabled: sync.Enabled,AutoSync: sync.AutoSync,LastSyncAt: sync.LastSyncAt,LastSyncStatus: sync.LastSyncStatus,@@ -350,7 +339,7 @@ func (s *GitOpsSyncService) GetSyncStatus(ctx context.Context, environmentID, id}// Calculate next sync time- if sync.AutoSync && sync.Enabled && sync.LastSyncAt != nil {+ if sync.AutoSync && sync.LastSyncAt != nil {nextSync := sync.LastSyncAt.Add(time.Duration(sync.SyncInterval) * time.Minute)status.NextSyncAt = &nextSync}@@ -363,9 +352,9 @@ func (s *GitOpsSyncService) SyncAllEnabled(ctx context.Context) error {if err := s.db.WithContext(ctx).Preload("Repository").Preload("Project").- Where("enabled = ? AND auto_sync = ?", true, true).+ Where("auto_sync = ?", true).Find(&syncs).Error; err != nil {- return fmt.Errorf("failed to get enabled syncs: %w", err)+ return fmt.Errorf("failed to get auto-sync enabled syncs: %w", err)}for _, sync := range syncs {@@ -456,7 +445,6 @@ func (s *GitOpsSyncService) ImportSyncs(ctx context.Context, environmentID strinProjectName: importItem.SyncName,AutoSync: &importItem.AutoSync,SyncInterval: &importItem.SyncInterval,- Enabled: &importItem.Enabled,}_, err = s.CreateSync(ctx, environmentID, createReq)diff --git a/backend/resources/migrations/postgres/030_remove_gitops_sync_enabled.down.sql b/backend/resources/migrations/postgres/030_remove_gitops_sync_enabled.down.sqlnew file mode 100644index 000000000..121f905b0--- /dev/null+++ b/backend/resources/migrations/postgres/030_remove_gitops_sync_enabled.down.sql@@ -0,0 +1,3 @@+-- Re-add the enabled column to gitops_syncs table+ALTER TABLE gitops_syncs ADD COLUMN IF NOT EXISTS enabled BOOLEAN NOT NULL DEFAULT true;+CREATE INDEX IF NOT EXISTS idx_gitops_syncs_enabled ON gitops_syncs(enabled);diff --git a/backend/resources/migrations/postgres/030_remove_gitops_sync_enabled.up.sql b/backend/resources/migrations/postgres/030_remove_gitops_sync_enabled.up.sqlnew file mode 100644index 000000000..149e2d0ec--- /dev/null+++ b/backend/resources/migrations/postgres/030_remove_gitops_sync_enabled.up.sql@@ -0,0 +1,3 @@+-- Remove the enabled column from gitops_syncs table+-- Only autoSync field will control automatic syncing behavior+ALTER TABLE gitops_syncs DROP COLUMN IF EXISTS enabled;diff --git a/backend/resources/migrations/sqlite/030_remove_gitops_sync_enabled.down.sql b/backend/resources/migrations/sqlite/030_remove_gitops_sync_enabled.down.sqlnew file mode 100644index 000000000..a459844e3--- /dev/null+++ b/backend/resources/migrations/sqlite/030_remove_gitops_sync_enabled.down.sql@@ -0,0 +1,50 @@+-- Re-add the enabled column to gitops_syncs table+-- SQLite doesn't support ADD COLUMN with constraints directly, so we need to recreate the table++-- Create new table with enabled column+CREATE TABLE gitops_syncs_new (+ id TEXT PRIMARY KEY,+ name TEXT NOT NULL,+ environment_id TEXT NOT NULL,+ repository_id TEXT NOT NULL,+ branch TEXT NOT NULL,+ compose_path TEXT NOT NULL,+ project_name TEXT NOT NULL,+ project_id TEXT,+ auto_sync BOOLEAN NOT NULL DEFAULT false,+ sync_interval INTEGER NOT NULL DEFAULT 60,+ last_sync_at DATETIME,+ last_sync_status TEXT,+ last_sync_error TEXT,+ last_sync_commit TEXT,+ enabled BOOLEAN NOT NULL DEFAULT true,+ created_at DATETIME NOT NULL,+ updated_at DATETIME NOT NULL,+ FOREIGN KEY (environment_id) REFERENCES environments(id) ON DELETE CASCADE,+ FOREIGN KEY (repository_id) REFERENCES git_repositories(id) ON DELETE CASCADE,+ FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE SET NULL+);++-- Copy data from old table to new table+INSERT INTO gitops_syncs_new (+ id, name, environment_id, repository_id, branch, compose_path,+ project_name, project_id, auto_sync, sync_interval, last_sync_at,+ last_sync_status, last_sync_error, last_sync_commit, enabled, created_at, updated_at+)+SELECT+ id, name, environment_id, repository_id, branch, compose_path,+ project_name, project_id, auto_sync, sync_interval, last_sync_at,+ last_sync_status, last_sync_error, last_sync_commit, true, created_at, updated_at+FROM gitops_syncs;++-- Drop old table+DROP TABLE gitops_syncs;++-- Rename new table to original name+ALTER TABLE gitops_syncs_new RENAME TO gitops_syncs;++-- Recreate indexes+CREATE INDEX IF NOT EXISTS idx_gitops_syncs_environment_id ON gitops_syncs(environment_id);+CREATE INDEX IF NOT EXISTS idx_gitops_syncs_repository_id ON gitops_syncs(repository_id);+CREATE INDEX IF NOT EXISTS idx_gitops_syncs_project_id ON gitops_syncs(project_id);+CREATE INDEX IF NOT EXISTS idx_gitops_syncs_enabled ON gitops_syncs(enabled);diff --git a/backend/resources/migrations/sqlite/030_remove_gitops_sync_enabled.up.sql b/backend/resources/migrations/sqlite/030_remove_gitops_sync_enabled.up.sqlnew file mode 100644index 000000000..b2a1f4acf--- /dev/null+++ b/backend/resources/migrations/sqlite/030_remove_gitops_sync_enabled.up.sql@@ -0,0 +1,49 @@+-- Remove the enabled column from gitops_syncs table+-- SQLite doesn't support DROP COLUMN directly, so we need to recreate the table+-- Only autoSync field will control automatic syncing behavior++-- Create new table without enabled column+CREATE TABLE gitops_syncs_new (+ id TEXT PRIMARY KEY,+ name TEXT NOT NULL,+ environment_id TEXT NOT NULL,+ repository_id TEXT NOT NULL,+ branch TEXT NOT NULL,+ compose_path TEXT NOT NULL,+ project_name TEXT NOT NULL,+ project_id TEXT,+ auto_sync BOOLEAN NOT NULL DEFAULT false,+ sync_interval INTEGER NOT NULL DEFAULT 60,+ last_sync_at DATETIME,+ last_sync_status TEXT,+ last_sync_error TEXT,+ last_sync_commit TEXT,+ created_at DATETIME NOT NULL,+ updated_at DATETIME NOT NULL,+ FOREIGN KEY (environment_id) REFERENCES environments(id) ON DELETE CASCADE,+ FOREIGN KEY (repository_id) REFERENCES git_repositories(id) ON DELETE CASCADE,+ FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE SET NULL+);++-- Copy data from old table to new table+INSERT INTO gitops_syncs_new (+ id, name, environment_id, repository_id, branch, compose_path,+ project_name, project_id, auto_sync, sync_interval, last_sync_at,+ last_sync_status, last_sync_error, last_sync_commit, created_at, updated_at+)+SELECT+ id, name, environment_id, repository_id, branch, compose_path,+ project_name, project_id, auto_sync, sync_interval, last_sync_at,+ last_sync_status, last_sync_error, last_sync_commit, created_at, updated_at+FROM gitops_syncs;++-- Drop old table+DROP TABLE gitops_syncs;++-- Rename new table to original name+ALTER TABLE gitops_syncs_new RENAME TO gitops_syncs;++-- Recreate indexes+CREATE INDEX IF NOT EXISTS idx_gitops_syncs_environment_id ON gitops_syncs(environment_id);+CREATE INDEX IF NOT EXISTS idx_gitops_syncs_repository_id ON gitops_syncs(repository_id);+CREATE INDEX IF NOT EXISTS idx_gitops_syncs_project_id ON gitops_syncs(project_id);diff --git a/frontend/src/lib/components/dialogs/gitops-import-dialog.svelte b/frontend/src/lib/components/dialogs/gitops-import-dialog.svelteindex abf5b6295..463188508 100644--- a/frontend/src/lib/components/dialogs/gitops-import-dialog.svelte+++ b/frontend/src/lib/components/dialogs/gitops-import-dialog.svelte@@ -92,7 +92,7 @@<Textareaid="json-content"bind:value={jsonContent}- placeholder={`[\n {\n "syncName": "example-sync",\n "gitRepo": "my-repo",\n "branch": "main",\n "dockerComposePath": "docker-compose.yml",\n "autoSync": true,\n "syncInterval": 10,\n "enabled": true\n }\n]`}+ placeholder={`[\n {\n "syncName": "example-sync",\n "gitRepo": "my-repo",\n "branch": "main",\n "dockerComposePath": "docker-compose.yml",\n "autoSync": true,\n "syncInterval": 10\n }\n]`}class="h-[300px] font-mono text-xs"/>{#if error}diff --git a/frontend/src/lib/components/dialogs/gitops-sync-dialog.svelte b/frontend/src/lib/components/dialogs/gitops-sync-dialog.svelteindex 2ae91cf35..9aa959340 100644--- a/frontend/src/lib/components/dialogs/gitops-sync-dialog.svelte+++ b/frontend/src/lib/components/dialogs/gitops-sync-dialog.svelte@@ -36,8 +36,7 @@branch: z.string().min(1, m.common_required()),composePath: z.string().min(1, m.common_required()),autoSync: z.boolean().default(true),- syncInterval: z.number().min(1).default(5),- enabled: z.boolean().default(true)+ syncInterval: z.number().min(1).default(5)});let formData = $derived({@@ -46,8 +45,7 @@branch: open && syncToEdit ? syncToEdit.branch : 'main',composePath: open && syncToEdit ? syncToEdit.composePath : 'docker-compose.yml',autoSync: open && syncToEdit ? (syncToEdit.autoSync ?? true) : true,- syncInterval: open && syncToEdit ? (syncToEdit.syncInterval ?? 5) : 5,- enabled: open && syncToEdit ? (syncToEdit.enabled ?? true) : true+ syncInterval: open && syncToEdit ? (syncToEdit.syncInterval ?? 5) : 5});let { inputs, ...form } = $derived(createForm<typeof formSchema>(formSchema, formData));@@ -123,8 +121,7 @@composePath: data.composePath,projectName: data.name,autoSync: data.autoSync,- syncInterval: data.syncInterval,- enabled: data.enabled+ syncInterval: data.syncInterval};onSubmit({ sync: payload, isEditMode });@@ -249,14 +246,6 @@/><FormInput label={m.git_sync_sync_interval()} type="number" placeholder="5" bind:input={$inputs.syncInterval} />-- <SwitchWithLabel- id="isEnabledSwitch"- label={m.common_enabled()}- description={m.common_enabled_description()}- error={$inputs.enabled.error}- bind:checked={$inputs.enabled.value}- /></form>{/if}{/snippet}diff --git a/frontend/src/lib/types/gitops.type.ts b/frontend/src/lib/types/gitops.type.tsindex cd6f6bab1..c8e4077be 100644--- a/frontend/src/lib/types/gitops.type.ts+++ b/frontend/src/lib/types/gitops.type.ts@@ -43,7 +43,6 @@ export interface GitOpsSyncCreateDto {projectName?: string;autoSync?: boolean;syncInterval?: number;- enabled?: boolean;}export interface GitOpsSyncUpdateDto {@@ -54,7 +53,6 @@ export interface GitOpsSyncUpdateDto {projectName?: string;autoSync?: boolean;syncInterval?: number;- enabled?: boolean;}export interface GitOpsSync {@@ -73,7 +71,6 @@ export interface GitOpsSync {lastSyncStatus?: string;lastSyncError?: string;lastSyncCommit?: string;- enabled: boolean;createdAt: string;updatedAt: string;}@@ -100,7 +97,6 @@ export interface BrowseResponse {export interface SyncStatus {id: string;- enabled: boolean;autoSync: boolean;nextSyncAt?: string;lastSyncAt?: string;@@ -129,7 +125,6 @@ export interface ImportGitOpsSyncRequest {dockerComposePath: string;autoSync: boolean;syncInterval: number;- enabled: boolean;}export interface ImportGitOpsSyncResponse {diff --git a/frontend/src/routes/(app)/environments/[id]/gitops/+page.svelte b/frontend/src/routes/(app)/environments/[id]/gitops/+page.svelteindex 18056ac6c..1186cf817 100644--- a/frontend/src/routes/(app)/environments/[id]/gitops/+page.svelte+++ b/frontend/src/routes/(app)/environments/[id]/gitops/+page.svelte@@ -31,7 +31,7 @@import: false});- const activeSyncs = $derived(syncs.data?.filter((s) => s.enabled && s.autoSync).length ?? 0);+ const activeSyncs = $derived(syncs.data?.filter((s) => s.autoSync).length ?? 0);const successfulSyncs = $derived(syncs.data?.filter((s) => s.lastSyncStatus === 'success').length ?? 0);$effect(() => {diff --git a/frontend/src/routes/(app)/environments/[id]/gitops/sync-table.svelte b/frontend/src/routes/(app)/environments/[id]/gitops/sync-table.svelteindex d868d2675..ae8ccb0ea 100644--- a/frontend/src/routes/(app)/environments/[id]/gitops/sync-table.svelte+++ b/frontend/src/routes/(app)/environments/[id]/gitops/sync-table.svelte@@ -176,12 +176,6 @@title: m.git_sync_last_sync(),sortable: true,cell: LastSyncCell- },- {- accessorKey: 'enabled',- title: m.common_status(),- sortable: true,- cell: EnabledCell}] satisfies ColumnSpec<GitOpsSync>[];@@ -193,8 +187,7 @@{ id: 'autoSync', label: m.git_sync_auto_sync(), defaultVisible: true },{ id: 'lastSyncStatus', label: m.git_sync_status(), defaultVisible: true },{ id: 'lastSyncCommit', label: 'Commit', defaultVisible: false },- { id: 'lastSyncAt', label: m.git_sync_last_sync(), defaultVisible: true },- { id: 'enabled', label: m.common_status(), defaultVisible: true }+ { id: 'lastSyncAt', label: m.git_sync_last_sync(), defaultVisible: true }];</script>@@ -261,10 +254,6 @@<span class="text-sm">{value ? format(new Date(value), 'PP p') : m.common_never()}</span>{/snippet}-{#snippet EnabledCell({ value }: { value: any; item: GitOpsSync; row: Row<GitOpsSync> })}- <StatusBadge variant={value ? 'green' : 'red'} text={value ? m.common_enabled() : m.common_disabled()} />-{/snippet}-{#snippet SyncMobileCardSnippet({item,mobileFieldVisibility,diff --git a/types/gitops/gitops.go b/types/gitops/gitops.goindex 222dba416..871e64c3b 100644--- a/types/gitops/gitops.go+++ b/types/gitops/gitops.go@@ -132,11 +132,6 @@ type GitOpsSync struct {// Required: falseLastSyncCommit *string `json:"lastSyncCommit,omitempty"`- // Enabled indicates if the sync is enabled.- //- // Required: true- Enabled bool `json:"enabled"`-// CreatedAt is the date and time at which the sync was created.//// Required: true@@ -285,11 +280,6 @@ type CreateSyncRequest struct {//// Required: falseSyncInterval *int `json:"syncInterval,omitempty"`-- // Enabled indicates if the sync is enabled.- //- // Required: false- Enabled *bool `json:"enabled,omitempty"`}// UpdateSyncRequest represents the request to update a gitops sync.@@ -328,11 +318,6 @@ type UpdateSyncRequest struct {//// Required: falseSyncInterval *int `json:"syncInterval,omitempty"`-- // Enabled indicates if the sync is enabled.- //- // Required: false- Enabled *bool `json:"enabled,omitempty"`}// SyncResult represents the result of a sync operation.@@ -516,11 +501,6 @@ type SyncStatus struct {// Required: trueID string `json:"id"`- // Enabled indicates if the sync is enabled.- //- // Required: true- Enabled bool `json:"enabled"`-// AutoSync indicates if automatic sync is enabled.//// Required: true@@ -583,11 +563,6 @@ type ImportGitOpsSyncRequest struct {//// Required: trueSyncInterval int `json:"syncInterval"`-- // Enabled indicates if the sync is enabled.- //- // Required: true- Enabled bool `json:"enabled"`}// ImportGitOpsSyncResponse represents the response for importing gitops syncs.