[PR #533] [CLOSED] fix: fix create unique index failed to lead the server can not start #565

Closed
opened 2026-02-16 01:16:20 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langgenius/dify-plugin-daemon/pull/533
Author: @fatelei
Created: 12/10/2025
Status: Closed

Base: mainHead: panic


📝 Commits (1)

  • dfdc19b fix: fix create unique index failed to lead the server can not start

📊 Changes

24 files changed (+369 additions, -30 deletions)

View changed files

📝 go.mod (+1 -0)
📝 go.sum (+3 -0)
📝 internal/cluster/plugin.go (+1 -1)
📝 internal/core/io_tunnel/datasource.gen.go (+1 -1)
📝 internal/core/io_tunnel/dynamic_parameter.gen.go (+1 -1)
📝 internal/core/io_tunnel/model.gen.go (+1 -1)
📝 internal/core/io_tunnel/oauth.gen.go (+1 -1)
📝 internal/core/io_tunnel/tool.gen.go (+1 -1)
📝 internal/core/io_tunnel/trigger.gen.go (+1 -1)
📝 internal/db/cache.go (+1 -1)
📝 internal/db/init.go (+67 -0)
📝 internal/db/init_test.go (+270 -0)
📝 internal/service/datasource.gen.go (+1 -1)
📝 internal/service/dynamic_parameter.gen.go (+1 -1)
📝 internal/service/model.gen.go (+1 -1)
📝 internal/service/oauth.gen.go (+1 -1)
📝 internal/service/tool.gen.go (+1 -1)
📝 internal/service/trigger.gen.go (+1 -1)
📝 internal/service/unauthorized_langgenius_test.go (+6 -6)
📝 internal/types/app/config.go (+2 -2)

...and 4 more files

📄 Description

Description

because

type PluginInstallation struct {
	Model
	TenantID               string         `json:"tenant_id" gorm:"index;uniqueIndex:idx_tenant_plugin;type:uuid;"`
	PluginID               string         `json:"plugin_id" gorm:"index;uniqueIndex:idx_tenant_plugin;size:255"`
	PluginUniqueIdentifier string         `json:"plugin_unique_identifier" gorm:"index;size:255"`
	RuntimeType            string         `json:"runtime_type" gorm:"size:127"`
	EndpointsSetups        int            `json:"endpoints_setups"`
	EndpointsActive        int            `json:"endpoints_active"`
	Source                 string         `json:"source" gorm:"column:source;size:63"`
	Meta                   map[string]any `json:"meta" gorm:"column:meta;serializer:json"`
}

add unique index, if the table has duplicate data, it will lead the server can not start

2025/12/11 03:22:49 /app/internal/db/init.go:12 SLOW SQL >= 200ms
[236.720ms] [rows:-] SELECT c.column_name, c.is_nullable = 'YES', c.udt_name, c.character_maximum_length, c.numeric_precision, c.numeric_precision_radix, c.numeric_scale, c.datetime_precision, 8 * typlen, c.column_default, pd.description, c.identity_increment FROM information_schema.columns AS c JOIN pg_type AS pgt ON c.udt_name = pgt.typname LEFT JOIN pg_catalog.pg_description as pd ON pd.objsubid = c.ordinal_position AND pd.objoid = (SELECT oid FROM pg_catalog.pg_class WHERE relname = c.table_name AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE nspname = c.table_schema)) where table_catalog = 'dify_plugin' AND table_schema = CURRENT_SCHEMA() AND table_name = 'plugins'

2025/12/11 03:22:49 /app/internal/db/init.go:12 ERROR: could not create unique index "idx_tenant_plugin" (SQLSTATE 23505)
[4.477ms] [rows:0] CREATE UNIQUE INDEX IF NOT EXISTS "idx_tenant_plugin" ON "plugin_installations" ("tenant_id","plugin_id")
2025/12/11 03:22:49 init.go:104: [PANIC]failed to auto migrate: ERROR: could not create unique index "idx_tenant_plugin" (SQLSTATE 23505)
panic: [PANIC]failed to auto migrate: ERROR: could not create unique index "idx_tenant_plugin" (SQLSTATE 23505)

goroutine 1 [running]:
github.com/langgenius/dify-plugin-daemon/pkg/utils/log.writeLog({0x1ff583a, 0x5}, {0x2029e50?, 0x0?}, 0x1, {0x400062fba8, 0x1, 0x1})
	/app/pkg/utils/log/log.go:40 +0x354
github.com/langgenius/dify-plugin-daemon/pkg/utils/log.Panic(...)
	/app/pkg/utils/log/log.go:66
github.com/langgenius/dify-plugin-daemon/internal/db.Init(0x2710?)
	/app/internal/db/init.go:104 +0x2e8
github.com/langgenius/dify-plugin-daemon/internal/server.(*App).Run(0x400049b1a0, 0x4000461808)
	/app/internal/server/server.go:96 +0x94
main.main()
	/app/cmd/server/main.go:28 +0x114

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Performance improvement
  • Other

Essential Checklist

Testing

  • I have tested the changes locally and confirmed they work as expected
  • I have added unit tests where necessary and they pass successfully

