From efb02c55d8a10eb97bd7cae5dbf35abeb1ea7749 Mon Sep 17 00:00:00 2001 From: Ryo Kusnadi Date: Wed, 4 Nov 2026 21:42:09 +0700 Subject: [PATCH] fix(jira): widen connection token column to text so long tokens are not truncated Signed-off-by: Ryo Kusnadi --- ...0261104_change_connection_token_to_text.go | 43 ++++++++++++ ...04_change_connection_token_to_text_test.go | 69 +++++++++++++++++++ .../jira/models/migrationscripts/register.go | 1 + 3 files changed, 113 insertions(+) create mode 100644 backend/plugins/jira/models/migrationscripts/20261104_change_connection_token_to_text.go create mode 100644 backend/plugins/jira/models/migrationscripts/20261104_change_connection_token_to_text_test.go diff --git a/backend/plugins/jira/models/migrationscripts/20261104_change_connection_token_to_text.go b/backend/plugins/jira/models/migrationscripts/20261104_change_connection_token_to_text.go new file mode 100644 index 00000000000..48486417652 --- /dev/null +++ b/backend/plugins/jira/models/migrationscripts/20261104_change_connection_token_to_text.go @@ -0,0 +1,43 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package migrationscripts + +import ( + "github.com/apache/devlake/core/context" + "github.com/apache/devlake/core/errors" + "github.com/apache/devlake/core/plugin" +) + +var _ plugin.MigrationScript = (*changeConnectionTokenToText20261104)(nil) + +type changeConnectionTokenToText20261104 struct{} + +// Up widens the token column. The token is stored encrypted and base64 encoded, +// which is longer than the plain token, so varchar(255) cut long tokens +// (for example scoped service-account tokens). +func (*changeConnectionTokenToText20261104) Up(basicRes context.BasicRes) errors.Error { + return basicRes.GetDal().ModifyColumnType("_tool_jira_connections", "token", "text") +} + +func (*changeConnectionTokenToText20261104) Version() uint64 { + return 20261104120000 +} + +func (*changeConnectionTokenToText20261104) Name() string { + return "change token type to text in _tool_jira_connections" +} diff --git a/backend/plugins/jira/models/migrationscripts/20261104_change_connection_token_to_text_test.go b/backend/plugins/jira/models/migrationscripts/20261104_change_connection_token_to_text_test.go new file mode 100644 index 00000000000..0c82e84db9a --- /dev/null +++ b/backend/plugins/jira/models/migrationscripts/20261104_change_connection_token_to_text_test.go @@ -0,0 +1,69 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package migrationscripts + +import ( + "testing" + + "github.com/apache/devlake/core/context" + "github.com/apache/devlake/core/dal" + "github.com/apache/devlake/core/errors" +) + +type tokenColumnCall struct { + table, column, columnType string +} + +type tokenColumnRecordingDal struct { + dal.Dal + calls []tokenColumnCall +} + +func (d *tokenColumnRecordingDal) ModifyColumnType(table, column, columnType string) errors.Error { + d.calls = append(d.calls, tokenColumnCall{table, column, columnType}) + return nil +} + +type tokenColumnBasicRes struct { + context.BasicRes + database dal.Dal +} + +func (r *tokenColumnBasicRes) GetDal() dal.Dal { + return r.database +} + +func TestChangeConnectionTokenToText(t *testing.T) { + database := new(tokenColumnRecordingDal) + script := new(changeConnectionTokenToText20261104) + + if err := script.Up(&tokenColumnBasicRes{database: database}); err != nil { + t.Fatalf("migration failed: %v", err) + } + want := tokenColumnCall{"_tool_jira_connections", "token", "text"} + if len(database.calls) != 1 || database.calls[0] != want { + t.Fatalf("ModifyColumnType calls = %#v, want [%#v]", database.calls, want) + } + + for _, registered := range All() { + if registered.Version() == script.Version() { + return + } + } + t.Fatalf("migration version %d is not registered", script.Version()) +} diff --git a/backend/plugins/jira/models/migrationscripts/register.go b/backend/plugins/jira/models/migrationscripts/register.go index 7716da342e9..6c49ce1684a 100644 --- a/backend/plugins/jira/models/migrationscripts/register.go +++ b/backend/plugins/jira/models/migrationscripts/register.go @@ -61,5 +61,6 @@ func All() []plugin.MigrationScript { new(addSprintReportTable), new(addRawDataColumnsToSprintReport), new(addJiraOAuth20260907), + new(changeConnectionTokenToText20261104), } }