55import fire , meta , util
66isJSON = util .isJSON
77import re
8- import sqlite3 as _sqlite3
98
109MY_HOME = util .MY_HOME
1110
@@ -83,20 +82,8 @@ def update():
8382 """Update with a new list of available components."""
8483 run_cmd ("update" )
8584
86-
87-
88- # Match both "spock50" and "spock50-pg17" (and variants like spock5, spock5-pg16)
89- _SPOCK5_NAME_RE = re .compile (r"^spock5(?:0)?(?:-pg\d+)?$" , re .IGNORECASE )
90- _SPOCK5_VER_RE = re .compile (r"^5\." , re .IGNORECASE )
91- _SPOCK50_RE = re .compile (r"^spock50(?:-pg\d+)?$" , re .IGNORECASE )
92-
9385def install (component , active = True ):
9486 """Install a component."""
95-
96- # Trigger pre-check ONLY for Spock 5.0 artifacts
97- if _SPOCK50_RE .match (component ):
98- validate_spock_upgrade (component ) # should sys.exit(1) on failure; otherwise just returns
99-
10087 # Common path (no duplication)
10188 if active not in (True , False ):
10289 util .exit_message ("'active' parm must be True or False" )
@@ -105,8 +92,6 @@ def install(component, active=True):
10592 util .message (f"um.install({ cmd } { component } )" , "debug" )
10693 run_cmd (cmd , component )
10794
108-
109-
11095def remove (component ):
11196 """Uninstall a component."""
11297 installed_comp_list = meta .get_component_list ()
@@ -244,78 +229,6 @@ def verify_metadata(Project="", Stage="prod", IsCurrent=0):
244229
245230 meta .pretty_sql (sql )
246231
247- def validate_spock_upgrade (spock_component ):
248- """
249- Validate Spock↔PostgreSQL compatibility for an upcoming Spock 5 install.
250- """
251-
252- DB_PATH = "data/conf/db_local.db"
253-
254- SPOCK_SQL = """
255- SELECT version AS spock_ver, component AS spock_comp
256- FROM components
257- WHERE component LIKE 'spock%'
258- ORDER BY CASE
259- WHEN version LIKE '5.%' THEN 5
260- WHEN version LIKE '4.%' THEN 4
261- ELSE 0
262- END DESC,
263- version DESC
264- LIMIT 1;
265- """
266-
267- PG_SQL = """
268- SELECT version AS pg_ver
269- FROM components
270- WHERE component LIKE 'pg__'
271- ORDER BY CAST(substr(component, 3) AS INTEGER) DESC
272- LIMIT 1;
273- """
274-
275- try :
276- with _sqlite3 .connect (DB_PATH ) as conn :
277- sp_row = conn .execute (SPOCK_SQL ).fetchone ()
278- pg_row = conn .execute (PG_SQL ).fetchone ()
279- except _sqlite3 .Error as err :
280- sys .exit (f"ERROR: SQLite query failed: { err } " )
281-
282- if not pg_row :
283- sys .exit ("ERROR: No PostgreSQL version row found." )
284-
285- existing_pg_ver = pg_row [0 ]
286- existing_spock_ver , existing_spock_comp = (sp_row or (None , None ))
287-
288- # Already on Spock 5? No-op.
289- if existing_spock_ver and (
290- _SPOCK5_NAME_RE .match (existing_spock_comp ) or _SPOCK5_VER_RE .match (existing_spock_ver )
291- ):
292- return 0
293-
294- # Trim "spock" off the front to get the version (e.g., "spock50" -> "50")
295- requested_spock_ver = spock_component
296- if requested_spock_ver and requested_spock_ver .lower ().startswith ("spock" ):
297- requested_spock_ver = requested_spock_ver [5 :]
298-
299- # Downtime warning
300- banner = "=" * 80
301-
302- if existing_spock_ver :
303- # Case 2: Spock 4.x installed, this is a major upgrade
304- print (f"\n { banner } " )
305- print ("*** WARNING: This operation will cause downtime! ***" )
306- print (f"{ banner } \n " )
307- print (f"Detected existing Spock version { existing_spock_ver } on PostgreSQL { existing_pg_ver } " )
308-
309- try :
310- util .validate_spock_pg_compat (requested_spock_ver , existing_pg_ver )
311- except Exception as exc :
312- sys .exit (f"ERROR: Compatibility check failed: { exc } " )
313-
314- if existing_spock_ver :
315- print ("Compatibility check passed." )
316-
317- return 0
318-
319232if __name__ == "__main__" :
320233 fire .Fire (
321234 {
0 commit comments