Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: not checking for nil-pointer errors on migrations #906

Merged
merged 3 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/database/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions internal/database/pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions internal/database/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Loading