diff --git a/components/notifications/form/form_templ.go b/components/notifications/form/form_templ.go deleted file mode 100644 index 7336dad..0000000 --- a/components/notifications/form/form_templ.go +++ /dev/null @@ -1,398 +0,0 @@ -// Code generated by templ - DO NOT EDIT. - -// templ: version: v0.3.833 -package form - -//lint:file-ignore SA4006 This context is only used if a nested component is present. - -import "github.com/a-h/templ" -import templruntime "github.com/a-h/templ/runtime" - -import ( - "context" - "fmt" - "github.com/starfleetcptn/gomft/components" // For LayoutWithContext - "github.com/starfleetcptn/gomft/components/notifications/form/fields" // Import fields - "github.com/starfleetcptn/gomft/components/notifications/form/utils" - "github.com/starfleetcptn/gomft/components/notifications/types" -) - -func NotificationForm(ctx context.Context, data types.NotificationFormData) templ.Component { - return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { - templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context - if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { - return templ_7745c5c3_CtxErr - } - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) - if !templ_7745c5c3_IsBuffer { - defer func() { - templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) - if templ_7745c5c3_Err == nil { - templ_7745c5c3_Err = templ_7745c5c3_BufErr - } - }() - } - ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var1 := templ.GetChildren(ctx) - if templ_7745c5c3_Var1 == nil { - templ_7745c5c3_Var1 = templ.NopComponent - } - ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = FormScripts().Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Var2 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { - templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) - if !templ_7745c5c3_IsBuffer { - defer func() { - templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) - if templ_7745c5c3_Err == nil { - templ_7745c5c3_Err = templ_7745c5c3_BufErr - } - }() - } - ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - if data.SuccessMessage != "" { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var3 string - templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(data.SuccessMessage) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/notifications/form/form.templ`, Line: 21, Col: 62} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - if data.ErrorMessage != "" { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var4 string - templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(data.ErrorMessage) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/notifications/form/form.templ`, Line: 25, Col: 58} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var5 string - templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(utils.GetNotificationFormTitle(data.IsNew)) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/notifications/form/form.templ`, Line: 31, Col: 50} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "

Back to Notification Services
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = fields.EmailFields(data).Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = fields.WebhookFields(data).Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = fields.PushbulletFields(data).Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = fields.NtfyFields(data).Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = fields.GotifyFields(data).Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = fields.PushoverFields(data).Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "

