From e65b18eddf5e06d44b4222973dba9460336acd0f Mon Sep 17 00:00:00 2001 From: "Felipe M." Date: Sun, 12 May 2024 14:02:38 +0200 Subject: [PATCH 1/2] check non-nil err --- internal/database/pg.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/database/pg.go b/internal/database/pg.go index 115976daf..22dc485e4 100644 --- a/internal/database/pg.go +++ b/internal/database/pg.go @@ -28,7 +28,7 @@ var postgresMigrations = []migration{ defer tx.Rollback() _, err = tx.Exec(`ALTER TABLE bookmark ADD COLUMN has_content BOOLEAN DEFAULT FALSE NOT NULL`) - if strings.Contains(err.Error(), `column "has_content" of relation "bookmark" already exists`) { + if err != nil && strings.Contains(err.Error(), `column "has_content" of relation "bookmark" already exists`) { tx.Rollback() } else if err != nil { return fmt.Errorf("failed to add has_content column to bookmark table: %w", err) @@ -45,7 +45,7 @@ var postgresMigrations = []migration{ defer tx.Rollback() _, err = tx.Exec(`ALTER TABLE account ADD COLUMN config JSONB NOT NULL DEFAULT '{}'`) - if strings.Contains(err.Error(), `column "config" of relation "account" already exists`) { + if err != nil && strings.Contains(err.Error(), `column "config" of relation "account" already exists`) { tx.Rollback() } else if err != nil { return fmt.Errorf("failed to add config column to account table: %w", err) From e0fa4cc0e02270d46cc2c3bc9540a78538158e7c Mon Sep 17 00:00:00 2001 From: "Felipe M." Date: Sun, 12 May 2024 16:33:23 +0200 Subject: [PATCH 2/2] apply to mysql and sqlite too --- internal/database/mysql.go | 4 ++-- internal/database/sqlite.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/database/mysql.go b/internal/database/mysql.go index 7465efd67..72aa18b97 100644 --- a/internal/database/mysql.go +++ b/internal/database/mysql.go @@ -32,7 +32,7 @@ var mysqlMigrations = []migration{ defer tx.Rollback() _, err = tx.Exec(`ALTER TABLE bookmark ADD COLUMN has_content BOOLEAN DEFAULT 0`) - if strings.Contains(err.Error(), `Duplicate column name`) { + if err != nil && strings.Contains(err.Error(), `Duplicate column name`) { tx.Rollback() } else if err != nil { return fmt.Errorf("failed to add has_content column to bookmark table: %w", err) @@ -49,7 +49,7 @@ var mysqlMigrations = []migration{ defer tx.Rollback() _, err = tx.Exec(`ALTER TABLE account ADD COLUMN config JSON NOT NULL DEFAULT '{}'`) - if strings.Contains(err.Error(), `Duplicate column name`) { + if err != nil && strings.Contains(err.Error(), `Duplicate column name`) { tx.Rollback() } else if err != nil { return fmt.Errorf("failed to add config column to account table: %w", err) diff --git a/internal/database/sqlite.go b/internal/database/sqlite.go index 4cc117b12..e6b76528a 100644 --- a/internal/database/sqlite.go +++ b/internal/database/sqlite.go @@ -29,7 +29,7 @@ var sqliteMigrations = []migration{ defer tx.Rollback() _, err = tx.Exec(`ALTER TABLE bookmark ADD COLUMN has_content BOOLEAN DEFAULT FALSE NOT NULL`) - if strings.Contains(err.Error(), `duplicate column name`) { + if err != nil && strings.Contains(err.Error(), `duplicate column name`) { tx.Rollback() } else if err != nil { return fmt.Errorf("failed to add has_content column to bookmark table: %w", err) @@ -46,7 +46,7 @@ var sqliteMigrations = []migration{ defer tx.Rollback() _, err = tx.Exec(`ALTER TABLE account ADD COLUMN config JSON NOT NULL DEFAULT '{}'`) - if strings.Contains(err.Error(), `duplicate column name`) { + if err != nil && strings.Contains(err.Error(), `duplicate column name`) { tx.Rollback() } else if err != nil { return fmt.Errorf("failed to add config column to account table: %w", err)