3030JAR_HEX = "0001027fff"
3131DIALECTS = {
3232 "mysql" : ("mysql:8.0@sha256:7dcddc01f13bab2f15cde676d44d01f61fc9f99fe7785e86196dfc07d358ae2b" , "db/init/mysql/schema.sql" ),
33- "ob" : ("oceanbase/oceanbase-ce:4.3.5-lts@sha256:31086a6900c21c479c2bcd942b6a28c53b17a51f4e9b9eb8eafcc596adfcd2e3" , "db/init/ob /schema.sql" ),
33+ "ob" : ("oceanbase/oceanbase-ce:4.3.5-lts@sha256:31086a6900c21c479c2bcd942b6a28c53b17a51f4e9b9eb8eafcc596adfcd2e3" , "db/init/mysql /schema.sql" ),
3434 "pg" : ("postgres:15@sha256:724292da1f2e50bdccfc3302ce75bbba7f4a6076701b588cc795fcac65683550" , "db/init/pg/create-table.sql" ),
3535 "og" : ("enmotech/opengauss-lite:5.0.1@sha256:b0e9d4e7452007cb0a216e39f1927c889178dac695176af7ab0eec43ce077af3" , "db/init/og/create-table.sql" ),
3636 "oracle" : ("gvenzl/oracle-free:23.26.3-slim@sha256:6d61d267a3b978c24c5ac1790e62e927416a0aec446bd86e4b3a1527562757bd" , "db/init/oracle/schema.sql" ),
3939REQUIRED = {"selector" : "plugin_id" , "resource" : "parent_id" , "user_role" : "user_id" }
4040
4141
42+ def schema_source (dialect , flow ):
43+ # The released OceanBase baseline belongs to the historical upgrade flow.
44+ # Only fresh installations share the current MySQL initialization source.
45+ if dialect == "ob" and flow == "upgrade" :
46+ return "db/init/ob/schema.sql"
47+ return DIALECTS [dialect ][1 ]
48+
49+
4250def run (command , data = None , timeout = 180 ):
4351 result = subprocess .run (command , input = data , stdout = subprocess .PIPE , stderr = subprocess .STDOUT ,
4452 text = True , encoding = "utf-8" , errors = "replace" , timeout = timeout )
@@ -122,6 +130,10 @@ def start(self):
122130 "oracle" : ["ORACLE_PASSWORD=" + PASSWORD , "APP_USER=sqlmatrix" , "APP_USER_PASSWORD=" + PASSWORD ],
123131 }[self .dialect ]
124132 command = ["docker" , "run" , "-d" , "--name" , self .name , "--shm-size=1g" ]
133+ if self .dialect == "ob" :
134+ # OceanBase requires at least 20000 file descriptors. Docker daemon
135+ # defaults vary, so set the limit for this disposable container only.
136+ command += ["--ulimit" , "nofile=65536:65536" ]
125137 for variable in environment :
126138 command += ["-e" , variable ]
127139 run (command + [image ])
@@ -215,11 +227,74 @@ def indexes(self):
215227 (self .output / (self .name + ".indexes.txt" )).write_text (rows , encoding = "utf-8" )
216228 return verify_index_rows (rows , self .dialect in ("pg" , "og" ))
217229
230+ def check_fresh_mysql_schema (self , schema , indexes ):
231+ """Validate the shared fresh-install contract on MySQL and OceanBase."""
232+ tables = {name .lower () for name in re .findall (r"CREATE TABLE\s+(?:IF NOT EXISTS\s+)?`?(\w+)`?" , schema , re .I )}
233+ actual = set (self .sql ("SELECT table_name FROM information_schema.tables WHERE table_schema='shenyu';" ).lower ().split ())
234+ if actual != tables :
235+ raise AssertionError (f"Fresh tables differ: missing={ tables - actual } , extra={ actual - tables } " )
236+ for name , table , columns in re .findall (r"CREATE INDEX (\w+) ON `(\w+)` \(([^)]+)\)" , schema ):
237+ if indexes .get ((table , name )) != [column .strip () for column in columns .split ("," )]:
238+ raise AssertionError (f"Missing shared secondary index: { table } .{ name } " )
239+ unique = set (self .sql ("SELECT DISTINCT CONCAT(table_name,'|',index_name) FROM information_schema.statistics "
240+ "WHERE table_schema='shenyu' AND non_unique=0;" ).lower ().split ())
241+ for key in ("dashboard_user|unique_user_name" , "proxy_api_key_mapping|uk_selector_proxy_key" ,
242+ "plugin_handle|plugin_id_field_type" , "shenyu_dict|dict_type_dict_code_dict_name" ,
243+ "discovery_upstream|discovery_upstream_discovery_handler_id_IDX" ):
244+ if key .lower () not in unique :
245+ raise AssertionError ("Missing shared unique constraint: " + key )
246+
247+ checks = []
248+ for table , column , parent , parent_column in (
249+ ("plugin_handle" , "plugin_id" , "plugin" , "id" ),
250+ ("permission" , "resource_id" , "resource" , "id" ),
251+ ("permission" , "object_id" , "role" , "id" ),
252+ ("user_role" , "user_id" , "dashboard_user" , "id" ),
253+ ("user_role" , "role_id" , "role" , "id" ),
254+ ("namespace_plugin_rel" , "plugin_id" , "plugin" , "id" ),
255+ ("namespace_plugin_rel" , "namespace_id" , "namespace" , "namespace_id" ),
256+ ("namespace_user_rel" , "namespace_id" , "namespace" , "namespace_id" ),
257+ ("namespace_user_rel" , "user_id" , "dashboard_user" , "id" ),
258+ ("selector" , "plugin_id" , "plugin" , "id" ),
259+ ("selector" , "namespace_id" , "namespace" , "namespace_id" ),
260+ ("rule" , "selector_id" , "selector" , "id" ),
261+ ("rule" , "namespace_id" , "namespace" , "namespace_id" )):
262+ # Some legacy tables use different collations. Compare identifier bytes
263+ # so validation does not depend on either engine's default collation.
264+ checks .append ((f"{ table } .{ column } orphan" , f"SELECT child.id FROM { table } child LEFT JOIN { parent } parent "
265+ f"ON BINARY child.{ column } =BINARY parent.{ parent_column } WHERE parent.{ parent_column } IS NULL" ))
266+ checks .append (("resource.parent_id orphan" , "SELECT child.id FROM resource child LEFT JOIN resource parent "
267+ "ON BINARY child.parent_id=BINARY parent.id WHERE child.parent_id NOT IN ('', '0') AND parent.id IS NULL" ))
268+ for table , columns in (("plugin_handle" , "plugin_id,field,type" ),
269+ ("permission" , "object_id,resource_id" ),
270+ ("namespace_plugin_rel" , "namespace_id,plugin_id" )):
271+ checks .append ((table + " duplicate natural key" ,
272+ f"SELECT { columns } FROM { table } GROUP BY { columns } HAVING COUNT(*)>1" ))
273+ checks .append (("missing admin resource permission" , "SELECT r.id FROM resource r LEFT JOIN permission p "
274+ "ON BINARY p.resource_id=BINARY r.id AND p.object_id='1346358560427216896' WHERE p.id IS NULL" ))
275+ checks .append (("missing default namespace plugin" , "SELECT p.id FROM plugin p LEFT JOIN namespace_plugin_rel r "
276+ "ON BINARY r.plugin_id=BINARY p.id AND r.namespace_id='649330b6-c2d7-4edc-be8e-8a54df9eb385' "
277+ f"WHERE p.id<>'{ SENTINEL } ' AND r.id IS NULL" ))
278+ for label , query in checks :
279+ if scalar (self .sql ("SELECT COUNT(*) FROM (" + query + ") violations;" )) != "0" :
280+ raise AssertionError ("Invalid fresh seed: " + label )
281+ if scalar (self .sql ("SELECT COUNT(*) FROM namespace WHERE namespace_id='649330b6-c2d7-4edc-be8e-8a54df9eb385' "
282+ "AND name='default';" )) != "1" :
283+ raise AssertionError ("Missing default namespace" )
284+ for plugin_id in ("33" , "50" ):
285+ config = json .loads (scalar (self .sql (f"SELECT config FROM plugin WHERE id='{ plugin_id } ';" )))
286+ namespace_config = json .loads (scalar (self .sql ("SELECT config FROM namespace_plugin_rel "
287+ f"WHERE plugin_id='{ plugin_id } ' AND "
288+ "namespace_id='649330b6-c2d7-4edc-be8e-8a54df9eb385';" )))
289+ if config != namespace_config :
290+ raise AssertionError ("Default namespace config differs for plugin " + plugin_id )
291+ if plugin_id == "33" and config .get ("bootstrapServer" ) != "localhost:9092" :
292+ raise AssertionError ("loggingKafka must seed bootstrapServer" )
293+
218294
219295def execute_matrix (dialect , root , output ):
220296 output .mkdir (parents = True , exist_ok = True )
221297 listing , detail = fragment_columns (root / "shenyu-admin/src/main/resources/mappers/plugin-sqlmap.xml" )
222- _ , schema_path = DIALECTS [dialect ]
223298 results = {"dialect" : dialect , "baseline" : BASELINE , "image" : DIALECTS [dialect ][0 ], "flows" : []}
224299 for flow in ("upgrade" , "fresh" ):
225300 engine = Engine (dialect , flow , output )
@@ -228,6 +303,7 @@ def execute_matrix(dialect, root, output):
228303 results ["flows" ].append (report )
229304 try :
230305 engine .start ()
306+ schema_path = schema_source (dialect , flow )
231307 schema = (run (["git" , "show" , f"{ BASELINE } :{ schema_path } " ]) if flow == "upgrade"
232308 else (root / schema_path ).read_text (encoding = "utf-8" ))
233309 engine .sql (schema , database = False )
@@ -245,7 +321,9 @@ def execute_matrix(dialect, root, output):
245321 after = set (engine .sql ("SELECT id FROM " + engine .table (table ) + ";" ).split ())
246322 if not identifiers .issubset (after ):
247323 raise AssertionError (f"Migration removed rows from { table } : { sorted (identifiers - after )} " )
248- engine .indexes ()
324+ indexes = engine .indexes ()
325+ if flow == "fresh" and dialect in ("mysql" , "ob" ):
326+ engine .check_fresh_mysql_schema (schema , indexes )
249327 report ["status" ] = "success"
250328 print (f"{ dialect } : { flow } SQL, projections, JAR preservation and index metadata passed" , flush = True )
251329 except Exception as error :
0 commit comments