Configure your notification service to receive alerts for job events. Different notification types have different configuration options.

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - return nil - }) - templ_7745c5c3_Err = components.LayoutWithContext(utils.GetNotificationFormTitle(data.IsNew), ctx).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - return nil - }) -} - -var _ = templruntime.GeneratedTemplate diff --git a/internal/db/migrations/011b_recover_notification_services_rename.go b/internal/db/migrations/011b_recover_notification_services_rename.go new file mode 100644 index 0000000..5966725 --- /dev/null +++ b/internal/db/migrations/011b_recover_notification_services_rename.go @@ -0,0 +1,45 @@ +package migrations + +import ( + "fmt" + + "github.com/go-gormigrate/gormigrate/v2" + "gorm.io/gorm" +) + +// RecoverNotificationServicesRename checks for and corrects a specific inconsistent state +// left by a potentially failed run of migration 012, where the notification_services +// table might have been left renamed as _notification_services_old. +func RecoverNotificationServicesRename() *gormigrate.Migration { + return &gormigrate.Migration{ + ID: "011b_recover_notification_services_rename", + Migrate: func(tx *gorm.DB) error { + fmt.Println("Running migration 011b: Checking for notification_services rename recovery...") + + var oldTableExists int + tx.Raw("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='_notification_services_old'").Scan(&oldTableExists) + + var newTableExists int + tx.Raw("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='notification_services'").Scan(&newTableExists) + + if oldTableExists > 0 && newTableExists == 0 { + fmt.Println("Found _notification_services_old table but not notification_services. Attempting recovery rename...") + if err := tx.Exec("ALTER TABLE _notification_services_old RENAME TO notification_services").Error; err != nil { + return fmt.Errorf("failed to rename _notification_services_old back to notification_services: %w", err) + } + fmt.Println("Successfully renamed _notification_services_old to notification_services.") + } else if oldTableExists > 0 && newTableExists > 0 { + fmt.Println("Warning: Both notification_services and _notification_services_old tables exist. Manual inspection might be needed.") + } else { + fmt.Println("No recovery needed for notification_services rename.") + } + + return nil + }, + Rollback: func(tx *gorm.DB) error { + // Rollback doesn't make sense for a recovery step. + fmt.Println("Rollback for migration 011b_recover_notification_services_rename is not applicable.") + return nil + }, + } +} diff --git a/internal/db/migrations/011c_recover_auth_providers_rename.go b/internal/db/migrations/011c_recover_auth_providers_rename.go new file mode 100644 index 0000000..510ba97 --- /dev/null +++ b/internal/db/migrations/011c_recover_auth_providers_rename.go @@ -0,0 +1,45 @@ +package migrations + +import ( + "fmt" + + "github.com/go-gormigrate/gormigrate/v2" + "gorm.io/gorm" +) + +// RecoverAuthProvidersRename checks for and corrects a specific inconsistent state +// left by a potentially failed run of migration 012, where the auth_providers +// table might have been left renamed as _auth_providers_old. +func RecoverAuthProvidersRename() *gormigrate.Migration { + return &gormigrate.Migration{ + ID: "011c_recover_auth_providers_rename", + Migrate: func(tx *gorm.DB) error { + fmt.Println("Running migration 011c: Checking for auth_providers rename recovery...") + + var oldTableExists int + tx.Raw("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='_auth_providers_old'").Scan(&oldTableExists) + + var newTableExists int + tx.Raw("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='auth_providers'").Scan(&newTableExists) + + if oldTableExists > 0 && newTableExists == 0 { + fmt.Println("Found _auth_providers_old table but not auth_providers. Attempting recovery rename...") + if err := tx.Exec("ALTER TABLE _auth_providers_old RENAME TO auth_providers").Error; err != nil { + return fmt.Errorf("failed to rename _auth_providers_old back to auth_providers: %w", err) + } + fmt.Println("Successfully renamed _auth_providers_old to auth_providers.") + } else if oldTableExists > 0 && newTableExists > 0 { + fmt.Println("Warning: Both auth_providers and _auth_providers_old tables exist. Manual inspection might be needed.") + } else { + fmt.Println("No recovery needed for auth_providers rename.") + } + + return nil + }, + Rollback: func(tx *gorm.DB) error { + // Rollback doesn't make sense for a recovery step. + fmt.Println("Rollback for migration 011c_recover_auth_providers_rename is not applicable.") + return nil + }, + } +} diff --git a/internal/db/migrations/migrations.go b/internal/db/migrations/migrations.go index 956e58b..5367941 100644 --- a/internal/db/migrations/migrations.go +++ b/internal/db/migrations/migrations.go @@ -11,20 +11,22 @@ var migrations []*gormigrate.Migration func GetMigrations(db *gorm.DB) *gormigrate.Gormigrate { // Add all migrations in order migrations = append(migrations, - InitialSchema(), // 001 - UpdateGDriveType(), // 002 - Add2FA(), // 003 - AddAuditLogs(), // 004 - AddDefaultRoles(), // 005 - AddTimestampsToJobHistories(), // 006 - AddNotificationServices(), // 007 - AddUserNotifications(), // 008 - AddRcloneTables(), // 009 - AddRcloneCommandToConfig(), // 010 - AddAuthProviders(), // 011 - RecoverTransferConfigsRename(), // 011a - AlterBooleanDefaults(), // 012 - CleanupInvalidBooleans(), // 013 + InitialSchema(), // 001 + UpdateGDriveType(), // 002 + Add2FA(), // 003 + AddAuditLogs(), // 004 + AddDefaultRoles(), // 005 + AddTimestampsToJobHistories(), // 006 + AddNotificationServices(), // 007 + AddUserNotifications(), // 008 + AddRcloneTables(), // 009 + AddRcloneCommandToConfig(), // 010 + AddAuthProviders(), // 011 + RecoverTransferConfigsRename(), // 011a + RecoverNotificationServicesRename(), // 011b + RecoverAuthProvidersRename(), // 011c + AlterBooleanDefaults(), // 012 + CleanupInvalidBooleans(), // 013 ) return gormigrate.New(db, gormigrate.DefaultOptions, migrations)