Bug Fix (if applicable)

  • I have used GitHub syntax to close the related issue (e.g., Fixes #123 or Closes #123)

Additional Information

Please provide any additional context that would help reviewers understand the changes.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langgenius/dify-plugin-daemon/pull/533 **Author:** [@fatelei](https://github.com/fatelei) **Created:** 12/10/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `panic` --- ### 📝 Commits (1) - [`dfdc19b`](https://github.com/langgenius/dify-plugin-daemon/commit/dfdc19be5f866b117031b598a75cec6702406e37) fix: fix create unique index failed to lead the server can not start ### 📊 Changes **24 files changed** (+369 additions, -30 deletions) <details> <summary>View changed files</summary> 📝 `go.mod` (+1 -0) 📝 `go.sum` (+3 -0) 📝 `internal/cluster/plugin.go` (+1 -1) 📝 `internal/core/io_tunnel/datasource.gen.go` (+1 -1) 📝 `internal/core/io_tunnel/dynamic_parameter.gen.go` (+1 -1) 📝 `internal/core/io_tunnel/model.gen.go` (+1 -1) 📝 `internal/core/io_tunnel/oauth.gen.go` (+1 -1) 📝 `internal/core/io_tunnel/tool.gen.go` (+1 -1) 📝 `internal/core/io_tunnel/trigger.gen.go` (+1 -1) 📝 `internal/db/cache.go` (+1 -1) 📝 `internal/db/init.go` (+67 -0) 📝 `internal/db/init_test.go` (+270 -0) 📝 `internal/service/datasource.gen.go` (+1 -1) 📝 `internal/service/dynamic_parameter.gen.go` (+1 -1) 📝 `internal/service/model.gen.go` (+1 -1) 📝 `internal/service/oauth.gen.go` (+1 -1) 📝 `internal/service/tool.gen.go` (+1 -1) 📝 `internal/service/trigger.gen.go` (+1 -1) 📝 `internal/service/unauthorized_langgenius_test.go` (+6 -6) 📝 `internal/types/app/config.go` (+2 -2) _...and 4 more files_ </details> ### 📄 Description ## Description because ```go type PluginInstallation struct { Model TenantID string `json:"tenant_id" gorm:"index;uniqueIndex:idx_tenant_plugin;type:uuid;"` PluginID string `json:"plugin_id" gorm:"index;uniqueIndex:idx_tenant_plugin;size:255"` PluginUniqueIdentifier string `json:"plugin_unique_identifier" gorm:"index;size:255"` RuntimeType string `json:"runtime_type" gorm:"size:127"` EndpointsSetups int `json:"endpoints_setups"` EndpointsActive int `json:"endpoints_active"` Source string `json:"source" gorm:"column:source;size:63"` Meta map[string]any `json:"meta" gorm:"column:meta;serializer:json"` } ``` add unique index, if the table has duplicate data, it will lead the server can not start ``` 2025/12/11 03:22:49 /app/internal/db/init.go:12 SLOW SQL >= 200ms [236.720ms] [rows:-] SELECT c.column_name, c.is_nullable = 'YES', c.udt_name, c.character_maximum_length, c.numeric_precision, c.numeric_precision_radix, c.numeric_scale, c.datetime_precision, 8 * typlen, c.column_default, pd.description, c.identity_increment FROM information_schema.columns AS c JOIN pg_type AS pgt ON c.udt_name = pgt.typname LEFT JOIN pg_catalog.pg_description as pd ON pd.objsubid = c.ordinal_position AND pd.objoid = (SELECT oid FROM pg_catalog.pg_class WHERE relname = c.table_name AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE nspname = c.table_schema)) where table_catalog = 'dify_plugin' AND table_schema = CURRENT_SCHEMA() AND table_name = 'plugins' 2025/12/11 03:22:49 /app/internal/db/init.go:12 ERROR: could not create unique index "idx_tenant_plugin" (SQLSTATE 23505) [4.477ms] [rows:0] CREATE UNIQUE INDEX IF NOT EXISTS "idx_tenant_plugin" ON "plugin_installations" ("tenant_id","plugin_id") 2025/12/11 03:22:49 init.go:104: [PANIC]failed to auto migrate: ERROR: could not create unique index "idx_tenant_plugin" (SQLSTATE 23505) panic: [PANIC]failed to auto migrate: ERROR: could not create unique index "idx_tenant_plugin" (SQLSTATE 23505) goroutine 1 [running]: github.com/langgenius/dify-plugin-daemon/pkg/utils/log.writeLog({0x1ff583a, 0x5}, {0x2029e50?, 0x0?}, 0x1, {0x400062fba8, 0x1, 0x1}) /app/pkg/utils/log/log.go:40 +0x354 github.com/langgenius/dify-plugin-daemon/pkg/utils/log.Panic(...) /app/pkg/utils/log/log.go:66 github.com/langgenius/dify-plugin-daemon/internal/db.Init(0x2710?) /app/internal/db/init.go:104 +0x2e8 github.com/langgenius/dify-plugin-daemon/internal/server.(*App).Run(0x400049b1a0, 0x4000461808) /app/internal/server/server.go:96 +0x94 main.main() /app/cmd/server/main.go:28 +0x114 ``` ## Type of Change - [x] Bug fix - [ ] New feature - [ ] Refactor - [ ] Performance improvement - [ ] Other ## Essential Checklist ### Testing - [x] I have tested the changes locally and confirmed they work as expected - [x] I have added unit tests where necessary and they pass successfully ### Bug Fix (if applicable) - [x] I have used GitHub syntax to close the related issue (e.g., `Fixes #123` or `Closes #123`) ## Additional Information Please provide any additional context that would help reviewers understand the changes. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 01:16:20 -05:00
yindo closed this issue 2026-02-16 01:16:20 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-plugin-daemon#565