Skip to content

Commit f9eb7ba

Browse files
committed
fix(agent-gateway): preserve released upgrade migrations
1 parent c8b7a32 commit f9eb7ba

16 files changed

Lines changed: 168 additions & 70 deletions

‎.github/scripts/check-agent-gateway-migrations.py‎

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
from pathlib import Path
2121

2222
DIALECTS = ("mysql", "ob", "og", "oracle", "pg")
23+
RELEASED_ORDER = 198
24+
CURRENT_ORDER = 169
25+
ORDER_KEYS = {
26+
("plugin", "68"),
27+
("namespace_plugin_rel", "1960000000000001030"),
28+
}
2329
EXPECTED = {
2430
"plugin": {"68"},
2531
"plugin_handle": {str(1960000000000001000 + i) for i in range(2)},
@@ -63,12 +69,66 @@ def seeds(sql):
6369
return result
6470

6571

72+
def agent_order_token(values):
73+
"""Return the Agent Gateway sort token range and value."""
74+
tokens = normalized_tokens(values)
75+
if "'agentGateway'" in tokens:
76+
marker = tokens.index("'agentGateway'")
77+
else:
78+
marker = tokens.index("'68'")
79+
order_start = next(index for index, token in enumerate(tokens[marker + 1:], marker + 1) if token.isdigit())
80+
order_end = order_start + 1
81+
while order_end < len(tokens) and tokens[order_end].isdigit() and order_end - order_start < 3:
82+
order_end += 1
83+
return (order_start, order_end), int("".join(tokens[order_start:order_end]))
84+
85+
86+
def normalized_tokens(values):
87+
"""Normalize tokenizer character runs into complete numeric literals."""
88+
tokens = []
89+
number = []
90+
91+
def flush_number():
92+
if number:
93+
tokens.append("".join(number))
94+
number.clear()
95+
96+
for token in values:
97+
if len(token) == 1 and token.isdigit():
98+
number.append(token)
99+
else:
100+
flush_number()
101+
tokens.append(token)
102+
flush_number()
103+
return tuple(tokens)
104+
105+
106+
def only_order_moved(expected, actual):
107+
"""Whether two seeds differ in exactly the allowed Agent Gateway order value."""
108+
expected = normalized_tokens(expected)
109+
actual = normalized_tokens(actual)
110+
(expected_start, expected_end), expected_order = agent_order_token(expected)
111+
(actual_start, actual_end), actual_order = agent_order_token(actual)
112+
return (
113+
expected_order == CURRENT_ORDER
114+
and actual_order == RELEASED_ORDER
115+
and len(expected) == len(actual)
116+
and all(expected[index] == actual[index]
117+
for index in range(len(expected))
118+
if not (expected_start <= index < expected_end or actual_start <= index < actual_end))
119+
)
120+
121+
66122
def check_pair(schema, migration):
67-
"""Compare every value and column list in each dialect's own seed records."""
123+
"""Compare released seeds, allowing only the deliberate 2.7.3 order move."""
68124
expected, actual = seeds(schema), seeds(migration)
69125
for key in expected:
70-
if expected[key] != actual[key]:
71-
raise ValueError(f"fresh-install/upgrade mismatch: {key}")
126+
if expected[key] == actual[key]:
127+
continue
128+
if key in ORDER_KEYS:
129+
if only_order_moved(expected[key], actual[key]):
130+
continue
131+
raise ValueError(f"fresh-install/upgrade mismatch: {key}")
72132
return len(expected)
73133

74134

‎.github/scripts/test-agent-gateway-migrations.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def test_null_keyword_case_is_ignored(self):
8686

8787
def test_quoted_null_is_not_a_null_literal(self):
8888
changed, replacements = re.subn(
89-
r"('68', )NULL(, \d+)",
89+
r"('68', 'agentGateway', )null(, 'Ai', \d+)",
9090
r"\1'NULL'\2",
9191
self.migration,
9292
count=1,

‎db/upgrade/2.7.1-upgrade-2.7.2-mysql.sql‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ ALTER TABLE `selector` ADD INDEX `idx_selector_plugin_id` (`plugin_id`) USING BT
5959
ALTER TABLE `permission` ADD INDEX `idx_permission_resource_id` (`resource_id`) USING BTREE;
6060

6161
-- Agent Gateway: keep upgrade seeds consistent with the fresh-install schema.
62-
INSERT INTO `plugin` VALUES ('68', 'agentGateway', null, 'Ai', 169, 0, '2026-09-19 00:00:00', '2026-09-19 00:00:00', null);
62+
INSERT INTO `plugin` VALUES ('68', 'agentGateway', null, 'Ai', 198, 0, '2026-09-19 00:00:00', '2026-09-19 00:00:00', null);
6363
INSERT INTO `plugin_handle` VALUES ('1960000000000001000', '68', 'trafficType', 'trafficType', 2, 2, 0, '{"required":"1","defaultValue":"LLM","rule":""}', '2026-09-19 00:00:00', '2026-09-19 00:00:00');
6464
INSERT INTO `plugin_handle` VALUES ('1960000000000001001', '68', 'responseRequestId', 'responseRequestId', 3, 2, 1, '{"required":"0","defaultValue":"false","rule":""}', '2026-09-19 00:00:00', '2026-09-19 00:00:00');
6565
INSERT INTO `resource` VALUES ('1960000000000001010', '1346775491550474240', 'agentGateway', 'agentGateway', '/plug/agentGateway', 'agentGateway', 1, 0, 'pic-center', 0, 0, '', 1, '2026-09-19 00:00:00', '2026-09-19 00:00:00');
@@ -82,7 +82,7 @@ INSERT INTO `permission` VALUES ('1960000000000001026', '1346358560427216896', '
8282
INSERT INTO `permission` VALUES ('1960000000000001027', '1346358560427216896', '1960000000000001017', '2026-09-19 00:00:00', '2026-09-19 00:00:00');
8383
INSERT INTO `permission` VALUES ('1960000000000001028', '1346358560427216896', '1960000000000001018', '2026-09-19 00:00:00', '2026-09-19 00:00:00');
8484
INSERT INTO `permission` VALUES ('1960000000000001029', '1346358560427216896', '1960000000000001019', '2026-09-19 00:00:00', '2026-09-19 00:00:00');
85-
INSERT INTO `namespace_plugin_rel` (`id`,`namespace_id`,`plugin_id`, `config`, `sort`, `enabled`, `date_created`, `date_updated`) VALUES ('1960000000000001030','649330b6-c2d7-4edc-be8e-8a54df9eb385','68', NULL, 169, 0, '2026-09-19 00:00:00.000', '2026-09-19 00:00:00.000');
85+
INSERT INTO `namespace_plugin_rel` (`id`,`namespace_id`,`plugin_id`, `config`, `sort`, `enabled`, `date_created`, `date_updated`) VALUES ('1960000000000001030','649330b6-c2d7-4edc-be8e-8a54df9eb385','68', NULL, 198, 0, '2026-09-19 00:00:00.000', '2026-09-19 00:00:00.000');
8686

8787
-- add index to speed up the meta data path uniqueness check
8888
ALTER TABLE `meta_data` ADD INDEX `idx_meta_data_namespace_path` (`namespace_id`, `path`) USING BTREE;

‎db/upgrade/2.7.1-upgrade-2.7.2-ob.sql‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ ALTER TABLE `resource` ADD INDEX `idx_resource_parent_id` (`parent_id`) USING BT
6262
ALTER TABLE `user_role` ADD INDEX `idx_user_role_user_id` (`user_id`) USING BTREE;
6363

6464
-- Agent Gateway: keep upgrade seeds consistent with the fresh-install schema.
65-
INSERT INTO `plugin` VALUES ('68', 'agentGateway', NULL, 'Ai', 169, 0, '2026-09-19 00:00:00', '2026-09-19 00:00:00', null);
65+
INSERT INTO `plugin` VALUES ('68', 'agentGateway', NULL, 'Ai', 198, 0, '2026-09-19 00:00:00', '2026-09-19 00:00:00', null);
6666
INSERT INTO `plugin_handle` VALUES ('1960000000000001000', '68', 'trafficType', 'trafficType', 2, 2, 0, '{"required":"1","defaultValue":"LLM","rule":""}', '2026-09-19 00:00:00', '2026-09-19 00:00:00');
6767
INSERT INTO `plugin_handle` VALUES ('1960000000000001001', '68', 'responseRequestId', 'responseRequestId', 3, 2, 1, '{"required":"0","defaultValue":"false","rule":""}', '2026-09-19 00:00:00', '2026-09-19 00:00:00');
6868
INSERT INTO `resource` VALUES ('1960000000000001010', '1346775491550474240', 'agentGateway', 'agentGateway', '/plug/agentGateway', 'agentGateway', 1, 0, 'pic-center', 0, 0, '', 1, '2026-09-19 00:00:00', '2026-09-19 00:00:00');
@@ -85,7 +85,7 @@ INSERT INTO `permission` VALUES ('1960000000000001026', '1346358560427216896', '
8585
INSERT INTO `permission` VALUES ('1960000000000001027', '1346358560427216896', '1960000000000001017', '2026-09-19 00:00:00', '2026-09-19 00:00:00');
8686
INSERT INTO `permission` VALUES ('1960000000000001028', '1346358560427216896', '1960000000000001018', '2026-09-19 00:00:00', '2026-09-19 00:00:00');
8787
INSERT INTO `permission` VALUES ('1960000000000001029', '1346358560427216896', '1960000000000001019', '2026-09-19 00:00:00', '2026-09-19 00:00:00');
88-
INSERT INTO `namespace_plugin_rel` (`id`,`namespace_id`,`plugin_id`, `config`, `sort`, `enabled`, `date_created`, `date_updated`) VALUES ('1960000000000001030','649330b6-c2d7-4edc-be8e-8a54df9eb385','68', NULL, 169, 0, '2026-09-19 00:00:00.000', '2026-09-19 00:00:00.000');
88+
INSERT INTO `namespace_plugin_rel` (`id`,`namespace_id`,`plugin_id`, `config`, `sort`, `enabled`, `date_created`, `date_updated`) VALUES ('1960000000000001030','649330b6-c2d7-4edc-be8e-8a54df9eb385','68', NULL, 198, 0, '2026-09-19 00:00:00.000', '2026-09-19 00:00:00.000');
8989
-- add index to speed up the meta data path uniqueness check
9090
ALTER TABLE `meta_data` ADD INDEX `idx_meta_data_namespace_path` (`namespace_id`, `path`) USING BTREE;
9191
ALTER TABLE `operation_record_log` ADD INDEX `idx_operation_log_time` (`operation_time`) USING BTREE;

‎db/upgrade/2.7.1-upgrade-2.7.2-og.sql‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ CREATE INDEX IF NOT EXISTS "idx_resource_parent_id" ON "public"."resource" USING
6262
CREATE INDEX IF NOT EXISTS "idx_user_role_user_id" ON "public"."user_role" USING btree ("user_id");
6363

6464
-- Agent Gateway: keep upgrade seeds consistent with the fresh-install schema.
65-
INSERT INTO "public"."plugin" VALUES ('68', 'agentGateway', NULL, 'Ai', 169, 0, '2026-09-19 00:00:00', '2026-09-19 00:00:00', NULL);
65+
INSERT INTO "public"."plugin" VALUES ('68', 'agentGateway', NULL, 'Ai', 198, 0, '2026-09-19 00:00:00', '2026-09-19 00:00:00', NULL);
6666
INSERT INTO "public"."plugin_handle" VALUES ('1960000000000001000', '68', 'trafficType', 'trafficType', 2, 2, 0, '{"required":"1","defaultValue":"LLM","rule":""}', '2026-09-19 00:00:00', '2026-09-19 00:00:00');
6767
INSERT INTO "public"."plugin_handle" VALUES ('1960000000000001001', '68', 'responseRequestId', 'responseRequestId', 3, 2, 1, '{"required":"0","defaultValue":"false","rule":""}', '2026-09-19 00:00:00', '2026-09-19 00:00:00');
6868
INSERT INTO "public"."resource" VALUES ('1960000000000001010', '1346775491550474240', 'agentGateway', 'agentGateway', '/plug/agentGateway', 'agentGateway', 1, 0, 'pic-center', 0, 0, '', 1, '2026-09-19 00:00:00', '2026-09-19 00:00:00');
@@ -85,7 +85,7 @@ INSERT INTO "public"."permission" VALUES ('1960000000000001026', '13463585604272
8585
INSERT INTO "public"."permission" VALUES ('1960000000000001027', '1346358560427216896', '1960000000000001017', '2026-09-19 00:00:00', '2026-09-19 00:00:00');
8686
INSERT INTO "public"."permission" VALUES ('1960000000000001028', '1346358560427216896', '1960000000000001018', '2026-09-19 00:00:00', '2026-09-19 00:00:00');
8787
INSERT INTO "public"."permission" VALUES ('1960000000000001029', '1346358560427216896', '1960000000000001019', '2026-09-19 00:00:00', '2026-09-19 00:00:00');
88-
INSERT INTO "public"."namespace_plugin_rel" VALUES ('1960000000000001030','649330b6-c2d7-4edc-be8e-8a54df9eb385','68', NULL, 169, 0, '2026-09-19 00:00:00.000', '2026-09-19 00:00:00.000');
88+
INSERT INTO "public"."namespace_plugin_rel" VALUES ('1960000000000001030','649330b6-c2d7-4edc-be8e-8a54df9eb385','68', NULL, 198, 0, '2026-09-19 00:00:00.000', '2026-09-19 00:00:00.000');
8989
-- add index to speed up the meta data path uniqueness check
9090
CREATE INDEX "idx_meta_data_namespace_path" ON "public"."meta_data" USING btree ("namespace_id","path");
9191
CREATE INDEX "idx_operation_log_time" ON "public"."operation_record_log" USING btree ("operation_time");

‎db/upgrade/2.7.1-upgrade-2.7.2-oracle.sql‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ create index idx_user_role_user_id on user_role (user_id);
6363

6464
-- Agent Gateway: keep upgrade seeds consistent with the fresh-install schema.
6565
INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin(id)) */ INTO plugin (id, name, config, role, sort, enabled, date_created, date_updated)
66-
VALUES ('68', 'agentGateway', NULL, 'Ai', 169, 0, sysdate, sysdate);
66+
VALUES ('68', 'agentGateway', NULL, 'Ai', 198, 0, sysdate, sysdate);
6767
INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin_handle(id)) */ INTO plugin_handle (id, plugin_id, field, label, data_type, type, sort, ext_obj, date_created, date_updated)
6868
VALUES ('1960000000000001000', '68', 'trafficType', 'trafficType', 2, 2, 0, '{"required":"1","defaultValue":"LLM","rule":""}', sysdate, sysdate);
6969
INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin_handle(id)) */ INTO plugin_handle (id, plugin_id, field, label, data_type, type, sort, ext_obj, date_created, date_updated)
@@ -99,7 +99,7 @@ INSERT INTO permission (id, object_id, resource_id, date_created, date_updated)
9999
INSERT INTO permission (id, object_id, resource_id, date_created, date_updated) VALUES ('1960000000000001028', '1346358560427216896', '1960000000000001018', sysdate, sysdate);
100100
INSERT INTO permission (id, object_id, resource_id, date_created, date_updated) VALUES ('1960000000000001029', '1346358560427216896', '1960000000000001019', sysdate, sysdate);
101101
INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (namespace_plugin_rel(id)) */ INTO namespace_plugin_rel (id,namespace_id,plugin_id, config, sort, enabled)
102-
VALUES ('1960000000000001030','649330b6-c2d7-4edc-be8e-8a54df9eb385','68', NULL, 169, 0);
102+
VALUES ('1960000000000001030','649330b6-c2d7-4edc-be8e-8a54df9eb385','68', NULL, 198, 0);
103103
-- add index to speed up the meta data path uniqueness check
104104
create index idx_meta_data_namespace_path on meta_data (namespace_id, path);
105105
create index idx_operation_log_time on operation_record_log (operation_time);

‎db/upgrade/2.7.1-upgrade-2.7.2-pg.sql‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ CREATE INDEX IF NOT EXISTS "idx_resource_parent_id" ON "public"."resource" USING
6262
CREATE INDEX IF NOT EXISTS "idx_user_role_user_id" ON "public"."user_role" USING btree ("user_id");
6363

6464
-- Agent Gateway: keep upgrade seeds consistent with the fresh-install schema.
65-
INSERT INTO "public"."plugin" VALUES ('68', 'agentGateway', NULL, 'Ai', 169, 0, '2026-09-19 00:00:00', '2026-09-19 00:00:00', NULL);
65+
INSERT INTO "public"."plugin" VALUES ('68', 'agentGateway', NULL, 'Ai', 198, 0, '2026-09-19 00:00:00', '2026-09-19 00:00:00', NULL);
6666
INSERT INTO "public"."plugin_handle" VALUES ('1960000000000001000', '68', 'trafficType', 'trafficType', 2, 2, 0, '{"required":"1","defaultValue":"LLM","rule":""}', '2026-09-19 00:00:00', '2026-09-19 00:00:00');
6767
INSERT INTO "public"."plugin_handle" VALUES ('1960000000000001001', '68', 'responseRequestId', 'responseRequestId', 3, 2, 1, '{"required":"0","defaultValue":"false","rule":""}', '2026-09-19 00:00:00', '2026-09-19 00:00:00');
6868
INSERT INTO "public"."resource" VALUES ('1960000000000001010', '1346775491550474240', 'agentGateway', 'agentGateway', '/plug/agentGateway', 'agentGateway', 1, 0, 'pic-center', 0, 0, '', 1, '2026-09-19 00:00:00', '2026-09-19 00:00:00');
@@ -85,7 +85,7 @@ INSERT INTO "public"."permission" VALUES ('1960000000000001026', '13463585604272
8585
INSERT INTO "public"."permission" VALUES ('1960000000000001027', '1346358560427216896', '1960000000000001017', '2026-09-19 00:00:00', '2026-09-19 00:00:00');
8686
INSERT INTO "public"."permission" VALUES ('1960000000000001028', '1346358560427216896', '1960000000000001018', '2026-09-19 00:00:00', '2026-09-19 00:00:00');
8787
INSERT INTO "public"."permission" VALUES ('1960000000000001029', '1346358560427216896', '1960000000000001019', '2026-09-19 00:00:00', '2026-09-19 00:00:00');
88-
INSERT INTO "public"."namespace_plugin_rel" VALUES ('1960000000000001030','649330b6-c2d7-4edc-be8e-8a54df9eb385','68', NULL, 169, 0, '2026-09-19 00:00:00.000', '2026-09-19 00:00:00.000');
88+
INSERT INTO "public"."namespace_plugin_rel" VALUES ('1960000000000001030','649330b6-c2d7-4edc-be8e-8a54df9eb385','68', NULL, 198, 0, '2026-09-19 00:00:00.000', '2026-09-19 00:00:00.000');
8989
-- add index to speed up the meta data path uniqueness check
9090
CREATE INDEX "idx_meta_data_namespace_path" ON "public"."meta_data" USING btree ("namespace_id","path");
9191
CREATE INDEX "idx_operation_log_time" ON "public"."operation_record_log" USING btree ("operation_time");

‎db/upgrade/2.7.2-agent-gateway-order.sql‎

Lines changed: 0 additions & 35 deletions
This file was deleted.

‎db/upgrade/2.7.2-upgrade-2.7.3-h2.sql‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
ALTER TABLE selector RENAME COLUMN loged TO logged;
1919
ALTER TABLE rule RENAME COLUMN loged TO logged;
2020

21+
-- Move Agent Gateway ahead of the AI governance chain for existing installs.
22+
-- Preserve deliberate custom orders: only the old default sort value changes.
23+
UPDATE plugin SET sort = 169 WHERE name = 'agentGateway' AND sort = 198;
24+
UPDATE namespace_plugin_rel SET sort = 169
25+
WHERE sort = 198
26+
AND plugin_id IN (SELECT id FROM plugin WHERE name = 'agentGateway');
27+
2128
-- Stop all Admin writers and back up instance_info before this one-time migration.
2229
-- Retain the latest heartbeat, then latest update/create timestamp, then greatest id.
2330
-- Rows upgraded from 2.7.1 have heartbeat 0 and are ordered by timestamps and id.

‎db/upgrade/2.7.2-upgrade-2.7.3-mysql.sql‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
ALTER TABLE `selector` RENAME COLUMN `loged` TO `logged`;
1919
ALTER TABLE `rule` RENAME COLUMN `loged` TO `logged`;
2020

21+
-- Move Agent Gateway ahead of the AI governance chain for existing installs.
22+
-- Preserve deliberate custom orders: only the old default sort value changes.
23+
UPDATE `plugin` SET `sort` = 169 WHERE `name` = 'agentGateway' AND `sort` = 198;
24+
UPDATE `namespace_plugin_rel` SET `sort` = 169
25+
WHERE `sort` = 198
26+
AND `plugin_id` IN (SELECT `id` FROM `plugin` WHERE `name` = 'agentGateway');
27+
2128
-- Stop all Admin writers and back up instance_info before this one-time migration.
2229
-- Retain the latest heartbeat, then latest update/create timestamp, then greatest id.
2330
-- Rows upgraded from 2.7.1 have heartbeat 0 and are ordered by timestamps and id.

0 commit comments

Comments
 (0)